Skip to main content

a653rs_xng/
lib.rs

1//! Bindings to a XNG MonoCore implementation of the ARINC653 P1/P2/P4 API
2
3#![no_std]
4#![deny(missing_docs)]
5#![deny(rustdoc::broken_intra_doc_links)]
6
7/// This module contains bindings to the services defined by ARINC653
8pub mod bindings {
9    #![allow(clippy::redundant_static_lifetimes)]
10    #![allow(dead_code)]
11    #![allow(missing_docs)]
12    #![allow(non_camel_case_types)]
13    #![allow(non_snake_case)]
14    #![allow(non_upper_case_globals)]
15    include!("bindings.rs");
16}
17
18/// This module contains the mappings from [crate::bindings] to [a653rs::bindings]
19pub mod apex;
20
21/// This panic handler reports the reason for a panic to the hypervisor and
22/// then enters an infinite loop
23#[cfg(feature = "panic_handler")]
24#[panic_handler]
25fn panic(info: &core::panic::PanicInfo) -> ! {
26    log::error!("{info}");
27
28    let message = match info.payload().downcast_ref::<&str>() {
29        Some(str) => str,
30        None => "panic of unknown cause occured",
31    };
32
33    let last_index = core::cmp::min(bindings::MAX_ERROR_MESSAGE_SIZE as usize, message.len());
34
35    // This function can fail if the message len in bytes is longer than
36    // MAX_ERROR_MESSAGE_SIZE. To make it safe to unwrap, we have to shorten
37    // the message if it exceeds the allowed length. As the slicing only happen
38    // on the byte level, cutting of a multi-byte char (UTF-8) will not yield
39    // internal panic, but of course it might disturb the hypervisors output.
40    <apex::XngHypervisor as a653rs::prelude::ApexErrorP4Ext>::raise_application_error(
41        &message.as_bytes()[0..last_index],
42    )
43    .unwrap();
44
45    loop {}
46}