//! # Interface library for communicating with the system state service.
#![no_std]
use core::ffi::CStr; use core::slice::from_raw_parts; use libfdt::{Fdt, FdtError, FdtNode}; use rust_support::ktipc::ktipc_port_acl; use thiserror::Error;
#[derive(Error, Debug)] pubenum DtbServiceError { #[error("failed to construct Fdt {0}")]
FailedFdtConstruction(FdtError), #[error("failed to retrieve global device tree {0}")]
NoGlobalDeviceTree(rust_support::Error), #[error("failed to access device tree property {property_name}. {fdt_err}")]
PropertyNotFound { property_name: &'static str, fdt_err: FdtError }, #[error("failed to share memory with vmm_obj_service {0}")]
FailedVmmObjServiceShare(rust_support::Error),
}
/// Get a static reference to the device tree, if it has been set and /// is successfully validated. pubfn get_dtb() -> Result<&'static Fdt, DtbServiceError> { letmut fdt_ptr: *const u8 = core::ptr::null_mut(); letmut fdt_size = 0usize; // SAFETY: Neither pointer is retained by dtb_get. dbt_get does not read from *fdt_ptr. let rc = unsafe { sys::dtb_get(&mut fdt_ptr as *mut *const u8, &tyle='color:red'>mut fdt_size) }; if rc != sys::NO_ERROR as i32 || fdt_ptr.is_null() { return Err(DtbServiceError::NoGlobalDeviceTree( // We know rc != NO_ERROR so unwrap_err on from_lk should be a safe assumption
rust_support::Error::from_lk(rc).unwrap_err(),
));
} // SAFETY: Outputs from dtb_get are defined to be static, read only, and span the size returned. // fdt_ptr has already been checked for null. let fdt = unsafe { from_raw_parts(fdt_ptr, fdt_size) };
/// Expose the region described by a reserved-memory node as a /// vmm_obj_service. If the given name is found as a compatible /// string on the reserved_mem node, the vmm_obj_service is exposed /// on a port with the provided name and ACL, and Ok(()) is returned. /// /// Otherwise, Err(DtbServiceError) is returned. /// /// Note that this implementation only handles the first memory range /// on a reserved-memory node. If more ranges are specified via /// additional reg entries, they are ignored with a logged warning. pubfn map_reserved_memory(
reserved_mem: &FdtNode,
name: &'static CStr,
acl: &'static ktipc_port_acl,
) -> Result<(), DtbServiceError> { let node = reserved_mem
.next_compatible(name)
.map_err(|e| DtbServiceError::PropertyNotFound { property_name: "compatible", fdt_err: e })?
.ok_or_else(|| DtbServiceError::PropertyNotFound {
property_name: "compatible",
fdt_err: FdtError::NotFound,
})?; letmut reg_itr = node
.reg()
.map_err(|e| DtbServiceError::PropertyNotFound { property_name: "reg", fdt_err: e })?
.ok_or_else(|| DtbServiceError::PropertyNotFound {
property_name: "reg",
fdt_err: FdtError::NotFound,
})?; let reg = reg_itr.next().ok_or_else(|| DtbServiceError::PropertyNotFound {
property_name: "reg",
fdt_err: FdtError::NotFound,
})?;
vmm_obj_service_rust::share_sized_buffer(
reg.addr as *const u8,
reg.size.unwrap_or(0) as usize, 0,
name,
acl,
)
.map_err(|e| DtbServiceError::FailedVmmObjServiceShare(e))?;
if reg_itr.next().is_some() {
log::warn!("Found unexpected address in reg node. Ignoring.");
}
Ok(())
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.0 Sekunden
(vorverarbeitet am 2026-06-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.