diff options
| author | Alice Ryhl <[email protected]> | 2025-06-12 11:17:33 +0000 |
|---|---|---|
| committer | Miguel Ojeda <[email protected]> | 2025-06-29 16:54:54 +0000 |
| commit | d6763e0abb43d550791eb66d2b91e82cb29807f9 (patch) | |
| tree | 8f9a668ad2732c5424ac4bf0831ce97c6b524e28 /rust/pin-init/examples/static_init.rs | |
| parent | rust: rbtree: add RBTree::is_empty (diff) | |
| download | kernel-d6763e0abb43d550791eb66d2b91e82cb29807f9.tar.gz kernel-d6763e0abb43d550791eb66d2b91e82cb29807f9.zip | |
rust: revocable: document why &T is not used in RevocableGuard
When a reference appears in a function argument, the reference is
assumed to be valid for the entire duration of that function call; this
is called a stack protector [1]. Because of that, custom pointer types
whose destructor may invalidate the pointee (i.e. they are more similar
to Box<T> than &T) cannot internally use a reference, and must instead
use a raw pointer.
This issue is something that is often missed during unsafe review. For
examples, see [2] and [3]. To ensure that people don't try to simplify
RevocableGuard by changing the raw pointer to a reference, add a comment
to that effect.
Link: https://perso.crans.org/vanille/treebor/protectors.html [1]
Link: https://users.rust-lang.org/t/unsafe-code-review-semi-owning-weak-rwlock-t-guard/95706 [2]
Link: https://lore.kernel.org/all/[email protected]/ [3]
Signed-off-by: Alice Ryhl <[email protected]>
Reviewed-by: Benno Lossin <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
[ Adjusted title. - Miguel ]
Signed-off-by: Miguel Ojeda <[email protected]>
Diffstat (limited to 'rust/pin-init/examples/static_init.rs')
0 files changed, 0 insertions, 0 deletions
