Skip to content

Commit 66e8177

Browse files
committed
Fix macos
1 parent a0898ac commit 66e8177

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/memray/_memray/ghost_stack/src/ghost_stack.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,15 @@ class GhostStackImpl {
491491
}
492492

493493
// Store the stack pointer that the trampoline will pass.
494-
// Use libunwind's SP value directly.
494+
// Linux: libunwind's SP matches what the trampoline passes
495+
// macOS: trampoline passes ret_loc + sizeof(void*), NOT libunwind's SP
496+
#ifdef __APPLE__
497+
uintptr_t expected_sp = reinterpret_cast<uintptr_t>(ret_loc) + sizeof(void*);
498+
#else
495499
unw_word_t actual_sp;
496500
unw_get_reg(&cursor, UNW_REG_SP, &actual_sp);
497501
uintptr_t expected_sp = static_cast<uintptr_t>(actual_sp);
502+
#endif
498503
// Store both IP (for returning to caller) and return_address (for trampoline restoration)
499504
// Insert at beginning to reverse order (oldest at index 0, newest at end)
500505
new_entries.insert(new_entries.begin(), {ip, ret_addr, ret_loc, expected_sp});

0 commit comments

Comments
 (0)