#include "xray_interface_internal.h"
#include <cinttypes>
#include <cstdio>
#include <errno.h>
#include <limits>
#include <string.h>
#include <sys/mman.h>
#if SANITIZER_FUCHSIA
#include <zircon/process.h>
#include <zircon/sanitizer.h>
#include <zircon/status.h>
#include <zircon/syscalls.h>
#endif
#include "sanitizer_common/sanitizer_addrhashmap.h"
#include "sanitizer_common/sanitizer_common.h"
#include "xray_defs.h"
#include "xray_flags.h"
extern __sanitizer::SpinMutex XRayInstrMapMutex;
extern __sanitizer::atomic_uint8_t XRayInitialized;
extern __xray::XRaySledMap XRayInstrMap;
namespace __xray {
#if defined(__x86_64__)
static const int16_t cSledLength = …;
#elif defined(__aarch64__)
static const int16_t cSledLength = 32;
#elif defined(__arm__)
static const int16_t cSledLength = 28;
#elif SANITIZER_LOONGARCH64
static const int16_t cSledLength = 48;
#elif SANITIZER_MIPS32
static const int16_t cSledLength = 48;
#elif SANITIZER_MIPS64
static const int16_t cSledLength = 64;
#elif defined(__powerpc64__)
static const int16_t cSledLength = 8;
#elif defined(__hexagon__)
static const int16_t cSledLength = 20;
#else
#error "Unsupported CPU Architecture"
#endif
atomic_uintptr_t XRayPatchedFunction{ … };
atomic_uintptr_t XRayArgLogger{ … };
atomic_uintptr_t XRayPatchedCustomEvent{ … };
atomic_uintptr_t XRayPatchedTypedEvent{ … };
atomic_uint8_t XRayPatching{ … };
struct TypeDescription { … };
TypeDescriptorMapType;
TypeDescriptorMapType TypeDescriptorAddressMap{ … };
atomic_uint32_t TypeEventDescriptorCounter{ … };
class MProtectHelper { … };
namespace {
bool patchSled(const XRaySledEntry &Sled, bool Enable,
int32_t FuncId) XRAY_NEVER_INSTRUMENT { … }
const XRayFunctionSledIndex
findFunctionSleds(int32_t FuncId,
const XRaySledMap &InstrMap) XRAY_NEVER_INSTRUMENT { … }
XRayPatchingStatus patchFunction(int32_t FuncId,
bool Enable) XRAY_NEVER_INSTRUMENT { … }
XRayPatchingStatus controlPatching(bool Enable) XRAY_NEVER_INSTRUMENT { … }
XRayPatchingStatus mprotectAndPatchFunction(int32_t FuncId,
bool Enable) XRAY_NEVER_INSTRUMENT { … }
}
}
usingnamespace__xray;
int __xray_set_handler(void (*entry)(int32_t,
XRayEntryType)) XRAY_NEVER_INSTRUMENT { … }
int __xray_set_customevent_handler(void (*entry)(void *, size_t))
XRAY_NEVER_INSTRUMENT { … }
int __xray_set_typedevent_handler(void (*entry)(size_t, const void *,
size_t)) XRAY_NEVER_INSTRUMENT { … }
int __xray_remove_handler() XRAY_NEVER_INSTRUMENT { … }
int __xray_remove_customevent_handler() XRAY_NEVER_INSTRUMENT { … }
int __xray_remove_typedevent_handler() XRAY_NEVER_INSTRUMENT { … }
uint16_t __xray_register_event_type(
const char *const event_type) XRAY_NEVER_INSTRUMENT { … }
XRayPatchingStatus __xray_patch() XRAY_NEVER_INSTRUMENT { … }
XRayPatchingStatus __xray_unpatch() XRAY_NEVER_INSTRUMENT { … }
XRayPatchingStatus __xray_patch_function(int32_t FuncId) XRAY_NEVER_INSTRUMENT { … }
XRayPatchingStatus
__xray_unpatch_function(int32_t FuncId) XRAY_NEVER_INSTRUMENT { … }
int __xray_set_handler_arg1(void (*entry)(int32_t, XRayEntryType, uint64_t)) { … }
int __xray_remove_handler_arg1() { … }
uintptr_t __xray_function_address(int32_t FuncId) XRAY_NEVER_INSTRUMENT { … }
size_t __xray_max_function_id() XRAY_NEVER_INSTRUMENT { … }