Skip to content

Commit 69b62ec

Browse files
committed
define 'read-only memory'
1 parent 07b8c10 commit 69b62ec

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

library/core/src/sync/atomic.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,19 @@
8181
//!
8282
//! # Atomic accesses to read-only memory
8383
//!
84-
//! In general, atomic accesses on read-only memory are Undefined Behavior. For instance, attempting
84+
//! In general, *all* atomic accesses on read-only memory are Undefined Behavior. For instance, attempting
8585
//! to do a `compare_exchange` that will definitely fail (making it conceptually a read-only
8686
//! operation) can still cause a page fault if the underlying memory page is mapped read-only. Since
8787
//! atomic `load`s might be implemented using compare-exchange operations, even a `load` can fault
8888
//! on read-only memory.
8989
//!
90+
//! For the purpose of this section, "read-only memory" is defined as memory that is read-only in
91+
//! the underlying target, i.e., the pages are mapped with a read-only flag and any attempt to write
92+
//! will cause a page fault. In particular, an `&u128` reference that points to memory that is
93+
//! read-write mapped is *not* considered to point to "read-only memory". In Rust, almost all memory
94+
//! is read-write; the only exceptions are memory created by `const` items or `static` items without
95+
//! interior mutability.
96+
//!
9097
//! However, as an exception from this general rule, Rust guarantees that "sufficiently small"
9198
//! atomic loads are implemented in a way that works on read-only memory. This threshold of
9299
//! "sufficiently small" depends on the architecture:

0 commit comments

Comments
 (0)