8000 segmentation · sarvex/rust-memory-model@ad2822b · GitHub
[go: up one dir, main page]

Skip to content

Commit ad2822b

Browse files
committed
segmentation
1 parent 7fada7d commit ad2822b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

specification/terms.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,33 @@ A value, in order to get stored into memory, must first undergo the process of t
220220
### §4.4 Conversion from Memory
221221

222222
Conversion from memory will be a conversion to memory, but in reverse, going from computer-friendly form to pure mathematical object.
223+
224+
## §5 Memory
225+
226+
### §5.1 Segmentation
227+
228+
Rust works on a flat address space - addresses are numbers between
229+
`0` and `2^wordlen`. However, for semantic purposes, memory is divided into an
230+
hierarchy of segments, each of which describes a contiguous set of addresses.
231+
232+
The addresses `0` and `2^wordlen-1` are not assigned to any segment. This prevents
233+
segments from wrapping around the end of address space.
234+
235+
Coexisting segments may not overlap (unless one is the supersegment of another). However, segments may be added or removed at run-time, possibly through intrinsics that can be triggered from user code.
236+
237+
Segments have an identity - removing a segment and creating another with the same address-set does not result in the same segment.
238+
239+
During their lifetime, each stack allocation and global variable is contained within a single segment.
240+
241+
NOTE: segments are used to represent LLVM objects, and *not* Rust borrowed pointers.
242+
243+
Every stack allocation or global variable will contain only addresses for a single
244+
segment. There MAY exist intrinsics that subdivide segments.
245+
246+
Every pointer or reference is associated with a segment. That segment follows
247+
the pointer as it is stored and loaded from memory, and through projections.
248+
249+
Each of the `size_of::<T>()` bytes from the address of a reference to a type `T` must always be contained within that reference's segment.
250+
251+
When a raw pointer to type `T` is accessed, each of the `size_of::<T>()` bytes from
252+
its address must be contained within its segment.

0 commit comments

Comments
 (0)
0