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 (`cpu`, `host`, `host_slot`, `mem/*`, `trap`, `entry`, `thread`,
7//! `tls`, `fat_thin`, and `bottle::read_c_string`).
8
9pub mod bottle;
10pub mod cpu;
11pub mod dyld_table;
12pub mod entry;
13pub mod fat_thin;
14pub mod host;
15pub mod host_slot;
16pub mod mem;
17pub mod process;
18pub mod regs;
19pub mod stack;
20pub mod syscall;
21pub mod thread;
22pub mod tls;
23pub mod tls_fd;
24pub mod tls_verify;
25pub mod trap;
26
27pub use bottle::{
28    BottleError, BottleStatus, CreateOptions, CreateResult, DARWIN_7ZZ_URL, DARWIN_CURL_URL,
29    DEFAULT_7ZZ_PATH, ENV_7ZZ, ENV_CURL, GUEST_7ZZ_REL, GUEST_CURL_REL, GUEST_LIBCURL_REL,
30    GUEST_LIBCURL_TARGET, GUEST_LIBCXX_REL, GUEST_LIBCXX_TARGET, GUEST_PATH_DIRS, InstallPackage,
31    InstallReport, PathError, ToolError, active_root, bottle_root, create as create_bottle,
32    create_with as create_bottle_with, destroy as destroy_bottle, discover_7zz, discover_curl,
33    ensure as ensure_bottle, ensure_libcurl_symlink, ensure_libcxx_symlink, guest_path_to_host,
34    has_libcurl_symlink, has_libcxx_symlink, install_package, package_host_path,
35    resolve_guest_program, set_bottle_root, status as bottle_status, translate_path,
36    translate_path_with_root,
37};
38pub use dyld_table::{
39    RTLD_DEFAULT, RTLD_NEXT, RTLD_SELF, clear as dyld_table_clear, dlopen_lookup, dlsym_lookup,
40    register_image as dyld_register_image,
41};
42pub use process::{ProcessState, reset_run};
43
44pub use entry::{EntryError, call_guest, call_guest_args, jump_to_guest, jump_to_guest_args};
45pub use host::MappedFile;
46pub use mem::{
47    AddressSpace, DARWIN_ARM64_PAGE_SIZE, GuestMemory, GuestPageSize, HostPageSize, MapError,
48    MapRequest, MappedRegion, PageError, PageLayout, VM_PROT_EXECUTE, VM_PROT_READ, VM_PROT_WRITE,
49    map_stack, mprotect_darwin, mprotect_rw, register_borrowed, registry_clear, registry_install,
50    registry_take,
51};
52pub use regs::ThreadRegs;
53pub use stack::{StackError, bootstrap_stack};
54pub use syscall::{
55    BsdSyscall, SyscallArgs, SyscallResult, known_syscalls, lookup as lookup_syscall, name_of,
56};
57pub use tls::{
58    GUEST_TLS_MAGIC, enter_host_tls, install_main_guest_tls, leave_host_tls, prepare_host_meta,
59};
60#[cfg(all(target_arch = "aarch64", target_os = "linux"))]
61pub use trap::kh_trampoline_dispatch;
62pub use trap::{
63    PSTATE_C, TrapConfig, TrapError, TrapEvent, TrapOutcome, clear_expect_code,
64    clear_trace_on_exit, finish_with_exit_code, hypercall_entry_addr, install_trap_handlers,
65    patch_svc_to_brk, set_expect_code, set_trace_on_exit, take_trace_events,
66};
67// `kh_hypercall_entry` is a `global_asm!` symbol; address via `hypercall_entry_addr`.