Skip to content

Commit b94d61e

Browse files
committed
Linux: Use libc::SYS_getrandom for syscall number.
Instead of maintaining our own implementation, just defer to libc. This will enable ports to more architectures.
1 parent e898b00 commit b94d61e

File tree

1 file changed

+1
-17
lines changed

1 file changed

+1
-17
lines changed

src/rand.rs

+1-17
Original file line numberDiff line numberDiff line change
@@ -201,24 +201,8 @@ mod sysrand_chunk {
201201

202202
#[inline]
203203
pub fn chunk(dest: &mut [u8]) -> Result<usize, error::Unspecified> {
204-
use libc::c_long;
205-
206-
// See `SYS_getrandom` in #include <sys/syscall.h>.
207-
208-
#[cfg(target_arch = "aarch64")]
209-
const SYS_GETRANDOM: c_long = 278;
210-
211-
#[cfg(target_arch = "arm")]
212-
const SYS_GETRANDOM: c_long = 384;
213-
214-
#[cfg(target_arch = "x86")]
215-
const SYS_GETRANDOM: c_long = 355;
216-
217-
#[cfg(target_arch = "x86_64")]
218-
const SYS_GETRANDOM: c_long = 318;
219-
220204
let chunk_len: c::size_t = dest.len();
221-
let r = unsafe { libc::syscall(SYS_GETRANDOM, dest.as_mut_ptr(), chunk_len, 0) };
205+
let r = unsafe { libc::syscall(libc::SYS_getrandom, dest.as_mut_ptr(), chunk_len, 0) };
222206
if r < 0 {
223207
let errno;
224208

0 commit comments

Comments
 (0)