starnix_container_structured_config/
starnix_container_structured_config_rust_config_lib_source.rs1use fidl::unpersist;
2use fidl_cf_sc_internal_starnixcontainerstructuredconfig::Config as FidlConfig;
3use fuchsia_component_config::{Config as ComponentConfig, Error};
4use fuchsia_inspect::{ArrayProperty, Node};
5use std::convert::TryInto;
6const EXPECTED_CHECKSUM: &[u8] = &[
7 0x98, 0xee, 0x36, 0xff, 0xe5, 0x2d, 0x91, 0x14, 0x8e, 0xdb, 0x2f, 0x9e, 0xb0, 0x35, 0x45, 0xfe,
8 0x21, 0xa9, 0x14, 0xec, 0x01, 0xaf, 0x68, 0xda, 0x8b, 0xa0, 0xda, 0xe4, 0xf0, 0xba, 0xd5, 0xf2,
9];
10#[derive(Debug)]
11pub struct Config {
12 pub additional_mounts: Vec<String>,
13 pub cached_zx_map_info_bytes: u32,
14 pub crash_report_throttling: bool,
15 pub dirent_cache_size: u32,
16 pub enable_utc_time_adjustment: bool,
17 pub extra_features: Vec<String>,
18 pub mlock_always_onfault: bool,
19 pub mlock_pin_flavor: String,
20 pub selinux_exceptions: Vec<String>,
21 pub ui_visual_debugging_level: u8,
22}
23impl Config {
24 #[doc = r" Take the config startup handle and parse its contents."]
25 #[doc = r""]
26 #[doc = r" # Panics"]
27 #[doc = r""]
28 #[doc = r" If the config startup handle was already taken or if it is not valid."]
29 pub fn take_from_startup_handle() -> Self {
30 <Self as ComponentConfig>::take_from_startup_handle()
31 }
32 #[doc = r" Parse `Self` from `vmo`."]
33 pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
34 <Self as ComponentConfig>::from_vmo(vmo)
35 }
36 #[doc = r" Parse `Self` from `bytes`."]
37 pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
38 <Self as ComponentConfig>::from_bytes(bytes)
39 }
40 pub fn record_inspect(&self, inspector_node: &Node) {
41 <Self as ComponentConfig>::record_inspect(self, inspector_node)
42 }
43}
44impl ComponentConfig for Config {
45 #[doc = r" Parse `Self` from `bytes`."]
46 fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
47 let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
48 let checksum_len_bytes: [u8; 2] =
49 checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
50 let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
51 let (observed_checksum, bytes) =
52 bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
53 if observed_checksum != EXPECTED_CHECKSUM {
54 return Err(Error::ChecksumMismatch {
55 expected_checksum: EXPECTED_CHECKSUM.to_vec(),
56 observed_checksum: observed_checksum.to_vec(),
57 });
58 }
59 let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
60 Ok(Self {
61 additional_mounts: fidl_config.additional_mounts,
62 cached_zx_map_info_bytes: fidl_config.cached_zx_map_info_bytes,
63 crash_report_throttling: fidl_config.crash_report_throttling,
64 dirent_cache_size: fidl_config.dirent_cache_size,
65 enable_utc_time_adjustment: fidl_config.enable_utc_time_adjustment,
66 extra_features: fidl_config.extra_features,
67 mlock_always_onfault: fidl_config.mlock_always_onfault,
68 mlock_pin_flavor: fidl_config.mlock_pin_flavor,
69 selinux_exceptions: fidl_config.selinux_exceptions,
70 ui_visual_debugging_level: fidl_config.ui_visual_debugging_level,
71 })
72 }
73 fn record_inspect(&self, inspector_node: &Node) {
74 let arr =
75 inspector_node.create_string_array("additional_mounts", self.additional_mounts.len());
76 for i in 0..self.additional_mounts.len() {
77 arr.set(i, &self.additional_mounts[i]);
78 }
79 inspector_node.record(arr);
80 inspector_node
81 .record_uint("cached_zx_map_info_bytes", self.cached_zx_map_info_bytes as u64);
82 inspector_node.record_bool("crash_report_throttling", self.crash_report_throttling);
83 inspector_node.record_uint("dirent_cache_size", self.dirent_cache_size as u64);
84 inspector_node.record_bool("enable_utc_time_adjustment", self.enable_utc_time_adjustment);
85 let arr = inspector_node.create_string_array("extra_features", self.extra_features.len());
86 for i in 0..self.extra_features.len() {
87 arr.set(i, &self.extra_features[i]);
88 }
89 inspector_node.record(arr);
90 inspector_node.record_bool("mlock_always_onfault", self.mlock_always_onfault);
91 inspector_node.record_string("mlock_pin_flavor", &self.mlock_pin_flavor);
92 let arr =
93 inspector_node.create_string_array("selinux_exceptions", self.selinux_exceptions.len());
94 for i in 0..self.selinux_exceptions.len() {
95 arr.set(i, &self.selinux_exceptions[i]);
96 }
97 inspector_node.record(arr);
98 inspector_node
99 .record_uint("ui_visual_debugging_level", self.ui_visual_debugging_level as u64);
100 }
101}