Debian Codegraph @

debian/rust-vendor/bitvec/doc/ptr/span.md

raw
1 # Encoded Bit-Span Pointer
2
3 This module implements the logic used to encode and operate on values of
4 `*BitSlice`. It is the core operational module of the library.
5
6 ## Theory
7
8 Rust is slowly experimenting with allowing user-provided types to define
9 metadata structures attached to raw-pointers and references in a structured
10 manner. However, this is a fairly recent endeavour, much newer than `bitvec`’s
11 work in the same area, so `bitvec` does not attempt to use it.
12
13 The problem with bit-addressable memory is that it takes three more bits to
14 select a *bit* than it does a *byte*. While AMD64 specifies (and AArch64 likely
15 follows by fiat) that pointers are 64 bits wide but only contain 48 (or more
16 recently, 57) bits of information, leaving the remainder available to store
17 userspace information (as long as it is canonicalized before dereferencing),
18 x86 and Arm32 have no such luxury space in their pointers.
19
20 Since `bitvec` supports 32-bit targets, it instead opts to place the three
21 bit-selector bits outside the pointer address. The only other space available in
22 Rust pointers is in the length field of slice pointers. As such, `bitvec`
23 encodes its span description information into `*BitSlice` and, by extension,
24 `&/mut BitSlice`. The value underlying these language fundamentals is well-known
25 (though theoretically opaque), and the standard library provides APIs that it
26 promises will always be valid to manipulate them. Through careful use of these
27 APIs, and following type-system rules to prevent undefined behavior, `bitvec` is
28 able to define its span descriptions within the language fundamentals and appear
29 fully idiomatic and compliant with existing Rust patterns.
30
31 See the [`BitSpan`] type documentation for details on the encoding scheme used.
32
33 [`BitSpan`]: self::BitSpan