ukernel-sys 0.1.0

System interface types for µKernel — a Rust microkernel with hypervisor and real-time scheduling. Defines kernel operations, submission ring layout, and subsystem registration.
Documentation
//! Subsystem identity for loadable domain types.
//!
//! Each domain type (POSIX, VMM, mainframe, etc.) is identified by a
//! [`SubsystemId`] — a deterministic FNV-1a hash of the subsystem name.
//! The kernel has no compile-time knowledge of subsystem types. New
//! subsystems can be added without modifying the kernel.
//!
//! # Example
//!
//! ```
//! use ukernel_sys::SubsystemId;
//!
//! const POSIX: SubsystemId = SubsystemId::from_name(b"posix");
//! const VMM: SubsystemId = SubsystemId::from_name(b"vmm");
//!
//! // Deterministic — same name always produces the same ID
//! assert_eq!(POSIX, SubsystemId::from_name(b"posix"));
//! assert_ne!(POSIX, VMM);
//! ```

/// Subsystem identifier derived from name via FNV-1a hash.
///
/// Deterministic: `"posix"` always hashes to the same value.
#[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)]
pub struct SubsystemId(pub u64);

impl SubsystemId {
    /// Create from a name using const-evaluable FNV-1a hash.
    pub const fn from_name(name: &[u8]) -> Self {
        let mut hash: u64 = 0xcbf29ce484222325; // FNV offset basis
        let mut i = 0;
        while i < name.len() {
            hash ^= name[i] as u64;
            hash = hash.wrapping_mul(0x100000001b3); // FNV prime
            i += 1;
        }
        Self(hash)
    }

    /// Raw hash value.
    #[inline]
    pub const fn as_u64(self) -> u64 {
        self.0
    }
}