Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
33 changes: 4 additions & 29 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions dev_tests/src/ratchet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ fn ratchet_transmutes() -> Result<()> {
&[
("dev_tests/", 2),
("litebox/", 1),
("litebox_shim_linux/", 1),
("litebox_platform_linux_userland/", 2),
],
|file| {
Expand All @@ -34,7 +33,7 @@ fn ratchet_globals() -> Result<()> {
("litebox_platform_windows_userland/", 8),
("litebox_runner_linux_userland/", 1),
("litebox_shim_linux/", 11),
("litebox_shim_optee/", 6),
("litebox_shim_optee/", 5),
],
|file| {
Ok(file
Expand Down
26 changes: 19 additions & 7 deletions litebox/src/mm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,20 @@ where
unsafe { self.create_pages(suggested_address, length, flags, perms, perms, |_| Ok(0)) }
}

/// Set the initial program break address.
///
/// This function should be called once to set the initial program break,
/// which is usually the end of the data segment.
///
/// # Panics
///
/// Panics if the initial program break is already set.
pub fn set_initial_brk(&self, brk: usize) {
let mut vmem = self.vmem.write();
assert_eq!(vmem.brk, 0, "initial brk is already set");
vmem.brk = brk;
}

/// Set the program break to the given address.
///
/// Increasing the program break has the effect of allocating memory to the process;
Expand All @@ -290,18 +304,16 @@ where
///
/// If the operation is successful, it returns the new program break address.
///
/// # Panics
///
/// Panics if the initial program break is not set yet.
///
/// # Safety
///
/// If shrinking the program break, the caller must ensure that the released memory region is no longer used.
pub unsafe fn brk(&self, brk: usize) -> Result<usize, MappingError> {
let mut vmem = self.vmem.write();
if vmem.brk == 0 {
// If the old brk is not set yet, we set it to the new brk
// Note the first call should be made by the loader to set the initial brk
// to the end of the data segment.
vmem.brk = brk;
return Ok(brk);
}
assert_ne!(vmem.brk, 0, "initial brk is not set yet");
if brk == 0 {
// Calling `brk` with 0 can be used to find the current location of the program break.
return Ok(vmem.brk);
Expand Down
39 changes: 35 additions & 4 deletions litebox/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ mod private {
/// from implementing this trait.
pub trait Sealed {}

impl Sealed for &str {}
impl Sealed for str {}
impl Sealed for alloc::string::String {}
impl Sealed for &core::ffi::CStr {}
impl Sealed for core::ffi::CStr {}
impl Sealed for alloc::ffi::CString {}
impl Sealed for alloc::borrow::Cow<'_, str> {}
impl Sealed for alloc::borrow::Cow<'_, core::ffi::CStr> {}
impl<T: Sealed + ?Sized> Sealed for &T {}
}

/// Trait for passing path arguments
Expand Down Expand Up @@ -134,7 +135,37 @@ pub trait Arg: private::Sealed {
}
}

impl Arg for &str {
impl<T: Arg + ?Sized> Arg for &T {
fn to_c_str(&self) -> Result<Cow<'_, CStr>> {
T::to_c_str(self)
}

fn as_rust_str(&self) -> Result<&str> {
T::as_rust_str(self)
}

fn to_rust_str_lossy(&self) -> Cow<'_, str> {
T::to_rust_str_lossy(self)
}

fn components(&self) -> Result<impl Iterator<Item = &str>> {
T::components(self)
}

fn normalized_components(&self) -> Result<impl Iterator<Item = &str>> {
T::normalized_components(self)
}

fn normalized(&self) -> Result<String> {
T::normalized(self)
}

fn increasing_ancestors(&self) -> Result<impl Iterator<Item = &str>> {
T::increasing_ancestors(self)
}
}

impl Arg for str {
fn to_c_str(&self) -> Result<Cow<'_, CStr>> {
CString::new(self.as_bytes())
.map(Cow::Owned)
Expand Down Expand Up @@ -166,7 +197,7 @@ impl Arg for String {
}
}

impl Arg for &CStr {
impl Arg for CStr {
fn to_c_str(&self) -> Result<Cow<'_, CStr>> {
Ok(Cow::Borrowed(self))
}
Expand Down
2 changes: 2 additions & 0 deletions litebox_common_linux/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ edition = "2024"
bitfield = "0.19.1"
bitflags = "2.9.0"
cfg-if = "1.0.0"
elf = { version = "0.8.0", default-features = false }
litebox = { path = "../litebox/", version = "0.1.0" }
thiserror = { version = "2.0.6", default-features = false }
int-enum = "1.2.0"
syscalls = { version = "0.6", default-features = false }
zerocopy = { version = "0.8", features = ["derive"] }

[lints]
workspace = true
1 change: 1 addition & 0 deletions litebox_common_linux/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use litebox::{
use syscalls::Sysno;

pub mod errno;
pub mod loader;
pub mod mm;

extern crate alloc;
Expand Down
Loading