From 90b24d4e8138c93fec93ef4a4ec0ad8b1c98e0b7 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Fri, 31 May 2024 16:45:00 -0700 Subject: [PATCH] util_libc: Add a note about the x32 ABI. --- src/util_libc.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util_libc.rs b/src/util_libc.rs index 4f1b05e3..696bd9e4 100644 --- a/src/util_libc.rs +++ b/src/util_libc.rs @@ -110,8 +110,6 @@ pub fn getrandom_syscall(buf: &mut [MaybeUninit]) -> libc::ssize_t { // no real truncation here, even when running debug_assert!(buf.len() <= isize::MAX.unsigned_abs()); - // TODO: Add support for x32 and similar ABIs? - // pointers can be passed to libc::syscall. const _: () = assert!( core::mem::size_of::() == core::mem::size_of::<*mut core::ffi::c_void>() @@ -125,6 +123,8 @@ pub fn getrandom_syscall(buf: &mut [MaybeUninit]) -> libc::ssize_t { const ZERO: libc::c_ulong = 0; + // Note that the `libc` crate adds `__X32_SYSCALL_BIT` for x32 targets. + let res: libc::c_long = unsafe { libc::syscall(libc::SYS_getrandom, ptr, len, ZERO) }; // c_long to ssize_t conversion is lossless.