@@ -82,22 +82,15 @@ macro_rules! kani_lib {
8282 //! This module contains functions useful for checking unsafe memory access.
8383 //!
8484 //! Given the following validity rules provided in the Rust documentation:
85- //! <https://doc.rust-lang.org/std/ptr/index.html> (accessed Feb 6th, 2024 )
85+ //! <https://doc.rust-lang.org/std/ptr/index.html> (accessed May 20th, 2025 )
8686 //!
87- //! 1. A null pointer is never valid, not even for accesses of size zero.
88- //! 2. For a pointer to be valid, it is necessary, but not always sufficient, that the pointer
87+ //! 1. For memory accesses of size zero, every pointer is valid, including the null pointer.
88+ //! The following points are only concerned with non-zero-sized accesses.
89+ //! 2. A null pointer is never valid.
90+ //! 3. For a pointer to be valid, it is necessary, but not always sufficient, that the pointer
8991 //! be dereferenceable: the memory range of the given size starting at the pointer must all be
9092 //! within the bounds of a single allocated object. Note that in Rust, every (stack-allocated)
9193 //! variable is considered a separate allocated object.
92- //! ~~Even for operations of size zero, the pointer must not be pointing to deallocated memory,
93- //! i.e., deallocation makes pointers invalid even for zero-sized operations.~~
94- //! ZST access is not OK for any pointer.
95- //! See: <https://github.com/rust-lang/unsafe-code-guidelines/issues/472>
96- //! 3. However, casting any non-zero integer literal to a pointer is valid for zero-sized
97- //! accesses, even if some memory happens to exist at that address and gets deallocated.
98- //! This corresponds to writing your own allocator: allocating zero-sized objects is not very
99- //! hard. The canonical way to obtain a pointer that is valid for zero-sized accesses is
100- //! `NonNull::dangling`.
10194 //! 4. All accesses performed by functions in this module are non-atomic in the sense of atomic
10295 //! operations used to synchronize between threads.
10396 //! This means it is undefined behavior to perform two concurrent accesses to the same location
@@ -108,13 +101,7 @@ macro_rules! kani_lib {
108101 //! object is live and no reference (just raw pointers) is used to access the same memory.
109102 //! That is, reference and pointer accesses cannot be interleaved.
110103 //!
111- //! Kani is able to verify #1 and #2 today.
112- //!
113- //! For #3, we are overly cautious, and Kani will only consider zero-sized pointer access safe if
114- //! the address matches `NonNull::<()>::dangling()`.
115- //! The way Kani tracks provenance is not enough to check if the address was the result of a cast
116- //! from a non-zero integer literal.
117- //!
104+ //! Kani is able to verify #1, #2, and #3 today.
118105 kani_core:: kani_mem!( std) ;
119106 }
120107
0 commit comments