Skip to content
Draft
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
48 changes: 46 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
key: custom-out-${{ runner.os }}-${{ github.job }}-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('**/litebox_syscall_rewriter/**/*.rs') }}
- run: ./.github/tools/github_actions_run_cargo fmt
- run: |
./.github/tools/github_actions_run_cargo clippy --all-targets --all-features --workspace --exclude litebox_runner_lvbs --exclude litebox_runner_snp --exclude litebox_runner_optee_on_linux_userland
./.github/tools/github_actions_run_cargo clippy --all-targets --all-features --workspace --exclude litebox_runner_lvbs --exclude litebox_runner_snp --exclude litebox_runner_optee_on_linux_userland --exclude litebox_runner_linux_on_macos_userland
./.github/tools/github_actions_run_cargo clippy --all-targets --all-features -p litebox_runner_optee_on_linux_userland
# We exclude `litebox_runner_lvbs` because it requires a custom target and nightly
# features. `build_and_test_lvbs` covers it.
Expand All @@ -76,7 +76,7 @@ jobs:
# aren't included in nextest at the moment. See relevant discussion at
# https://github.com/nextest-rs/nextest/issues/16
- name: Build documentation (fail on warnings)
run: ./.github/tools/github_actions_run_cargo doc --no-deps --all-features --document-private-items --workspace --exclude litebox_runner_lvbs --exclude litebox_runner_snp
run: ./.github/tools/github_actions_run_cargo doc --no-deps --all-features --document-private-items --workspace --exclude litebox_runner_lvbs --exclude litebox_runner_snp --exclude litebox_runner_linux_on_macos_userland

build_and_test_arm64:
name: Build and Test (AArch64)
Expand Down Expand Up @@ -138,6 +138,42 @@ jobs:
RUSTDOCFLAGS: -Dwarnings
run: ./.github/tools/github_actions_run_cargo doc --no-deps --all-features --document-private-items $AARCH64_CRATES

build_and_test_macos_arm64:
name: Build and Test (macOS AArch64)
runs-on: macos-15
env:
RUSTFLAGS: -Dwarnings
MACOS_AARCH64_CRATES: >-
-p dev_tests
-p litebox
-p litebox_common_linux
-p litebox_syscall_rewriter
-p litebox_platform_macos_userland
-p litebox_shim_linux
-p litebox_runner_linux_on_macos_userland
steps:
- name: Check out repo
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Verify AArch64 host
run: test "$(uname -m)" = arm64
- name: Set up Rust
run: |
rustup toolchain install $(awk -F'"' '/channel/{print $2}' rust-toolchain.toml) --profile minimal --no-self-update --component rustfmt,clippy
- name: Set up Nextest
uses: taiki-e/install-action@ba47c86ac325773530516bb756137ac718732518 # v2.86.5
with:
tool: nextest@${{ env.NEXTEST_VERSION }}
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
- run: ./.github/tools/github_actions_run_cargo fmt
- run: ./.github/tools/github_actions_run_cargo clippy --all-targets --all-features $MACOS_AARCH64_CRATES
- run: ./.github/tools/github_actions_run_cargo build $MACOS_AARCH64_CRATES
- run: ./.github/tools/github_actions_run_cargo nextest $MACOS_AARCH64_CRATES
- run: ./.github/tools/github_actions_run_cargo test --doc $MACOS_AARCH64_CRATES
- name: Build documentation (fail on warnings)
env:
RUSTDOCFLAGS: -Dwarnings
run: ./.github/tools/github_actions_run_cargo doc --no-deps --all-features --document-private-items $MACOS_AARCH64_CRATES

