Make raw commands unsafe
diff --git a/src/syscalls/mod.rs b/src/syscalls/mod.rs index 7c5377a..4cbef0f 100644 --- a/src/syscalls/mod.rs +++ b/src/syscalls/mod.rs
@@ -89,7 +89,7 @@ arg1: usize, arg2: usize, ) -> Result<usize, CommandError> { - let return_code = raw::command(driver_number, command_number, arg1, arg2); + let return_code = unsafe { raw::command(driver_number, command_number, arg1, arg2) }; if return_code >= 0 { Ok(return_code as usize) } else {
diff --git a/src/syscalls/platform_arm.rs b/src/syscalls/platform_arm.rs index cf0048e..4ff146a 100644 --- a/src/syscalls/platform_arm.rs +++ b/src/syscalls/platform_arm.rs
@@ -48,15 +48,15 @@ } #[inline(always)] -pub fn command(major: usize, minor: usize, arg1: usize, arg2: usize) -> isize { - unsafe { - let res; - asm!("svc 2" : "={r0}"(res) +// Justification: documentation is generated from mocks +#[allow(clippy::missing_safety_doc)] +pub unsafe fn command(major: usize, minor: usize, arg1: usize, arg2: usize) -> isize { + let res; + asm!("svc 2" : "={r0}"(res) : "{r0}"(major) "{r1}"(minor) "{r2}"(arg1) "{r3}"(arg2) : "memory" : "volatile"); - res - } + res } #[inline(always)]
diff --git a/src/syscalls/platform_mock.rs b/src/syscalls/platform_mock.rs index e8e026f..30c528f 100644 --- a/src/syscalls/platform_mock.rs +++ b/src/syscalls/platform_mock.rs
@@ -16,7 +16,10 @@ unimplemented() } -pub fn command(_: usize, _: usize, _: usize, _: usize) -> isize { +/// Send a command to the tock kernel +/// # Safety +/// This function usually involves assembly calls which are unsafe. +pub unsafe fn command(_: usize, _: usize, _: usize, _: usize) -> isize { unimplemented() }
diff --git a/src/syscalls/platform_riscv32.rs b/src/syscalls/platform_riscv32.rs index 7985545..88ddeec 100644 --- a/src/syscalls/platform_riscv32.rs +++ b/src/syscalls/platform_riscv32.rs
@@ -33,17 +33,17 @@ } #[inline(always)] -pub fn command(major: usize, minor: usize, arg1: usize, arg2: usize) -> isize { - unsafe { - let res; - asm!("li a0, 2 +// Justification: documentation is generated from mocks +#[allow(clippy::missing_safety_doc)] +pub unsafe fn command(major: usize, minor: usize, arg1: usize, arg2: usize) -> isize { + let res; + asm!("li a0, 2 ecall" : "={x10}" (res) : "{x11}" (major), "{x12}" (minor), "{x13}" (arg1), "{x14}" (arg2) : "memory" : "volatile"); - res - } + res } #[inline(always)]