baryl 0.0.3

Public SDK for Baryl, a full-system emulation and introspection engine
//! The table a component `.so` exports, and the callback shapes its slots hold.
//!
//! [`ComponentDescriptor`] is the whole of what a run reads out of your
//! library: its name, the subsystems it cannot run without, how to construct
//! and drop it, and one block of event slots per subsystem. A populated slot
//! *is* the subscription — there is no runtime register call.
//!
//! Writing `#[component("name")]` over an `impl` block builds all of this and
//! exports it, so most components never name a type in this module. Reach for
//! it when you are filling a descriptor by hand, or writing the component in
//! another language against the same layout.
//!
//! [`BARYL_COMPONENT_ABI_VERSION`] and [`BARYL_COMPONENT_MIN_ABI_VERSION`] are
//! the revision this build speaks; a run refuses a descriptor outside its own
//! window rather than reading fields that have moved.

use core::ffi::c_void;

use crate::control::Control;

// Bindgen output cannot satisfy the workspace lints; the allow stops here.
mod generated {
    #![allow(non_camel_case_types, non_upper_case_globals, dead_code)]
    include!("generated.rs");
}
pub use generated::*;

/// A lifecycle event handler: your component's own state pointer — whatever
/// `new_` returned — and the [`Control`] for this event.
///
/// `ControlFn` in the descriptor is this wrapped in an `Option`, since an
/// unsubscribed slot is null. This alias is the unwrapped form, so a
/// hand-written block can write `Some(my_handler)` without a cast.
pub type GenericCb = unsafe extern "C" fn(*mut c_void, *mut Control);

/// [`GenericCb`] plus the 48-bit vmcall body, which [`crate::abi::VMCall`]
/// decodes.
pub type VmcallCb = unsafe extern "C" fn(*mut c_void, *mut Control, u64);

// SAFETY: an exported descriptor is immutable after link and the core only ever
// reads it; the raw `name` pointer that makes it `!Sync` targets another
// immutable static in the same binary.
unsafe impl Sync for ComponentDescriptor {}

const _: () = {
    assert!(size_of::<CoreCallbacks>() == 0x58);
    assert!(size_of::<ComponentDescriptor>() == 0xe0);
};