Skip to content

Commit

Permalink
Linux: Use libc::SYS_getrandom for syscall number.
Browse files Browse the repository at this point in the history
Instead of maintaining our own implementation, just defer to libc.

This will enable ports to more architectures.
  • Loading branch information
briansmith committed May 3, 2021
1 parent e898b00 commit b94d61e
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions src/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,24 +201,8 @@ mod sysrand_chunk {

#[inline]
pub fn chunk(dest: &mut [u8]) -> Result<usize, error::Unspecified> {
use libc::c_long;

// See `SYS_getrandom` in #include <sys/syscall.h>.

#[cfg(target_arch = "aarch64")]
const SYS_GETRANDOM: c_long = 278;

#[cfg(target_arch = "arm")]
const SYS_GETRANDOM: c_long = 384;

#[cfg(target_arch = "x86")]
const SYS_GETRANDOM: c_long = 355;

#[cfg(target_arch = "x86_64")]
const SYS_GETRANDOM: c_long = 318;

let chunk_len: c::size_t = dest.len();
let r = unsafe { libc::syscall(SYS_GETRANDOM, dest.as_mut_ptr(), chunk_len, 0) };
let r = unsafe { libc::syscall(libc::SYS_getrandom, dest.as_mut_ptr(), chunk_len, 0) };
if r < 0 {
let errno;

Expand Down

0 comments on commit b94d61e

Please sign in to comment.