Path: blob/main/contrib/llvm-project/compiler-rt/lib/xray/xray_s390x.cpp
213766 views
//===-- xray_s390x.cpp ------------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of XRay, a dynamic runtime instrumentation system.9//10// Implementation of s390x routines.11//12//===----------------------------------------------------------------------===//13#include "sanitizer_common/sanitizer_common.h"14#include "xray_defs.h"15#include "xray_interface_internal.h"16#include <cassert>17#include <cstring>1819bool __xray::patchFunctionEntry(const bool Enable, const uint32_t FuncId,20const XRaySledEntry &Sled,21const XRayTrampolines &Trampolines,22bool LogArgs) XRAY_NEVER_INSTRUMENT {23uint32_t *Address = reinterpret_cast<uint32_t *>(Sled.address());24// TODO: Trampoline addresses are currently inserted at compile-time, using25// __xray_FunctionEntry and __xray_FunctionExit only.26// To support DSO instrumentation, trampolines have to be written during27// patching (see implementation on X86_64, e.g.).28if (Enable) {29// The resulting code is:30// stmg %r2, %r15, 16(%r15)31// llilf %2, FuncID32// brasl %r14, __xray_FunctionEntry@GOT33// The FuncId and the stmg instruction must be written.3435// Write FuncId into llilf.36Address[2] = FuncId;37// Write last part of stmg.38reinterpret_cast<uint16_t *>(Address)[2] = 0x24;39// Write first part of stmg.40Address[0] = 0xeb2ff010;41} else {42// j +16 instructions.43Address[0] = 0xa7f4000b;44}45return true;46}4748bool __xray::patchFunctionExit(49const bool Enable, const uint32_t FuncId, const XRaySledEntry &Sled,50const XRayTrampolines &Trampolines) XRAY_NEVER_INSTRUMENT {51uint32_t *Address = reinterpret_cast<uint32_t *>(Sled.address());52// TODO: Trampoline addresses are currently inserted at compile-time, using53// __xray_FunctionEntry and __xray_FunctionExit only.54// To support DSO instrumentation, trampolines have to be written during55// patching (see implementation on X86_64, e.g.).56if (Enable) {57// The resulting code is:58// stmg %r2, %r15, 24(%r15)59// llilf %2,FuncID60// j __xray_FunctionEntry@GOT61// The FuncId and the stmg instruction must be written.6263// Write FuncId into llilf.64Address[2] = FuncId;65// Write last part of of stmg.66reinterpret_cast<uint16_t *>(Address)[2] = 0x24;67// Write first part of stmg.68Address[0] = 0xeb2ff010;69} else {70// br %14 instruction.71reinterpret_cast<uint16_t *>(Address)[0] = 0x07fe;72}73return true;74}7576bool __xray::patchFunctionTailExit(77const bool Enable, const uint32_t FuncId, const XRaySledEntry &Sled,78const XRayTrampolines &Trampolines) XRAY_NEVER_INSTRUMENT {79return patchFunctionExit(Enable, FuncId, Sled, Trampolines);80}8182bool __xray::patchCustomEvent(const bool Enable, const uint32_t FuncId,83const XRaySledEntry &Sled) XRAY_NEVER_INSTRUMENT {84// TODO Implement.85return false;86}8788bool __xray::patchTypedEvent(const bool Enable, const uint32_t FuncId,89const XRaySledEntry &Sled) XRAY_NEVER_INSTRUMENT {90// TODO Implement.91return false;92}9394extern "C" void __xray_ArgLoggerEntry() XRAY_NEVER_INSTRUMENT {95// TODO this will have to be implemented in the trampoline assembly file.96}9798extern "C" void __xray_FunctionTailExit() XRAY_NEVER_INSTRUMENT {99// For PowerPC, calls to __xray_FunctionEntry and __xray_FunctionExit100// are statically inserted into the sled. Tail exits are handled like normal101// function exits. This trampoline is therefore not implemented.102// This stub is placed here to avoid linking issues.103}104105106