}
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(
}
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(
// 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
// 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);
// 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
// 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);
#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))
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();
}
// 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
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) ",
__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;
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
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]);
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);
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;
#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 {