Skip to content

Commit ce3b017

Browse files
authored
Add #[inline] attribute to the inner functions (#596)
1 parent e4dcbbc commit ce3b017

22 files changed

+51
-13
lines changed

src/backends/apple_other.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use core::{ffi::c_void, mem::MaybeUninit};
44

55
pub use crate::util::{inner_u32, inner_u64};
66

7+
#[inline]
78
pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
89
let dst_ptr = dest.as_mut_ptr().cast::<c_void>();
910
let ret = unsafe { libc::CCRandomGenerateBytes(dst_ptr, dest.len()) };

src/backends/custom.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use core::mem::MaybeUninit;
44

55
pub use crate::util::{inner_u32, inner_u64};
66

7+
#[inline]
78
pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
89
extern "Rust" {
910
fn __getrandom_v03_custom(dest: *mut u8, len: usize) -> Result<(), Error>;

src/backends/esp_idf.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ extern "C" {
88
fn esp_fill_random(buf: *mut c_void, len: usize) -> u32;
99
}
1010

11+
#[inline]
1112
pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
1213
// Not that NOT enabling WiFi, BT, or the voltage noise entropy source (via `bootloader_random_enable`)
1314
// will cause ESP-IDF to return pseudo-random numbers based on the voltage noise entropy, after the initial boot process:

src/backends/fuchsia.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ extern "C" {
99
fn zx_cprng_draw(buffer: *mut u8, length: usize);
1010
}
1111

12+
#[inline]
1213
pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
1314
unsafe { zx_cprng_draw(dest.as_mut_ptr().cast::<u8>(), dest.len()) }
1415
Ok(())

src/backends/getentropy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub use crate::util::{inner_u32, inner_u64};
1515
#[path = "../util_libc.rs"]
1616
mod util_libc;
1717

18+
#[inline]
1819
pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
1920
for chunk in dest.chunks_mut(256) {
2021
let ret = unsafe { libc::getentropy(chunk.as_mut_ptr().cast::<c_void>(), chunk.len()) };

src/backends/getrandom.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub use crate::util::{inner_u32, inner_u64};
2323
#[path = "../util_libc.rs"]
2424
mod util_libc;
2525

26+
#[inline]
2627
pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
2728
util_libc::sys_fill_exact(dest, |buf| unsafe {
2829
libc::getrandom(buf.as_mut_ptr().cast::<c_void>(), buf.len(), 0)

src/backends/hermit.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ extern "C" {
1212
fn sys_secure_rand64(value: *mut u64) -> i32;
1313
}
1414

15+
#[inline]
1516
pub fn inner_u32() -> Result<u32, Error> {
1617
let mut res = MaybeUninit::uninit();
1718
let ret = unsafe { sys_secure_rand32(res.as_mut_ptr()) };
@@ -22,6 +23,7 @@ pub fn inner_u32() -> Result<u32, Error> {
2223
}
2324
}
2425

26+
#[inline]
2527
pub fn inner_u64() -> Result<u64, Error> {
2628
let mut res = MaybeUninit::uninit();
2729
let ret = unsafe { sys_secure_rand64(res.as_mut_ptr()) };
@@ -32,6 +34,7 @@ pub fn inner_u64() -> Result<u64, Error> {
3234
}
3335
}
3436

37+
#[inline]
3538
pub fn fill_inner(mut dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
3639
while !dest.is_empty() {
3740
let res = unsafe { sys_read_entropy(dest.as_mut_ptr().cast::<u8>(), dest.len(), 0) };

src/backends/linux_android.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod util_libc;
1010
#[cfg(not(any(target_os = "android", target_os = "linux")))]
1111
compile_error!("`linux_getrandom` backend can be enabled only for Linux/Android targets!");
1212

13+
#[inline]
1314
pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
1415
util_libc::sys_fill_exact(dest, |buf| unsafe {
1516
libc::getrandom(buf.as_mut_ptr().cast(), buf.len(), 0)

src/backends/linux_android_with_fallback.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const NOT_AVAILABLE: NonNull<c_void> = unsafe { NonNull::new_unchecked(usize::MA
2020
static GETRANDOM_FN: AtomicPtr<c_void> = AtomicPtr::new(ptr::null_mut());
2121

2222
#[cold]
23+
#[inline(never)]
2324
fn init() -> NonNull<c_void> {
2425
static NAME: &[u8] = b"getrandom\0";
2526
let name_ptr = NAME.as_ptr().cast::<libc::c_char>();
@@ -59,6 +60,7 @@ fn use_file_fallback(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
5960
use_file::fill_inner(dest)
6061
}
6162

63+
#[inline]
6264
pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
6365
// Despite being only a single atomic variable, we still cannot always use
6466
// Ordering::Relaxed, as we need to make sure a successful call to `init`
@@ -75,7 +77,7 @@ pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
7577
if fptr == NOT_AVAILABLE {
7678
use_file_fallback(dest)
7779
} else {
78-
// note: `transume` is currently the only way to convert pointer into function reference
80+
// note: `transmute` is currently the only way to convert a pointer into a function reference
7981
let getrandom_fn = unsafe { mem::transmute::<NonNull<c_void>, GetRandomFn>(fptr) };
8082
util_libc::sys_fill_exact(dest, |buf| unsafe {
8183
getrandom_fn(buf.as_mut_ptr().cast(), buf.len(), 0)

src/backends/netbsd.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type GetRandomFn = unsafe extern "C" fn(*mut c_void, libc::size_t, libc::c_uint)
4545
static GETRANDOM: AtomicPtr<c_void> = AtomicPtr::new(ptr::null_mut());
4646

4747
#[cold]
48+
#[inline(never)]
4849
fn init() -> *mut c_void {
4950
static NAME: &[u8] = b"getrandom\0";
5051
let name_ptr = NAME.as_ptr().cast::<libc::c_char>();
@@ -58,6 +59,7 @@ fn init() -> *mut c_void {
5859
ptr
5960
}
6061

62+
#[inline]
6163
pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
6264
// Despite being only a single atomic variable, we still cannot always use
6365
// Ordering::Relaxed, as we need to make sure a successful call to `init`

0 commit comments

Comments
 (0)