Skip to content

Commit e67d48e

Browse files
committed
mention that provenance also tracks whether a pointer can be used for writes
1 parent 8dd4bcf commit e67d48e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

library/core/src/ptr/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,14 @@
150150
//! absent, in which case the pointer does not have permission to access any memory.
151151
//!
152152
//! The exact structure of provenance is not yet specified, but the permission defined by a
153-
//! pointer's provenance have both a *spatial* and *temporal* component:
153+
//! pointer's provenance have a *spatial* component, a *temporal* component, and a *mutability*
154+
//! component:
154155
//!
155156
//! * Spatial: The set of memory addresses that the pointer is allowed to access.
156157
//! * Temporal: The timespan during which the pointer is allowed to access those memory addresses.
158+
//! * Mutability: Whether the pointer may only access the memory for reads, or also access it for
159+
//! writes. Note that this can interact with the other components, e.g. a pointer might permit
160+
//! mutation only for a subset of addresses, or only for a subset of its maximal timespan.
157161
//!
158162
//! When an [allocated object] is created, it has a unique Original Pointer. For alloc
159163
//! APIs this is literally the pointer the call returns, and for local variables and statics,
@@ -177,6 +181,9 @@
177181
//! Whether and when exactly the provenance of a reference gets "shrunk" to *exactly* fit
178182
//! the memory it points to is not yet determined.
179183
//!
184+
//! A *shared* reference only ever has provenance that permits reading from memory,
185+
//! and never permits writes, except inside [`UnsafeCell`].
186+
//!
180187
//! Provenance can affect whether a program has undefined behavior:
181188
//!
182189
//! * It is undefined behavior to access memory through a pointer that does not have provenance over
@@ -380,6 +387,7 @@
380387
//! [Miri]: https://github.com/rust-lang/miri
381388
//! [CHERI]: https://www.cl.cam.ac.uk/research/security/ctsrd/cheri/
382389
//! [Strict Provenance]: #strict-provenance
390+
//! [`UnsafeCell`]: core::cell::UnsafeCell
383391
384392
#![stable(feature = "rust1", since = "1.0.0")]
385393
// There are many unsafe functions taking pointers that don't dereference them.

0 commit comments

Comments
 (0)