Skip to content

Commit 4882ac8

Browse files
authored
Add notes when various functions were added (#257)
Signed-off-by: Joe Richey <joerichey@google.com>
1 parent fcece06 commit 4882ac8

File tree

7 files changed

+7
-0
lines changed

7 files changed

+7
-0
lines changed

src/bsd_arandom.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ fn kern_arnd(buf: &mut [u8]) -> libc::ssize_t {
3131
}
3232

3333
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
34+
// getrandom(2) was introduces in FreeBSD 12.0 and NetBsd 10.0
3435
#[cfg(target_os = "freebsd")]
3536
{
3637
use crate::util_libc::Weak;

src/dragonfly.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
1717
static GETRANDOM: Weak = unsafe { Weak::new("getrandom\0") };
1818
type GetRandomFn = unsafe extern "C" fn(*mut u8, libc::size_t, libc::c_uint) -> libc::ssize_t;
1919

20+
// getrandom(2) was introduced in DragonflyBSD 5.7
2021
if let Some(fptr) = GETRANDOM.ptr() {
2122
let func: GetRandomFn = unsafe { core::mem::transmute(fptr) };
2223
return sys_fill_exact(dest, |buf| unsafe { func(buf.as_mut_ptr(), buf.len(), 0) });

src/linux_android.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::{
1414
};
1515

1616
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
17+
// getrandom(2) was introduced in Linux 3.17
1718
static HAS_GETRANDOM: LazyBool = LazyBool::new();
1819
if HAS_GETRANDOM.unsync_init(is_getrandom_available) {
1920
sys_fill_exact(dest, |buf| unsafe {

src/macos.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use core::mem;
1717
type GetEntropyFn = unsafe extern "C" fn(*mut u8, libc::size_t) -> libc::c_int;
1818

1919
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
20+
// getentropy(2) was added in 10.12, Rust supports 10.7+
2021
static GETENTROPY: Weak = unsafe { Weak::new("getentropy\0") };
2122
if let Some(fptr) = GETENTROPY.ptr() {
2223
let func: GetEntropyFn = unsafe { mem::transmute(fptr) };

src/openbsd.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use crate::{util_libc::last_os_error, Error};
1111

1212
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
13+
// getentropy(2) was added in OpenBSD 5.6, so we can use it unconditionally.
1314
for chunk in dest.chunks_mut(256) {
1415
let ret = unsafe { libc::getentropy(chunk.as_mut_ptr() as *mut libc::c_void, chunk.len()) };
1516
if ret == -1 {

src/solaris_illumos.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type GetRandomFn = unsafe extern "C" fn(*mut u8, libc::size_t, libc::c_uint) ->
3030
type GetRandomFn = unsafe extern "C" fn(*mut u8, libc::size_t, libc::c_uint) -> libc::c_int;
3131

3232
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
33+
// getrandom(2) was introduced in Solaris 11.3 for Illumos in 2015.
3334
static GETRANDOM: Weak = unsafe { Weak::new("getrandom\0") };
3435
if let Some(fptr) = GETRANDOM.ptr() {
3536
let func: GetRandomFn = unsafe { mem::transmute(fptr) };

src/windows.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ extern "system" {
2424
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
2525
// Prevent overflow of u32
2626
for chunk in dest.chunks_mut(u32::max_value() as usize) {
27+
// BCryptGenRandom was introduced in Windows Vista
2728
let ret = unsafe {
2829
BCryptGenRandom(
2930
ptr::null_mut(),

0 commit comments

Comments
 (0)