Skip to content

Using pointer::add with volatile memory #582

@Darksonn

Description

@Darksonn

When working with volatile memory it's common to do so entirely using raw pointers, making sure to never create a reference so that the volatile memory never gets considered a real allocation in the opsem.

The pointer::add method has these safety requirements:

If the computed offset is non-zero, then self must be derived from a pointer to some allocation, and the entire memory range between self and the result must be in bounds of that allocation. In particular, this range must not “wrap around” the edge of the address space.

The point of never creating a reference to the memory is to avoid assuming that there is a real allocation there. This is so that it's illegal for LLVM to introduce a spurious read to the volatile memory. From my reading of pointer::add it seems the same applies to that method.

However, this puts us in a somewhat tricky situation. It means that &raw mut (*volatile_ptr).field does not work for getting a pointer to a field of a struct in volatile memory, and the layout of volatile memory is often described by referring to an equivalent C struct. This is a challenge since there are no convenient alternatives to &raw mut.

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