-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Tree Borrows & Stacked Borrows Violations #7
Fix Tree Borrows & Stacked Borrows Violations #7
Conversation
Should still not cause undefined behaviour even after clearing the list.
Deriving a mutable pointer from an immutable reference results in a `Frozen` mutable pointer, which is UB to write through. Since all of the contexts that a mutable pointer is needed also have a mutable reference available, we can derive the pointer from the mutable reference instead. This fixes TB violations.
Makes it more clear that we're comparing against the end marker without needing to think through what the cast is doing.
The issue with the original `containing_record{,_mut}` methods under SB is that the pointer derived from the list entry reference is only valid for the range of list entry, and not the containing record itself. By deferring the raw pointer dereference to once we have a pointer to the containing record, the resultant reference is valid for the whole record. This fixes all violations under SB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much @DropDemBits for looking into this, and coming up with such a detailed PR and comprehensible commit messages!
I know for a long time that I needed to look into this, but didn't find the time so far.
I have reviewed your PR and found just two minor things.
Please let me know what you think about the outstanding suggestions.
This was a left-over from when `end_marker` was used to also get a mutable pointer to the end marker. The extra mutable cast isn't needed as it gets coerced back into an immutable pointer, so we can remove it.
Since `containing_record{,_mut}` is the only use of these functions, they can be inlined to simplify things. As a bonus, this also makes the implementation nicely parallel with the `Nt{,SingleListHead}::entry` function which goes the other way.
Addressed both outstanding suggestions (took me a bit to figure out how to word the commit messages 😅). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Thank you again for taking care of this 👍
Now released as 0.2.1 and 0.3.0 |
Fixes #6
This resolves all TB violations, and with
6a64bfd
also resolves all SB violations. I separated out the commit fixing the SB violations since it's still sound under TB without it, and in the event that a TB or TB-like model becomes the default for miri, that commit can easily be reverted.This also adds miri to the CI workflow to hopefully catch any future UB.