(
context_ptr: *mut Context,
ptr: *const u8,
len: usize)
| 440 | } |
| 441 | |
| 442 | fn sys_open( |
| 443 | context_ptr: *mut Context, |
| 444 | ptr: *const u8, |
| 445 | len: usize) { |
| 446 | |
| 447 | let context = unsafe {&mut (*context_ptr)}; |
| 448 | |
| 449 | // Check input length |
| 450 | if len == 0 { |
| 451 | context.rax = SYSCALL_ERROR_PARAM; |
| 452 | return; |
| 453 | } |
| 454 | // Convert raw pointer to a slice |
| 455 | let u8_slice = unsafe {slice::from_raw_parts(ptr, len)}; |
| 456 | |
| 457 | if let Ok(path_string) = str::from_utf8(u8_slice) { |
| 458 | match process::open_path(context, &path_string) { |
| 459 | Ok((handle, match_len)) => { |
| 460 | context.rax = 0; // No error |
| 461 | context.rdi = handle; // Return handle |
| 462 | context.rsi = match_len; // Path match length |
| 463 | } |
| 464 | Err(error_code) => { |
| 465 | context.rax = error_code; |
| 466 | } |
| 467 | } |
| 468 | } else { |
| 469 | // Bad utf8 conversion |
| 470 | context.rax = SYSCALL_ERROR_UTF8; |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | /// Allocates a chunk of memory |
| 475 | /// |
no test coverage detected