File tree 1 file changed +12
-6
lines changed
uefi-test-runner/src/boot
1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change 1
1
use core:: ffi:: c_void;
2
2
use core:: ptr:: NonNull ;
3
3
4
- use uefi:: proto:: console:: text:: Output ;
5
4
use uefi:: table:: boot:: { BootServices , EventType , TimerTrigger , Tpl } ;
6
5
use uefi:: Event ;
7
6
@@ -37,28 +36,35 @@ fn test_event_callback(bt: &BootServices) {
37
36
}
38
37
39
38
fn test_callback_with_ctx ( bt : & BootServices ) {
39
+ let mut data = 123u32 ;
40
+
40
41
extern "efiapi" fn callback ( _event : Event , ctx : Option < NonNull < c_void > > ) {
41
42
info ! ( "Inside the event callback with context" ) ;
43
+ // Safety: this callback is run within the parent function's
44
+ // scope, so the context pointer is still valid.
42
45
unsafe {
43
- let ctx = & mut * ( ctx. unwrap ( ) . as_ptr ( ) as * mut Output ) ;
44
- // Clear the screen as a quick test that we successfully passed context
45
- ctx. clear ( ) . expect ( "Failed to clear screen" ) ;
46
+ let ctx = ctx. unwrap ( ) . as_ptr ( ) . cast :: < u32 > ( ) ;
47
+ * ctx = 456 ;
46
48
}
47
49
}
48
50
49
- let ctx = unsafe { & mut * ( bt. locate_protocol :: < Output > ( ) . unwrap ( ) . get ( ) ) } ;
51
+ let ctx: * mut u32 = & mut data;
52
+ let ctx = NonNull :: new ( ctx. cast :: < c_void > ( ) ) . unwrap ( ) ;
50
53
51
54
let event = unsafe {
52
55
bt. create_event (
53
56
EventType :: NOTIFY_WAIT ,
54
57
Tpl :: CALLBACK ,
55
58
Some ( callback) ,
56
- Some ( NonNull :: new_unchecked ( ctx as * mut _ as * mut c_void ) ) ,
59
+ Some ( ctx) ,
57
60
)
58
61
. expect ( "Failed to create event with context" )
59
62
} ;
60
63
61
64
bt. check_event ( event) . expect ( "Failed to check event" ) ;
65
+
66
+ // Check that `data` was updated inside the event callback.
67
+ assert_eq ! ( data, 456 ) ;
62
68
}
63
69
64
70
fn test_watchdog ( bt : & BootServices ) {
You can’t perform that action at this time.
0 commit comments