@@ -176,6 +176,31 @@ impl Kvm {
176176 self . check_extension_int ( Cap :: DebugHwWps )
177177 }
178178
179+ /// Wrapper over `KVM_CHECK_EXTENSION`.
180+ ///
181+ /// Returns 0 if the capability is not available and a positive integer otherwise.
182+ /// See the documentation for `KVM_CHECK_EXTENSION`.
183+ ///
184+ /// # Arguments
185+ ///
186+ /// * `c` - KVM capability to check in a form of a raw integer.
187+ ///
188+ /// # Example
189+ ///
190+ /// ```
191+ /// # use kvm_ioctls::Kvm;
192+ /// # use std::os::raw::c_ulong;
193+ /// use kvm_ioctls::Cap;
194+ ///
195+ /// let kvm = Kvm::new().unwrap();
196+ /// assert!(kvm.check_extension_raw(Cap::MaxVcpuId as c_ulong) > 0);
197+ /// ```
198+ pub fn check_extension_raw ( & self , c : c_ulong ) -> i32 {
199+ // SAFETY: Safe because we know that our file is a KVM fd.
200+ // If `c` is not a known kernel extension, kernel will return 0.
201+ unsafe { ioctl_with_val ( self , KVM_CHECK_EXTENSION ( ) , c) }
202+ }
203+
179204 /// Wrapper over `KVM_CHECK_EXTENSION`.
180205 ///
181206 /// Returns 0 if the capability is not available and a positive integer otherwise.
@@ -195,9 +220,7 @@ impl Kvm {
195220 /// assert!(kvm.check_extension_int(Cap::MaxVcpuId) > 0);
196221 /// ```
197222 pub fn check_extension_int ( & self , c : Cap ) -> i32 {
198- // SAFETY: Safe because we know that our file is a KVM fd and that the extension is one of
199- // the ones defined by kernel.
200- unsafe { ioctl_with_val ( self , KVM_CHECK_EXTENSION ( ) , c as c_ulong ) }
223+ self . check_extension_raw ( c as c_ulong )
201224 }
202225
203226 /// Checks if a particular `Cap` is available.
@@ -751,6 +774,13 @@ mod tests {
751774 assert ! ( kvm. check_extension( Cap :: UserMemory ) ) ;
752775 }
753776
777+ #[ test]
778+ fn test_kvm_check_extension ( ) {
779+ let kvm = Kvm :: new ( ) . unwrap ( ) ;
780+ // unsupported extension will return 0
781+ assert_eq ! ( kvm. check_extension_raw( 696969 ) , 0 ) ;
782+ }
783+
754784 #[ test]
755785 #[ cfg( target_arch = "aarch64" ) ]
756786 fn test_get_host_ipa_limit ( ) {
0 commit comments