Skip to content

Commit

Permalink
Use getrandom_syscall in getrandom_available
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov authored Feb 21, 2024
1 parent 319a426 commit 94e6986
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions src/linux_android_with_fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
}

fn is_getrandom_available() -> bool {
let res = unsafe { getrandom(core::ptr::null_mut(), 0, libc::GRND_NONBLOCK) };
if res < 0 {
if getrandom_syscall(&[]) < 0 {
match last_os_error().raw_os_error() {
Some(libc::ENOSYS) => false, // No kernel support
Some(libc::EPERM) => false, // Blocked by seccomp
Expand All @@ -28,11 +27,3 @@ fn is_getrandom_available() -> bool {
true
}
}

unsafe fn getrandom(
buf: *mut libc::c_void,
buflen: libc::size_t,
flags: libc::c_uint,
) -> libc::ssize_t {
libc::syscall(libc::SYS_getrandom, buf, buflen, flags) as libc::ssize_t
}

0 comments on commit 94e6986

Please sign in to comment.