From: Ralph Ronnquist Date: Sun, 20 Mar 2022 05:44:58 +0000 (+1100) Subject: initial X-Git-Tag: deb_0.1~30 X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=6237f6db6323eb559c9c10fb4a4b51019eb55051;p=rrq%2Foverlay-boot.git initial --- 6237f6db6323eb559c9c10fb4a4b51019eb55051 diff --git a/reaper/Makefile b/reaper/Makefile new file mode 100644 index 0000000..87ca419 --- /dev/null +++ b/reaper/Makefile @@ -0,0 +1,6 @@ +reaper: reaper.asm + fasm $^ $@ + chmod a+x $@ + +clean: + rm reaper diff --git a/reaper/reaper.asm b/reaper/reaper.asm new file mode 100644 index 0000000..b570481 --- /dev/null +++ b/reaper/reaper.asm @@ -0,0 +1,69 @@ +;;; Compact subhost repear program to merely wait for children to +;;; "reap" them, i.e. let them exit. + + format elf64 executable + entry main + + ;; A data segment + segment readable writable + + ;; sigset_t set -- bit mask for sigprocmask +set: dq -1 ; all bits set + +;;; siginfo_t status -- all ignored +status: rept 16 { dq 0 } + +status$end: + +;;; A code segment + segment readable executable + +;;; Main entry point +main: + ;; if (getpid() != 1) exit 1; + mov rax, qword 39 + syscall + cmp rax, 1 + je pid_1 + + ;; exit(1) + mov rdi, qword 1 + mov rax, qword 60 + syscall ; exit program + + ;; Continue here for pid 1 only +pid_1: + ;; Block all signals + ;; sigprocmask(SIG_BLOCK, &set, 0); + xor rdi, rdi ; SIG_BLOCK = 0 + lea rsi, [set] ; *set + xor rdx, rdx ; 0 + xor r10, r10 ; 0 + mov rax, qword 14 ; sys_rt_sigprocmask + syscall + + ;; loop waiting for children, and reading their exit status +reaper: + ;; first clear status area again + cld + xor rax, rax + lea rsi, [status$end] + lea rdi, [status] +clear: stosq + cmp rdi,rsi + jl clear + + ;; waitid( idtype, id, *status, options ) + xor rdi, rdi ; idtype_t idtype = P_ALL = 0 + xor rsi, rsi ; int id = 0 + lea rdx, [status] ; siginfo_t* = &status + mov r10, 4 ; int options = WEXITED = 4 + mov rax, 247 ; waitid + syscall + + cmp rax,-10 ; -10 = ECHILD (no child processes) + jne reaper + + mov rdi, rax + mov rax, qword 60 + syscall ; exit program