-
Couldn't load subscription status.
- Fork 33
Open
Labels
coding guidelinesRelated to work in the Coding Guidelines SubcommitteeRelated to work in the Coding Guidelines Subcommitteetracking issueAn issue that gathers activities toward a larger goalAn issue that gathers activities toward a larger goal
Description
Provide initial content for the Dangling and unaligned pointers chapter of the Learn unsafe Rust book.
Based on the guidelines for a chapter,
Dangling and unsafe pointers
Intro to what danging and unaligned pointers are
Usage:
- Working across FFI bounds, needing to pass pointer and length of a buffer
- Performance sensitive operations, e.g. I recall nalgebra uses unsafe for some things like this
- ... others
How UB happen when dealing with them
- Some operations we perform are OK to do and arrive at unaligned, others must be aligned
- Good to have some definition here about alignment and references
Thinking about dangling and unaligned pointers is relevant (not always obvious)
- Todo
Common techniques to work safely to avoid dangling and unaligned pointers
- The stdlib seems to have some reasonable resources here
- A fair number are marked unstable and nightly-only, would be good to see their usage in reality too (see e.g.
ptr::as_uninit_slice_mutfor a fairy comprehensive list of things that must be true to not get UB!)
- A fair number are marked unstable and nightly-only, would be good to see their usage in reality too (see e.g.
Decided vs current gaps in specification vs direction of Rust / Rust's spec
For example ptr::read_volatile, which acknowledges:
Rust does not currently have a rigorously and formally defined memory model, so the precise semantics of what “volatile” means here is subject to change over time. That being said, the semantics will almost always end up pretty similar to C11’s definition of volatile.
General notes to me / team
- In general, if there's a stdlib
unsafefunction to do something, we should lean towards recommending that when relevant- For someone new to this part of
unsafelike me, they also seem to go into enough detail to learn
- For someone new to this part of
Resources
Filling in some resources that seem useful, feel free to sound off with more and I can add them to the first comment.
- stdlib ptr documentation
- nalgebra makes use of pointers and pointer arithmetic IIRC to do things like get custom views into matrices
Folks interested
squelliglesias
Metadata
Metadata
Assignees
Labels
coding guidelinesRelated to work in the Coding Guidelines SubcommitteeRelated to work in the Coding Guidelines Subcommitteetracking issueAn issue that gathers activities toward a larger goalAn issue that gathers activities toward a larger goal
Type
Projects
Status
In Progress