File tree 2 files changed +33
-0
lines changed
2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright 2018 Developers of the Rand project.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4
+ // https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5
+ // <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6
+ // option. This file may not be copied, modified, or distributed
7
+ // except according to those terms.
8
+
9
+ //! An implementation which calls out to an externally defined function.
10
+ use crate :: Error ;
11
+
12
+ /// Reister a function to be invoked by getrandom on custom targets. This macro
13
+ /// is only avalible on custom targets to prevent registering a function that
14
+ /// will not be called.
15
+ #[ macro_export]
16
+ macro_rules! register_custom_getrandom {
17
+ ( $path: path) => {
18
+ #[ no_mangle]
19
+ fn __getrandom_custom( dest: & mut [ u8 ] ) -> Result <( ) , Error > {
20
+ $path( dest)
21
+ }
22
+ } ;
23
+ }
24
+
25
+ pub fn getrandom_inner ( dest : & mut [ u8 ] ) -> Result < ( ) , Error > {
26
+ extern "Rust" {
27
+ #[ allow( improper_ctypes) ] // See rust-lang/rust#64593
28
+ fn __getrandom_custom ( dest : & mut [ u8 ] ) -> Result < ( ) , Error > ;
29
+ }
30
+ unsafe { __getrandom_custom ( dest) }
31
+ }
Original file line number Diff line number Diff line change @@ -230,6 +230,8 @@ cfg_if! {
230
230
target_env = "sgx" ,
231
231
) ) ) ] {
232
232
#[ path = "rdrand.rs" ] mod imp;
233
+ } else if #[ cfg( feature = "custom" ) ] {
234
+ #[ path = "custom.rs" ] mod imp;
233
235
} else {
234
236
compile_error!( "\
235
237
target is not supported, for more information see: \
You can’t perform that action at this time.
0 commit comments