Skip to content

Commit c4496bd

Browse files
committed
Explicitly specify types to arguments of 'libc::syscall'
The 'libc::syscall' function uses varargs - as a result, its arguments are completely untyped. THe user must ensure that it is called with the proper types for the targeted syscall - otherwise, the calling convention might cause arguments to be put into the wrong registers. This commit explicitly casts the arguments to 'libc::syscall' to the proper type for the 'getrandom' syscall. This ensures that the correct types for the target platform will always be used, instead of relying on the types used happening to match those required by the target platform.
1 parent ab44edf commit c4496bd

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/linux_android.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,21 @@ pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
1515
static HAS_GETRANDOM: LazyBool = LazyBool::new();
1616
if HAS_GETRANDOM.unsync_init(is_getrandom_available) {
1717
sys_fill_exact(dest, |buf| unsafe {
18-
libc::syscall(libc::SYS_getrandom, buf.as_mut_ptr(), buf.len(), 0) as libc::ssize_t
18+
libc::syscall(libc::SYS_getrandom,
19+
buf.as_mut_ptr() as *mut libc::c_void,
20+
buf.len() as libc::size_t,
21+
0 as libc::c_uint) as libc::ssize_t
1922
})
2023
} else {
2124
use_file::getrandom_inner(dest)
2225
}
2326
}
2427

2528
fn is_getrandom_available() -> bool {
26-
let res = unsafe { libc::syscall(libc::SYS_getrandom, 0, 0, libc::GRND_NONBLOCK) };
29+
let res = unsafe { libc::syscall(libc::SYS_getrandom,
30+
0 as *mut libc::c_void,
31+
0 as libc::size_t,
32+
libc::GRND_NONBLOCK as libc::c_uint) };
2733
if res < 0 {
2834
match last_os_error().raw_os_error() {
2935
Some(libc::ENOSYS) => false, // No kernel support

0 commit comments

Comments
 (0)