From c3a809696a1fe97308785a562fb62b1c10e9b45c Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Tue, 26 Aug 2025 08:07:04 +0200 Subject: [PATCH] docs: add Safety section to unsafe functions This step was done manually by searching for "unsafe fn" in the code base and adding corresponding Safety sections. `clippy::missing_safety_doc` only works for public functions but none of the corresponding functions is public. Signed-off-by: Philipp Schuster On-behalf-of: SAP philipp.schuster@sap.com --- net_util/src/tap.rs | 9 +++++++++ vmm/src/clone3.rs | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/net_util/src/tap.rs b/net_util/src/tap.rs index 6d90293b8..533d6a45b 100644 --- a/net_util/src/tap.rs +++ b/net_util/src/tap.rs @@ -129,6 +129,9 @@ fn ipv6_mask_to_prefix(mask: Ipv6Addr) -> Result { } impl Tap { + /// # Safety + /// The caller should ensure to pass a valid file descriptor and valid + /// arguments for the `ioctl()` syscall. unsafe fn ioctl_with_mut_ref(fd: &F, req: c_ulong, arg: &mut T) -> Result<()> { let ret = ioctl_with_mut_ref(fd, req, arg); if ret < 0 { @@ -138,6 +141,9 @@ impl Tap { Ok(()) } + /// # Safety + /// The caller should ensure to pass a valid file descriptor and valid + /// arguments for the `ioctl()` syscall. unsafe fn ioctl_with_ref(fd: &F, req: c_ulong, arg: &T) -> Result<()> { let ret = ioctl_with_ref(fd, req, arg); if ret < 0 { @@ -147,6 +153,9 @@ impl Tap { Ok(()) } + /// # Safety + /// The caller should ensure to pass a valid file descriptor and valid + /// arguments for the `ioctl()` syscall. unsafe fn ioctl_with_val(fd: &F, req: c_ulong, arg: c_ulong) -> Result<()> { let ret = ioctl_with_val(fd, req, arg); if ret < 0 { diff --git a/vmm/src/clone3.rs b/vmm/src/clone3.rs index f08e5ad31..0ab08126e 100644 --- a/vmm/src/clone3.rs +++ b/vmm/src/clone3.rs @@ -22,6 +22,16 @@ pub struct clone_args { pub cgroup: u64, } +/// # Safety +/// `size` must have the proper size to match `args`. +/// Further, the caller needs to check the return value. +/// +/// # Return +/// - On success: +/// - Parent: child PID (`c_long`) +/// - Child: `0` +/// - On error: `-1` and `errno` is set +#[must_use] pub unsafe fn clone3(args: &mut clone_args, size: size_t) -> c_long { syscall(SYS_clone3, args, size) }