Skip to content

Validity of pointers and references to memory not allocated by the compiler #285

Open
@jrvanwhy

Description

@jrvanwhy

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:

  1. Do we want to support such "fabricated" pointers? I think the consensus is yes, but it doesn't appear to be documented anywhere.
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions