Skip to main content

running_process/
ape.rs

1//! Actually Portable Executable (APE / cosmocc) support.
2//!
3//! Cosmopolitan APE binaries start with a shell prologue rather than a native
4//! image header. A host without a `binfmt_misc` registration for them -- stock
5//! NixOS among them -- refuses them with `ENOEXEC` ("Exec format error"), and
6//! only a shell knows to retry.
7//!
8//! This crate launches them through a loader: an explicit one
9//! ([`LOADER_ENV`]), else the loader embedded in the image (the default
10//! `ape-loader` feature; installed into a private, exec-capable cache, or a
11//! sealed memfd), else an installed `ape`, else the host shell.
12//!
13//! - Spawns whose program and environment are known plan the loader before
14//!   the spawn: `SpawnSpec`/`AsyncProcess`, argv `NativeProcess`es, and
15//!   [`command`] / `tokio_command` for callers building their own command.
16//! - A caller-built command keeps every caller setting and is retried once
17//!   after a refusal, through `execvp`'s POSIX `ENOEXEC` shell rule
18//!   ([`spawn_std`]).
19//! - [`fork_guard`] / [`exclusive_fork_guard`] are the process-wide fork lock
20//!   that keeps a freshly written loader out of concurrently forked children
21//!   (`ETXTBSY`); a spawner outside this crate should hold [`fork_guard`]
22//!   across its spawn.
23
24pub use running_process_platform_internal::platform::ape::{
25    command, embedded_loader, exclusive_fork_guard, fork_guard, is_ape_file, is_ape_header,
26    is_exec_format_error, loader_blob_range, plan_launch, prepare_std_retry, resolve_program,
27    retry_while_busy, spawn_std, ApeLaunch, ApeOptions, LoaderKind, CACHE_DIR_ENV, LOADER_ENV,
28    MAGICS, NEEDS_LOADER,
29};
30#[cfg(feature = "ape-loader")]
31pub use running_process_platform_internal::platform::ape::{extract_loader, gunzip};
32#[cfg(feature = "async-process")]
33pub use running_process_platform_internal::platform::ape::{prepare_tokio_retry, tokio_command};