-
Notifications
You must be signed in to change notification settings - Fork 655
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
Avoid creating intermediate Rust references when taking pointers of memory / extern statics #3824
Conversation
This pull request partially fixes the issue regarding the usage of
|
Looks great, thank you! |
a1770e0
to
577ef2c
Compare
577ef2c
to
7773377
Compare
This should be ready now. I changed the newly introduced casts of #3597, as well as new boards added. I further extended this PR to also change all intermediate references which are subsequently converted to pointers across the entire codebase, using the following RegEx to find such usages: git grep -E '&[a-zA-Z0-9\_\.]* as \*' We may still be missing some usages that don't match on the above, but this should be a good step toward resolving #3841. |
let kernel_addresses = unsafe { | ||
process_console::KernelAddresses { | ||
stack_start: &_sstack as *const u8, | ||
stack_end: &_estack as *const u8, |
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 tried to remove the unsafe here, but the compiler still insists that this is a usage of an extern static. I think this is due to the implementation of a macro, which uses an experimental syntax that still triggers the safety lint.
Avoid creating intermediate references for taking pointers to variables or extern statics during process loading, setting up the RISC-V PMP, creating non-volatile storage drivers, and when taking the addresses of registers in chips. Extern statics are inaccessible in safe Rust code by default. However, when we perform an operation such as `&_sapp as *const u8`, we create a Rust reference to the underlying memory that is (a) safely dereferencable, and (b) does not necessarily conform to Rust requirements concerning initialized memory. This PR switches those occurrences to use `core::ptr::addr_of` (and its mutable sibling), a macro explicitly designed to return the address of some memory location without creating an intermediate reference. Suggested-by: Alyssa Haroldsen <kupiakos@google.com>
7773377
to
b423469
Compare
Merging this soon if anyone has any comments. |
Pull Request Overview
Avoid creating intermediate references to extern statics during process loading, setting up the RISC-V PMP, creating non-volatile storage drivers, and when taking the addresses of registers in chips. Extern statics are inaccessible in safe Rust code by default. However, when we perform an operation such as
&_sapp as *const u8
, we create a Rust reference to the underlying memory that is (a) safely dereferencable, and (b) does not necessarily conform to Rust requirements concerning initialized memory.This PR switches those occurrences to use
core::ptr::addr_of
(and its mutable sibling), a macro explicitly designed to return the address of some memory location without creating an intermediate reference.Suggested-by: Alyssa Haroldsen kupiakos@google.com @kupiakos
Testing Strategy
This pull request was tested by compiling.
TODO or Help Wanted
Blocked on #3597. Will need to port those changes to the new Kernel-protection PMP instances as well.
Documentation Updated
Updated the relevant files inno updates are required./docs
, orFormatting
make prepush
.