forked from OSchip/llvm-project
[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
This commit is contained in:
parent
6e2309d7fa
commit
0bfc489093
|
@ -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(
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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<char*>(State.GuardedPagePool);
|
||||
volatile char *p = reinterpret_cast<char *>(State.GuardedPagePool);
|
||||
*p = 0;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
|
|
@ -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 <unknown> 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 <unknown> 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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue