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];
10const EXPECTED_CHECKSUM_LENGTH: [u8; 2] = (EXPECTED_CHECKSUM.len() as u16).to_le_bytes();
11#[derive(Debug)]
12pub struct Config {
13 pub additional_mounts: Vec<String>,
14 pub cached_zx_map_info_bytes: u32,
15 pub crash_report_throttling: bool,
16 pub dirent_cache_size: u32,
17 pub enable_utc_time_adjustment: bool,
18 pub extra_features: Vec<String>,
19 pub mlock_always_onfault: bool,
20 pub mlock_pin_flavor: String,
21 pub selinux_exceptions: Vec<String>,
22 pub ui_visual_debugging_level: u8,
23}
24impl Config {
25 #[doc = r" Take the config startup handle and parse its contents."]
26 #[doc = r""]
27 #[doc = r" # Panics"]
28 #[doc = r""]
29 #[doc = r" If the config startup handle was already taken or if it is not valid."]
30 pub fn take_from_startup_handle() -> Self {
31 <Self as ComponentConfig>::take_from_startup_handle()
32 }
33 #[doc = r" Parse `Self` from `vmo`."]
34 pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
35 <Self as ComponentConfig>::from_vmo(vmo)
36 }
37 #[doc = r" Parse `Self` from `bytes`."]
38 pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
39 <Self as ComponentConfig>::from_bytes(bytes)
40 }
41 pub fn record_inspect(&self, inspector_node: &Node) {
42 <Self as ComponentConfig>::record_inspect(self, inspector_node)
43 }
44}
45impl ComponentConfig for Config {
46 #[doc = r" Parse `Self` from `bytes`."]
47 fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
48 let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
49 let checksum_len_bytes: [u8; 2] =
50 checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
51 let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
52 let (observed_checksum, bytes) =
53 bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
54 if observed_checksum != EXPECTED_CHECKSUM {
55 return Err(Error::ChecksumMismatch {
56 expected_checksum: EXPECTED_CHECKSUM.to_vec(),
57 observed_checksum: observed_checksum.to_vec(),
58 });
59 }
60 let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
61 Ok(Self {
62 additional_mounts: fidl_config.additional_mounts,
63 cached_zx_map_info_bytes: fidl_config.cached_zx_map_info_bytes,
64 crash_report_throttling: fidl_config.crash_report_throttling,
65 dirent_cache_size: fidl_config.dirent_cache_size,
66 enable_utc_time_adjustment: fidl_config.enable_utc_time_adjustment,
67 extra_features: fidl_config.extra_features,
68 mlock_always_onfault: fidl_config.mlock_always_onfault,
69 mlock_pin_flavor: fidl_config.mlock_pin_flavor,
70 selinux_exceptions: fidl_config.selinux_exceptions,
71 ui_visual_debugging_level: fidl_config.ui_visual_debugging_level,
72 })
73 }
74 fn to_bytes(&self) -> Result<Vec<u8>, Error> {
75 let fidl_config = FidlConfig {
76 additional_mounts: self.additional_mounts.clone(),
77 cached_zx_map_info_bytes: self.cached_zx_map_info_bytes.clone(),
78 crash_report_throttling: self.crash_report_throttling.clone(),
79 dirent_cache_size: self.dirent_cache_size.clone(),
80 enable_utc_time_adjustment: self.enable_utc_time_adjustment.clone(),
81 extra_features: self.extra_features.clone(),
82 mlock_always_onfault: self.mlock_always_onfault.clone(),
83 mlock_pin_flavor: self.mlock_pin_flavor.clone(),
84 selinux_exceptions: self.selinux_exceptions.clone(),
85 ui_visual_debugging_level: self.ui_visual_debugging_level.clone(),
86 };
87 let mut fidl_bytes = fidl::persist(&fidl_config).map_err(Error::Persist)?;
88 let mut bytes = Vec::with_capacity(
89 EXPECTED_CHECKSUM_LENGTH.len() + EXPECTED_CHECKSUM.len() + fidl_bytes.len(),
90 );
91 bytes.extend_from_slice(&EXPECTED_CHECKSUM_LENGTH);
92 bytes.extend_from_slice(EXPECTED_CHECKSUM);
93 bytes.append(&mut fidl_bytes);
94 Ok(bytes)
95 }
96 fn record_inspect(&self, inspector_node: &Node) {
97 let arr =
98 inspector_node.create_string_array("additional_mounts", self.additional_mounts.len());
99 for i in 0..self.additional_mounts.len() {
100 arr.set(i, &self.additional_mounts[i]);
101 }
102 inspector_node.record(arr);
103 inspector_node
104 .record_uint("cached_zx_map_info_bytes", self.cached_zx_map_info_bytes as u64);
105 inspector_node.record_bool("crash_report_throttling", self.crash_report_throttling);
106 inspector_node.record_uint("dirent_cache_size", self.dirent_cache_size as u64);
107 inspector_node.record_bool("enable_utc_time_adjustment", self.enable_utc_time_adjustment);
108 let arr = inspector_node.create_string_array("extra_features", self.extra_features.len());
109 for i in 0..self.extra_features.len() {
110 arr.set(i, &self.extra_features[i]);
111 }
112 inspector_node.record(arr);
113 inspector_node.record_bool("mlock_always_onfault", self.mlock_always_onfault);
114 inspector_node.record_string("mlock_pin_flavor", &self.mlock_pin_flavor);
115 let arr =
116 inspector_node.create_string_array("selinux_exceptions", self.selinux_exceptions.len());
117 for i in 0..self.selinux_exceptions.len() {
118 arr.set(i, &self.selinux_exceptions[i]);
119 }
120 inspector_node.record(arr);
121 inspector_node
122 .record_uint("ui_visual_debugging_level", self.ui_visual_debugging_level as u64);
123 }
124}