Skip to content

Commit

Permalink
fd >= 0 && fd <= 2
Browse files Browse the repository at this point in the history
  • Loading branch information
n0toose committed Jan 8, 2025
1 parent 2bbae9b commit e9968f6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/hypercall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ pub fn open(mem: &MmapMemory, sysopen: &mut OpenParams, file_map: &mut UhyveFile
let host_path_c_string = file_map.create_temporary_file(guest_path);
let new_host_path = host_path_c_string.as_c_str().as_ptr();
sysopen.ret = unsafe { libc::open(new_host_path, flags, sysopen.mode) };
let ret = sysopen.ret;
error!("{:#?}", ret);
if sysopen.ret >= 0 {
file_map.insert_fd_path(sysopen.ret.into_raw_fd(), guest_path);
}
Expand Down Expand Up @@ -187,6 +189,8 @@ pub fn write<B: VirtualizationBackend>(
syswrite: &WriteParams,
file_map: &mut UhyveFileMap,
) -> io::Result<()> {
let fd = syswrite.fd;
error!("{:#?}", fd);
let mut bytes_written: usize = 0;
while bytes_written != syswrite.len {
let guest_phys_addr = virt_to_phys(
Expand Down
8 changes: 5 additions & 3 deletions src/isolation/filemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ impl UhyveFileMap {
/// * `guest_path` - The guest path that is to be looked up in the map.
pub fn get_host_path(&mut self, guest_path: &str) -> Option<OsString> {
let host_path = self.files.get(guest_path).map(OsString::from);
debug!("get_host_path (host_path): {:#?}", host_path);
if host_path.is_some() {
host_path
} else {
Expand Down Expand Up @@ -112,14 +113,15 @@ impl UhyveFileMap {
.path()
.join(Uuid::new_v4().to_string())
.into_os_string();
debug!("create_temporary_file (host_path): {:#?}", host_path);
let ret = CString::new(host_path.as_bytes()).unwrap();
self.files.insert(String::from(guest_path), host_path);
ret
}

pub fn get_fd_presence(&mut self, fd: RawFd) -> bool {
debug!("get_fd_presence: {:#?}", &self.fdmap);
if fd >= 0 && self.fdmap.contains_left(&fd) {
if (fd >= 0 && self.fdmap.contains_left(&fd)) || (fd >= 0 && fd <= 2) {
return true;
}
false
Expand All @@ -131,7 +133,7 @@ impl UhyveFileMap {
/// * `guest_path` - The guest path.
pub fn insert_fd_path(&mut self, fd: RawFd, guest_path: &str) {
debug!("insert_fd_path: {:#?}", &self.fdmap);
if fd >= 0 {
if fd > 2 {
self.fdmap.insert(fd, guest_path.into());
}
}
Expand All @@ -143,7 +145,7 @@ impl UhyveFileMap {
/// * `fd` - The file descriptor of the file being removed.
pub fn remove_fd(&mut self, fd: RawFd) {
debug!("remove_fd: {:#?}", &self.fdmap);
if fd >= 0 {
if fd > 2 {
self.fdmap.remove_by_left(&fd);
}
}
Expand Down

0 comments on commit e9968f6

Please sign in to comment.