File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed
uefi-test-runner/src/boot Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change 11use core:: ffi:: c_void;
22use core:: ptr:: NonNull ;
33
4- use uefi:: proto:: console:: text:: Output ;
54use uefi:: table:: boot:: { BootServices , EventType , TimerTrigger , Tpl } ;
65use uefi:: Event ;
76
@@ -37,28 +36,35 @@ fn test_event_callback(bt: &BootServices) {
3736}
3837
3938fn test_callback_with_ctx ( bt : & BootServices ) {
39+ let mut data = 123u32 ;
40+
4041 extern "efiapi" fn callback ( _event : Event , ctx : Option < NonNull < c_void > > ) {
4142 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.
4245 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 ;
4648 }
4749 }
4850
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 ( ) ;
5053
5154 let event = unsafe {
5255 bt. create_event (
5356 EventType :: NOTIFY_WAIT ,
5457 Tpl :: CALLBACK ,
5558 Some ( callback) ,
56- Some ( NonNull :: new_unchecked ( ctx as * mut _ as * mut c_void ) ) ,
59+ Some ( ctx) ,
5760 )
5861 . expect ( "Failed to create event with context" )
5962 } ;
6063
6164 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 ) ;
6268}
6369
6470fn test_watchdog ( bt : & BootServices ) {
You can’t perform that action at this time.
0 commit comments