Skip to content

Commit

Permalink
Auto merge of #22637 - gterzian:fix_mac_sampler, r=jdm
Browse files Browse the repository at this point in the history
Fix frame-pointer stackwalking

<!-- Please describe your changes on the following line: -->

This seems to fix the problem, it's a check that is also done at https://dxr.mozilla.org/mozilla-central/rev/c2593a3058afdfeaac5c990e18794ee8257afe99/mozglue/misc/StackWalk.cpp#904

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #22604 (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because ___

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22637)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Jan 29, 2019
2 parents 65c2fcb + dccccef commit 62ff032
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion components/background_hang_monitor/sampler_mac.rs
Expand Up @@ -96,14 +96,22 @@ unsafe fn frame_pointer_stack_walk(regs: Registers) -> NativeStack {
// --dev,
// or --with-frame-pointer.

let stackaddr = libc::pthread_get_stackaddr_np(libc::pthread_self());
let pthread_t = libc::pthread_self();
let stackaddr = libc::pthread_get_stackaddr_np(pthread_t);
let stacksize = libc::pthread_get_stacksize_np(pthread_t);
let mut native_stack = NativeStack::new();
let pc = regs.instruction_ptr as *mut std::ffi::c_void;
let stack = regs.stack_ptr as *mut std::ffi::c_void;
let _ = native_stack.process_register(pc, stack);
let mut current = regs.frame_ptr as *mut *mut std::ffi::c_void;
while !current.is_null() {
if (current as usize) < stackaddr as usize {
// Reached the end of the stack.
break;
}
if current as usize >= stackaddr.add(stacksize * 8) as usize {
// Reached the beginning of the stack.
// Assumining 64 bit mac(see the stacksize * 8).
break;
}
let next = *current as *mut *mut std::ffi::c_void;
Expand All @@ -112,6 +120,9 @@ unsafe fn frame_pointer_stack_walk(regs: Registers) -> NativeStack {
if let Err(()) = native_stack.process_register(*pc, *stack) {
break;
}
if (next <= current) || (next as usize & 3 != 0) {
break;
}
current = next;
}
native_stack
Expand Down

0 comments on commit 62ff032

Please sign in to comment.