baryl 0.0.2

Public SDK for Baryl, a full-system emulation and introspection engine
//! Symbol lookup in the engine the run loaded.
//!
//! Reached as `ctl.subs.core`. This is a subsystem implementation's door into
//! the engine binary, not a component's; the calls a component makes on the run
//! are on [`crate::component_core`] instead.

// FIXME: does this belong in the public SDK at all? A component has no use for it.

use core::ffi::{CStr, c_void};

// 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::SubsystemCoreRef;
#[doc(hidden)]
pub use generated::SubsystemCoreVtable;

impl SubsystemCoreRef {
    /// The address `name` has in the engine binary this run loaded, or `None`
    /// when it exports no such symbol.
    ///
    /// The engine's full symbol table, not only its dynamic exports. There is
    /// one engine per run, so the call needs nothing to say which.
    pub fn symbol_lookup(&self, name: &CStr) -> Option<*mut c_void> {
        // SAFETY: `vtable` is the core's static table, valid for the process.
        let f = unsafe { (*self.vtable).symbol_lookup }?;
        let p = unsafe { f(*self, name.as_ptr()) };
        (!p.is_null()).then_some(p)
    }
}