// Implementation of ARM-specific routines (32-bit).
//
//===----------------------------------------------------------------------===//
-#include "xray_interface_internal.h"
#include "sanitizer_common/sanitizer_common.h"
+#include "xray_interface_internal.h"
#include <atomic>
#include <cassert>
namespace __xray {
// The machine codes for some instructions used in runtime patching.
-enum class PatchOpcodes : uint32_t
-{
+enum class PatchOpcodes : uint32_t {
PO_PushR0Lr = 0xE92D4001, // PUSH {r0, lr}
- PO_BlxIp = 0xE12FFF3C, // BLX ip
- PO_PopR0Lr = 0xE8BD4001, // POP {r0, lr}
- PO_B20 = 0xEA000005 // B #20
+ PO_BlxIp = 0xE12FFF3C, // BLX ip
+ PO_PopR0Lr = 0xE8BD4001, // POP {r0, lr}
+ PO_B20 = 0xEA000005 // B #20
};
// 0xUUUUWXYZ -> 0x000W0XYZ
// Writes the following instructions:
// MOVW R<regNo>, #<lower 16 bits of the |Value|>
// MOVT R<regNo>, #<higher 16 bits of the |Value|>
-inline static uint32_t* write32bitLoadReg(uint8_t regNo, uint32_t* Address,
- const uint32_t Value) {
- //This is a fatal error: we cannot just report it and continue execution.
+inline static uint32_t *write32bitLoadReg(uint8_t regNo, uint32_t *Address,
+ const uint32_t Value) {
+ // This is a fatal error: we cannot just report it and continue execution.
assert(regNo <= 15 && "Register number must be 0 to 15.");
// MOVW R, #0xWXYZ in machine code is 0xE30WRXYZ
- *Address = (0xE3000000 | (uint32_t(regNo)<<12) | getMovwMask(Value));
+ *Address = (0xE3000000 | (uint32_t(regNo) << 12) | getMovwMask(Value));
Address++;
// MOVT R, #0xWXYZ in machine code is 0xE34WRXYZ
- *Address = (0xE3400000 | (uint32_t(regNo)<<12) | getMovtMask(Value));
+ *Address = (0xE3400000 | (uint32_t(regNo) << 12) | getMovtMask(Value));
return Address + 1;
}
#include <unistd.h>
#if defined(__x86_64__)
- #include <x86intrin.h>
+#include <x86intrin.h>
#elif defined(__arm__)
- static const int64_t NanosecondsPerSecond = 1000LL*1000*1000;
+static const int64_t NanosecondsPerSecond = 1000LL * 1000 * 1000;
#else
- #error "Unsupported CPU Architecture"
+#error "Unsupported CPU Architecture"
#endif /* CPU architecture */
#include "sanitizer_common/sanitizer_libc.h"
// one TSC tick is 1 nanosecond.
CPUFrequency = NanosecondsPerSecond;
#else
- #error "Unsupported CPU Architecture"
+#error "Unsupported CPU Architecture"
#endif /* CPU architecture */
// Since we're here, we get to write the header. We set it up so that the
{
timespec TS;
int result = clock_gettime(CLOCK_REALTIME, &TS);
- if(result != 0)
- {
+ if (result != 0) {
Report("clock_gettime() returned %d, errno=%d.", result, int(errno));
TS.tv_sec = 0;
TS.tv_nsec = 0;
R.CPU = 0;
}
#else
- #error "Unsupported CPU Architecture"
+#error "Unsupported CPU Architecture"
#endif /* CPU architecture */
R.TId = TId;
R.Type = Type;
namespace __xray {
#if defined(__x86_64__)
- // FIXME: The actual length is 11 bytes. Why was length 12 passed to mprotect() ?
- static const int16_t cSledLength = 12;
+// FIXME: The actual length is 11 bytes. Why was length 12 passed to mprotect()
+// ?
+static const int16_t cSledLength = 12;
#elif defined(__arm__)
- static const int16_t cSledLength = 28;
+static const int16_t cSledLength = 28;
#else
- #error "Unsupported CPU Architecture"
+#error "Unsupported CPU Architecture"
#endif /* CPU architecture */
// This is the function to call when we encounter the entry or exit sleds.
return XRayPatchingStatus::NOT_INITIALIZED;
const uint64_t PageSize = GetPageSizeCached();
- if((PageSize == 0) || ( (PageSize & (PageSize-1)) != 0) ) {
+ if ((PageSize == 0) || ((PageSize & (PageSize - 1)) != 0)) {
Report("System page size is not a power of two: %lld", PageSize);
return XRayPatchingStatus::FAILED;
}
// While we're here, we should patch the nop sled. To do that we mprotect
// the page containing the function to be writeable.
void *PageAlignedAddr =
- reinterpret_cast<void *>(Sled.Address & ~(PageSize-1));
- std::size_t MProtectLen =
- (Sled.Address + cSledLength) - reinterpret_cast<uint64_t>(PageAlignedAddr);
+ reinterpret_cast<void *>(Sled.Address & ~(PageSize - 1));
+ std::size_t MProtectLen = (Sled.Address + cSledLength) -
+ reinterpret_cast<uint64_t>(PageAlignedAddr);
MProtectHelper Protector(PageAlignedAddr, MProtectLen);
if (Protector.MakeWriteable() == -1) {
printf("Failed mprotect: %d\n", errno);
}
bool Success = false;
- switch(Sled.Kind) {
+ switch (Sled.Kind) {
case XRayEntryType::ENTRY:
Success = patchFunctionEntry(Enable, FuncId, Sled);
break;
#ifndef XRAY_INTERFACE_INTERNAL_H
#define XRAY_INTERFACE_INTERNAL_H
-#include "xray/xray_interface.h"
#include "sanitizer_common/sanitizer_platform.h"
+#include "xray/xray_interface.h"
#include <cstddef>
#include <cstdint>
unsigned char AlwaysInstrument;
unsigned char Padding[6]; // Need 16 bytes
#else
- #error "Unsupported word size."
+#error "Unsupported word size."
#endif
};
-
}
namespace __xray {
size_t Entries;
};
-bool patchFunctionEntry(const bool Enable, const uint32_t FuncId, const XRaySledEntry& Sled);
-bool patchFunctionExit(const bool Enable, const uint32_t FuncId, const XRaySledEntry& Sled);
+bool patchFunctionEntry(const bool Enable, const uint32_t FuncId,
+ const XRaySledEntry &Sled);
+bool patchFunctionExit(const bool Enable, const uint32_t FuncId,
+ const XRaySledEntry &Sled);
} // namespace __xray
-#include "xray_interface_internal.h"
#include "sanitizer_common/sanitizer_common.h"
+#include "xray_interface_internal.h"
#include <atomic>
#include <cstdint>
#include <limits>
static constexpr int64_t MinOffset{std::numeric_limits<int32_t>::min()};
static constexpr int64_t MaxOffset{std::numeric_limits<int32_t>::max()};
-bool patchFunctionEntry(const bool Enable, const uint32_t FuncId, const XRaySledEntry& Sled)
-{
+bool patchFunctionEntry(const bool Enable, const uint32_t FuncId,
+ const XRaySledEntry &Sled) {
// Here we do the dance of replacing the following sled:
//
// xray_sled_n:
//
// Prerequisite is to compute the relative offset to the
// __xray_FunctionEntry function's address.
- int64_t TrampolineOffset =
- reinterpret_cast<int64_t>(__xray_FunctionEntry) -
- (static_cast<int64_t>(Sled.Address) + 11);
+ int64_t TrampolineOffset = reinterpret_cast<int64_t>(__xray_FunctionEntry) -
+ (static_cast<int64_t>(Sled.Address) + 11);
if (TrampolineOffset < MinOffset || TrampolineOffset > MaxOffset) {
Report("XRay Entry trampoline (%p) too far from sled (%p); distance = "
"%ld\n",
return true;
}
-bool patchFunctionExit(const bool Enable, const uint32_t FuncId, const XRaySledEntry& Sled)
-{
+bool patchFunctionExit(const bool Enable, const uint32_t FuncId,
+ const XRaySledEntry &Sled) {
// Here we do the dance of replacing the following sled:
//
// xray_sled_n:
//
// Prerequisite is to compute the relative offset fo the
// __xray_FunctionExit function's address.
- int64_t TrampolineOffset =
- reinterpret_cast<int64_t>(__xray_FunctionExit) -
- (static_cast<int64_t>(Sled.Address) + 11);
+ int64_t TrampolineOffset = reinterpret_cast<int64_t>(__xray_FunctionExit) -
+ (static_cast<int64_t>(Sled.Address) + 11);
if (TrampolineOffset < MinOffset || TrampolineOffset > MaxOffset) {
Report("XRay Exit trampoline (%p) too far from sled (%p); distance = "
"%ld\n",