MCPcopy Create free account
hub / github.com/bendudson/EuraliOS / dispatch_syscall

Function dispatch_syscall

kernel/src/syscalls.rs:275–313  ·  view source on GitHub ↗
(context_ptr: *mut Context, syscall_id: u64,
                               arg1: u64, arg2: u64, arg3: u64)

Source from the content-addressed store, hash-verified

273}
274
275extern "C" fn dispatch_syscall(context_ptr: *mut Context, syscall_id: u64,
276 arg1: u64, arg2: u64, arg3: u64) {
277
278 let context = unsafe{&mut *context_ptr};
279
280 // Set the CS and SS segment selectors
281 let (code_selector, data_selector) =
282 if context.rip < process::USER_CODE_START as usize {
283 // Called from kernel code
284 gdt::get_kernel_segments()
285 } else {
286 gdt::get_user_segments()
287 };
288 context.cs = code_selector.0 as usize;
289 context.ss = data_selector.0 as usize;
290
291 match syscall_id & SYSCALL_MASK {
292 SYSCALL_FORK_THREAD => process::fork_current_thread(context),
293 SYSCALL_EXIT_THREAD => process::exit_current_thread(context),
294 SYSCALL_DEBUG_WRITE => sys_debug_write(arg1 as *const u8, arg2 as usize),
295 SYSCALL_RECEIVE => sys_receive(context_ptr, arg1),
296 SYSCALL_SEND => sys_send(context_ptr, syscall_id, arg1, arg2, arg3),
297 SYSCALL_SENDRECEIVE => sys_send(context_ptr, syscall_id, arg1, arg2, arg3), // sys_sendreceive
298 SYSCALL_OPEN => sys_open(context_ptr, arg1 as *const u8, arg2 as usize),
299 SYSCALL_MALLOC => sys_malloc(context_ptr, arg1, arg2),
300 SYSCALL_FREE => sys_free(context_ptr, arg1),
301 SYSCALL_YIELD => sys_yield(context_ptr),
302 SYSCALL_NEW_RENDEZVOUS => sys_new_rendezvous(context_ptr),
303 SYSCALL_COPY_RENDEZVOUS => sys_copy_rendezvous(context_ptr, arg1),
304 SYSCALL_EXEC => sys_exec(context_ptr, syscall_id, arg1 as *const u8, arg2, arg3 as *const u8),
305 SYSCALL_MOUNT => sys_mount(context_ptr, syscall_id, arg1 as *const u8, arg2),
306 SYSCALL_LISTMOUNTS => sys_listmounts(context_ptr),
307 SYSCALL_UMOUNT => sys_umount(context_ptr, arg1 as *const u8, arg2),
308 SYSCALL_CLOSE => sys_close(context_ptr, arg1),
309 SYSCALL_AWAIT_INTERRUPT => sys_await_interrupt(context_ptr, arg1),
310 _ => println!("Unknown syscall {:?} {} {} {}",
311 context_ptr, syscall_id, arg1, arg2)
312 }
313}
314
315fn sys_debug_write(ptr: *const u8, len:usize) {
316 // Check all inputs: Does ptr -> ptr+len lie entirely in user address space?

Callers

nothing calls this directly

Calls 15

get_kernel_segmentsFunction · 0.85
get_user_segmentsFunction · 0.85
fork_current_threadFunction · 0.85
exit_current_threadFunction · 0.85
sys_debug_writeFunction · 0.85
sys_receiveFunction · 0.85
sys_sendFunction · 0.85
sys_openFunction · 0.85
sys_mallocFunction · 0.85
sys_freeFunction · 0.85
sys_yieldFunction · 0.85
sys_new_rendezvousFunction · 0.85

Tested by

no test coverage detected