File tree 5 files changed +48
-7
lines changed
5 files changed +48
-7
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ appveyor = { repository = "rust-random/getrandom" }
16
16
17
17
[workspace ]
18
18
members = [
19
+ " custom/cpurand" ,
19
20
" custom/stdweb" ,
20
21
" custom/wasm-bindgen" ,
21
22
]
Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " cpurand-getrandom"
3
+ version = " 0.1.0"
4
+ edition = " 2018"
5
+ authors = [" The Rand Project Developers" ]
6
+ license = " MIT OR Apache-2.0"
7
+ description = " Custom shim for using getrandom with CPU RNG instructions"
8
+ documentation = " https://docs.rs/cpurand-getrandom"
9
+ repository = " https://github.com/rust-random/getrandom"
10
+ categories = [" hardware-support" , " no-std" ]
11
+
12
+ [dependencies ]
13
+ cfg-if = " 0.1.2"
14
+ getrandom = { path = " ../.." , version = " 0.2" , features = [" custom" ] }
15
+
16
+ [[test ]]
17
+ name = " common"
18
+ path = " ../../tests/common.rs"
19
+
20
+ [package .metadata .docs .rs ]
21
+ default-target = " x86_64-unknown-linux"
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
+ #![ no_std]
9
+
10
+ #[ macro_use]
11
+ extern crate cfg_if;
12
+
13
+ use getrandom:: { register_custom_getrandom, Error } ;
14
+
15
+ cfg_if ! {
16
+ if #[ cfg( target_arch = "x86_64" ) ] {
17
+ #[ path = "../../../src/util.rs" ] mod util;
18
+ #[ path = "../../../src/rdrand.rs" ] mod imp;
19
+ } else {
20
+ compile_error!( "CPU-based randomness is not supported for this arch" ) ;
21
+ }
22
+ }
23
+
24
+ register_custom_getrandom ! ( imp:: getrandom_inner) ;
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ macro_rules! register_custom_getrandom {
23
23
// We use an extern "C" function to get the guarantees of a stable ABI.
24
24
#[ no_mangle]
25
25
extern "C" fn __getrandom_custom( dest: * mut u8 , len: usize ) -> u32 {
26
- let slice = unsafe { :: std :: slice:: from_raw_parts_mut( dest, len) } ;
26
+ let slice = unsafe { :: core :: slice:: from_raw_parts_mut( dest, len) } ;
27
27
match $path( slice) {
28
28
Ok ( ( ) ) => 0 ,
29
29
Err ( e) => e. code( ) . get( ) ,
Original file line number Diff line number Diff line change @@ -183,12 +183,7 @@ cfg_if! {
183
183
#[ path = "windows_uwp.rs" ] mod imp;
184
184
} else if #[ cfg( windows) ] {
185
185
#[ path = "windows.rs" ] mod imp;
186
- } else if #[ cfg( all( target_arch = "x86_64" , any(
187
- target_os = "hermit" ,
188
- target_os = "l4re" ,
189
- target_os = "uefi" ,
190
- target_env = "sgx" ,
191
- ) ) ) ] {
186
+ } else if #[ cfg( all( target_arch = "x86_64" , target_env = "sgx" ) ) ] {
192
187
#[ path = "rdrand.rs" ] mod imp;
193
188
} else if #[ cfg( feature = "custom" ) ] {
194
189
use custom as imp;
You can’t perform that action at this time.
0 commit comments