driver_index_config/
driver_index_config_rust_config_lib_source.rsuse fidl::unpersist;
use fidl_cf_sc_internal_driverindexconfig::Config as FidlConfig;
use fuchsia_inspect::{ArrayProperty, Node};
use fuchsia_runtime::{take_startup_handle, HandleInfo, HandleType};
#[derive(Debug)]
pub struct Config {
pub base_drivers: Vec<String>,
pub bind_eager: Vec<String>,
pub boot_drivers: Vec<String>,
pub delay_fallback_until_base_drivers_indexed: bool,
pub disabled_drivers: Vec<String>,
pub driver_load_fuzzer_max_delay_ms: i64,
pub enable_driver_load_fuzzer: bool,
pub enable_ephemeral_drivers: bool,
pub stop_on_idle_timeout_millis: i64,
}
impl Config {
pub fn take_from_startup_handle() -> Self {
let config_vmo: zx::Vmo =
take_startup_handle(HandleInfo::new(HandleType::ComponentConfigVmo, 0))
.expect("Config VMO handle must be provided and cannot already have been taken.")
.into();
let config_size =
config_vmo.get_content_size().expect("must be able to read config vmo content size");
assert_ne!(config_size, 0, "config vmo must be non-empty");
let config_bytes =
config_vmo.read_to_vec(0, config_size).expect("must be able to read config vmo");
let checksum_length = u16::from_le_bytes([config_bytes[0], config_bytes[1]]) as usize;
let fidl_start = 2 + checksum_length;
let observed_checksum = &config_bytes[2..fidl_start];
let expected_checksum = vec![
0x3c, 0x8f, 0x22, 0x9c, 0xa6, 0x41, 0xb9, 0x6e, 0xb8, 0x3e, 0x8c, 0xe1, 0xfd, 0xa9,
0x89, 0xbc, 0x75, 0x5b, 0xf0, 0xf0, 0x50, 0xc1, 0x55, 0xc8, 0x1a, 0xeb, 0xb0, 0x34,
0xce, 0x53, 0xe0, 0x43,
];
assert_eq!(
observed_checksum, expected_checksum,
"checksum from config VMO does not match expected checksum"
);
let fidl_config: FidlConfig = unpersist(&config_bytes[fidl_start..])
.expect("must be able to parse bytes as config FIDL");
Self {
base_drivers: fidl_config.base_drivers,
bind_eager: fidl_config.bind_eager,
boot_drivers: fidl_config.boot_drivers,
delay_fallback_until_base_drivers_indexed: fidl_config
.delay_fallback_until_base_drivers_indexed,
disabled_drivers: fidl_config.disabled_drivers,
driver_load_fuzzer_max_delay_ms: fidl_config.driver_load_fuzzer_max_delay_ms,
enable_driver_load_fuzzer: fidl_config.enable_driver_load_fuzzer,
enable_ephemeral_drivers: fidl_config.enable_ephemeral_drivers,
stop_on_idle_timeout_millis: fidl_config.stop_on_idle_timeout_millis,
}
}
pub fn record_inspect(&self, inspector_node: &Node) {
let arr = inspector_node.create_string_array("base_drivers", self.base_drivers.len());
for i in 0..self.base_drivers.len() {
arr.set(i, &self.base_drivers[i]);
}
inspector_node.record(arr);
let arr = inspector_node.create_string_array("bind_eager", self.bind_eager.len());
for i in 0..self.bind_eager.len() {
arr.set(i, &self.bind_eager[i]);
}
inspector_node.record(arr);
let arr = inspector_node.create_string_array("boot_drivers", self.boot_drivers.len());
for i in 0..self.boot_drivers.len() {
arr.set(i, &self.boot_drivers[i]);
}
inspector_node.record(arr);
inspector_node.record_bool(
"delay_fallback_until_base_drivers_indexed",
self.delay_fallback_until_base_drivers_indexed,
);
let arr =
inspector_node.create_string_array("disabled_drivers", self.disabled_drivers.len());
for i in 0..self.disabled_drivers.len() {
arr.set(i, &self.disabled_drivers[i]);
}
inspector_node.record(arr);
inspector_node
.record_int("driver_load_fuzzer_max_delay_ms", self.driver_load_fuzzer_max_delay_ms);
inspector_node.record_bool("enable_driver_load_fuzzer", self.enable_driver_load_fuzzer);
inspector_node.record_bool("enable_ephemeral_drivers", self.enable_ephemeral_drivers);
inspector_node.record_int("stop_on_idle_timeout_millis", self.stop_on_idle_timeout_millis);
}
}