From: Dean Michael Berris Date: Thu, 6 Oct 2016 07:09:40 +0000 (+0000) Subject: [compiler-rt][XRay][NFC] clang-format XRay sources X-Git-Tag: llvmorg-4.0.0-rc1~7950 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4ef1a69b405a9017599a5dab5e10089b572de988;p=platform%2Fupstream%2Fllvm.git [compiler-rt][XRay][NFC] clang-format XRay sources llvm-svn: 283421 --- diff --git a/compiler-rt/lib/xray/xray_arm.cc b/compiler-rt/lib/xray/xray_arm.cc index 00150f6..d1b953e 100644 --- a/compiler-rt/lib/xray/xray_arm.cc +++ b/compiler-rt/lib/xray/xray_arm.cc @@ -12,20 +12,19 @@ // Implementation of ARM-specific routines (32-bit). // //===----------------------------------------------------------------------===// -#include "xray_interface_internal.h" #include "sanitizer_common/sanitizer_common.h" +#include "xray_interface_internal.h" #include #include 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 @@ -41,15 +40,15 @@ inline static uint32_t getMovtMask(const uint32_t Value) { // Writes the following instructions: // MOVW R, # // MOVT R, # -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; } diff --git a/compiler-rt/lib/xray/xray_inmemory_log.cc b/compiler-rt/lib/xray/xray_inmemory_log.cc index 286ba71..8495892 100644 --- a/compiler-rt/lib/xray/xray_inmemory_log.cc +++ b/compiler-rt/lib/xray/xray_inmemory_log.cc @@ -26,11 +26,11 @@ #include #if defined(__x86_64__) - #include +#include #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" @@ -197,7 +197,7 @@ void __xray_InMemoryRawLog(int32_t FuncId, XRayEntryType Type) { // 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 @@ -237,8 +237,7 @@ void __xray_InMemoryRawLog(int32_t FuncId, XRayEntryType Type) { { 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; @@ -247,7 +246,7 @@ void __xray_InMemoryRawLog(int32_t FuncId, XRayEntryType Type) { R.CPU = 0; } #else - #error "Unsupported CPU Architecture" +#error "Unsupported CPU Architecture" #endif /* CPU architecture */ R.TId = TId; R.Type = Type; diff --git a/compiler-rt/lib/xray/xray_interface.cc b/compiler-rt/lib/xray/xray_interface.cc index 360a6ad..ec393b9 100644 --- a/compiler-rt/lib/xray/xray_interface.cc +++ b/compiler-rt/lib/xray/xray_interface.cc @@ -27,12 +27,13 @@ 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. @@ -136,7 +137,7 @@ XRayPatchingStatus ControlPatching(bool Enable) { 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; } @@ -156,9 +157,9 @@ XRayPatchingStatus ControlPatching(bool Enable) { // 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(Sled.Address & ~(PageSize-1)); - std::size_t MProtectLen = - (Sled.Address + cSledLength) - reinterpret_cast(PageAlignedAddr); + reinterpret_cast(Sled.Address & ~(PageSize - 1)); + std::size_t MProtectLen = (Sled.Address + cSledLength) - + reinterpret_cast(PageAlignedAddr); MProtectHelper Protector(PageAlignedAddr, MProtectLen); if (Protector.MakeWriteable() == -1) { printf("Failed mprotect: %d\n", errno); @@ -166,7 +167,7 @@ XRayPatchingStatus ControlPatching(bool Enable) { } bool Success = false; - switch(Sled.Kind) { + switch (Sled.Kind) { case XRayEntryType::ENTRY: Success = patchFunctionEntry(Enable, FuncId, Sled); break; diff --git a/compiler-rt/lib/xray/xray_interface_internal.h b/compiler-rt/lib/xray/xray_interface_internal.h index 3465b67..fe58f8a 100644 --- a/compiler-rt/lib/xray/xray_interface_internal.h +++ b/compiler-rt/lib/xray/xray_interface_internal.h @@ -15,8 +15,8 @@ #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 #include @@ -36,10 +36,9 @@ struct XRaySledEntry { unsigned char AlwaysInstrument; unsigned char Padding[6]; // Need 16 bytes #else - #error "Unsupported word size." +#error "Unsupported word size." #endif }; - } namespace __xray { @@ -49,8 +48,10 @@ struct XRaySledMap { 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 diff --git a/compiler-rt/lib/xray/xray_x86_64.cc b/compiler-rt/lib/xray/xray_x86_64.cc index 398d6fc..0443c5e 100644 --- a/compiler-rt/lib/xray/xray_x86_64.cc +++ b/compiler-rt/lib/xray/xray_x86_64.cc @@ -1,5 +1,5 @@ -#include "xray_interface_internal.h" #include "sanitizer_common/sanitizer_common.h" +#include "xray_interface_internal.h" #include #include #include @@ -15,8 +15,8 @@ static constexpr uint8_t RetOpCode = 0xc3; static constexpr int64_t MinOffset{std::numeric_limits::min()}; static constexpr int64_t MaxOffset{std::numeric_limits::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: @@ -39,9 +39,8 @@ bool patchFunctionEntry(const bool Enable, const uint32_t FuncId, const XRaySled // // Prerequisite is to compute the relative offset to the // __xray_FunctionEntry function's address. - int64_t TrampolineOffset = - reinterpret_cast(__xray_FunctionEntry) - - (static_cast(Sled.Address) + 11); + int64_t TrampolineOffset = reinterpret_cast(__xray_FunctionEntry) - + (static_cast(Sled.Address) + 11); if (TrampolineOffset < MinOffset || TrampolineOffset > MaxOffset) { Report("XRay Entry trampoline (%p) too far from sled (%p); distance = " "%ld\n", @@ -65,8 +64,8 @@ bool patchFunctionEntry(const bool Enable, const uint32_t FuncId, const XRaySled 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: @@ -87,9 +86,8 @@ bool patchFunctionExit(const bool Enable, const uint32_t FuncId, const XRaySledE // // Prerequisite is to compute the relative offset fo the // __xray_FunctionExit function's address. - int64_t TrampolineOffset = - reinterpret_cast(__xray_FunctionExit) - - (static_cast(Sled.Address) + 11); + int64_t TrampolineOffset = reinterpret_cast(__xray_FunctionExit) - + (static_cast(Sled.Address) + 11); if (TrampolineOffset < MinOffset || TrampolineOffset > MaxOffset) { Report("XRay Exit trampoline (%p) too far from sled (%p); distance = " "%ld\n",