diff --git a/src/consts.rs b/src/consts.rs index 05cec2ca..da809793 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -28,17 +28,3 @@ pub const UHYVE_QUEUE_SIZE: usize = 8; pub const UHYVE_IRQ_NET: u32 = 11; pub const GUEST_PAGE_SIZE: u64 = 0x200000; /* 2 MB pages in guest */ - -// File operations supported by Hermit and Uhyve -pub const O_RDONLY: i32 = 0o0000; -pub const O_WRONLY: i32 = 0o0001; -pub const O_RDWR: i32 = 0o0002; -pub const O_CREAT: i32 = 0o0100; -pub const O_EXCL: i32 = 0o0200; -pub const O_TRUNC: i32 = 0o1000; -pub const O_APPEND: i32 = 0o2000; -pub const O_DIRECT: i32 = 0o40000; -pub const O_DIRECTORY: i32 = 0o200000; - -pub const ALLOWED_OPEN_FLAGS: i32 = - O_RDONLY | O_WRONLY | O_RDWR | O_CREAT | O_EXCL | O_TRUNC | O_APPEND | O_DIRECT | O_DIRECTORY; diff --git a/src/hypercall.rs b/src/hypercall.rs index f8f6cb6c..18548f21 100644 --- a/src/hypercall.rs +++ b/src/hypercall.rs @@ -4,11 +4,12 @@ use std::{ os::unix::ffi::OsStrExt, }; +use libc::{EINVAL, EIO, ENOENT}; use tempfile::TempDir; use uhyve_interface::{parameters::*, GuestPhysAddr, Hypercall, HypercallAddress, MAX_ARGC_ENVC}; use crate::{ - consts::{ALLOWED_OPEN_FLAGS, BOOT_PML4, O_CREAT, O_DIRECTORY, O_EXCL}, + consts::BOOT_PML4, isolation::UhyveFileMap, mem::{MemoryError, MmapMemory}, virt_to_phys, @@ -97,11 +98,11 @@ pub fn unlink(mem: &MmapMemory, sysunlink: &mut UnlinkParams, file_map: &mut Uhy } } else { error!("The kernel requested to unlink() an unknown path ({guest_path}): Rejecting..."); - sysunlink.ret = -1; + sysunlink.ret = -ENOENT; } } else { error!("The kernel requested to open() a path that is not valid UTF-8. Rejecting..."); - sysunlink.ret = -1; + sysunlink.ret = -EIO; } } @@ -142,7 +143,7 @@ pub fn open( // See: https://github.com/hermit-os/kernel/commit/71bc629 if (flags & (O_DIRECTORY | O_CREAT)) == (O_DIRECTORY | O_CREAT) { error!("An open() call used O_DIRECTORY and O_CREAT at the same time. Aborting..."); - sysopen.ret = -1 + sysopen.ret = -EINVAL } // Existing files that already exist should be in the file map, not here. @@ -162,7 +163,7 @@ pub fn open( } } else { error!("The kernel requested to open() a path that is not valid UTF-8. Rejecting..."); - sysopen.ret = -1; + sysopen.ret = -EINVAL; } } diff --git a/uhyve-interface/src/parameters.rs b/uhyve-interface/src/parameters.rs index e255ae08..70638247 100644 --- a/uhyve-interface/src/parameters.rs +++ b/uhyve-interface/src/parameters.rs @@ -144,3 +144,17 @@ pub struct SerialWriteBufferParams { pub buf: GuestPhysAddr, pub len: usize, } + +// File operations supported by Hermit and Uhyve +pub const O_RDONLY: i32 = 0o0000; +pub const O_WRONLY: i32 = 0o0001; +pub const O_RDWR: i32 = 0o0002; +pub const O_CREAT: i32 = 0o0100; +pub const O_EXCL: i32 = 0o0200; +pub const O_TRUNC: i32 = 0o1000; +pub const O_APPEND: i32 = 0o2000; +pub const O_DIRECT: i32 = 0o40000; +pub const O_DIRECTORY: i32 = 0o200000; + +pub const ALLOWED_OPEN_FLAGS: i32 = + O_RDONLY | O_WRONLY | O_RDWR | O_CREAT | O_EXCL | O_TRUNC | O_APPEND | O_DIRECT | O_DIRECTORY;