@@ -11,7 +11,7 @@ use core::ops::{Deref, DerefMut};
11
11
use core:: ptr:: { self , NonNull } ;
12
12
use core:: sync:: atomic:: { AtomicPtr , Ordering } ;
13
13
use core:: { mem, slice} ;
14
- use uefi:: { table, Char16 , Event , Guid , Handle , Result , Status , StatusExt } ;
14
+ use uefi:: { table, Char16 , Error , Event , Guid , Handle , Result , Status , StatusExt } ;
15
15
use uefi_raw:: table:: boot:: InterfaceType ;
16
16
17
17
#[ cfg( doc) ]
@@ -612,6 +612,38 @@ pub fn open_protocol_exclusive<P: ProtocolPointer + ?Sized>(
612
612
}
613
613
}
614
614
615
+ /// Tests whether a handle supports a protocol.
616
+ ///
617
+ /// Returns `Ok(true)` if the handle supports the protocol, `Ok(false)` if not.
618
+ ///
619
+ /// # Errors
620
+ ///
621
+ /// * [`Status::INVALID_PARAMETER`]: one of the handles in `params` is invalid.
622
+ pub fn test_protocol < P : ProtocolPointer + ?Sized > ( params : OpenProtocolParams ) -> Result < bool > {
623
+ const TEST_PROTOCOL : u32 = 0x04 ;
624
+
625
+ let bt = boot_services_raw_panicking ( ) ;
626
+ let bt = unsafe { bt. as_ref ( ) } ;
627
+
628
+ let mut interface = ptr:: null_mut ( ) ;
629
+ let status = unsafe {
630
+ ( bt. open_protocol ) (
631
+ params. handle . as_ptr ( ) ,
632
+ & P :: GUID ,
633
+ & mut interface,
634
+ params. agent . as_ptr ( ) ,
635
+ Handle :: opt_to_ptr ( params. controller ) ,
636
+ TEST_PROTOCOL ,
637
+ )
638
+ } ;
639
+
640
+ match status {
641
+ Status :: SUCCESS => Ok ( true ) ,
642
+ Status :: UNSUPPORTED => Ok ( false ) ,
643
+ _ => Err ( Error :: from ( status) ) ,
644
+ }
645
+ }
646
+
615
647
/// Loads a UEFI image into memory and return a [`Handle`] to the image.
616
648
///
617
649
/// There are two ways to load the image: by copying raw image data
0 commit comments