shithub: scc

Download patch

ref: 041d2d96655de6afaac6b20437df8897b03f6c92
parent: 3316919fa6b703a5514a3817b8f22cde27ccf569
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue May 17 17:39:23 EDT 2022

libc: Add wait4() syscall in bsd alike systems

BSD systems and linux implement waitpid using a syscall
called wait4() that receives an additional parameter to
account the resource usage.

--- a/include/bits/darwin/sys.h
+++ b/include/bits/darwin/sys.h
@@ -19,8 +19,10 @@
 typedef int pid_t;
 
 struct sigaction;
+struct rusage;
 
 extern int _fork(void);
 extern pid_t _getpid(void);
 extern int _kill(pid_t, int);
 extern int _sigaction(int, struct sigaction *, struct sigaction *);
+extern pid_t _wait4(pid_t, int *, int, struct rusage *);
--- a/include/bits/dragonfly/sys.h
+++ b/include/bits/dragonfly/sys.h
@@ -19,8 +19,10 @@
 typedef int pid_t;
 
 struct sigaction;
+struct rusage;
 
 extern int _fork(void);
 extern pid_t _getpid(void);
 extern int _kill(pid_t, int);
 extern int _sigaction(int, struct sigaction *, struct sigaction *);
+extern pid_t _wait4(pid_t, int *, int, struct rusage *);
--- a/include/bits/linux/sys.h
+++ b/include/bits/linux/sys.h
@@ -19,8 +19,10 @@
 typedef int pid_t;
 
 struct sigaction;
+struct rusage;
 
 extern int _fork(void);
 extern pid_t _getpid(void);
 extern int _kill(pid_t, int);
 extern int _sigaction(int, struct sigaction *, struct sigaction *);
+extern pid_t _wait4(pid_t, int *, int, struct rusage *);
--- a/include/bits/netbsd/sys.h
+++ b/include/bits/netbsd/sys.h
@@ -19,8 +19,10 @@
 typedef int pid_t;
 
 struct sigaction;
+struct rusage;
 
 extern int _fork(void);
 extern pid_t _getpid(void);
 extern int _kill(pid_t, int);
 extern int _sigaction(int, struct sigaction *, struct sigaction *);
+extern pid_t _wait4(pid_t, int *, int, struct rusage *);
--- a/include/bits/openbsd/sys.h
+++ b/include/bits/openbsd/sys.h
@@ -19,8 +19,10 @@
 typedef int pid_t;
 
 struct sigaction;
+struct rusage;
 
 extern int _fork(void);
 extern pid_t _getpid(void);
 extern int _kill(pid_t, int);
 extern int _sigaction(int, struct sigaction *, struct sigaction *);
+extern pid_t _wait4(pid_t, int *, int, struct rusage *);
--- a/src/libc/arch/amd64/linux/.gitignore
+++ b/src/libc/arch/amd64/linux/.gitignore
@@ -13,4 +13,5 @@
 _sys_brk.s
 _sys_errlist.c
 _unlink.s
+_wait4.s
 _write.s
--- a/src/libc/arch/amd64/linux/Makefile
+++ b/src/libc/arch/amd64/linux/Makefile
@@ -21,6 +21,7 @@
 	_sys_brk.$O\
 	_unlink.$O\
 	_write.$O\
+	_wait4.$O\
 
 OBJS =\
 	$(GENOBJS)\
--- a/src/libc/arch/amd64/linux/syscall.lst
+++ b/src/libc/arch/amd64/linux/syscall.lst
@@ -11,6 +11,7 @@
 39	_getpid	0
 57	_fork	0
 60	_exit	1
+61	_wait4	4
 62	_kill	2
 87	_unlink	1
 96	_gettimeofday	2
--- a/src/libc/arch/amd64/netbsd/.gitignore
+++ b/src/libc/arch/amd64/netbsd/.gitignore
@@ -11,4 +11,5 @@
 _setcontext.s
 _sigaction2.s
 _sys_errlist.c
+_wait4.s
 _write.s
--- a/src/libc/arch/amd64/netbsd/Makefile
+++ b/src/libc/arch/amd64/netbsd/Makefile
@@ -18,6 +18,7 @@
 	_setcontext.$O\
 	_sigaction2.$O\
 	_write.$O\
+	_wait4.$O\
 
 OBJS =\
 	$(GENOBJS)\
--- a/src/libc/arch/amd64/netbsd/syscall.lst
+++ b/src/libc/arch/amd64/netbsd/syscall.lst
@@ -13,3 +13,4 @@
 308	_setcontext	1
 340	_sigaction2	5
 418	_gettimeofday	2
+449	_wait4	4
--- a/src/libc/arch/amd64/openbsd/.gitignore
+++ b/src/libc/arch/amd64/openbsd/.gitignore
@@ -10,4 +10,5 @@
 _read.s
 _sigaction.s
 _sys_errlist.c
+_wait4.s
 _write.s
--- a/src/libc/arch/amd64/openbsd/Makefile
+++ b/src/libc/arch/amd64/openbsd/Makefile
@@ -17,6 +17,7 @@
 	_read.$O\
 	_sigaction.$O\
 	_write.$O\
+	_wait4.$O\
 
 OBJS =\
 	$(GENOBJS)\
--- a/src/libc/arch/amd64/openbsd/syscall.lst
+++ b/src/libc/arch/amd64/openbsd/syscall.lst
@@ -6,6 +6,7 @@
 4	_write	3
 5	_open	3
 6	_close	1
