Skip to main content

Module exec

Module exec 

Source
Expand description

Shell executor state for zshrs.

Not a port of Src/exec.c. C zsh runs compiled programs on the native wordcode VM in Src/exec.c (execlist / execpline / execcmd). zshrs uses fusevm bytecode instead; the bridge lives in src/fusevm_bridge.rs. This file holds:

  • ShellExecutor — the runtime state struct that the VM and every ported builtin/utility threads through
  • VM-adjacent helpers that read/write that state
  • drift extension scaffolding still being moved out

Path-wise this file lives at the crate root (src/exec.rs) rather than in src/ported/ because nothing here corresponds 1:1 to a Src/*.c source file. crate::ported::exec is kept as a re-export alias so existing call-sites continue to compile.

Re-exports§

pub use crate::ported::params::convbase as format_int_in_base;
pub use crate::ported::params::convbase_underscore;
pub use crate::intercepts::AdviceKind;
pub use crate::intercepts::Intercept;
pub use crate::compinit_bg::CompInitBgResult;
pub use crate::bash_complete::CompSpec;
pub use crate::bash_complete::CompMatch;
pub use crate::bash_complete::CompGroup;
pub use crate::bash_complete::CompState;
pub use crate::ported::modules::zutil::zstyle_entry;
pub use crate::ported::builtin::AutoloadFlags;
pub use crate::fusevm_bridge::*;

Modules§

zsh_version
ZSH_VERSION / ZSH_PATCHLEVEL / ZSH_VERSION_DATE consts generated by build.rs from src/zsh/Config/version.mk. Use zsh_version::ZSH_VERSION etc. at call sites so version bumps pick up automatically.

Structs§

ForkFlags
Flags for zfork()
ShellExecutor
Top-level shell executor state. Port of the file-static globals + Estate chain Src/exec.c uses — execlist() (line 1349) drives every list, with execpline() (line 1668), execpline2() (line 1991), execsimple() (line 1290), and the per-WC_* execfuncs[] table (line 268) feeding off it. The Rust port collapses everything into one ShellExecutor so we don’t need thread-local globals.
SubshellFlags
Flags for entersubsh()
SubshellSnapshot
Snapshot of subshell-isolated state. Captured at ( entry, restored at ) exit. zsh subshell semantics: assignments inside (…) don’t leak to the outer scope — and that includes export. zsh forks a child for the subshell so the child’s env::set_var dies with the child; without a fork (zshrs runs subshells in-process for perf), we snapshot+restore the OS env table around the subshell. Otherwise (export y=v) would leak y to the parent shell, breaking every script that uses a subshell to scope an env override. Snapshot of mutable executor state across a subshell boundary. Port of the entersubsh() save/restore Src/exec.c does at line 1084 — captures everything that must be replaced when a (...) group fires.

Enums§

BuiltinType
Builtin command type Builtin classification. Mirrors the BINF_* flag set Src/builtin.c uses to classify special vs regular builtins.
ForkResult
Result of fork operation fork() outcome (parent / child / error). Mirrors the integer return of zfork() from Src/exec.c:349.
LoopSignal
Cross-VM loop-control signal. When break/continue is hit inside a body that runs on a sub-VM (e.g. select’s body), the inline patches mechanism can’t reach the outer loop — set this flag and the outer-loop builtin drains it after each iteration. Loop control signal from a command body. Mirrors the LF_* set Src/loop.c uses to thread break/continue/return flags up through the executor.
RedirMode
Redirection mode File-redirection mode (> / >> / < / etc.). Mirrors the REDIR_* enum from Src/zsh.h.

Statics§

FORKLEVEL
Port of int forklevel; from Src/exec.c:1052. Records the locallevel at the most recent fork point (set at c:1221: forklevel = locallevel; inside entersubsh()). Used by:
TRAP_RETURN
Port of int trap_return; from Src/exec.c:155. Carries the pending exit status from inside a trap; sentinel -2 means “running an EXIT/DEBUG-style trap at the current level” (signals.c:1166). Promoted to the user’s return N value by bin_return when POSIX-trap semantics apply (builtin.c:5852).
TRAP_STATE
Port of int trap_state; from Src/exec.c:134. Tracks whether a trap handler is currently being processed and, paired with TRAP_RETURN below, whether a return inside the trap should promote to TRAP_STATE_FORCE_RETURN to unwind the trap caller.

Functions§

getfpfunc
Port of getfpfunc(char *s, int *ksh, char **fdir, char **alt_path, int test_only) from Src/exec.c:5260. Walks $fpath (or the supplied spec_path slice) for a file named name and writes the resolved directory through *dir_path_out (matching the C char **dir_path). Returns Some(file_contents_path) on success, None when not found.
gethere
Convert a here-document into a here-string. Line-by-line port of gethere() from Src/exec.c:4569-4652. Reads the body from the input stream via hgetc() until the terminator line is matched, returning the collected body as a string. strp is in/out: on entry the raw terminator (possibly with token markers + leading tabs); on return the munged terminator (after quotesubst + untokenize and, for REDIR_HEREDOCDASH, leading-tab strip).
getoutput
Free-function wrapper for getoutput() from Src/exec.c:4712. Runs a command-substitution body in the active executor and returns its captured stdout. The C signature is LinkList getoutput(char *cmd, int qt) but every caller in subst.rs joins the list back into a string, so the Rust port collapses the intermediate.
glob_match_static
Static glob match — same logic as glob_match but callable without &self, needed for Rayon parallel iterators that can’t capture &self.
loadautofn
Direct port of Shfunc loadautofn(Shfunc shf, int ks, int test_only, int ignore_loaddir) from Src/exec.c:5050. Walks $fpath for a file named shf->node.nam, reads it, installs the text body on the corresponding shfunctab entry, and clears PM_UNDEFINED.
scan_magic_assoc_keys