Skip to content

Commit 6367efe

Browse files
zhengyu123Copilot
andauthored
Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent a12b80b commit 6367efe

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

ddprof-lib/src/main/cpp/faultInjection.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,13 @@ bool shouldFire(u64 threshold, const char* fn) {
9595

9696
uintptr_t poisonAddress() {
9797
u64 r = nextRandom();
98-
if (g_guard_ok && (r & 1u)) {
98+
if (g_guard_ok.load(std::memory_order_acquire)) {
9999
// Guaranteed-unmapped guard page — deterministic SIGSEGV.
100-
return (g_guard_base + (uintptr_t)(r % g_guard_span)) & ALIGN_MASK;
100+
uintptr_t base = g_guard_base.load(std::memory_order_relaxed);
101+
uintptr_t span = g_guard_span.load(std::memory_order_relaxed);
102+
return (base + (uintptr_t)(r % span)) & ALIGN_MASK;
101103
}
102-
// Random non-canonical address (high bit set keeps it well above any mapped
103-
// low page) — may raise SIGSEGV or SIGBUS.
104+
// Fallback: best-effort garbage address if init() failed.
104105
return ((uintptr_t)r | (uintptr_t)0x8000000000000000ULL) & ALIGN_MASK;
105106
}
106107

0 commit comments

Comments
 (0)