Skip to content

Commit

Permalink
Migrate fd_renumber
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Konka committed Mar 18, 2020
1 parent 4f32310 commit 52a9467
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions crates/wasi-common/src/snapshots/wasi_snapshot_preview1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,28 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx {
unimplemented!("fd_readdir")
}

fn fd_renumber(&self, _fd: types::Fd, _to: types::Fd) -> Result<()> {
unimplemented!("fd_renumber")
fn fd_renumber(&self, from: types::Fd, to: types::Fd) -> Result<()> {
trace!("fd_renumber(from={:?}, to={:?})", from, to);

if unsafe { !self.contains_entry(from) } {
return Err(Errno::Badf);
}

// Don't allow renumbering over a pre-opened resource.
// TODO: Eventually, we do want to permit this, once libpreopen in
// userspace is capable of removing entries from its tables as well.
let from_fe = unsafe { self.get_entry(from)? };
if from_fe.preopen_path.is_some() {
return Err(Errno::Notsup);
}
if let Ok(to_fe) = unsafe { self.get_entry(to) } {
if to_fe.preopen_path.is_some() {
return Err(Errno::Notsup);
}
}
let fe = self.remove_entry(from)?;
self.insert_entry_at(to, fe);
Ok(())
}

fn fd_seek(
Expand Down

0 comments on commit 52a9467

Please sign in to comment.