Skip to content

Commit 41cc07a

Browse files
authored
Switch the custom backend to Rust ABI (#347)
Closes #345 This change makes the code safe against potential panics in custom functions.
1 parent 2f9989f commit 41cc07a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/custom.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ macro_rules! register_custom_getrandom {
7878
($path:path) => {
7979
// TODO(MSRV 1.37): change to unnamed block
8080
const __getrandom_internal: () = {
81-
// We use an extern "C" function to get the guarantees of a stable ABI.
81+
// We use Rust ABI to be safe against potential panics in the passed function.
8282
#[no_mangle]
83-
unsafe extern "C" fn __getrandom_custom(dest: *mut u8, len: usize) -> u32 {
83+
unsafe fn __getrandom_custom(dest: *mut u8, len: usize) -> u32 {
8484
// Make sure the passed function has the type of getrandom::getrandom
8585
type F = fn(&mut [u8]) -> ::core::result::Result<(), $crate::Error>;
8686
let _: F = $crate::getrandom;
@@ -97,7 +97,7 @@ macro_rules! register_custom_getrandom {
9797

9898
#[allow(dead_code)]
9999
pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
100-
extern "C" {
100+
extern "Rust" {
101101
fn __getrandom_custom(dest: *mut u8, len: usize) -> u32;
102102
}
103103
// Previously we always passed a valid, initialized slice to

0 commit comments

Comments
 (0)