build_and_test_lvbs:
name: Build and Test LVBS
runs-on: ubuntu-latest
Expand Down Expand Up @@ -298,6 +334,9 @@ jobs:
# - `litebox_platform_linux_userland` is allowed to have `std` access,
# since it is a purely-userland implementation.
#
# - `litebox_platform_macos_userland` is allowed to have `std` access,
# since it is a purely-userland implementation.
#
# - `litebox_platform_windows_userland` is allowed to have `std` access,
# since it is a purely-userland implementation.
#
Expand Down Expand Up @@ -327,6 +366,9 @@ jobs:
# - `litebox_platform_lvbs` has a custom target (`no_std`), so it does
# not work with the current no_std checker.
#
# - `litebox_runner_linux_on_macos_userland` is allowed to have `std`
# access since it loads files and runs LiteBox on a hosted platform.
#
# - `litebox_runner_linux_on_windows_userland` is allowed to have `std`
# access since it needs to actually access the file-system, pull in
# relevant files, and then actually trigger LiteBox itself.
Expand Down Expand Up @@ -386,7 +428,9 @@ jobs:
-not -path './litebox_broker_userland/Cargo.toml' \
-not -path './litebox_egress_proxy/Cargo.toml' \
-not -path './litebox_platform_linux_userland/Cargo.toml' \
-not -path './litebox_platform_macos_userland/Cargo.toml' \
-not -path './litebox_platform_windows_userland/Cargo.toml' \
-not -path './litebox_runner_linux_on_macos_userland/Cargo.toml' \
-not -path './litebox_runner_linux_on_windows_userland/Cargo.toml' \
-not -path './litebox_runner_windows_on_linux_userland/Cargo.toml' \
-not -path './litebox_platform_lvbs/Cargo.toml' \
Expand Down
29 changes: 29 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ members = [
"litebox_egress_proxy",
"litebox_platform_linux_kernel",
"litebox_platform_linux_userland",
"litebox_platform_macos_userland",
"litebox_platform_windows_userland",
"litebox_platform_lvbs",
"litebox_runner_linux_userland",
"litebox_runner_linux_on_macos_userland",
"litebox_runner_linux_on_windows_userland",
"litebox_runner_windows_on_linux_userland",
"litebox_runner_windows_userland",
Expand Down Expand Up @@ -61,6 +63,7 @@ default-members = [
"litebox_egress_proxy",
"litebox_platform_linux_kernel",
"litebox_platform_linux_userland",
"litebox_platform_macos_userland",
"litebox_platform_windows_userland",
"litebox_platform_lvbs",
"litebox_runner_linux_userland",
Expand Down
2 changes: 2 additions & 0 deletions dev_tests/src/boilerplate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ const SKIP_FILES: &[&str] = &[
"LICENSE",
"litebox_platform/src/sync/mutex.rs",
"litebox_platform/src/sync/rwlock.rs",
"litebox_runner_linux_on_macos_userland/tests/test-bins/hello_world_dyn",
"litebox_runner_linux_on_macos_userland/tests/test-bins/ld-linux-aarch64.so.1",
"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
3 changes: 3 additions & 0 deletions dev_tests/src/ratchet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fn ratchet_transmutes() -> Result<()> {
("dev_tests/", 2),
("litebox/", 8),
("litebox_platform_linux_userland/", 2),
("litebox_platform_macos_userland/", 2),
],
|file| {
Ok(file
Expand Down Expand Up @@ -41,6 +42,7 @@ fn ratchet_globals() -> Result<()> {
("litebox_platform/", 2),
("litebox_platform_linux_kernel/", 5),
("litebox_platform_linux_userland/", 5),
("litebox_platform_macos_userland/", 5),
("litebox_platform_lvbs/", 21),
("litebox_platform_windows_userland/", 8),
("litebox_runner_lvbs/", 8),
Expand Down Expand Up @@ -77,6 +79,7 @@ fn ratchet_maybe_uninit() -> Result<()> {
("litebox/", 1),
("litebox_broker_transport_linux_userland/", 3),
("litebox_platform_linux_userland/", 2),
("litebox_platform_macos_userland/", 2),
],
|file| {
Ok(file
Expand Down
17 changes: 14 additions & 3 deletions litebox/src/mm/exception_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ macro_rules! ex_table_section {
};
}

#[cfg(target_os = "macos")]
macro_rules! ex_table_section {
() => {
// Regular data; retain entries even when the linker cannot see their users.
"__DATA,__ex_table,regular,no_dead_strip"
};
}

macro_rules! ex_table_entry {
($start:tt, $stop:tt, $recover:tt) => {
concat!(
Expand Down Expand Up @@ -302,14 +310,17 @@ struct ExceptionTableEntry {

/// Returns the exception table, found by linker-defined symbols marking the
/// start and end of the section.
#[cfg(any(target_os = "linux", target_os = "none"))]
#[cfg(any(target_os = "linux", target_os = "none", target_os = "macos"))]
fn exception_table() -> &'static [ExceptionTableEntry] {
// SAFETY: the linker automatically defines these symbols when the section
// is non-empty.
unsafe extern "C" {
#[link_name = "__start_ex_table"]
// \x01 suppresses Mach-O's leading underscore.
#[cfg_attr(target_os = "macos", link_name = "\x01section$start$__DATA$__ex_table")]
#[cfg_attr(not(target_os = "macos"), link_name = "__start_ex_table")]
static START_EX_TABLE: [ExceptionTableEntry; 0];
#[link_name = "__stop_ex_table"]
#[cfg_attr(target_os = "macos", link_name = "\x01section$end$__DATA$__ex_table")]
#[cfg_attr(not(target_os = "macos"), link_name = "__stop_ex_table")]
static STOP_EX_TABLE: [ExceptionTableEntry; 0];
}

Expand Down
12 changes: 11 additions & 1 deletion litebox/src/mm/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ use crate::platform::page_mgmt::AllocationError;
use crate::platform::page_mgmt::FixedAddressBehavior;
use crate::platform::page_mgmt::MemoryRegionPermissions;

/// Page size in bytes
/// Host page size in bytes on Apple Silicon macOS.
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
pub const PAGE_SIZE: usize = 16384;

/// Page size in bytes.
#[cfg(not(all(target_os = "macos", target_arch = "aarch64")))]
pub const PAGE_SIZE: usize = 4096;

bitflags::bitflags! {
Expand Down Expand Up @@ -660,6 +665,9 @@ impl<Platform: PageManagementProvider<ALIGN> + 'static, const ALIGN: usize> Vmem
} {
Ok(_) => {}
Err(AllocationError::OutOfMemory) => return Err(VmemResizeError::OutOfMemory),
Err(AllocationError::PermissionDenied) => {
return Err(VmemResizeError::PermissionDenied);
}
Err(
AllocationError::AddressInUse
| AllocationError::AddressInUseByPlatform
Expand Down Expand Up @@ -979,6 +987,8 @@ pub(super) enum VmemResizeError {
InvalidAddr { range: Range<usize>, addr: usize },
#[error("range {0:?} is already (partially) occupied")]
RangeOccupied(Range<usize>),
#[error("requested page permissions are denied")]
PermissionDenied,
#[error("out of memory")]
OutOfMemory,
}
Expand Down
1 change: 1 addition & 0 deletions litebox/src/mm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ where
Err(linux::VmemResizeError::NotExist(_)) => Err(RemapError::AlreadyUnallocated),
Err(linux::VmemResizeError::InvalidAddr { .. }) => Err(RemapError::AlreadyAllocated),
Err(linux::VmemResizeError::OutOfMemory) => Err(RemapError::OutOfMemory),
Err(linux::VmemResizeError::PermissionDenied) => Err(RemapError::PermissionDenied),
}
}

Expand Down
4 changes: 4 additions & 0 deletions litebox/src/mm/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ impl crate::platform::PageManagementProvider<PAGE_SIZE> for DummyVmemBackend {
const TASK_ADDR_MAX: usize = 0x7FFF_FFFF_F000; // (1 << 47) - PAGE_SIZE;
#[cfg(all(target_arch = "aarch64", target_os = "linux"))]
const TASK_ADDR_MAX: usize = 0xFFFF_FFFF_F000; // 48-bit VA space
#[cfg(all(target_arch = "aarch64", target_os = "macos"))]
const TASK_ADDR_MIN: usize = 0x1_0000; // Vmem unit-test bound
#[cfg(all(target_arch = "aarch64", target_os = "macos"))]
const TASK_ADDR_MAX: usize = 0x7FFF_FE00_0000; // MACH_VM_MAX_ADDRESS

fn allocate_pages(
&self,
Expand Down
11 changes: 11 additions & 0 deletions litebox/src/platform/page_mgmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub trait PageManagementProvider<const ALIGN: usize>: RawPointerProvider {
)
.map_err(|e| match e {
AllocationError::OutOfMemory => RemapError::OutOfMemory,
AllocationError::PermissionDenied => RemapError::PermissionDenied,
AllocationError::AddressInUse | AllocationError::AddressInUseByPlatform => {
RemapError::AlreadyAllocated
}
Expand Down Expand Up @@ -220,6 +221,8 @@ pub enum AllocationError {
AboveMaxAddress,
#[error("out of memory")]
OutOfMemory,
#[error("requested page permissions are denied")]
PermissionDenied,
#[error("provided fixed address range is in use")]
AddressInUse,
#[error("provided fixed address range is in use by the platform")]
Expand Down Expand Up @@ -250,6 +253,8 @@ pub enum RemapError {
Overlapping,
#[error("provided new range is already allocated")]
AlreadyAllocated,
#[error("requested page permissions are denied")]
PermissionDenied,
#[error("out of memory")]
OutOfMemory,
}
Expand All @@ -262,6 +267,12 @@ pub enum PermissionUpdateError {
Unaligned,
#[error("provided range contains unallocated pages")]
Unallocated,
#[error("requested page permissions are denied")]
PermissionDenied,
#[error("out of memory")]
OutOfMemory,
#[error("platform failed to update page permissions")]
PlatformFailure,
}

/// Possible errors for [`PageManagementProvider::try_allocate_cow_pages`]
Expand Down
9 changes: 7 additions & 2 deletions litebox_common_linux/src/errno/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ impl From<litebox::platform::page_mgmt::AllocationError> for Errno {
litebox::platform::page_mgmt::AllocationError::Unaligned
| litebox::platform::page_mgmt::AllocationError::AboveMaxAddress => Errno::EINVAL,
litebox::platform::page_mgmt::AllocationError::BelowMinAddress => Errno::EPERM,
litebox::platform::page_mgmt::AllocationError::PermissionDenied => Errno::EACCES,
litebox::platform::page_mgmt::AllocationError::OutOfMemory
| litebox::platform::page_mgmt::AllocationError::AddressPartiallyInUse
| litebox::platform::page_mgmt::AllocationError::AddressInUseByPlatform => {
Expand Down Expand Up @@ -299,7 +300,8 @@ impl From<litebox::platform::page_mgmt::RemapError> for Errno {
| litebox::platform::page_mgmt::RemapError::Overlapping => Errno::EINVAL,
litebox::platform::page_mgmt::RemapError::AlreadyAllocated
| litebox::platform::page_mgmt::RemapError::AlreadyUnallocated => Errno::EFAULT,
litebox::platform::page_mgmt::RemapError::OutOfMemory => Errno::ENOMEM,
litebox::platform::page_mgmt::RemapError::OutOfMemory
| litebox::platform::page_mgmt::RemapError::PermissionDenied => Errno::ENOMEM,
_ => unimplemented!(),
}
}
Expand All @@ -309,7 +311,10 @@ impl From<litebox::platform::page_mgmt::PermissionUpdateError> for Errno {
fn from(value: litebox::platform::page_mgmt::PermissionUpdateError) -> Self {
match value {
litebox::platform::page_mgmt::PermissionUpdateError::Unaligned => Errno::EINVAL,
litebox::platform::page_mgmt::PermissionUpdateError::Unallocated => Errno::ENOMEM,
litebox::platform::page_mgmt::PermissionUpdateError::Unallocated
| litebox::platform::page_mgmt::PermissionUpdateError::OutOfMemory => Errno::ENOMEM,
litebox::platform::page_mgmt::PermissionUpdateError::PermissionDenied => Errno::EACCES,
litebox::platform::page_mgmt::PermissionUpdateError::PlatformFailure => Errno::EINVAL,
_ => unimplemented!(),
}
}
Expand Down
Loading
Loading