(path: &str, flags: u64)
| 350 | } |
| 351 | |
| 352 | fn _open(path: &str, flags: u64) -> Result<CommHandle, SyscallError> { |
| 353 | let error: u64; |
| 354 | let handle: u32; |
| 355 | let match_len: usize; |
| 356 | unsafe { |
| 357 | asm!("syscall", |
| 358 | in("rax") SYSCALL_OPEN, |
| 359 | in("rdi") path.as_ptr(), // First argument |
| 360 | in("rsi") path.len(), // Second argument |
| 361 | lateout("rax") error, |
| 362 | lateout("rdi") handle, |
| 363 | lateout("rsi") match_len, |
| 364 | out("rcx") _, |
| 365 | out("r11") _); |
| 366 | } |
| 367 | if error == 0 { |
| 368 | // Found mount point |
| 369 | let subpath = &path[match_len..]; |
| 370 | |
| 371 | if subpath.len() != 0 { |
| 372 | // Send unmatched part of the path to the given handle |
| 373 | let bytes = subpath.as_bytes(); |
| 374 | |
| 375 | match message::rcall( |
| 376 | &CommHandle(handle), |
| 377 | message::OPEN_READONLY + flags, |
| 378 | (bytes.len() as u64).into(), |
| 379 | MemoryHandle::from_u8_slice(bytes).into(), |
| 380 | None) { |
| 381 | // Success, returning a communication handle |
| 382 | Ok((message::COMM_HANDLE, |
| 383 | message::MessageData::CommHandle(handle), _)) => { |
| 384 | return Ok(handle); |
| 385 | } |
| 386 | Ok(_) => { |
| 387 | // Unexpected message type |
| 388 | return Err(SyscallError::new(0)); |
| 389 | } |
| 390 | Err((err, _msg)) => { |
| 391 | return Err(err); |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 | Ok(CommHandle(handle)) |
| 396 | } else { |
| 397 | Err(SyscallError(error)) |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | pub fn malloc( |
| 402 | num_bytes: u64, |
no test coverage detected