Description
Rust's core::ptr
documentation currently says:
For a pointer to be valid, it is necessary, but not always sufficient, that the pointer be dereferenceable: the memory range of the given size starting at the pointer must all be within the bounds of a single allocated object.
This is difficult to satisfy when working with MMIO as well as when working across kernelspace:userspace boundaries. For example, the above constraint prevents a kernel from creating a valid pointer into userspace memory when the address range of the userspace memory is determined at runtime.
This leads to the following questions:
- Do we want to support such "fabricated" pointers? I think the consensus is yes, but it doesn't appear to be documented anywhere.
- How do bounds checks work for such pointers? Are they always in bounds as long as they do not overlap any compiler-allocated objects?
It's also unclear how this works for a malloc
written in Rust. Presumably, that allocator would get raw pointers from a system call like mmap
, but it would eventually return something like an "allocated object" the compiler does know about.