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 unsafe AtomicRefCell<T> transmutes in Layout component #16833
Conversation
|
||
// Required alignment in 32 bit architectures for safe | ||
// transmute between PersistentLayoutData and PartialPersistentLayoutData. | ||
#[cfg(target_pointer_width = "32")] _align: u64 |
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.
Why not have this dummy field unconditionally?
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.
Or, better yet, make it a [u64; 0]
, which affects alignment without size penalties.
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.
I did that way as a size optimization. Do you think that it isn't worth it?
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.
@emilio nice! I didn't know that
…y alignment differences
ae6d724
to
593e890
Compare
Nice one @emilio, for @bors-servo r+ |
📌 Commit 593e890 has been approved by |
Fix unsafe AtomicRefCell<T> transmutes in Layout component <!-- Please describe your changes on the following line: --> Fixes unsafe transmute between `AtomicRefCell<PersistentLayoutData>` and `AtomicRefCell<PartialPersistentLayoutData>` which have different memory alignment in 32 bit archs leading to SEGV crashes. See #16817 and #16816 mem::align_of values in 32 bit archs (e.g. Android): ``` PersistentLayoutData 8 PersistentLayoutData 4 AtomicRefCell<PersistentLayoutData> 8 AtomicRefCell<PartialPersistentLayoutData> 4 ``` mem::align_of values in 64 bit archs ``` PersistentLayoutData 8 PersistentLayoutData 8 AtomicRefCell<PersistentLayoutData> 8 AtomicRefCell<PartialPersistentLayoutData> 8 ``` --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #16817 (github issue number if applicable). <!-- Either: --> - [x] 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/16833) <!-- Reviewable:end -->
☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css, mac-rel-wpt1, mac-rel-wpt2, windows-msvc-dev |
Fixes unsafe transmute between
AtomicRefCell<PersistentLayoutData>
andAtomicRefCell<PartialPersistentLayoutData>
which have different memory alignment in 32 bit archs leading to SEGV crashes. See #16817 and #16816mem::align_of values in 32 bit archs (e.g. Android):
mem::align_of values in 64 bit archs
./mach build -d
does not report any errors./mach test-tidy
does not report any errorsThis change is