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.

5 changes: 2 additions & 3 deletions dev_bench/unixbench/prepare_unixbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ def prepare_benchmark(
"""
Prepare a single benchmark using litebox_packager.
The packager discovers dependencies, rewrites all ELFs, and creates a tar
(including litebox_rtld_audit.so). The rewritten main binary is extracted
from the tar and placed alongside it.
The packager discovers dependencies, rewrites all ELFs, and creates a tar.
The rewritten main binary is extracted from the tar and placed alongside it.
Returns True on success.
"""
Expand Down
1 change: 0 additions & 1 deletion dev_tests/src/boilerplate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ const SKIP_FILES: &[&str] = &[
"LICENSE",
"litebox/src/sync/mutex.rs",
"litebox/src/sync/rwlock.rs",
"litebox_rtld_audit/Makefile",
"litebox_runner_linux_on_windows_userland/tests/test-bins/hello_exec_nolibc",
"litebox_runner_linux_on_windows_userland/tests/test-bins/hello_thread",
"litebox_runner_linux_on_windows_userland/tests/test-bins/hello_thread_static",
Expand Down
2 changes: 1 addition & 1 deletion litebox/src/mm/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl From<VmFlags> for MemoryRegionPermissions {
}
}

const DEFAULT_RESERVED_SPACE_SIZE: usize = 0x100_0000; // 16 MiB
pub const DEFAULT_RESERVED_SPACE_SIZE: usize = 0x100_0000; // 16 MiB

bitflags::bitflags! {
/// Options for page creation.
Expand Down
26 changes: 21 additions & 5 deletions litebox_common_linux/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ pub enum ElfParseError<E> {
BadTrampoline,
#[error("Invalid trampoline version")]
BadTrampolineVersion,
#[error("Binary not patched for syscall rewriting")]
UnpatchedBinary,
#[error("Unsupported ELF type")]
UnsupportedType,
#[error("Bad interpreter")]
Expand All @@ -139,6 +141,7 @@ impl<E: Into<Errno>> From<ElfParseError<E>> for Errno {
| ElfParseError::BadFormat
| ElfParseError::BadTrampoline
| ElfParseError::BadTrampolineVersion
| ElfParseError::UnpatchedBinary
| ElfParseError::BadInterp
| ElfParseError::UnsupportedType => Errno::ENOEXEC,
ElfParseError::Io(err) => err.into(),
Expand Down Expand Up @@ -216,6 +219,11 @@ impl ElfParsedFile {
})
}

/// Returns `true` if a trampoline was parsed and will be mapped by `load()`.
pub fn has_trampoline(&self) -> bool {
self.trampoline.is_some()
}

/// Parse the LiteBox trampoline data, if any.
///
/// The trampoline header is located at the end of the file (last 32/20 bytes).
Expand Down Expand Up @@ -249,7 +257,8 @@ impl ElfParsedFile {

// File must be large enough to contain the header
if file_size < header_size as u64 {
return Ok(());
// Too small for a trampoline header — binary is unpatched.
return Err(ElfParseError::UnpatchedBinary);
}

// Read the header from the end of the file
Expand All @@ -265,8 +274,8 @@ impl ElfParsedFile {
if &header_buf[0..7] == b"LITEBOX" {
return Err(ElfParseError::BadTrampolineVersion);
}
// No trampoline found, which is OK (not all binaries are rewritten)
return Ok(());
// No trampoline found.
return Err(ElfParseError::UnpatchedBinary);
}

let (file_offset, vaddr, trampoline_size) = if cfg!(target_pointer_width = "64") {
Expand All @@ -291,9 +300,10 @@ impl ElfParsedFile {
)
};

// Validate trampoline size
// trampoline_size == 0 means the rewriter checked this binary and found
// no syscall instructions.
if trampoline_size == 0 {
return Err(ElfParseError::BadTrampoline);
return Ok(());
}

// Verify the file offset is page-aligned (as required by the rewriter)
Expand Down Expand Up @@ -366,6 +376,7 @@ impl ElfParsedFile {
&self,
mapper: &mut M,
mem: &mut impl AccessMemory,
reserve_trampoline: Option<usize>,
) -> Result<MappingInfo, ElfLoadError<M::Error>> {
let base_addr = if self.header.e_type == elf::abi::ET_DYN {
// Find an aligned load address that will fit all PT_LOAD segments.
Expand Down Expand Up @@ -473,6 +484,11 @@ impl ElfParsedFile {

if self.trampoline.is_some() {
self.load_trampoline(mapper, mem, &mut info)?;
} else if let Some(size) = reserve_trampoline {
// Reserve space for a runtime trampoline so brk starts past it.
// The runtime patching path (do_mmap_file → maybe_patch_exec_segment)
// will allocate the actual trampoline in this region via MAP_FIXED.
info.brk = page_align_up(info.brk) + page_align_up(size);
}

Ok(info)
Expand Down
43 changes: 0 additions & 43 deletions litebox_packager/build.rs

This file was deleted.

17 changes: 0 additions & 17 deletions litebox_packager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,23 +356,6 @@ fn finalize_tar(
});
}

// Include the rtld audit library so the rewriter backend can load it.
#[cfg(target_arch = "x86_64")]
{
const RTLD_AUDIT_TAR_PATH: &str = "lib/litebox_rtld_audit.so";
if !added_tar_paths.insert(RTLD_AUDIT_TAR_PATH.to_string()) {
bail!(
"tar already contains {RTLD_AUDIT_TAR_PATH} -- \
remove the conflicting entry or use --no-rewrite"
);
}
tar_entries.push(TarEntry {
tar_path: RTLD_AUDIT_TAR_PATH.to_string(),
data: include_bytes!(concat!(env!("OUT_DIR"), "/litebox_rtld_audit.so")).to_vec(),
mode: 0o755,
});
}

// Build tar.
eprintln!("Creating {}...", args.output.display());
build_tar(&tar_entries, &args.output)?;
Expand Down
1 change: 0 additions & 1 deletion litebox_rtld_audit/.gitignore

This file was deleted.

26 changes: 0 additions & 26 deletions litebox_rtld_audit/Makefile

This file was deleted.

Loading
Loading