• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023, The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 //! Access to hypervisor capabilities via system properties set by the bootloader.
16 
17 use anyhow::{Error, Result};
18 use rustutils::system_properties;
19 
20 /// Returns whether there is a hypervisor present that supports non-protected VMs.
is_vm_supported() -> Result<bool>21 pub fn is_vm_supported() -> Result<bool> {
22     system_properties::read_bool("ro.boot.hypervisor.vm.supported", false).map_err(Error::new)
23 }
24 
25 /// Returns whether there is a hypervisor present that supports protected VMs.
is_protected_vm_supported() -> Result<bool>26 pub fn is_protected_vm_supported() -> Result<bool> {
27     system_properties::read_bool("ro.boot.hypervisor.protected_vm.supported", false)
28         .map_err(Error::new)
29 }
30 
31 /// Returns whether there is a hypervisor present that supports any sort of VM, either protected
32 /// or non-protected.
is_any_vm_supported() -> Result<bool>33 pub fn is_any_vm_supported() -> Result<bool> {
34     is_vm_supported().and_then(|ok| if ok { Ok(true) } else { is_protected_vm_supported() })
35 }
36 
37 /// Returns the version of the hypervisor, if there is one.
version() -> Result<Option<String>>38 pub fn version() -> Result<Option<String>> {
39     system_properties::read("ro.boot.hypervisor.version").map_err(Error::new)
40 }
41