summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostya Kortchinsky <kostyak@google.com>2021-09-27 12:31:59 -0700
committerCopybara-Service <copybara-worker@google.com>2021-09-27 13:56:08 -0700
commitb8c47cafa63e272e2d4d76c21c7add0ffd975090 (patch)
tree0c2131167c5559ea73d6159d4c42d868a360223a
parent634351b545d5a98be1eaf84ce70a70f7b3bab352 (diff)
downloadgwp_asan-b8c47cafa63e272e2d4d76c21c7add0ffd975090.tar.gz
[gwp-asan] Initialize AllocatorVersionMagic at runtime
GWP-ASan's `AllocatorState` was recently extended with a `AllocatorVersionMagic` structure required so that GWP-ASan bug reports can be understood by tools at different versions. On Fuchsia, this in included in the `scudo::Allocator` structure, and by having non-zero initializers, this effectively moved the static allocator structure from the `.bss` segment to the `.data` segment, thus increasing (significantly) the size of the libc. This CL proposes to initialize the structure with its magic numbers at runtime, allowing for the allocator to go back into the `.bss` segment. I will work on adding a test on the Scudo side to ensure that this type of changes get detected early on. Additional work is also needed to reduce the footprint of the (large) memory-tagging related structures that are currently part of the allocator. Differential Revision: https://reviews.llvm.org/D110575 GitOrigin-RevId: 04f5913395de23a5f6745156021ab10a4a0039de Change-Id: Id528db62440726589f60f40b0bd9595f0d7b3bbe
-rw-r--r--gwp_asan/common.h18
-rw-r--r--gwp_asan/guarded_pool_allocator.cpp7
2 files changed, 19 insertions, 6 deletions
diff --git a/gwp_asan/common.h b/gwp_asan/common.h
index 520f577..6b238ad 100644
--- a/gwp_asan/common.h
+++ b/gwp_asan/common.h
@@ -22,16 +22,22 @@ namespace gwp_asan {
// Magic header that resides in the AllocatorState so that GWP-ASan bugreports
// can be understood by tools at different versions. Out-of-process crash
-// handlers, like crashpad on Fuchsia, take the raw conents of the
+// handlers, like crashpad on Fuchsia, take the raw contents of the
// AllocationMetatada array and the AllocatorState, and shove them into the
// minidump. Online unpacking of these structs needs to know from which version
-// of GWP-ASan its extracting the information, as the structures are not stable.
+// of GWP-ASan it's extracting the information, as the structures are not
+// stable.
struct AllocatorVersionMagic {
- const uint8_t Magic[4] = {'A', 'S', 'A', 'N'};
+ // The values are copied into the structure at runtime, during
+ // `GuardedPoolAllocator::init()` so that GWP-ASan remains completely in the
+ // `.bss` segment.
+ static constexpr uint8_t kAllocatorVersionMagic[4] = {'A', 'S', 'A', 'N'};
+ uint8_t Magic[4] = {};
// Update the version number when the AllocatorState or AllocationMetadata
// change.
- const uint16_t Version = 1;
- const uint16_t Reserved = 0;
+ static constexpr uint16_t kAllocatorVersion = 1;
+ uint16_t Version = 0;
+ uint16_t Reserved = 0;
};
enum class Error : uint8_t {
@@ -99,7 +105,7 @@ struct AllocationMetadata {
// set of information required for understanding a GWP-ASan crash.
struct AllocatorState {
constexpr AllocatorState() {}
- const AllocatorVersionMagic VersionMagic{};
+ AllocatorVersionMagic VersionMagic{};
// Returns whether the provided pointer is a current sampled allocation that
// is owned by this pool.
diff --git a/gwp_asan/guarded_pool_allocator.cpp b/gwp_asan/guarded_pool_allocator.cpp
index 8ce5fc9..7096b42 100644
--- a/gwp_asan/guarded_pool_allocator.cpp
+++ b/gwp_asan/guarded_pool_allocator.cpp
@@ -59,6 +59,13 @@ void GuardedPoolAllocator::init(const options::Options &Opts) {
SingletonPtr = this;
Backtrace = Opts.Backtrace;
+ State.VersionMagic = {{AllocatorVersionMagic::kAllocatorVersionMagic[0],
+ AllocatorVersionMagic::kAllocatorVersionMagic[1],
+ AllocatorVersionMagic::kAllocatorVersionMagic[2],
+ AllocatorVersionMagic::kAllocatorVersionMagic[3]},
+ AllocatorVersionMagic::kAllocatorVersion,
+ 0};
+
State.MaxSimultaneousAllocations = Opts.MaxSimultaneousAllocations;
const size_t PageSize = getPlatformPageSize();