Next Generation WASM Microkernel Operating System
at main 51 lines 1.6 kB view raw
1// Copyright 2025 Jonas Kruckenberg 2// 3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or 4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or 5// http://opensource.org/licenses/MIT>, at your option. This file may not be 6// copied, modified, or distributed except according to those terms. 7 8const CFG_MAGIC: u32 = u32::from_le_bytes(*b"lcfg"); 9 10#[derive(Debug, PartialEq, Eq, Clone, Copy)] 11#[non_exhaustive] 12#[repr(C)] 13pub struct LoaderConfig { 14 magic: u32, 15 /// The size of the stack that the loader should allocate for the kernel (in pages). 16 /// 17 /// The loader starts the kernel with a valid stack pointer. This setting defines 18 /// the stack size that the loader should allocate and map. 19 /// 20 /// The stack is created with an additional guard page, so a stack overflow will lead to 21 /// a page fault. 22 pub kernel_stack_size_pages: u32, 23} 24 25impl LoaderConfig { 26 /// Creates a new default configuration with the following values: 27 /// 28 /// - `kernel_stack_size_pages`: 20 29 #[must_use] 30 pub const fn new_default() -> Self { 31 Self { 32 magic: CFG_MAGIC, 33 kernel_stack_size_pages: 20, 34 } 35 } 36 37 /// Asserts that the configuration is valid. 38 /// 39 /// # Panics 40 /// 41 /// Panics if the configuration is invalid. 42 pub fn assert_valid(&self) { 43 assert_eq!(self.magic, CFG_MAGIC, "malformed loader config"); 44 } 45} 46 47impl Default for LoaderConfig { 48 fn default() -> Self { 49 Self::new_default() 50 } 51}