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 0xdf, 0xf1, 0xb2, 0x3a, 0x5e, 0xeb, 0xef, 0xbc, 0x57, 0xb0, 0x06, 0x16, 0x04, 0x06, 0xb5, 0x5d,
8 0xa8, 0xbf, 0xed, 0x6b, 0x44, 0x7c, 0xbd, 0x82, 0x75, 0x2c, 0xb9, 0x45, 0xa9, 0x84, 0x4c, 0xf9,
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 enable_utc_time_adjustment: bool,
16 pub extra_features: Vec<String>,
17 pub mlock_always_onfault: bool,
18 pub mlock_pin_flavor: String,
19 pub selinux_exceptions: Vec<String>,
20 pub ui_visual_debugging_level: u8,
21}
22impl Config {
23 #[doc = r" Take the config startup handle and parse its contents."]
24 #[doc = r""]
25 #[doc = r" # Panics"]
26 #[doc = r""]
27 #[doc = r" If the config startup handle was already taken or if it is not valid."]
28 pub fn take_from_startup_handle() -> Self {
29 <Self as ComponentConfig>::take_from_startup_handle()
30 }
31 #[doc = r" Parse `Self` from `vmo`."]
32 pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
33 <Self as ComponentConfig>::from_vmo(vmo)
34 }
35 #[doc = r" Parse `Self` from `bytes`."]
36 pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
37 <Self as ComponentConfig>::from_bytes(bytes)
38 }
39 pub fn record_inspect(&self, inspector_node: &Node) {
40 <Self as ComponentConfig>::record_inspect(self, inspector_node)
41 }
42}
43impl ComponentConfig for Config {
44 #[doc = r" Parse `Self` from `bytes`."]
45 fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
46 let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
47 let checksum_len_bytes: [u8; 2] =
48 checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
49 let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
50 let (observed_checksum, bytes) =
51 bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
52 if observed_checksum != EXPECTED_CHECKSUM {
53 return Err(Error::ChecksumMismatch {
54 expected_checksum: EXPECTED_CHECKSUM.to_vec(),
55 observed_checksum: observed_checksum.to_vec(),
56 });
57 }
58 let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
59 Ok(Self {
60 additional_mounts: fidl_config.additional_mounts,
61 cached_zx_map_info_bytes: fidl_config.cached_zx_map_info_bytes,
62 crash_report_throttling: fidl_config.crash_report_throttling,
63 enable_utc_time_adjustment: fidl_config.enable_utc_time_adjustment,
64 extra_features: fidl_config.extra_features,
65 mlock_always_onfault: fidl_config.mlock_always_onfault,
66 mlock_pin_flavor: fidl_config.mlock_pin_flavor,
67 selinux_exceptions: fidl_config.selinux_exceptions,
68 ui_visual_debugging_level: fidl_config.ui_visual_debugging_level,
69 })
70 }
71 fn record_inspect(&self, inspector_node: &Node) {
72 let arr =
73 inspector_node.create_string_array("additional_mounts", self.additional_mounts.len());
74 for i in 0..self.additional_mounts.len() {
75 arr.set(i, &self.additional_mounts[i]);
76 }
77 inspector_node.record(arr);
78 inspector_node
79 .record_uint("cached_zx_map_info_bytes", self.cached_zx_map_info_bytes as u64);
80 inspector_node.record_bool("crash_report_throttling", self.crash_report_throttling);
81 inspector_node.record_bool("enable_utc_time_adjustment", self.enable_utc_time_adjustment);
82 let arr = inspector_node.create_string_array("extra_features", self.extra_features.len());
83 for i in 0..self.extra_features.len() {
84 arr.set(i, &self.extra_features[i]);
85 }
86 inspector_node.record(arr);
87 inspector_node.record_bool("mlock_always_onfault", self.mlock_always_onfault);
88 inspector_node.record_string("mlock_pin_flavor", &self.mlock_pin_flavor);
89 let arr =
90 inspector_node.create_string_array("selinux_exceptions", self.selinux_exceptions.len());
91 for i in 0..self.selinux_exceptions.len() {
92 arr.set(i, &self.selinux_exceptions[i]);
93 }
94 inspector_node.record(arr);
95 inspector_node
96 .record_uint("ui_visual_debugging_level", self.ui_visual_debugging_level as u64);
97 }
98}