(context_ptr: *mut Context, syscall_id: u64,
arg1: u64, arg2: u64, arg3: u64)
| 273 | } |
| 274 | |
| 275 | extern "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 | |
| 315 | fn sys_debug_write(ptr: *const u8, len:usize) { |
| 316 | // Check all inputs: Does ptr -> ptr+len lie entirely in user address space? |
nothing calls this directly
no test coverage detected