Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  lib.rs

  Sprache: Rust
 

/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


//! # 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;

#[allow(non_upper_case_globals)]
#[allow(non_camel_case_types)]
#[allow(unused)]
pub mod sys {
    include!(env!("BINDGEN_INC_FILE"));
}

#[derive(Error, Debug)]
pub enum 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.
pub fn get_dtb() -> Result<&'static Fdt, DtbServiceError> {
    let mut fdt_ptr: *const u8 = core::ptr::null_mut();
    let mut 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) };

    libfdt::Fdt::from_slice(fdt).map_err(|e| DtbServiceError::FailedFdtConstruction(e))
}

/// 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.
pub fn 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,
        })?;
    let mut 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(0as 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
C=92 H=89 G=90

¤ Dauer der Verarbeitung: 0.10 Sekunden  (vorverarbeitet am  2026-06-27) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

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.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik