Skip to main content

proka_kernel/
lib.rs

1//! # Proka Kernel - A kernel for ProkaOS
2//! Copyright (C) RainSTR Studio 2025, All rights reserved.
3//!
4//! This provides the public functions, and they will help you
5//! to use the kernel functions easily.
6
7#![no_std]
8#![cfg_attr(test, no_main)]
9#![feature(custom_test_frameworks)]
10#![feature(abi_x86_interrupt)]
11#![test_runner(crate::test::test_runner)]
12#![reexport_test_harness_main = "test_main"]
13pub mod drivers;
14pub mod fs;
15pub mod graphics;
16pub mod interrupts;
17pub mod libs;
18pub mod memory;
19pub mod output;
20pub mod panic;
21pub mod process;
22pub mod test;
23
24pub mod config {
25    include!(concat!(env!("OUT_DIR"), "/config.rs"));
26}
27
28// Re-export common memory management types and functions
29pub use memory::frame_allocator::{format_bytes, FrameStats, LockedFrameAllocator};
30pub use memory::paging::{
31    get_hhdm_offset, get_memory_stats, init_frame_allocator, init_offset_page_table,
32    print_memory_stats,
33};
34pub use memory::protection::{kernel_flags, user_flags, Protection};
35
36use limine::{
37    modules::InternalModule,
38    request::{FramebufferRequest, MemoryMapRequest, ModuleRequest},
39    BaseRevision,
40};
41
42/* The section data define area */
43#[unsafe(link_section = ".requests")]
44#[used]
45/// The base revision of the kernel.
46pub static BASE_REVISION: BaseRevision = BaseRevision::new();
47
48#[unsafe(link_section = ".requests")]
49#[used]
50/// The framebuffer request of the kernel.
51pub static FRAMEBUFFER_REQUEST: FramebufferRequest = FramebufferRequest::new();
52
53#[unsafe(link_section = ".requests")]
54#[used]
55pub static MEMORY_MAP_REQUEST: MemoryMapRequest = MemoryMapRequest::new();
56
57#[unsafe(link_section = ".requests")]
58#[used]
59pub static HHDM_REQUEST: limine::request::HhdmRequest = limine::request::HhdmRequest::new();
60
61#[unsafe(link_section = ".requests")]
62#[used]
63pub static MODULE_REQUEST: ModuleRequest = ModuleRequest::new()
64    .with_internal_modules(&[&InternalModule::new().with_path(c"/initrd.cpio")]);
65
66/// This will extern the C function and make it to safe.
67///
68/// # Example
69/// ```rust
70/// use proka_kernel::extern_safe;
71///
72/// // Make sure that the C function was defined and linked currectly.
73/// extern_safe! {
74///     fn add(a: i32, b: i32) -> i32;
75/// }
76///
77/// // Then use it, with the header "safe_".
78/// let result = safe_add(1, 2);
79/// assert_eq!(result, 3);
80/// ```
81#[macro_export]
82macro_rules! extern_safe {
83    (
84        $(
85            $(#[$meta:meta])*
86            fn $name:ident($($arg:ident: $ty:ty),* $(,)?) -> $ret:ty;
87        )*
88    ) => {
89        unsafe extern "C" {
90            $(
91                $(#[$meta])*
92                fn $name($($arg: $ty),*) -> $ret;
93            )*
94        }
95
96       $(
97           paste::paste! {
98                pub fn [<safe_ $name>]($($arg: $ty),*) -> $ret {
99                    unsafe { $name($($arg),*) }
100                }
101            }
102        )*
103    };
104}