+11	_wait4	4
 17	_brk	1
 20	_getpid	0
 46	_sigaction	3
--- a/src/libc/arch/arm/linux/.gitignore
+++ b/src/libc/arch/arm/linux/.gitignore
@@ -8,4 +8,5 @@
 _openat.s
 _read.s
 _sys_errlist.c
+_wait4.s
 _write.s
--- a/src/libc/arch/arm/linux/Makefile
+++ b/src/libc/arch/arm/linux/Makefile
@@ -16,6 +16,7 @@
 	_sigaction.$O\
 	_sys_brk.$O\
 	_write.$O\
+	_wait4.$O\
 
 GENSRC = $(GENOBJS:.$O=.s)
 
--- a/src/libc/arch/arm/linux/syscall.lst
+++ b/src/libc/arch/arm/linux/syscall.lst
@@ -9,4 +9,5 @@
 37	_kill
 19	_lseek
 45	_sys_brk
+114	_wait4
 134	__sigaction
--- a/src/libc/arch/arm64/linux/.gitignore
+++ b/src/libc/arch/arm64/linux/.gitignore
@@ -7,4 +7,5 @@
 _openat.s
 _read.s
 _sys_errlist.c
+_wait4.s
 _write.s
--- a/src/libc/arch/arm64/linux/Makefile
+++ b/src/libc/arch/arm64/linux/Makefile
@@ -16,6 +16,7 @@
 	_sigaction.$O\
 	_sys_brk.$O\
 	_write.$O\
+	_wait4.$O\
 
 OBJS =\
 	$(GENOBJS)\
--- a/src/libc/arch/arm64/linux/syscall.lst
+++ b/src/libc/arch/arm64/linux/syscall.lst
@@ -9,3 +9,4 @@
 134	__sigaction
 172	_getpid
 214	_sys_brk
+260	_wait4
--- a/src/libc/arch/i386/linux/.gitignore
+++ b/src/libc/arch/i386/linux/.gitignore
@@ -8,4 +8,5 @@
 _read.s
 _sigaction.s
 _sys_brk.s
+_wait4.s
 _write.s
--- a/src/libc/arch/i386/linux/Makefile
+++ b/src/libc/arch/i386/linux/Makefile
@@ -16,6 +16,7 @@
 	_sigaction.$O\
 	_sys_brk.$O\
 	_write.$O\
+	_wait4.$O\
 
 GENSRC = $(GENOBJS:.$O=.s)
 
--- a/src/libc/arch/i386/linux/syscall.lst
+++ b/src/libc/arch/i386/linux/syscall.lst
@@ -10,3 +10,4 @@
 37	_kill		2
 45	_sys_brk	1
 67	__sigaction	4
+114	_wait4	4
--- a/src/libc/arch/ppc/linux/.gitignore
+++ b/src/libc/arch/ppc/linux/.gitignore
@@ -10,5 +10,6 @@
 _sys_brk.s
 _sys_errlist.c
 _unlink.s
+_wait4.s
 _waitpid.s
 _write.s
--- a/src/libc/arch/ppc/linux/Makefile
+++ b/src/libc/arch/ppc/linux/Makefile
@@ -18,8 +18,8 @@
 	_read.$O\
 	_sys_brk.$O\
 	_unlink.$O\
-	_waitpid.$O\
 	_write.$O\
+	_wait4.$O\
 
 OBJS =\
 	$(GENOBJS)\
--- a/src/libc/arch/ppc/linux/syscall.lst
+++ b/src/libc/arch/ppc/linux/syscall.lst
@@ -5,7 +5,6 @@
 4	_write
 5	_open
 6	_close
-7	_waitpid
 8	_creat
 9	_link
 10	_unlink
@@ -12,3 +11,4 @@
 20	_getpid
 37	_kill
 45	_sys_brk
+114	_wait4
--- a/src/libc/objs/amd64-linux.mk
+++ b/src/libc/objs/amd64-linux.mk
@@ -17,6 +17,7 @@
 	arch/amd64/linux/_sys_brk.$O\
 	arch/amd64/linux/_sys_errlist.$O\
 	arch/amd64/linux/_unlink.$O\
+	arch/amd64/linux/_wait4.$O\
 	arch/amd64/linux/_write.$O\
 	arch/amd64/linux/crt.$O\
 	arch/amd64/longjmp.$O\
--- a/src/libc/objs/amd64-netbsd.mk
+++ b/src/libc/objs/amd64-netbsd.mk
@@ -19,6 +19,7 @@
 	arch/amd64/netbsd/_setcontext.$O\
 	arch/amd64/netbsd/_sigaction2.$O\
 	arch/amd64/netbsd/_sys_errlist.$O\
+	arch/amd64/netbsd/_wait4.$O\
 	arch/amd64/netbsd/_write.$O\
 	arch/amd64/netbsd/crt.$O\
 	arch/amd64/setjmp.$O\
--- a/src/libc/objs/amd64-openbsd.mk
+++ b/src/libc/objs/amd64-openbsd.mk
@@ -12,6 +12,7 @@
 	arch/amd64/openbsd/_open.$O\
 	arch/amd64/openbsd/_read.$O\
 	arch/amd64/openbsd/_sigaction.$O\
+	arch/amd64/openbsd/_wait4.$O\
 	arch/amd64/openbsd/_write.$O\
 	arch/amd64/openbsd/crt.$O\
 	arch/amd64/openbsd/_sys_errlist.$O\