Skip to content

Conversation

phil-opp
Copy link
Owner

@phil-opp phil-opp commented Nov 1, 2016

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 added cherry-pick-needed enhancement Potential improvements for the code or the blog. relnotes "Release notes" – Notable changes that are rendered on the blog. labels Nov 1, 2016
@phil-opp phil-opp self-assigned this Nov 1, 2016
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 phil-opp force-pushed the stack_frame-reference branch 3 times, most recently from 787a073 to 6ac8251 Compare November 1, 2016 16:46
@phil-opp phil-opp force-pushed the stack_frame-reference branch from 6ac8251 to 7bff7d8 Compare November 1, 2016 16:47
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 force-pushed the stack_frame-reference branch from 7bff7d8 to 9963961 Compare November 1, 2016 16:50
phil-opp added a commit that referenced this pull request Nov 1, 2016
@phil-opp phil-opp merged commit 571f1d2 into master Nov 1, 2016
@phil-opp phil-opp deleted the stack_frame-reference branch November 1, 2016 16:56
phil-opp added a commit that referenced this pull request Nov 1, 2016
@phil-opp
Copy link
Owner Author

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

Labels

enhancement Potential improvements for the code or the blog. relnotes "Release notes" – Notable changes that are rendered on the blog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant