Exceptions: Take the ExceptionStackFrame per reference #252

merged 4 commits into from Nov 1, 2016


None yet

1 participant

phil-opp commented Nov 1, 2016 edited

This PR changes the type of exception handler functions. Instead of a *const ExceptionStackFrame, they now take a &ExceptionStackFrame as argument. The reason is that they require the pointer to be valid (they used to blindly derefence the raw pointer). So the old implementation was unsound, since the functions used to violate memory safety when an invalid pointer is passed.

A consequence of this change is that we should no longer modify the exception stack frame (since we have an immutable reference to it). And transmuting a & to a &mut is undefined behavior. So the last section of Returning from Exceptions (“Page Faults as Breakpoints”) becomes even more hacky. Therefore, this PR removes that section. Instead, we now test the iretq logic by entering an endless loop between the exception handler and the instruction accessing 0xdeadbeaf.

@phil-opp phil-opp self-assigned this Nov 1, 2016
added some commits Oct 30, 2016
@phil-opp Use references for the ExceptionStackFrame argument
We require/assume that these pointers are correct. Using references is cleaner than blindly dereferencing raw pointers.

Important: The Rust book guarantees that: “At runtime, a raw pointer * and a reference pointing to the same piece of data have an identical representation.”
@phil-opp Better Exception Messages: Take stack_frame argument as reference e129da8
@phil-opp Returning from Exceptions: Take stack_frame as reference 67857bd
@phil-opp Test the handler_with_error_code macro in a different way
We now take stack_frame as a immutable reference and we shouldn't write to a &. So the old test example (page faults as breakpoints) becomes even more hacky. Instead, we're now deliberately entering an endless page fault loop to check our iretq logic.
@phil-opp phil-opp added a commit that referenced this pull request Nov 1, 2016
@phil-opp Update images for #252 0c9a5e9
@phil-opp phil-opp merged commit 571f1d2 into master Nov 1, 2016

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
continuous-integration/travis-ci/push The Travis CI build passed
@phil-opp phil-opp deleted the stack_frame-reference branch Nov 1, 2016
@phil-opp phil-opp added a commit that referenced this pull request Nov 1, 2016
@phil-opp Update images for #252 e304b8e
phil-opp commented Nov 1, 2016

Cherry picked to better_exception_messages and returning_from_exceptions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment