Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
589faf3
feat(fspy): add target-none foundations
wan9chi Aug 20, 2026
dd64546
refactor(fspy-shared): make the shared-memory sender no-std
wan9chi Aug 20, 2026
fda100c
feat(fspy-elf-loader): define ELF execution API
wan9chi Sep 6, 2026
ba9c331
feat(fspy-nostd): add stdio and panic handling
wan9chi Sep 6, 2026
1ffd188
feat(fspy-nostd): add Linux entry point and initial stack views
wan9chi Sep 6, 2026
4e3f3ee
refactor(fspy-elf-loader): use shared auxiliary vector entries
wan9chi Sep 6, 2026
6131d2b
test(fspy-elf-loader): add freestanding launcher
wan9chi Sep 6, 2026
0d0f3ee
feat(fspy-nostd): add link-time global allocator guard
wan9chi Sep 10, 2026
fc4bc29
feat(fspy-elf-loader): load dynamic ELF images in process
wan9chi Sep 15, 2026
cfdd317
docs(fspy-elf-loader): explain crate motivations and scope
wan9chi Sep 15, 2026
5e3d971
feat(fspy-elf-loader): support fixed-address executables
wan9chi Sep 19, 2026
ac6514f
test(fspy-elf-loader): select high fixed launcher addresses
wan9chi Nov 3, 2026
e76921e
fix(fspy-elf-loader): match Linux PT_LOAD and PT_INTERP loading
cursoragent Nov 18, 2026
22c450d
feat(fspy-elf-loader): load static ELF images without PT_INTERP
cursoragent Nov 20, 2026
fb8cc71
fix(fspy-nostd): keep allocator guard off Windows std links
cursoragent Nov 20, 2026
b771e1b
docs(fspy-elf-loader): record userland-exec scope and remaining work
cursoragent Nov 24, 2026
0462a94
fix(fspy-elf-loader): scope padzero to writable or BSS segments and c…
wan9chi Nov 25, 2026
06f49fb
perf(fspy-nostd): allow seeding cached page size from AT_PAGESZ
wan9chi Nov 25, 2026
45d7fef
fix(fspy-elf-loader): harden interpreter, alignment, auxv, stack head…
wan9chi Nov 25, 2026
fa5ae59
test(fspy-elf-loader): avoid assuming /bin/echo is ET_DYN and check f…
wan9chi Nov 25, 2026
5056f55
refactor(fspy-elf-loader): move test launcher binary to its own crate
wan9chi Nov 25, 2026
fb3bb18
test(fspy-elf-loader): unify 4-cell ELF fixtures in C with target-awa…
wan9chi Nov 25, 2026
a49faa3
test(fspy-elf-loader): run runtime fixtures differentially against ke…
wan9chi Nov 25, 2026
bfdb806
fix(fspy-elf-loader): support cargo-zigbuild for static C test fixtures
wan9chi Nov 25, 2026
8acc878
test(fspy-elf-loader): use typed ELF64 helpers and mutate own fixture…
wan9chi Nov 25, 2026
1453b7b
test(fspy-elf-loader): remove redundant Rust runtime fixture binary
wan9chi Nov 25, 2026
f3573f4
ci(fspy-elf-loader): run release loader tests and bare-metal clippy
wan9chi Nov 25, 2026
8fbfe09
refactor(fspy-elf-loader): share ELF size constants and simplify reta…
wan9chi Nov 25, 2026
3e27886
refactor(fspy-elf-loader): stage startup pointer table in stack mappi…
wan9chi Nov 25, 2026
5788cfb
refactor(fspy-elf-loader): drop cc build-dep in favor of direct env l…
wan9chi Nov 25, 2026
e9eb058
test(fspy-elf-loader): drop redundant echo args test and deduplicate …
wan9chi Nov 25, 2026
7ab5e99
chore(fspy-elf-loader): format README and revert residual param.rs diff
wan9chi Nov 25, 2026
cd3bdf0
fix(fspy-elf-loader): embed launcher bytes in launcher_image test
wan9chi Nov 25, 2026
3279a12
fix(fspy-nostd): read runtime CARGO_MANIFEST_DIR in no_global_alloc test
wan9chi Nov 25, 2026
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
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ jobs:

