Skip to content

Wrapper type for memory address #241

@nazar-pc

Description

@nazar-pc

Right now memory addresses are represented by u32 (though maybe they shouldn't be), but not all addresses are actually usable.

It might be beneficial to create a new type that wraps the address value and enforces some invariants on it, like those mentioned in description of some functions:

/// Fills the given memory region with zeros.
///
/// `address` must be greater or equal to 0x10000 and `address + length` cannot be greater than 0x100000000.
/// If `length` is zero then this call has no effect and will always succeed.
///
/// When dynamic paging is enabled calling this can be used to resolve a segfault. It can also
/// be used to preemptively initialize pages for which no segfault is currently triggered.
pub fn zero_memory(&mut self, address: u32, length: u32) -> Result<(), MemoryAccessError> {

For example sbrk can return a proper address instance to begin with. Not entirely sure about all sources, but maybe it'll be possible to forbid direct casting of u32 to address, helping to make invalid addresses impossible to construct.

Similarly new type can be used to attach constants, again, like those shown above.

Essentially an type similar to usize but for VM's memory. Similarly length in many cases has similar constraints and could use a new type like isize.

If machine supports 64-bit addresses then the instance can be parametrized by const BITS: u8 and return/accept different address types.

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