starnix_core/execution/
loop_entry.rs1use crate::task::{CurrentTask, ExitStatus};
6use std::sync::atomic::{AtomicPtr, Ordering};
7
8pub type SyscallLoopEntry = fn(&mut CurrentTask) -> ExitStatus;
10
11static_assertions::assert_eq_size!(SyscallLoopEntry, *const ());
13
14static SYSCALL_LOOP_ENTRY: AtomicPtr<()> = AtomicPtr::new(std::ptr::null_mut());
15
16pub fn initialize_syscall_loop(enter_loop: SyscallLoopEntry) {
18 SYSCALL_LOOP_ENTRY.store(enter_loop as *mut (), Ordering::Relaxed);
19}
20
21pub(crate) fn enter_syscall_loop(current_task: &mut CurrentTask) -> ExitStatus {
25 let raw_entry: *mut () = SYSCALL_LOOP_ENTRY.load(Ordering::Relaxed);
26 assert!(!raw_entry.is_null(), "must call initialize_syscall_loop() before executing tasks");
27 let entry: SyscallLoopEntry = unsafe {
29 let raw_entry_ptr = &raw_entry as *const *mut ();
30 let entry_ptr = raw_entry_ptr as *const SyscallLoopEntry;
31 *entry_ptr
32 };
33 entry(current_task)
34}