Return to Laboratory Monograph
ARTIFACT 02 // SYSTEMS SPECIFICATIONRUST UKERNEL · AARCH64 ELF LOADER · SPARSE QCOW2
Bilvalabs emblem
Petrel application crest

Petrel: A Userspace Linux Kernel for Unrooted OCI Containers

Named after the storm petrel — the smallest pelagic seabird, built to walk across rough ocean waves without sinking and desalinate toxic seawater through its dorsal tubenose. Petrel runs official docker (v27.5.1), docker compose (v2.32.4), and unmodified Linux/ARM64 OCI containers natively on unrooted Android Termux with zero VM and zero root.

STATUS: v0.1.0·Apache-2.0 License·Authors: N. Rakkasi, Ranapratap
GitHub Repository — Public Release Forthcoming
Hot-Path Pipe I/O
1.67M ops/s
~1.0× native · SECCOMP_RET_ALLOW
Valkey / Postgres
59.2K / 2,692
req/s & pgbench TPS on phone
Upstream Test Pass
140,000+
GCC · Go · Python · PG · Node · Zig
QCOW2 Compaction
12.4 → 1.5 GiB
Lossless SHA-256 atomic repack
01 // Etymology & Architectural Thesis

Why Petrel: skimming the host kernel without sinking into a VM

Earlier efforts to run Linux containers on unrooted phones either sank into heavy QEMU virtual machines or wrapped processes in proot/udocker layers that trap every syscall twice and crash under Android 12+ SELinux rules. Every biological trait of the storm petrel maps directly to an architectural invariant across our ~32.5k-line Rust engine:

Walks on Water
Zero-VM Kernel Skim

Skims Android's Linux kernel at ~1.0× speed (SECCOMP_RET_ALLOW) without sinking into a heavy VM or needing root.

Plucks One Container
0x20_0000_0000 + ADDFD

Lifts unmodified Linux/ARM64 OCI containers via a #![no_std] loader while heavy bloat stays submerged.

Tubenose Desalination
SIGSYS & SELinux Recovery

Distills hostile Zygote SIGSYS traps (accept4, memfd SysV SHM, PF_X stack pivot) into clean POSIX in flight.

30g Storm Survivor
Sparse QCOW2 + 140K Tests

Survives GCC 3-stage bootstrap, Postgres, Go, and CPython inside one crash-safe ~/.docker/data/data.qcow image.

Every binary, Unix socket ($PREFIX/var/run/docker.sock), CoW materialization cache, and ~/.docker/data/data.qcow image stays strictly inside /data/data/com.termux/ with zero bundled host glibc.

02 // Modular Decomposition

Five Rust crates & official Docker CLI integration

termux-ukernel (21,358 LOC)
Hybrid 4-tier userspace Linux kernel

Compiled cBPF router (RET_ALLOW / RET_ERRNO / RET_TRACE / RET_USER_NOTIF), 4-worker unotify pool, Zygote SIGSYS catcher, SA_RESTART dedup, VFS, /proc + /sys + cgroup v2, virtual inotify, memfd SysV SHM/SEM, and embedded 127.0.0.11 DNS + bridge networking.

termux-docker-loader (765 LOC)
Zero-dependency #![no_std] AArch64 ELF loader

Static binary linked at 0x20_0000_0000 inside Android's 39-bit VA space. Receives backing FDs via sentinel openat calls, maps guest PT_LOAD + ld-linux, builds Linux auxv, and pivots SP onto an 8 MiB RWX stack when PT_GNU_STACK requests PF_X.

termux-qcowfs (4,056 LOC)
Sparse QCOW2 v3 + TFS + OverlayFS block engine

64 KiB clusters (64 GiB default up to 4 TiB), FALLOC_FL_PUNCH_HOLE discard, dual-slot CRC32 ping-pong superblocks, Zstd+bincode catalog, (layer_idx << 48) | ino xino encoding, SHA-256 RO materialization cache, and crash-safe startup orphan GC.

termux-oci + termux-dockerd (6,352 LOC)
OCI Registry v2, Dockerfile builder & Engine API (v1.41–v1.47)

Native rustls OCI puller, multi-stage classic Dockerfile builder, Hyper HTTP/1.1 + TCP upgrade framing over $PREFIX/var/run/docker.sock, lossless setup-disk compaction CLI, and minimal path patches for official Go docker v27.5.1 & docker-compose v2.32.4.

03 // Syscall & Loader Architecture

4-tier cBPF routing + static ELF handoff at 0x20_0000_0000

Before execve, every container root installs a compiled cBPF filter and hands its listener FD to the supervisor over SCM_RIGHTS. Guest binaries whose PT_INTERP points to /lib/ld-linux-aarch64.so.1 are loaded via a sentinel-driven #![no_std] stub linked high at 128 GiB so guest PIE/ET_EXEC mappings never collide:

# 1. Static AArch64 Loader @ 0x20_0000_0000 (inside Android's 39-bit 0x00..0x7f_ffff_ffff VA space)
openat("/\x01td_exec_meta")   -> memfd ExecMeta (544 B: magic 0x5444455845430001, uid/gid, guest_exe)
openat("/\x01td_exec_bin")    -> materialized guest ELF64 (PT_LOAD mmap + sub-page .bss zeroing)
openat("/\x01td_exec_interp") -> guest PT_INTERP (ld-linux-aarch64.so.1 / ld-musl-aarch64.so.1)
# If PT_GNU_STACK has PF_X (blocked on kernel [stack] by SELinux): pivot SP -> 8 MiB RWX + guard page

