sel4_externally_shared/ops/
zerocopy_ops.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// Copyright 2023, Colias Group, LLC
//
// SPDX-License-Identifier: BSD-2-Clause
//

use core::marker::PhantomData;

use volatile::ops::{BulkOps, Ops, UnitaryOps};
use zerocopy::{FromBytes, IntoBytes};

#[derive(Default, Copy, Clone)]
pub struct ZerocopyOps<O> {
    _phantom: PhantomData<O>,
}

impl<O: Ops> Ops for ZerocopyOps<O> {}

impl<O: UnitaryOps<T>, T: FromBytes + IntoBytes> UnitaryOps<T> for ZerocopyOps<O> {
    unsafe fn read(src: *const T) -> T {
        unsafe { O::read(src) }
    }

    unsafe fn write(dst: *mut T, src: T) {
        unsafe { O::write(dst, src) }
    }
}

impl<O: BulkOps<T>, T: FromBytes + IntoBytes> BulkOps<T> for ZerocopyOps<O> {
    unsafe fn memmove(dst: *mut T, src: *const T, count: usize) {
        unsafe { O::memmove(dst, src, count) }
    }

    unsafe fn memcpy(dst: *mut T, src: *const T, count: usize) {
        unsafe { O::memcpy(dst, src, count) }
    }

    unsafe fn memset(dst: *mut T, val: u8, count: usize) {
        unsafe { O::memset(dst, val, count) }
    }
}