Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions litebox_common_linux/src/errno/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ impl From<litebox::net::errors::CloseError> for Errno {
impl From<litebox::fs::errors::ReadError> for Errno {
fn from(value: litebox::fs::errors::ReadError) -> Self {
match value {
litebox::fs::errors::ReadError::ClosedFd => Errno::EBADF,
litebox::fs::errors::ReadError::NotAFile => Errno::EISDIR,
litebox::fs::errors::ReadError::NotForReading => Errno::EBADF,
litebox::fs::errors::ReadError::Io => Errno::EIO,
Expand Down Expand Up @@ -337,6 +338,7 @@ impl From<litebox::path::ConversionError> for Errno {
impl From<litebox::fs::errors::FileStatusError> for Errno {
fn from(value: litebox::fs::errors::FileStatusError) -> Self {
match value {
litebox::fs::errors::FileStatusError::ClosedFd => Errno::EBADF,
litebox::fs::errors::FileStatusError::PathError(path_error) => path_error.into(),
_ => unimplemented!(),
}
Expand Down
4 changes: 2 additions & 2 deletions litebox_common_linux/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub mod ioctl {

bitflags::bitflags! {
/// Desired memory protection of a memory mapping.
#[derive(PartialEq, Debug)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub struct ProtFlags: core::ffi::c_int {
/// Pages cannot be accessed.
const PROT_NONE = 0;
Expand All @@ -128,7 +128,7 @@ bitflags::bitflags! {

bitflags::bitflags! {
/// Additional parameters for [`mmap`].
#[derive(Debug)]
#[derive(Copy, Clone, Debug)]
pub struct MapFlags: core::ffi::c_int {
/// Share this mapping. Mutually exclusive with `MAP_PRIVATE`.
const MAP_SHARED = 0x1;
Expand Down
15 changes: 9 additions & 6 deletions litebox_common_linux/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ struct TrampolineHeader32 {
trampoline_size: u32,
}

/// Size in bytes of the trampoline footer for the target architecture.
pub const TRAMPOLINE_HEADER_SIZE: usize = if cfg!(target_pointer_width = "64") {
size_of::<TrampolineHeader64>()
} else {
size_of::<TrampolineHeader32>()
};

const CLASS: elf::file::Class = if cfg!(target_pointer_width = "64") {
elf::file::Class::ELF64
} else {
Expand Down Expand Up @@ -265,11 +272,7 @@ impl ElfParsedFile {

let file_size = file.size().map_err(ElfParseError::Io)?;

let header_size = if cfg!(target_pointer_width = "64") {
size_of::<TrampolineHeader64>()
} else {
size_of::<TrampolineHeader32>()
};
let header_size = TRAMPOLINE_HEADER_SIZE;

// File must be large enough to contain the header
if file_size < header_size as u64 {
Expand All @@ -279,7 +282,7 @@ impl ElfParsedFile {

// Read the header from the end of the file
let header_offset = file_size - header_size as u64;
let mut header_buf = [0u8; size_of::<TrampolineHeader64>()]; // Max header size
let mut header_buf = [0u8; TRAMPOLINE_HEADER_SIZE];
file.read_at(header_offset, &mut header_buf[..header_size])
.map_err(ElfParseError::Io)?;

Expand Down
1 change: 1 addition & 0 deletions litebox_shim_linux/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ringbuf = { version = "0.4.8", default-features = false, features = ["alloc"] }
zerocopy = { version = "0.8", default-features = false, features = ["derive"] }
litebox_syscall_rewriter = { version = "0.1.0", path = "../litebox_syscall_rewriter", default-features = false }
object = { version = "0.36.7", default-features = false, features = ["elf", "read_core"] }
rangemap = { version = "1.5.1", features = ["const_fn"] }

[features]
alarm_fallback = []
Expand Down
2 changes: 1 addition & 1 deletion litebox_shim_linux/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ struct GlobalState<Platform: ShimPlatform> {
/// UNIX domain socket address table
unix_addr_table: litebox::sync::RwLock<Platform, syscalls::unix::UnixAddrTable<Platform>>,
/// Per-process collection of ELF patching state for runtime syscall rewriting.
elf_patch_cache: litebox::sync::Mutex<Platform, syscalls::mm::ElfPatchCache>,
elf_patch_cache: litebox::sync::Mutex<Platform, syscalls::mm::ElfPatchCache<Platform>>,
}

struct Task<Platform: ShimPlatform> {
Expand Down
7 changes: 3 additions & 4 deletions litebox_shim_linux/src/syscalls/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,10 +927,9 @@ impl<Platform: ShimPlatform> Task<Platform> {

match consumed {
AnyTypedFd::Fs(fd) => {
if let Ok(raw_fd) = i32::try_from(raw_fd) {
self.finalize_elf_patch(raw_fd);
}
files.fs.close(&fd).map_err(Errno::from)
let result = files.fs.close(&fd).map_err(Errno::from);
self.finalize_elf_patch(fd);
result
}
AnyTypedFd::Network(fd) => self.global.close_socket(&self.wait_cx(), fd),
AnyTypedFd::Pipes(fd) => self.global.close_linux_pipe(&fd),
Expand Down
Loading
Loading