summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostya Kortchinsky <kostyak@google.com>2021-09-28 16:26:08 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-09-28 16:26:08 +0000
commit03c905f14a28f46a98371d6ef058153cac66d6a0 (patch)
tree0c2131167c5559ea73d6159d4c42d868a360223a
parent5237b07bf8737b5227b0d30dd6fd23cdaa26c0c2 (diff)
parent36ce06d35a1e429b5d74b05a5b0c17be70791712 (diff)
downloadgwp_asan-03c905f14a28f46a98371d6ef058153cac66d6a0.tar.gz
[gwp-asan] Initialize AllocatorVersionMagic at runtime am: b8c47cafa6 am: 36ce06d35a
Original change: https://android-review.googlesource.com/c/platform/external/gwp_asan/+/1838054 Change-Id: I5268642fd104c4c9cd8847e7c2809d3a4d0a1ef7
-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();