Skip to content

Commit e4992d8

Browse files
committed
Use libc::SYS_getrandom
This has been in libc for a while, so we don't need to increment the libc version in Cargo.toml. Note that we cannot use the `getrandom()` function from libc, as it isn't avalible on Android.
1 parent a804615 commit e4992d8

2 files changed

Lines changed: 2 additions & 20 deletions

File tree

src/c.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,3 @@ pub(crate) type uint = libc::c_uint;
2828
any(target_arch = "aarch64", target_arch = "arm")
2929
))]
3030
pub(crate) type ulong = libc::c_ulong;
31-
32-
#[cfg(any(target_os = "android", target_os = "linux"))]
33-
pub(crate) type long = libc::c_long;

src/rand.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,26 +115,11 @@ use crate::sealed;
115115

116116
#[cfg(any(target_os = "android", target_os = "linux"))]
117117
mod sysrand_chunk {
118-
use crate::{c, error};
118+
use crate::error;
119119

120120
#[inline]
121121
pub fn chunk(dest: &mut [u8]) -> Result<usize, error::Unspecified> {
122-
// See `SYS_getrandom` in #include <sys/syscall.h>.
123-
124-
#[cfg(target_arch = "aarch64")]
125-
const SYS_GETRANDOM: c::long = 278;
126-
127-
#[cfg(target_arch = "arm")]
128-
const SYS_GETRANDOM: c::long = 384;
129-
130-
#[cfg(target_arch = "x86")]
131-
const SYS_GETRANDOM: c::long = 355;
132-
133-
#[cfg(target_arch = "x86_64")]
134-
const SYS_GETRANDOM: c::long = 318;
135-
136-
let chunk_len: c::size_t = dest.len();
137-
let r = unsafe { libc::syscall(SYS_GETRANDOM, dest.as_mut_ptr(), chunk_len, 0) };
122+
let r = unsafe { libc::syscall(libc::SYS_getrandom, dest.as_mut_ptr(), dest.len(), 0) };
138123
if r < 0 {
139124
let errno;
140125

0 commit comments

Comments
 (0)