Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requesting Feedback: WIP changes to rand.rs #846

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
josephlr committed Jun 14, 2019
commit e4992d89e0be8397e0002ce8884eeecd8a5a7124
3 changes: 0 additions & 3 deletions src/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,3 @@ pub(crate) type uint = libc::c_uint;
any(target_arch = "aarch64", target_arch = "arm")
))]
pub(crate) type ulong = libc::c_ulong;

#[cfg(any(target_os = "android", target_os = "linux"))]
pub(crate) type long = libc::c_long;
19 changes: 2 additions & 17 deletions src/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,26 +115,11 @@ use crate::sealed;

#[cfg(any(target_os = "android", target_os = "linux"))]
mod sysrand_chunk {
use crate::{c, error};
use crate::error;

#[inline]
pub fn chunk(dest: &mut [u8]) -> Result<usize, error::Unspecified> {
// 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(), dest.len(), 0) };
if r < 0 {
let errno;

Expand Down