# --locked: verify Cargo.lock is up to date (replaces the removed `cargo check --locked`)
- run: cargo clippy --locked --all-targets --all-features -- -D warnings
- run: |
cargo clippy --locked -p fspy_elf_loader -p fspy_elf_loader_test_launcher --target x86_64-unknown-none -- -D warnings
cargo clippy --locked -p fspy_elf_loader -p fspy_elf_loader_test_launcher --target aarch64-unknown-none-softfloat -- -D warnings

# fspy builds only on Windows, macOS, and Linux, but vp must still build
# without it on other platforms. Cross-building `vt_bin` for FreeBSD catches
Expand Down Expand Up @@ -149,6 +152,10 @@ jobs:
- name: Run tests
run: $TEST_CARGO_CMD test --target $TEST_BUILD_TARGET

- name: Run ELF loader tests (release)
if: ${{ env.TEST_TARGET == 'x86_64-unknown-linux-gnu' }}
run: $TEST_CARGO_CMD test --release -p fspy_elf_loader_tests --target $TEST_BUILD_TARGET

# x86_64-apple-darwin runs on arm64 runner under Rosetta; install x64 Node
# so fspy's x86_64 preload dylib can be injected into spawned node procs.
- uses: oxc-project/setup-node@f46a72f95efdc55273fcd042d61c84e723b2892c # v1.4.1
Expand Down Expand Up @@ -378,6 +385,9 @@ jobs:
- name: Run tests
run: cargo test

- name: Run ELF loader tests (release)
run: cargo test --release -p fspy_elf_loader_tests

- uses: oxc-project/setup-node@f46a72f95efdc55273fcd042d61c84e723b2892c # v1.4.1

- name: Run ignored tests
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/target
/crates/fspy_elf_loader_tests/compat/
node_modules
# Fixture node_modules that stand in for real npm installs in snapshot tests.
# `**` covers nested monorepo layouts (e.g. packages/foo/node_modules/.bin).
Expand Down
31 changes: 31 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async-trait = "0.1.89"
base64 = "0.22.1"
bytes = "1.11.1"
url = "2.5.8"
wincode = "0.6.0"
wincode = { version = "0.6.0", default-features = false, features = ["alloc"] }
bindgen = "0.72.1"
bitflags = "2.10.0"
brush-parser = "0.4.0"
Expand Down Expand Up @@ -150,7 +150,7 @@ syscalls = { version = "0.8.0", default-features = false }
tar = "0.4.45"
tempfile = "3.14.0"
test-log = "0.2.18"
thiserror = "2"
thiserror = { version = "2", default-features = false }
tokio = "1.53.3"
tokio-util = "0.7.17"
toml = "1.0.0"
Expand Down
22 changes: 22 additions & 0 deletions crates/fspy_elf_loader/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "fspy_elf_loader"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
publish.workspace = true
rust-version.workspace = true

[target.'cfg(any(target_os = "linux", target_os = "none"))'.dependencies]
elf = { workspace = true }
fspy_nostd = { workspace = true }
linux-raw-sys = { workspace = true, features = ["auxvec", "no_std"] }

[target.'cfg(target_os = "linux")'.dev-dependencies]
tempfile = { workspace = true }

[lib]
doctest = false

[lints]
workspace = true
84 changes: 84 additions & 0 deletions crates/fspy_elf_loader/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# fspy_elf_loader

Linux userland exec for fspy, the file tracker behind `vp run`: map a target
ELF into the current process and jump to it, so intercept state installed
before entry (SIGSYS, handlers, mappings) survives.

