--- /dev/null
+;;; This is a "repear" program that merely waits for child processes
+;;; to appear and "reap" them, i.e. read their exit status to let them
+;;; exit. The program allows an arbitrary first argument that is
+;;; indended for identifying the reaper process.
+
+ 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
+
+;;; The rest of memory is not executable
+ segment readable writable
+++ /dev/null
-;;; This is a "repear" program that merely waits for child processes
-;;; to appear and "reap" them, i.e. read their exit status to let them
-;;; exit. The program allows an arbitrary first argument that is
-;;; indended for identifying the reaper process.
-
- 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
-
-;;; The rest of memory is not executable
- segment readable writable