Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ jobs:
strategy:
matrix:
target: [
x86_64-fuchsia,
x86_64-unknown-fuchsia,
x86_64-unknown-redox,
x86_64-fortanix-unknown-sgx,
]
Expand Down
24 changes: 15 additions & 9 deletions src/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,22 @@ use core::{mem::MaybeUninit, num::NonZeroU32};
#[cfg_attr(docsrs, doc(cfg(feature = "custom")))]
macro_rules! register_custom_getrandom {
($path:path) => {
// We use an extern "C" function to get the guarantees of a stable ABI.
#[no_mangle]
extern "C" fn __getrandom_custom(dest: *mut u8, len: usize) -> u32 {
let f: fn(&mut [u8]) -> Result<(), $crate::Error> = $path;
let slice = unsafe { ::core::slice::from_raw_parts_mut(dest, len) };
match f(slice) {
Ok(()) => 0,
Err(e) => e.code().get(),
// TODO(MSRV 1.37): change to unnamed block
const __getrandom_internal: () = {
// We use an extern "C" function to get the guarantees of a stable ABI.
#[no_mangle]
unsafe extern "C" fn __getrandom_custom(dest: *mut u8, len: usize) -> u32 {
// Make sure the passed function has the type of getrandom::getrandom
type F = fn(&mut [u8]) -> ::core::result::Result<(), $crate::Error>;
let _: F = $crate::getrandom;
let f: F = $path;
let slice = ::core::slice::from_raw_parts_mut(dest, len);
match f(slice) {
Ok(()) => 0,
Err(e) => e.code().get(),
}
}
}
};
};
}

Expand Down