|
17 | 17 | //! # Safety
|
18 | 18 | //!
|
19 | 19 | //! Many functions in this module take raw pointers as arguments and dereference
|
20 |
| -//! them. For this to be safe, these pointers must be valid. A valid pointer |
21 |
| -//! is one that satisfies **all** of the following conditions: |
| 20 | +//! them. For this to be safe, these pointers must be valid. However, because |
| 21 | +//! rust does not yet have a formal memory model, determining whether an |
| 22 | +//! arbitrary pointer is a valid one can be tricky. One thing is certain: |
| 23 | +//! creating a raw pointer from a reference (e.g. `&x as *const _`) *always* |
| 24 | +//! results in a valid pointer. By exploiting this—and by taking care when |
| 25 | +//! using [pointer arithmetic]—users can be confident in the correctness of |
| 26 | +//! their unsafe code. |
22 | 27 | //!
|
23 |
| -//! * The pointer is not null. |
24 |
| -//! * The pointer is not dangling (it does not point to memory which has been |
25 |
| -//! freed). |
26 |
| -//! * The pointer satisfies [LLVM's pointer aliasing rules]. |
| 28 | +//! For more information on dereferencing raw pointers, see the both the [book] |
| 29 | +//! and the section in the reference devoted to [undefined behavior][ub]. |
| 30 | +//! |
| 31 | +//! ## Alignment |
27 | 32 | //!
|
28 | 33 | //! Valid pointers are not necessarily properly aligned. However, most functions
|
29 | 34 | //! require their arguments to be properly aligned, and will explicitly state
|
30 | 35 | //! this requirement in the `Safety` section. Notable exceptions to this are
|
31 | 36 | //! [`read_unaligned`] and [`write_unaligned`].
|
32 | 37 | //!
|
33 |
| -//! [LLVM's pointer aliasing rules]: https://llvm.org/docs/LangRef.html#pointer-aliasing-rules |
| 38 | +//! [ub]: ../../reference/behavior-considered-undefined.html |
| 39 | +//! [book]: ../../book/second-edition/ch19-01-unsafe-rust.html#dereferencing-a-raw-pointer |
| 40 | +//! [pointer arithmetic]: ../../std/primitive.pointer.html#method.offset |
34 | 41 | //! [`read_unaligned`]: ./fn.read_unaligned.html
|
35 | 42 | //! [`write_unaligned`]: ./fn.write_unaligned.html
|
36 | 43 |
|
|
0 commit comments