File tree 4 files changed +22
-4
lines changed
4 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -106,6 +106,7 @@ matrix:
106
106
- rustup target add x86_64-unknown-netbsd
107
107
- rustup target add x86_64-unknown-redox
108
108
- rustup target add x86_64-fortanix-unknown-sgx
109
+ - cargo install cargo-xbuild # For no_std targets
109
110
script :
110
111
- cargo build --target=x86_64-sun-solaris --all-features
111
112
- cargo build --target=x86_64-unknown-cloudabi --all-features
@@ -114,6 +115,7 @@ matrix:
114
115
- cargo build --target=x86_64-unknown-netbsd --all-features
115
116
- cargo build --target=x86_64-unknown-redox --all-features
116
117
- cargo build --target=x86_64-fortanix-unknown-sgx --all-features
118
+ - cargo xbuild --target=x86_64-unknown-uefi
117
119
# also test minimum dependency versions are usable
118
120
- cargo generate-lockfile -Z minimal-versions
119
121
- cargo build --target=x86_64-sun-solaris --all-features
@@ -123,6 +125,7 @@ matrix:
123
125
- cargo build --target=x86_64-unknown-netbsd --all-features
124
126
- cargo build --target=x86_64-unknown-redox --all-features
125
127
- cargo build --target=x86_64-fortanix-unknown-sgx --all-features
128
+ - cargo xbuild --target=x86_64-unknown-uefi
126
129
127
130
# Trust cross-built/emulated targets. We must repeat all non-default values.
128
131
- rust : stable
Original file line number Diff line number Diff line change @@ -39,5 +39,8 @@ stdweb = { version = "0.4.9", optional = true }
39
39
[target .wasm32-wasi .dependencies ]
40
40
libc = " 0.2.54"
41
41
42
+ [target .'cfg(any(target_env = "sgx", target_os = "uefi"))' .dependencies ]
43
+ lazy_static = { version = " 1.3.0" , features = [" spin_no_std" ] }
44
+
42
45
[features ]
43
46
std = []
Original file line number Diff line number Diff line change @@ -190,6 +190,7 @@ mod_use!(cfg(target_os = "redox"), use_file);
190
190
mod_use ! ( cfg( target_os = "solaris" ) , solaris_illumos) ;
191
191
mod_use ! ( cfg( windows) , windows) ;
192
192
mod_use ! ( cfg( target_env = "sgx" ) , rdrand) ;
193
+ mod_use ! ( cfg( target_os = "uefi" ) , rdrand) ;
193
194
mod_use ! ( cfg( target_os = "wasi" ) , wasi) ;
194
195
195
196
mod_use ! (
@@ -231,6 +232,7 @@ mod_use!(
231
232
target_os = "openbsd" ,
232
233
target_os = "redox" ,
233
234
target_os = "solaris" ,
235
+ target_os = "uefi" ,
234
236
target_env = "sgx" ,
235
237
windows,
236
238
all(
Original file line number Diff line number Diff line change 9
9
//! Implementation for SGX using RDRAND instruction
10
10
use crate :: Error ;
11
11
use core:: mem;
12
- use core:: arch:: x86_64:: _rdrand64_step;
12
+ use core:: arch:: x86_64:: { __cpuid , _rdrand64_step} ;
13
13
use core:: num:: NonZeroU32 ;
14
-
15
- #[ cfg( not( target_feature = "rdrand" ) ) ]
16
- compile_error ! ( "enable rdrand target feature!" ) ;
14
+ use lazy_static:: lazy_static;
17
15
18
16
// Recommendation from "Intel® Digital Random Number Generator (DRNG) Software
19
17
// Implementation Guide" - Section 5.2.1 and "Intel® 64 and IA-32 Architectures
@@ -35,7 +33,19 @@ fn rdrand() -> Result<[u8; WORD_SIZE], Error> {
35
33
Err ( Error :: UNKNOWN )
36
34
}
37
35
36
+ fn cpuid_check ( ) -> bool {
37
+ const FEATURE_INFO_LEAF : u32 = 1 ;
38
+ const RDRAND_FLAG : u32 = 1 << 30 ;
39
+ // SAFETY: All platforms with CPUID support leaf 1
40
+ unsafe { __cpuid ( FEATURE_INFO_LEAF ) . ecx & RDRAND_FLAG != 0 }
41
+ }
42
+
38
43
pub fn getrandom_inner ( dest : & mut [ u8 ] ) -> Result < ( ) , Error > {
44
+ lazy_static ! { static ref HAS_RDRAND : bool = cpuid_check( ) ; }
45
+ if cfg ! ( not( target_feature = "rdrand" ) ) && !* HAS_RDRAND {
46
+ return Err ( Error :: UNAVAILABLE ) ;
47
+ }
48
+
39
49
// We use chunks_exact_mut instead of chunks_mut as it allows almost all
40
50
// calls to memcpy to be elided by the compiler.
41
51
let mut chunks = dest. chunks_exact_mut ( WORD_SIZE ) ;
You can’t perform that action at this time.
0 commit comments