osiris/uapi/
sched.rs

1use hal::stack::EntryFn;
2
3pub fn sleep(_until: u64) -> isize {
4    hal::asm::syscall!(1, (_until >> 32) as u32, _until as u32)
5}
6
7pub fn sleep_for(_duration: u64) -> isize {
8    hal::asm::syscall!(2, (_duration >> 32) as u32, _duration as u32)
9}
10
11pub fn yield_thread() -> isize {
12    let _until = u64::MAX;
13    hal::asm::syscall!(1, (_until >> 32) as u32, _until as u32)
14}
15
16#[repr(C)]
17#[derive(Clone, Copy)]
18pub struct RtAttrs {
19    pub deadline: u64,
20    pub period: u32,
21    pub budget: u32,
22}
23
24pub fn spawn_thread(_func_ptr: EntryFn, attrs: Option<RtAttrs>) -> isize {
25    if let Some(attrs) = attrs {
26        if attrs.budget == 0 || attrs.period == 0 {
27            return -1; // Invalid attributes
28        }
29
30        if attrs.budget > attrs.period {
31            return -1; // Budget cannot exceed period
32        }
33
34        if attrs.budget > u32::MAX / 2 || attrs.period > u32::MAX / 2 {
35            return -1; // Prevent potential overflow in calculations
36        }
37
38        hal::asm::syscall!(3, _func_ptr as u32, &attrs as *const RtAttrs as usize)
39    } else {
40        -1
41    }
42}
43
44pub fn exit(_code: usize) -> ! {
45    hal::asm::syscall!(4, _code as u32);
46    loop {
47        hal::asm::nop!();
48    }
49}