458 lines · plain
1================================================================================2K9 process-model — source-site snapshot3================================================================================4 5Generated by linux-wasm/tools/k9-process-model-probe/snapshot-sources.sh6from Documentation/wasm/process-model.rst §10.7 8Pinned at K9-A2 sub-phase close (per §13 K9-A2). Snapshots9across five trees:10 11 [LIN] upstream linux/ tree (kernel/exit.c, fs/pipe.c,12 fs/file.c, kernel/sys.c)13 [WAS] our wasm32-port/ tree (kernel/spawn.c K5/K7/K8 path;14 K9-B1 extends with exit-notification ring shape;15 kernel/signal.c K8 reuse for SIGCHLD; include/asm/16 clone.h spawn-ring ABI mirror)17 [UPS] wackywasm-tools/musl-1.2.5/src/ (wait/pipe/sigchld18 surfaces K9 demos exercise unchanged)19 [OVR] wackywasm-tools/musl-src/src_overrides/ (existing20 K7/K8 src_overrides; K9 may add stdin/wasm32/ if21 stdin syscall handler needs musl-side wiring)22 [HWJ] hardwarejs/src/ (kernelSpawnHandler.ts per-tid23 registry K9-B2 reads from; worker.mjs SYS_read fd=024 / SYS_pipe2 / SYS_dup2 stubs K9-C1/B3/B2 turn into25 real handlers; bootKernel.ts BootKernelOptions26 extension point for stdinChannel?)27 28Section legend:29 [DEF] the function definition (file:line + leading prose)30 [CALL] call sites in the relevant tree31 [SITE] inline excerpt of a load-bearing site (no function32 definition but a code shape we depend on)33 [K9-B] where K9-B-phases will insert NEW code (annotation34 only; does not exist in any tree yet)35 36Snapshot taken against:37 upstream linux: v6.1238 upstream musl: 1.2.539 wackywasm-tools/musl-src: K8 src_overrides state (signal/wasm32/ + internal/wasm32/)40Generated: 2026-05-25 (UTC, deterministic stamp from `date -u`)41Note: snapshot file deliberately omits HH:MM:SS in the42 stamp so re-runs on the same day produce byte-identical43 output. Drift detection is at line-number granularity.44 45================================================================================461. linux/kernel/exit.c — do_exit + do_wait + release_task (K9-B1 core)47================================================================================48 49Module: upstream child-reaping core. K9-B1's50arch_notify_child_exit hook lands a wasm32-side caller into51do_exit (or composes the do_exit-ish state transitions52directly). do_wait is the parent-side syscall handler;53release_task is the zombie-reap; do_notify_parent is the54SIGCHLD post-exit step that K8's arch_signal_wake_target55delivers.56 57[DEF] linux/kernel/exit.c::do_exit(long code)58 kernel/exit.c:877 void __noreturn do_exit(long code)59 60[DEF] linux/kernel/exit.c::release_task(struct task_struct *p)61 kernel/exit.c:241 void release_task(struct task_struct *p)62 63[DEF] linux/kernel/exit.c::do_wait(struct wait_opts *)64 kernel/exit.c:1680 static long do_wait(struct wait_opts *wo)65 66[DEF] linux/kernel/exit.c::do_notify_parent(struct task_struct *, int)67 68[DEF] linux/kernel/exit.c::wait_consider_task(...)69 kernel/exit.c:1423 static int wait_consider_task(struct wait_opts *wo, int ptrace,70 71[DEF] linux/kernel/exit.c::forget_original_parent(struct task_struct *)72 kernel/exit.c:692 static void forget_original_parent(struct task_struct *father,73 74[CALL] linux/kernel/exit.c — EXIT_ZOMBIE state references:75 kernel/exit.c:268: && leader->exit_state == EXIT_ZOMBIE) {76 kernel/exit.c:674: p->exit_state == EXIT_ZOMBIE && thread_group_empty(p)) {77 kernel/exit.c:743: tsk->exit_state = EXIT_ZOMBIE;78 kernel/exit.c:1138: * Handle sys_wait4 work for one task in state EXIT_ZOMBIE. We hold79 kernel/exit.c:1169: if (cmpxchg(&p->exit_state, EXIT_ZOMBIE, state) != EXIT_ZOMBIE)80 kernel/exit.c:1243: state = EXIT_ZOMBIE;81 kernel/exit.c:1428: * Ensure that EXIT_ZOMBIE -> EXIT_DEAD/EXIT_TRACE transition82 kernel/exit.c:1468: if (exit_state == EXIT_ZOMBIE) {83 84[DEF] linux/kernel/exit.c::SYSCALL_DEFINE(wait4|waitid):85 kernel/exit.c:1783:SYSCALL_DEFINE5(waitid, int, which, pid_t, upid, struct siginfo __user *,86 kernel/exit.c:1875:SYSCALL_DEFINE4(wait4, pid_t, upid, int __user *, stat_addr,87 kernel/exit.c:1902:COMPAT_SYSCALL_DEFINE4(wait4,88 kernel/exit.c:1917:COMPAT_SYSCALL_DEFINE5(waitid,89 90================================================================================912. linux/fs/pipe.c — pipe_read / pipe_write / alloc_pipe_info (K9-B3 core)92================================================================================93 94Module: upstream pipefs. K9 inherits this unchanged. The95load-bearing question is whether the kernel's96copy_to_user / copy_from_user calls inside pipe_read /97pipe_write can target a DIFFERENT user's env.user_memory98(not current's) — the K9-B2 cross-process copy work.99 100[DEF] linux/fs/pipe.c::pipe_read(struct kiocb *, struct iov_iter *)101 102[DEF] linux/fs/pipe.c::pipe_write(struct kiocb *, struct iov_iter *)103 104[DEF] linux/fs/pipe.c::alloc_pipe_info(void)105 fs/pipe.c:790 struct pipe_inode_info *alloc_pipe_info(void)106 107[DEF] linux/fs/pipe.c::do_pipe2(int *, int)108 fs/pipe.c:1018 static int do_pipe2(int __user *fildes, int flags)109 110[DEF] linux/fs/pipe.c::SYSCALL_DEFINE(pipe|pipe2):111 fs/pipe.c:1040:SYSCALL_DEFINE2(pipe2, int __user *, fildes, int, flags)112 fs/pipe.c:1045:SYSCALL_DEFINE1(pipe, int __user *, fildes)113 114================================================================================1153. linux/fs/file.c — fd table operations (K9-B2 / K9-B3 mirror)116================================================================================117 118Module: upstream fd table. K9 inherits unchanged. dup2 +119copy_files + do_close_on_exec are all upstream-clean; the120shell-pipeline pattern (fork → dup2(pipe_w, STDOUT) → exec)121relies on these.122 123[DEF] linux/fs/file.c::ksys_dup3 / do_dup2:124 fs/file.c:1321 static int ksys_dup3(unsigned int oldfd, unsigned int newfd, int flags)125 fs/file.c:1198 static int do_dup2(struct files_struct *files,126 127[DEF] linux/fs/file.c::copy_files(unsigned long, struct task_struct *)128 129[DEF] linux/fs/file.c::do_close_on_exec(struct files_struct *)130 fs/file.c:796 void do_close_on_exec(struct files_struct *files)131 132[CALL] linux/fs/ — FD_CLOEXEC references:133 fs/fcntl.c:463: err = get_close_on_exec(fd) ? FD_CLOEXEC : 0;134 fs/fcntl.c:467: set_close_on_exec(fd, argi & FD_CLOEXEC);135 136================================================================================1374. linux/kernel/sys.c — process-group syscalls (K9-C2 — mostly upstream-clean)138================================================================================139 140Module: upstream pgrp/session. K9 inherits unchanged.141sys_setpgid / sys_setsid / sys_getpgid / sys_getpgrp all142manipulate task->signal->pgrp / task->signal->session;143no arch hook needed.144 145[DEF] linux/kernel/sys.c::SYSCALL_DEFINE(setpgid|setsid|getpgid|getpgrp|getsid):146 kernel/sys.c:1082:SYSCALL_DEFINE2(setpgid, pid_t, pid, pid_t, pgid)147 kernel/sys.c:1181:SYSCALL_DEFINE1(getpgid, pid_t, pid)148 kernel/sys.c:1188:SYSCALL_DEFINE0(getpgrp)149 kernel/sys.c:1195:SYSCALL_DEFINE1(getsid, pid_t, pid)150 kernel/sys.c:1267:SYSCALL_DEFINE0(setsid)151 152[DEF] linux/kernel/sys.c::ksys_setpgid / ksys_getpgid (helpers):153 154[CALL] linux/kernel/ — kill_pgrp + group signal delivery:155 kernel/signal.c:1926:int kill_pgrp(struct pid *pid, int sig, int priv)156 157================================================================================1585. linux/include/linux/sched/signal.h — task_pgrp / task_session helpers159================================================================================160 161[DEF] linux/include/linux/sched/signal.h::task_pgrp/task_session/same_thread_group helpers:162 include/linux/sched/signal.h:686:static inline struct pid *task_pgrp(struct task_struct *task)163 include/linux/sched/signal.h:691:static inline struct pid *task_session(struct task_struct *task)164 165================================================================================1666. linux/include/linux/uaccess.h — copy_to_user / copy_from_user (K9-B2 ref)167================================================================================168 169Module: upstream user-memory access. The "current" assumption170is baked into copy_{to,from}_user; K9-B2 introduces wasm32-side171copy_{to,from}_user_for(tid, ...) helpers that route to the172target Worker's named-memory import.173 174[DEF] linux/include/linux/uaccess.h::copy_to_user / copy_from_user:175 include/linux/uaccess.h:205:copy_from_user(void *to, const void __user *from, unsigned long n)176 include/linux/uaccess.h:217:copy_to_user(void __user *to, const void *from, unsigned long n)177 178[CALL] linux/fs/pipe.c — copy_{to,from}_user inside pipe r/w:179 fs/pipe.c:1026: if (unlikely(copy_to_user(fildes, fd, sizeof(fd)))) {180 181================================================================================1827. wasm32-port/kernel/ — surface inventory (what exists at K9-A2 time)183================================================================================184 185[SITE] wasm32-port/kernel/ files at K9-A2:186 wasm32-port/kernel/asm-offsets.c187 wasm32-port/kernel/asyncify.c188 wasm32-port/kernel/binfmt_wasm.c189 wasm32-port/kernel/clone.c190 wasm32-port/kernel/entry.c191 wasm32-port/kernel/fork.c192 wasm32-port/kernel/head.c193 wasm32-port/kernel/init.c194 wasm32-port/kernel/k6_a1_probes.c195 wasm32-port/kernel/k6_b1_probes.c196 wasm32-port/kernel/k6_b2_probes.c197 wasm32-port/kernel/k6_b4_probes.c198 wasm32-port/kernel/k7_u4b_probes.c199 wasm32-port/kernel/percpu.c200 wasm32-port/kernel/percpu_anchors.c201 wasm32-port/kernel/process.c202 wasm32-port/kernel/sched.c203 wasm32-port/kernel/sections.c204 wasm32-port/kernel/setup.c205 wasm32-port/kernel/signal.c206 wasm32-port/kernel/smp.c207 wasm32-port/kernel/spawn.c208 wasm32-port/kernel/switch_to.c209 wasm32-port/kernel/syscall_table.c210 wasm32-port/kernel/time.c211 wasm32-port/kernel/traps.c212 wasm32-port/kernel/wasm_module.c213 214[SITE] wasm32-port/include/asm/ files at K9-A2:215 wasm32-port/include/asm/asyncify.h216 wasm32-port/include/asm/atomic.h217 wasm32-port/include/asm/barrier.h218 wasm32-port/include/asm/boot.h219 wasm32-port/include/asm/bug.h220 wasm32-port/include/asm/cache.h221 wasm32-port/include/asm/clone.h222 wasm32-port/include/asm/cmpxchg.h223 wasm32-port/include/asm/current.h224 wasm32-port/include/asm/elf.h225 wasm32-port/include/asm/futex.h226 wasm32-port/include/asm/host.h227 wasm32-port/include/asm/io.h228 wasm32-port/include/asm/irq.h229 wasm32-port/include/asm/irqflags.h230 wasm32-port/include/asm/linkage.h231 wasm32-port/include/asm/mmu_context.h232 wasm32-port/include/asm/page.h233 wasm32-port/include/asm/pgalloc.h234 wasm32-port/include/asm/pgtable.h235 wasm32-port/include/asm/processor.h236 wasm32-port/include/asm/ptrace.h237 wasm32-port/include/asm/signal.h238 wasm32-port/include/asm/smp.h239 wasm32-port/include/asm/switch_to.h240 wasm32-port/include/asm/syscall.h241 wasm32-port/include/asm/thread_info.h242 wasm32-port/include/asm/tlbflush.h243 wasm32-port/include/asm/uaccess.h244 wasm32-port/include/asm/vmalloc.h245 wasm32-port/include/asm/wasm_module.h246 247================================================================================2488. wasm32-port/kernel/spawn.c — K5/K7/K8 ring producer (K9-B1 mirror site)249================================================================================250 251The K5/K7/K8-pattern producer. K9-B1's exit-notification ring252follows the IDENTICAL submit-and-bump shape (slot allocation by253atomic seq increment, payload write, ack-wait by Atomics.wait254on the ack word). The producer signature for K9 is sketched255as:256 int wasm_exit_submit(pid_t tid, int code)257or alternatively K9-B1 may extend the spawn-ring shape with a258WASM_SPAWN_KIND_EXIT message. The decision is K9-B1's; the259substrate is identical either way.260 261[DEF] wasm32-port/kernel/spawn.c — exported submit functions:262 263================================================================================2649. wasm32-port/kernel/signal.c — K8 reuse (SIGCHLD via arch_signal_wake_target)265================================================================================266 267K8 implementation. K9 reuses arch_signal_wake_target unchanged268for SIGCHLD-on-child-exit delivery; K9-B1's269arch_notify_child_exit calls into the kernel-side270do_notify_parent path which eventually calls signal_wake_up271(a wrapper around signal_wake_up_state) which routes through272arch_signal_wake_target.273 274[DEF] wasm32-port/kernel/signal.c — exported functions:275 kernel/signal.c:123:int wasm_signal_submit(int tid, int sig, int sender_pid)276 kernel/signal.c:176:void arch_signal_wake_target(struct task_struct *t)277 278================================================================================27910. wackywasm-tools/musl-1.2.5/src/ — wait/pipe/stdin syscall surface280================================================================================281 282The musl-side glue K9 demos exercise unchanged. wait4 /283waitpid / wait wrappers, pipe / pipe2 wrappers, dup2 wrapper,284fread/fgets/getline reading from stdin.285 286[DEF] musl-1.2.5/src/process/wait.c + waitpid.c:287 src/process/waitpid.c:4:pid_t waitpid(pid_t pid, int *status, int options)288 src/process/wait.c:3:pid_t wait(int *status)289 290[DEF] musl-1.2.5/src/unistd/pipe.c + pipe2.c:291 src/unistd/pipe2.c:6:int pipe2(int fd[2], int flag)292 src/unistd/pipe.c:4:int pipe(int fd[2])293 294[DEF] musl-1.2.5/src/unistd/dup2.c + dup3.c:295 src/unistd/dup2.c:6:int dup2(int old, int new)296 src/unistd/dup.c:4:int dup(int fd)297 298[CALL] musl-1.2.5 — SYS_wait4 / SYS_pipe2 / SYS_dup3 / SYS_setpgid call sites:299 src/internal/emulate_wait4.c:4:#ifndef SYS_wait4300 src/internal/emulate_wait4.c:23: if (cp) r = __syscall_cp(SYS_waitid, t, pid, &info, options|WEXITED, kru);301 src/internal/emulate_wait4.c:24: else r = __syscall(SYS_waitid, t, pid, &info, options|WEXITED, kru);302 src/internal/syscall.h:394:#ifdef SYS_wait4303 src/internal/syscall.h:395:#define __sys_wait4(a,b,c,d) __syscall(SYS_wait4,a,b,c,d)304 src/internal/syscall.h:396:#define __sys_wait4_cp(a,b,c,d) __syscall_cp(SYS_wait4,a,b,c,d)305 src/linux/wait4.c:24: if (SYS_wait4_time64 == SYS_wait4 || r != -ENOSYS)306 src/process/posix_spawn.c:28: return __syscall(SYS_dup3, old, new, 0);307 src/process/posix_spawn.c:70: if ((ret=__syscall(SYS_setsid)) < 0)308 src/process/posix_spawn.c:74: if ((ret=__syscall(SYS_setpgid, 0, attr->__pgrp)))309 src/process/waitid.c:6: return syscall_cp(SYS_waitid, type, id, info, options, 0);310 src/unistd/dup2.c:16: while ((r=__syscall(SYS_dup3, old, new, 0))==-EBUSY);311 src/unistd/dup3.c:13: while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY);312 src/unistd/dup3.c:21: while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY);313 src/unistd/getpgid.c:6: return syscall(SYS_getpgid, pid);314 src/unistd/getpgrp.c:6: return __syscall(SYS_getpgid, 0);315 src/unistd/getsid.c:6: return syscall(SYS_getsid, pid);316 src/unistd/pipe.c:9: return syscall(SYS_pipe2, fd, 0);317 src/unistd/pipe2.c:9: int ret = __syscall(SYS_pipe2, fd, flag);318 src/unistd/setpgid.c:6: return syscall(SYS_setpgid, pid, pgid);319 src/unistd/setsid.c:6: return syscall(SYS_setsid);320 321================================================================================32211. wackywasm-tools/musl-src/src_overrides/ — K8-state overrides (K9 may extend)323================================================================================324 325Existing src_overrides at K9-A2 (K8's state). K9 may add a new326stdin/wasm32/ subtree if the stdin syscall handler needs327musl-side wiring; otherwise it stays at the worker.mjs level.328 329[SITE] wackywasm-tools/musl-src/src_overrides/ — files at K9-A2:330 ../wackywasm-tools/musl-src/src_overrides/env/wasm32/__init_tls.c331 ../wackywasm-tools/musl-src/src_overrides/internal/wasm32/syscall_ret.c332 ../wackywasm-tools/musl-src/src_overrides/signal/wasm32/__wasm_signal_dispatch.c333 ../wackywasm-tools/musl-src/src_overrides/signal/wasm32/sigaction.c334 ../wackywasm-tools/musl-src/src_overrides/signal/wasm32/sigsuspend.c335 ../wackywasm-tools/musl-src/src_overrides/signal/wasm32/sigtimedwait.c336 ../wackywasm-tools/musl-src/src_overrides/thread/wasm32/__set_thread_area.c337 ../wackywasm-tools/musl-src/src_overrides/thread/wasm32/clone.c338 ../wackywasm-tools/musl-src/src_overrides/thread/wasm32/pthread_sigmask.c339 340================================================================================34112. hardwarejs/src/kernelSpawnHandler.ts — per-tid registry (K9-B2 reads)342================================================================================343 344The K7-U4c / K8-B2 registry: tid → { wasmBytes, userMemory,345signalPendingOffset }. K9-B2 reads from this registry to346resolve a target tid's env.user_memory SAB during347copy_to_user_for / copy_from_user_for. K9-C1 reads from it348to resolve a target tid's per-Worker stdin region offset349when the HardwareJS-side stdin channel writes bytes.350 351[DEF] hardwarejs/src/kernelSpawnHandler.ts — exported types/functions:352 kernelSpawnHandler.ts:214:export interface KernelSpawnParentRecord {353 kernelSpawnHandler.ts:241:export type KernelSpawnHandler = SpawnHandler & {354 kernelSpawnHandler.ts:247:export interface KernelSpawnHandlerOptions {355 kernelSpawnHandler.ts:319:export function makeKernelSpawnHandler(356 357[CALL] hardwarejs/src/kernelSpawnHandler.ts — SYS_read / SYS_pipe2 / SYS_dup3 / SYS_setpgid stubs:358 kernelSpawnHandler.ts:79:const __NR_read = 0;359 kernelSpawnHandler.ts:811: case __NR_read: {360 361================================================================================36213. hardwarejs/src/worker.mjs — SYS_read fd=0 / SYS_pipe2 / SYS_dup2 stubs363================================================================================364 365The user-Worker syscall fast path. SYS_read with fd==0 is366currently the K5 stub returning 0 (EOF). K9-C1 turns this into367a real handler that reads from the per-Worker stdin region.368 369[CALL] hardwarejs/src/worker.mjs — SYS_read (the K9-C1 wire-in site):370 371[CALL] hardwarejs/src/worker.mjs — SYS_FUTEX (K9 will mirror the in-Worker dispatch shape):372 worker.mjs:116: const SYS_FUTEX = 202;373 worker.mjs:179: function handleFutex(uaddr, futex_op, val, timeout_ptr, _uaddr2, _val3) {374 worker.mjs:278: if (nr === SYS_FUTEX) {375 worker.mjs:279: return handleFutex(a0 | 0, a1 | 0, a2 | 0, a3 | 0, a4 | 0, a5 | 0);376 377================================================================================37814. hardwarejs/src/bootKernel.ts — BootKernelOptions (K9-C1 extension point)379================================================================================380 381The K5+/K6+/K7+/K8+ public API surface. K9-C1 adds the382optional stdinChannel field (UserStdinChannel interface).383Default at K9-C1 is a no-op channel (read returns EOF;384preserves K5/K6 regression behavior).385 386[DEF] hardwarejs/src/bootKernel.ts — BootKernelOptions interface:387 bootKernel.ts:45:export interface BootKernelOptions {388 389[CALL] hardwarejs/src/bootKernel.ts — onUserExit / onUserOutput callback shape (K9-B1 mirror):390 391================================================================================39215. K9-B insertion-point summary (annotation only; no code yet)393================================================================================394 395 [K9-B1] linux-wasm/patches/0009-exit-add-arch_notify_child_exit-hook.patch396 Upstream weak-hook in kernel/exit.c::do_exit (or397 equivalent — likely a sibling of do_notify_parent),398 invoked AFTER the EXIT_ZOMBIE transition so the399 arch can route the exit event to its embedder.400 401 [K9-B1] arch/wasm32/include/asm/process.h (NEW)402 struct wasm_exit_request layout (mirror of403 wasm_signal_request); arch_notify_child_exit404 prototype.405 406 [K9-B1] arch/wasm32/kernel/process.c (NEW; or extend407 spawn.c) — kernel-side hook; composes a408 wasm_exit_request payload, submits via the new409 exit-notification ring (or extends spawn-ring410 with WASM_SPAWN_KIND_EXIT).411 412 [K9-B1] hardwarejs/src/exitNotificationRing.ts (NEW)413 — JS-side ring producer (HardwareJS observes414 the user Worker's 'exit' event, submits the415 exit payload via the ring).416 417 [K9-B2] arch/wasm32/include/asm/uaccess.h (extend) +418 arch/wasm32/kernel/uaccess.c (extend) —419 copy_to_user_for(tid, ...) / copy_from_user_for(tid,420 ...) helpers reading/writing the target Worker's421 named-memory import.422 423 [K9-B2] hardwarejs/src/kernelSpawnHandler.ts (extend) —424 name-and-import every fork-mode user Worker's425 env.user_memory into the kernel Worker as426 env.user_memory_<tid> at spawn time (extends427 K7-U4c thread-mode-only).428 429 [K9-B3] hardwarejs/src/kernelSpawnHandler.ts (extend) —430 SYS_pipe2 handler that allocates a kernel-side431 ring buffer + returns two fds; SYS_read/SYS_write432 handlers that route fd-by-fd-table-lookup.433 434 [K9-C1] arch/wasm32/include/asm/stdin.h (NEW)435 struct wasm_stdin_region layout (16-byte header436 + ring buffer) + arch_user_stdin_region accessor.437 438 [K9-C1] hardwarejs/src/stdinChannel.ts (NEW)439 UserStdinChannel interface + makeStdinChannel440 factory.441 442 [K9-C1] hardwarejs/src/worker.mjs::SYS_read fd==0 case443 (extend) — read from the per-Worker stdin region444 at tail; Atomics.wait on read_notify when empty;445 honor signal-pending pre/post-check (K8-B1 shape).446 447 [K9-C1] hardwarejs/src/bootKernel.ts (extend) —448 BootKernelOptions.stdinChannel? optional field;449 default no-op; threading through to450 kernelSpawnHandler.451 452 [K9-C2] (all upstream-clean: setpgid/getpgid/setsid/getpgrp/453 getsid + kill_pgrp). Acceptance test only.454 455================================================================================456END OF SNAPSHOT457================================================================================458