Sha256: 12d0fb4d4f45097bf2c14f73cb1ce21325eae193b537e9f18af73ed5281b5e63

Contents?: true

Size: 1.11 KB

Versions: 19

Compression:

Stored size: 1.11 KB

Contents

use core::ptr::{read_volatile, write_volatile, addr_of, addr_of_mut};
use core::mem::MaybeUninit;
use core::ops::{BitAnd, BitOr, Not};

use super::io::Io;

#[repr(packed)]
pub struct Mmio<T> {
    value: MaybeUninit<T>,
}

impl<T> Mmio<T> {
    /// Create a new Mmio without initializing
    #[deprecated = "unsound because it's possible to read even though it's uninitialized"]
    pub fn new() -> Self {
        unsafe { Self::uninit() }
    }
    pub unsafe fn zeroed() -> Self {
        Self {
            value: MaybeUninit::zeroed(),
        }
    }
    pub unsafe fn uninit() -> Self {
        Self {
            value: MaybeUninit::uninit(),
        }
    }
    pub const fn from(value: T) -> Self {
        Self {
            value: MaybeUninit::new(value),
        }
    }
}

impl<T> Io for Mmio<T> where T: Copy + PartialEq + BitAnd<Output = T> + BitOr<Output = T> + Not<Output = T> {
    type Value = T;

    fn read(&self) -> T {
        unsafe { read_volatile(addr_of!(self.value).cast::<T>()) }
    }

    fn write(&mut self, value: T) {
        unsafe { write_volatile(addr_of_mut!(self.value).cast::<T>(), value) };
    }
}

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
wasmtime-14.0.4 ./ext/cargo-vendor/redox_syscall-0.2.16/src/io/mmio.rs
wasmtime-14.0.3 ./ext/cargo-vendor/redox_syscall-0.2.16/src/io/mmio.rs
wasmtime-14.0.1 ./ext/cargo-vendor/redox_syscall-0.2.16/src/io/mmio.rs
wasmtime-14.0.0 ./ext/cargo-vendor/redox_syscall-0.2.16/src/io/mmio.rs
wasmtime-13.0.0 ./ext/cargo-vendor/redox_syscall-0.2.16/src/io/mmio.rs
wasmtime-12.0.1 ./ext/cargo-vendor/redox_syscall-0.2.16/src/io/mmio.rs
wasmtime-12.0.0 ./ext/cargo-vendor/redox_syscall-0.2.16/src/io/mmio.rs
wasmtime-11.0.0 ./ext/cargo-vendor/redox_syscall-0.2.16/src/io/mmio.rs
wasmtime-10.0.1 ./ext/cargo-vendor/redox_syscall-0.2.16/src/io/mmio.rs
wasmtime-10.0.0 ./ext/cargo-vendor/redox_syscall-0.2.16/src/io/mmio.rs
wasmtime-9.0.4 ./ext/cargo-vendor/redox_syscall-0.2.16/src/io/mmio.rs
wasmtime-9.0.1 ./ext/cargo-vendor/redox_syscall-0.2.16/src/io/mmio.rs
wasmtime-8.0.0 ./ext/cargo-vendor/redox_syscall-0.2.16/src/io/mmio.rs
wasmtime-7.0.0 ./ext/cargo-vendor/redox_syscall-0.2.16/src/io/mmio.rs
wasmtime-6.0.1 ./ext/cargo-vendor/redox_syscall-0.2.16/src/io/mmio.rs
wasmtime-6.0.0 ./ext/cargo-vendor/redox_syscall-0.2.16/src/io/mmio.rs
wasmtime-5.0.0 ./ext/cargo-vendor/redox_syscall-0.2.16/src/io/mmio.rs
wasmtime-0.4.1 ./ext/cargo-vendor/redox_syscall-0.2.16/src/io/mmio.rs
wasmtime-0.4.0 ./ext/cargo-vendor/redox_syscall-0.2.16/src/io/mmio.rs