From 0bfc4890931943388b6c9f5aae3d036668093c92 Mon Sep 17 00:00:00 2001 From: Mitch Phillips <31459023+hctim@users.noreply.github.com> Date: Wed, 5 Feb 2020 17:31:27 -0800 Subject: [PATCH] [GWP-ASan] Fix unused variables from crash handler + clang-format Summary: NFC - See title Reviewers: eugenis Reviewed By: eugenis Subscribers: merge_guards_bot, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D74100 --- compiler-rt/lib/gwp_asan/crash_handler.cpp | 7 ------- compiler-rt/lib/gwp_asan/crash_handler.h | 7 ------- compiler-rt/lib/gwp_asan/definitions.h | 3 ++- compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp | 2 +- .../lib/gwp_asan/optional/segv_handler_posix.cpp | 20 ++++++++------------ compiler-rt/lib/gwp_asan/tests/crash_handler_api.cpp | 19 ++++++++----------- compiler-rt/lib/gwp_asan/tests/harness.h | 2 +- 7 files changed, 20 insertions(+), 40 deletions(-) diff --git a/compiler-rt/lib/gwp_asan/crash_handler.cpp b/compiler-rt/lib/gwp_asan/crash_handler.cpp index f287d02..c3b9e14 100644 --- a/compiler-rt/lib/gwp_asan/crash_handler.cpp +++ b/compiler-rt/lib/gwp_asan/crash_handler.cpp @@ -95,25 +95,21 @@ __gwp_asan_get_metadata(const gwp_asan::AllocatorState *State, } uintptr_t __gwp_asan_get_allocation_address( - const gwp_asan::AllocatorState *State, const gwp_asan::AllocationMetadata *AllocationMeta) { return AllocationMeta->Addr; } size_t __gwp_asan_get_allocation_size( - const gwp_asan::AllocatorState *State, const gwp_asan::AllocationMetadata *AllocationMeta) { return AllocationMeta->Size; } uint64_t __gwp_asan_get_allocation_thread_id( - const gwp_asan::AllocatorState *State, const gwp_asan::AllocationMetadata *AllocationMeta) { return AllocationMeta->AllocationTrace.ThreadID; } size_t __gwp_asan_get_allocation_trace( - const gwp_asan::AllocatorState *State, const gwp_asan::AllocationMetadata *AllocationMeta, uintptr_t *Buffer, size_t BufferLen) { return gwp_asan::compression::unpack( @@ -122,19 +118,16 @@ size_t __gwp_asan_get_allocation_trace( } bool __gwp_asan_is_deallocated( - const gwp_asan::AllocatorState *State, const gwp_asan::AllocationMetadata *AllocationMeta) { return AllocationMeta->IsDeallocated; } uint64_t __gwp_asan_get_deallocation_thread_id( - const gwp_asan::AllocatorState *State, const gwp_asan::AllocationMetadata *AllocationMeta) { return AllocationMeta->DeallocationTrace.ThreadID; } size_t __gwp_asan_get_deallocation_trace( - const gwp_asan::AllocatorState *State, const gwp_asan::AllocationMetadata *AllocationMeta, uintptr_t *Buffer, size_t BufferLen) { return gwp_asan::compression::unpack( diff --git a/compiler-rt/lib/gwp_asan/crash_handler.h b/compiler-rt/lib/gwp_asan/crash_handler.h index db9e864..631c319 100644 --- a/compiler-rt/lib/gwp_asan/crash_handler.h +++ b/compiler-rt/lib/gwp_asan/crash_handler.h @@ -73,19 +73,16 @@ __gwp_asan_get_metadata(const gwp_asan::AllocatorState *State, // Returns the start of the allocation whose metadata is in `AllocationMeta`. uintptr_t __gwp_asan_get_allocation_address( - const gwp_asan::AllocatorState *State, const gwp_asan::AllocationMetadata *AllocationMeta); // Returns the size of the allocation whose metadata is in `AllocationMeta` size_t __gwp_asan_get_allocation_size( - const gwp_asan::AllocatorState *State, const gwp_asan::AllocationMetadata *AllocationMeta); // Returns the Thread ID that allocated the memory that caused the error at // `ErrorPtr`. This function may not be called if __gwp_asan_has_metadata() // returns false. uint64_t __gwp_asan_get_allocation_thread_id( - const gwp_asan::AllocatorState *State, const gwp_asan::AllocationMetadata *AllocationMeta); // Retrieve the allocation trace for the allocation whose metadata is in @@ -95,7 +92,6 @@ uint64_t __gwp_asan_get_allocation_thread_id( // frames were stored by GWP-ASan). A return value greater than `BufferLen` // indicates that the trace was truncated when storing to `Buffer`. size_t __gwp_asan_get_allocation_trace( - const gwp_asan::AllocatorState *State, const gwp_asan::AllocationMetadata *AllocationMeta, uintptr_t *Buffer, size_t BufferLen); @@ -103,14 +99,12 @@ size_t __gwp_asan_get_allocation_trace( // deallocated. This function may not be called if __gwp_asan_has_metadata() // returns false. bool __gwp_asan_is_deallocated( - const gwp_asan::AllocatorState *State, const gwp_asan::AllocationMetadata *AllocationMeta); // Returns the Thread ID that deallocated the memory whose metadata is in // `AllocationMeta`. This function may not be called if // __gwp_asan_is_deallocated() returns false. uint64_t __gwp_asan_get_deallocation_thread_id( - const gwp_asan::AllocatorState *State, const gwp_asan::AllocationMetadata *AllocationMeta); // Retrieve the deallocation trace for the allocation whose metadata is in @@ -121,7 +115,6 @@ uint64_t __gwp_asan_get_deallocation_thread_id( // indicates that the trace was truncated when storing to `Buffer`. This // function may not be called if __gwp_asan_is_deallocated() returns false. size_t __gwp_asan_get_deallocation_trace( - const gwp_asan::AllocatorState *State, const gwp_asan::AllocationMetadata *AllocationMeta, uintptr_t *Buffer, size_t BufferLen); diff --git a/compiler-rt/lib/gwp_asan/definitions.h b/compiler-rt/lib/gwp_asan/definitions.h index bebe56c..870dd96 100644 --- a/compiler-rt/lib/gwp_asan/definitions.h +++ b/compiler-rt/lib/gwp_asan/definitions.h @@ -9,7 +9,8 @@ #ifndef GWP_ASAN_DEFINITIONS_H_ #define GWP_ASAN_DEFINITIONS_H_ -#define GWP_ASAN_TLS_INITIAL_EXEC __thread __attribute__((tls_model("initial-exec"))) +#define GWP_ASAN_TLS_INITIAL_EXEC \ + __thread __attribute__((tls_model("initial-exec"))) #define GWP_ASAN_UNLIKELY(X) __builtin_expect(!!(X), 0) #define GWP_ASAN_ALWAYS_INLINE inline __attribute__((always_inline)) diff --git a/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp b/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp index cb8a183..4ce4d80 100644 --- a/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp +++ b/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp @@ -194,7 +194,7 @@ void GuardedPoolAllocator::trapOnAddress(uintptr_t Address, Error E) { State.FailureAddress = Address; // Raise a SEGV by touching first guard page. - volatile char *p = reinterpret_cast(State.GuardedPagePool); + volatile char *p = reinterpret_cast(State.GuardedPagePool); *p = 0; __builtin_unreachable(); } diff --git a/compiler-rt/lib/gwp_asan/optional/segv_handler_posix.cpp b/compiler-rt/lib/gwp_asan/optional/segv_handler_posix.cpp index f98c16b..22589b8 100644 --- a/compiler-rt/lib/gwp_asan/optional/segv_handler_posix.cpp +++ b/compiler-rt/lib/gwp_asan/optional/segv_handler_posix.cpp @@ -72,7 +72,6 @@ struct ScopedEndOfReportDecorator { // Prints the provided error and metadata information. void printHeader(Error E, uintptr_t AccessPtr, - const gwp_asan::AllocatorState *State, const gwp_asan::AllocationMetadata *Metadata, Printf_t Printf) { // Print using intermediate strings. Platforms like Android don't like when @@ -81,9 +80,8 @@ void printHeader(Error E, uintptr_t AccessPtr, constexpr size_t kDescriptionBufferLen = 128; char DescriptionBuffer[kDescriptionBufferLen] = ""; if (E != Error::UNKNOWN && Metadata != nullptr) { - uintptr_t Address = - __gwp_asan_get_allocation_address(State, Metadata); - size_t Size = __gwp_asan_get_allocation_size(State, Metadata); + uintptr_t Address = __gwp_asan_get_allocation_address(Metadata); + size_t Size = __gwp_asan_get_allocation_size(Metadata); if (E == Error::USE_AFTER_FREE) { snprintf(DescriptionBuffer, kDescriptionBufferLen, "(%zu byte%s into a %zu-byte allocation at 0x%zx) ", @@ -191,7 +189,7 @@ void dumpReport(uintptr_t ErrorPtr, const gwp_asan::AllocatorState *State, __gwp_asan_get_metadata(State, Metadata, ErrorPtr); // Print the error header. - printHeader(E, ErrorPtr, State, AllocMeta, Printf); + printHeader(E, ErrorPtr, AllocMeta, Printf); // Print the fault backtrace. static constexpr unsigned kMaximumStackFramesForCrashTrace = 512; @@ -204,27 +202,25 @@ void dumpReport(uintptr_t ErrorPtr, const gwp_asan::AllocatorState *State, return; // Maybe print the deallocation trace. - if (__gwp_asan_is_deallocated(State, AllocMeta)) { - uint64_t ThreadID = - __gwp_asan_get_deallocation_thread_id(State, AllocMeta); + if (__gwp_asan_is_deallocated(AllocMeta)) { + uint64_t ThreadID = __gwp_asan_get_deallocation_thread_id(AllocMeta); if (ThreadID == kInvalidThreadID) Printf("0x%zx was deallocated by thread here:\n", ErrorPtr); else Printf("0x%zx was deallocated by thread %zu here:\n", ErrorPtr, ThreadID); TraceLength = __gwp_asan_get_deallocation_trace( - State, AllocMeta, Trace, kMaximumStackFramesForCrashTrace); + AllocMeta, Trace, kMaximumStackFramesForCrashTrace); PrintBacktrace(Trace, TraceLength, Printf); } // Print the allocation trace. - uint64_t ThreadID = - __gwp_asan_get_allocation_thread_id(State, AllocMeta); + uint64_t ThreadID = __gwp_asan_get_allocation_thread_id(AllocMeta); if (ThreadID == kInvalidThreadID) Printf("0x%zx was allocated by thread here:\n", ErrorPtr); else Printf("0x%zx was allocated by thread %zu here:\n", ErrorPtr, ThreadID); TraceLength = __gwp_asan_get_allocation_trace( - State, AllocMeta, Trace, kMaximumStackFramesForCrashTrace); + AllocMeta, Trace, kMaximumStackFramesForCrashTrace); PrintBacktrace(Trace, TraceLength, Printf); } } // namespace crash_handler diff --git a/compiler-rt/lib/gwp_asan/tests/crash_handler_api.cpp b/compiler-rt/lib/gwp_asan/tests/crash_handler_api.cpp index 3df7ff5..10a014e 100644 --- a/compiler-rt/lib/gwp_asan/tests/crash_handler_api.cpp +++ b/compiler-rt/lib/gwp_asan/tests/crash_handler_api.cpp @@ -61,15 +61,14 @@ protected: void checkBacktrace(const AllocationMetadata *Meta, bool IsDeallocated) { uintptr_t Buffer[kNumBacktraceConstants]; size_t NumBacktraceConstants = kNumBacktraceConstants; - EXPECT_EQ(NumBacktraceConstants, - __gwp_asan_get_allocation_trace(&State, Meta, Buffer, - kNumBacktraceConstants)); + EXPECT_EQ(NumBacktraceConstants, __gwp_asan_get_allocation_trace( + Meta, Buffer, kNumBacktraceConstants)); for (size_t i = 0; i < kNumBacktraceConstants; ++i) EXPECT_EQ(Buffer[i], BacktraceConstants[i]); if (IsDeallocated) { EXPECT_EQ(NumBacktraceConstants, - __gwp_asan_get_deallocation_trace(&State, Meta, Buffer, + __gwp_asan_get_deallocation_trace(Meta, Buffer, kNumBacktraceConstants)); for (size_t i = 0; i < kNumBacktraceConstants; ++i) EXPECT_EQ(Buffer[i], BacktraceConstants[i]); @@ -80,14 +79,12 @@ protected: const AllocationMetadata *Meta = __gwp_asan_get_metadata(&State, Metadata, ErrorPtr); EXPECT_NE(nullptr, Meta); - EXPECT_EQ(Metadata[Index].Addr, - __gwp_asan_get_allocation_address(&State, Meta)); - EXPECT_EQ(Metadata[Index].Size, - __gwp_asan_get_allocation_size(&State, Meta)); + EXPECT_EQ(Metadata[Index].Addr, __gwp_asan_get_allocation_address(Meta)); + EXPECT_EQ(Metadata[Index].Size, __gwp_asan_get_allocation_size(Meta)); EXPECT_EQ(Metadata[Index].AllocationTrace.ThreadID, - __gwp_asan_get_allocation_thread_id(&State, Meta)); + __gwp_asan_get_allocation_thread_id(Meta)); - bool IsDeallocated = __gwp_asan_is_deallocated(&State, Meta); + bool IsDeallocated = __gwp_asan_is_deallocated(Meta); EXPECT_EQ(Metadata[Index].IsDeallocated, IsDeallocated); checkBacktrace(Meta, IsDeallocated); @@ -95,7 +92,7 @@ protected: return; EXPECT_EQ(Metadata[Index].DeallocationTrace.ThreadID, - __gwp_asan_get_deallocation_thread_id(&State, Meta)); + __gwp_asan_get_deallocation_thread_id(Meta)); } static constexpr size_t kNumBacktraceConstants = 4; diff --git a/compiler-rt/lib/gwp_asan/tests/harness.h b/compiler-rt/lib/gwp_asan/tests/harness.h index 4bada14..e47254e 100644 --- a/compiler-rt/lib/gwp_asan/tests/harness.h +++ b/compiler-rt/lib/gwp_asan/tests/harness.h @@ -15,8 +15,8 @@ #include "gwp_asan/guarded_pool_allocator.h" #include "gwp_asan/optional/backtrace.h" -#include "gwp_asan/options.h" #include "gwp_asan/optional/segv_handler.h" +#include "gwp_asan/options.h" namespace gwp_asan { namespace test { -- 2.7.4