File tree Expand file tree Collapse file tree 4 files changed +33
-6
lines changed Expand file tree Collapse file tree 4 files changed +33
-6
lines changed Original file line number Diff line number Diff line change @@ -2949,7 +2949,7 @@ dependencies = [
2949
2949
[[package ]]
2950
2950
name = " r-efi"
2951
2951
version = " 4.0.0"
2952
- source = " git+https://github.com/r-efi/r-efi#cfa10bdfe46f2f283d2a93f179c6feb699c4b58a "
2952
+ source = " git+https://github.com/r-efi/r-efi#30e0e8b8552179e1cc7f054a8b64f243db7c9bee "
2953
2953
dependencies = [
2954
2954
" compiler_builtins" ,
2955
2955
" rustc-std-workspace-core" ,
Original file line number Diff line number Diff line change @@ -48,7 +48,8 @@ pub fn get_runtime_services() -> Option<NonNull<RuntimeServices>> {
48
48
NonNull :: new ( runtime_services)
49
49
}
50
50
51
- pub ( crate ) fn open_protocol < T > (
51
+ #[ unstable( feature = "uefi_std" , issue = "none" ) ]
52
+ pub fn open_protocol < T > (
52
53
handle : NonNull < c_void > ,
53
54
mut protocol_guid : Guid ,
54
55
) -> io:: Result < NonNull < T > > {
@@ -77,7 +78,8 @@ pub(crate) fn open_protocol<T>(
77
78
}
78
79
}
79
80
80
- pub ( crate ) fn locate_handles ( mut guid : Guid ) -> io:: Result < Vec < NonNull < c_void > > > {
81
+ #[ unstable( feature = "uefi_std" , issue = "none" ) ]
82
+ pub fn locate_handles ( mut guid : Guid ) -> io:: Result < Vec < NonNull < c_void > > > {
81
83
fn inner (
82
84
guid : & mut Guid ,
83
85
boot_services : NonNull < BootServices > ,
Original file line number Diff line number Diff line change 1
1
//! This module just re-exports stuff from r-efi crate
2
2
3
- pub use r_efi:: efi:: { BootServices , RuntimeServices , SystemTable } ;
3
+ pub use r_efi:: efi:: { BootServices , Guid , RuntimeServices , SystemTable } ;
4
4
5
5
use crate :: alloc:: { Allocator , Global , Layout } ;
6
6
use crate :: io;
Original file line number Diff line number Diff line change @@ -117,9 +117,34 @@ pub extern "C" fn __rust_abort() {
117
117
abort_internal ( ) ;
118
118
}
119
119
120
- // FIXME: Use EFI_RNG_PROTOCOL
121
120
pub fn hashmap_random_keys ( ) -> ( u64 , u64 ) {
122
- ( 1 , 2 )
121
+ unsafe { ( get_random ( ) . unwrap_or ( 1 ) , get_random ( ) . unwrap_or ( 2 ) ) }
122
+ }
123
+
124
+ unsafe fn get_random ( ) -> Option < u64 > {
125
+ use r_efi:: protocols:: rng;
126
+
127
+ let mut buf = [ 0u8 ; 8 ] ;
128
+ let handles = uefi:: env:: locate_handles ( rng:: PROTOCOL_GUID ) . ok ( ) ?;
129
+ for handle in handles {
130
+ if let Ok ( protocol) = uefi:: env:: open_protocol :: < rng:: Protocol > ( handle, rng:: PROTOCOL_GUID )
131
+ {
132
+ let r = unsafe {
133
+ ( ( * protocol. as_ptr ( ) ) . get_rng ) (
134
+ protocol. as_ptr ( ) ,
135
+ crate :: ptr:: null_mut ( ) ,
136
+ buf. len ( ) ,
137
+ buf. as_mut_ptr ( ) ,
138
+ )
139
+ } ;
140
+ if r. is_error ( ) {
141
+ continue ;
142
+ } else {
143
+ return Some ( u64:: from_le_bytes ( buf) ) ;
144
+ }
145
+ }
146
+ }
147
+ None
123
148
}
124
149
125
150
extern "C" {
You can’t perform that action at this time.
0 commit comments