The **Linux end state** is this path alone. Kernel `execve` of the target
would reset intercept state, so fspy must not exec the target. Resolve PATH
and shebang in userland, kernel-exec a freestanding launcher, then
[`exec_elf`](src/lib.rs). That replaces today's `LD_PRELOAD` vs
`seccomp_unotify` split (chosen from `PT_INTERP`). SIGSYS stays as the
intercept; it is not a second spawn backend.

This is a **compatibility contract**, not a complete `execve`. This crate
only maps and enters an ELF. PATH, shebang, policy, nested exec, and fspy
wiring belong above it. fspy already parses shebang in `fspy_shared_unix`;
the kernel will not, once it never sees the target.

## Support

Native little-endian ELF64 on x86-64 and AArch64. `PT_GNU_STACK` must be
non-executable. `ET_EXEC` that overlaps any retained mapping is rejected.

| | `PT_INTERP` | no `PT_INTERP` |
| --------- | ------------------------------------------------- | -------------------------------------------------- |
| `ET_DYN` | dynamic PIE: enter ld.so, `AT_BASE` = interp bias | static-PIE / ld.so: enter `e_entry`, `AT_BASE` = 0 |
| `ET_EXEC` | dynamic non-PIE: same as dynamic PIE | traditional static: enter `e_entry`, `AT_BASE` = 0 |

All four cells load. With an interpreter, map both images and enter the
interpreter even though `AT_ENTRY` names the executable. Without one, map only
the executable.

The launcher is itself a static `ET_EXEC` at a high fixed address so the low
4 GiB stays free for non-PIE targets:

| Arch | Base |
| ------- | --------------------------- |
| x86-64 | `0x5500_0000_0000` (85 TiB) |
| AArch64 | `0x0002_0000_0000` (8 GiB) |

These sit in current LLVM Linux ASan/TSan application regions; GCC 12's AArch64
TSan still rejects the 8 GiB mapping. The addresses are conventions, not
reserved ranges.

## Done

- `PT_LOAD` mapping in the Linux `elf_map` shape (shared pages, BSS, padzero).
- Optional `PT_INTERP`, including padded interpreter paths.
- Startup stack: contiguous argv/envp strings, rebuilt auxv, copied
`AT_RANDOM` / platform strings, inherited scalars and resident vDSO.
- Naked enter stubs: install SP, clear dirty GPRs, jump (no return address).
- [`fspy_elf_loader_tests`](../fspy_elf_loader_tests/README.md): dynamic and
static PIE/`ET_EXEC` runtimes, overlap rejection, malformed images. An
ignored Node test exists (`--include-ignored` on Linux with Node on `PATH`).

## Not a complete exec

Do not try to close these in this crate unless a real target requires it:

- **`brk` / `start_brk`.** The kernel's brk belongs to the high launcher
mapping. It cannot be moved to a Linux-faithful image end. glibc malloc
still works via mmap; leave brk alone.
- **`/proc` identity.** `/proc/self/exe` and parent-visible `/proc/<pid>/exe`
still name the launcher. Parent `/proc/<pid>/exe` is not a JS/Chromium
identity gate. `/proc/self/exe` is, and needs virtualization later.
- GNU properties, executable stacks, ELF32, other arches, growable stack
(fixed 8 MiB + guard), fd/signal/personality cleanup.

Load failures panic and terminate. `exec_elf` is for a fresh single-threaded
process with no libc or TLS init. Trusted images only; this is not a sandbox.

## Product work (elsewhere)

fspy still spawns with `LD_PRELOAD` or `seccomp_unotify`. The loader is not
wired in. Remaining work is to make launcher + userland shebang + `exec_elf`
the only Linux spawn:

1. Shebang and PATH above `exec_elf`, then load the resulting ELF. Scripts
never hit kernel `binfmt_script`. Nested `execve` must re-enter this path
instead of kernel-execing the child image.
2. Virtualize `/proc/self/exe` so the target sees its own path (`process.execPath`
/ `fs.realpath`). The ignored Node test does not do this.
3. Drop the Linux preload/seccomp spawn split. One intercept setup in the
launcher covers dynamic glibc, musl, and static images.
Loading
Loading