Skip to main content

kh_runtime/
lib.rs

1//! Native ARM64 execution context, guest memory layout, and trap hooks.
2//!
3//! Dependency rule: this crate must not depend on `kh-loader` or `kh-cli`.
4//!
5//! `unsafe` is denied by workspace lints and only allowed in tightly scoped
6//! modules (`host`, `mem/*`, `trap`, `entry`, and `bottle::read_c_string`).
7
8pub mod bottle;
9pub mod entry;
10pub mod host;
11pub mod mem;
12pub mod process;
13pub mod regs;
14pub mod stack;
15pub mod syscall;
16pub mod thread;
17pub mod trap;
18
19pub use bottle::{
20    BottleError, BottleStatus, CreateOptions, CreateResult, DARWIN_7ZZ_URL, DEFAULT_7ZZ_PATH,
21    ENV_7ZZ, GUEST_7ZZ_REL, GUEST_LIBCXX_REL, GUEST_LIBCXX_TARGET, GUEST_PATH_DIRS, InstallPackage,
22    InstallReport, PathError, ToolError, active_root, bottle_root, create as create_bottle,
23    create_with as create_bottle_with, destroy as destroy_bottle, discover_7zz, ensure as ensure_bottle,
24    ensure_libcxx_symlink, guest_path_to_host, has_libcxx_symlink, install_package,
25    package_host_path, resolve_guest_program, set_bottle_root, status as bottle_status,
26    translate_path, translate_path_with_root,
27};
28pub use process::{ProcessState, reset_run};
29
30pub use entry::{EntryError, call_guest, call_guest_args, jump_to_guest, jump_to_guest_args};
31pub use mem::{
32    AddressSpace, DARWIN_ARM64_PAGE_SIZE, GuestMemory, GuestPageSize, HostPageSize, MapError,
33    MapRequest, MappedRegion, PageError, PageLayout, VM_PROT_EXECUTE, VM_PROT_READ, VM_PROT_WRITE,
34    map_stack, mprotect_darwin, mprotect_rw, register_borrowed, registry_clear, registry_install,
35    registry_take,
36};
37pub use regs::ThreadRegs;
38pub use stack::{StackError, bootstrap_stack};
39pub use syscall::{
40    BsdSyscall, SyscallArgs, SyscallResult, known_syscalls, lookup as lookup_syscall, name_of,
41};
42pub use trap::{
43    PSTATE_C, TrapConfig, TrapError, TrapEvent, TrapOutcome, clear_expect_code,
44    clear_trace_on_exit, clear_trampoline_cache, finish_with_exit_code, hypercall_entry_addr,
45    install_trap_handlers, patch_svc_to_brk, set_expect_code, set_trace_on_exit, take_trace_events,
46};
47#[cfg(all(target_arch = "aarch64", target_os = "linux"))]
48pub use trap::kh_trampoline_dispatch;
49// `kh_hypercall_entry` is a `global_asm!` symbol; address via `hypercall_entry_addr`.