# 2. Sparse data.qcow ("TFS1" Ping-Pong Superblocks in Guest Clusters 0 & 1)
superblock = [magic "TFS1" | ver=1 | gen (u64) | catalog_ext | zstd_len | CRC32]
virtual_ino(layer, ino) = ((layer_idx as u64) << 48) | (raw_ino & 0x0000_FFFF_FFFF_FFFF) // xino
Tier 1 · SECCOMP_RET_ALLOW0-overhead host kernel
read, write, pread64, pwrite64, mmap, futex, epoll_*, pipe2, accept4, connected TCP sendto/recvfrom

Zero userspace context switches on the data plane — steady-state servers & databases run at ~1.0× native speed.

Tier 2 · SECCOMP_RET_ERRNOIn-kernel fast fail
io_uring_* (425..427) → -ENOSYS · ioctl(FICLONE / FICLONERANGE / FIDEDUPERANGE) → -EOPNOTSUPP

Forces Node.js 22 / libuv onto mediated epoll and prevents Android SELinux EACCES on POSIX copyfile reflinks.

Tier 3 · SECCOMP_RET_TRACEAtomic ptrace stop
execve*, clone*, bind, connect, getsockname, mkdirat, unlinkat, renameat*, linkat, close, dup*, getpid, kill

Executes non-idempotent state transitions atomically, immune to Linux < 5.19 EINTR races under Go's 10 ms SIGURG.

Tier 4 · USER_NOTIF + SIGSYS4-worker pool + trap recovery
openat* (ADDFD), statx, getcwd, chmod/chown, inotify_*, AF_NETLINK, plus Zygote SIGSYS (accept→accept4, sem*, shmat)

Virtualizes VFS paths, permissions, short AF_UNIX sockets (<108B), and recovers Android-blocked glibc/Postgres syscalls.

04 // Empirical Verification

Battle-tested across 140,000+ upstream Linux tests

Hardware: Unrooted Android 12 · Linux 5.10.236 aarch64 · 8-core ARMv9 (Cortex-X2 / A710 / A510, 6.9 GiB RAM)

Go 1.24.2351 / 351 pkgs (100%)
Self-bootstrap (./make.bash) + full stdlib/toolchain (./run.bash -k)
10 ms SIGURG preemption, runtime/TestEINTR, cgo nptl_setxid, multi-threaded execve de_thread
CPython 3.13.244,148 / 44,148 (100%)
Native source build + full regrtest across 445 modules
/dev/shm POSIX semaphores, O_PATH, virtual HostBind hardlinks, PEP-383 non-UTF-8 paths, PTYs
GCC 14.2.0>71,000 pass (stage2 == stage3)
Full native 3-stage C/C++ bootstrap + official compiler testsuite
Bit-identical stage2/stage3 object code, OverlayFS xino, PT_GNU_STACK PF_X 8 MiB RWX pivot, LTO
PostgreSQL 17.12613 / 613 suites · 2,692 TPS
core + isolation + contrib + ecpg + multi-container pgbench (300K rows)
Multi-process memfd SysV SHM (shmat/shmdt), SO_PEERCRED via sp-128 native connect, QCOW2 durability
Valkey 9.2.07,327 / 7,329 · 59,171 req/s
TLS + jemalloc + LTO build · unit + 20-node cluster + Sentinel
Live CoW fork() BGSAVE/AOF, /proc/self/smaps, ptrace group-stop, 100% Sentinel failover
Git 2.56.1261 / 261 C + 12,500+ shell
Native build + C unit suite + shell waves (OverlayFS & HostBind)
Packfile mmap, async blocking FIFOs, shebang raw $0, virtualized PR_SET_DUMPABLE for ssh-agent
libuv v1.53.0527 / 527 tests (100%)
Full official C event-loop & OS syscall suite (non-root tester)
sendmmsg, SO_REUSEPORT refcounting, IPv4/IPv6 multicast, inotify, /proc/uptime, DAC checks
Zig 0.17.11,177 / 1,177 std (100%)
zig cc musl + 11 std groups + raw AArch64 svc #0 (-mcpu=baseline)
Libc-free raw syscalls, io_uring → ENOSYS fallback, raw clone + futex threads
Node.js 22.23 + Vite 8.4883/883 HTTP/TLS · 0 ukernel fails
1,930 upstream tests (HTTP/HTTP2/TLS, sequential, PTY) + live HMR
HostBind kernel inotify bridge triggering sub-second container Vite HMR on phone edits
05 // Explicit Boundaries

Security model, metadata latency & active roadmap

  • Compatibility Layer, Not a Hostile-Tenant Sandbox: Because Petrel runs unprivileged inside Termux's single Android UID (untrusted_app) without a hypervisor, userspace mediation protects developer workflows against host clutter and syscall incompatibilities, not adversarial kernel-escape workloads (which require hardware VMs such as AVF/pKVM).
  • Data Plane vs. Metadata Storms: Compute, pipes (0.60 µs/op), and connected TCP (8.87 µs/RTT) run at ~1.0× native speed on SECCOMP_RET_ALLOW, whereas metadata-heavy storms (stat/openat) incur seccomp_unotify round-trips (~500–840 µs).
  • Platform Scope & Next Milestones: Targets unrooted Android 12+ aarch64 devices (Linux >= 5.10). Active roadmap items include docker save/load, docker login/push, step-level Dockerfile layer caching, and read-only metadata fast-path caching.