From 6bc6e8354e711ce566a2884ed471f1da7ebcf920 Mon Sep 17 00:00:00 2001 From: "Jan (janneke) Nieuwenhuizen" Date: Tue, 15 Nov 2022 06:36:07 +0100 Subject: [PATCH] lib: linux: Add wait4. * lib/linux/waitpid.c (waitpid): Factor-out wait4 call to... * lib/linux/wait4.c: ...new file here. * include/sys/wait.h (wait4): Add prototype. Include sys/resource.h. * include/sys/resource.h (struct rusage): Remove gratuitous "int" for M2-Planet. * build-aux/configure-lib.sh (libc_SOURCES): Add it. * kaem.run, simple.make (M2_SOURCES), simple.sh: Likewise. Also add resource.h. --- build-aux/configure-lib.sh | 1 + include/sys/resource.h | 28 ++++++++++++++-------------- include/sys/wait.h | 6 +++++- kaem.run | 2 ++ lib/linux/wait4.c | 36 ++++++++++++++++++++++++++++++++++++ lib/linux/waitpid.c | 8 +++++--- simple.make | 3 +++ simple.sh | 2 ++ 8 files changed, 68 insertions(+), 18 deletions(-) create mode 100644 lib/linux/wait4.c diff --git a/build-aux/configure-lib.sh b/build-aux/configure-lib.sh index 7d1f9417..eb320a66 100644 --- a/build-aux/configure-lib.sh +++ b/build-aux/configure-lib.sh @@ -215,6 +215,7 @@ lib/linux/malloc.c lib/linux/_read.c lib/linux/time.c lib/linux/unlink.c +lib/linux/wait4.c lib/linux/waitpid.c lib/linux/$mes_cpu-mes-$compiler/syscall.c lib/linux/getpid.c diff --git a/include/sys/resource.h b/include/sys/resource.h index dab45d17..d277f08c 100644 --- a/include/sys/resource.h +++ b/include/sys/resource.h @@ -32,20 +32,20 @@ struct rusage { struct timeval ru_utime; struct timeval ru_stime; - long int ru_maxrss; - long int ru_ixrss; - long int ru_idrss; - long int ru_isrss; - long int ru_minflt; - long int ru_majflt; - long int ru_nswap; - long int ru_inblock; - long int ru_oublock; - long int ru_msgsnd; - long int ru_msgrcv; - long int ru_nsignals; - long int ru_nvcsw; - long int ru_nivcsw; + long ru_maxrss; + long ru_ixrss; + long ru_idrss; + long ru_isrss; + long ru_minflt; + long ru_majflt; + long ru_nswap; + long ru_inblock; + long ru_oublock; + long ru_msgsnd; + long ru_msgrcv; + long ru_nsignals; + long ru_nvcsw; + long ru_nivcsw; }; #define RUSAGE_SELF 0 diff --git a/include/sys/wait.h b/include/sys/wait.h index 4cff86fc..ca476b8e 100644 --- a/include/sys/wait.h +++ b/include/sys/wait.h @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -20,6 +20,8 @@ #ifndef __MES_SYS_WAIT_H #define __MES_SYS_WAIT_H 1 +#include + #if SYSTEM_LIBC #undef __MES_SYS_WAIT_H #include_next @@ -35,6 +37,8 @@ typedef int pid_t; pid_t waitpid (pid_t pid, int *status_ptr, int options); pid_t wait (int *status_ptr); +pid_t wait4 (pid_t pid, int *wstatus, int options, + struct rusage *rusage); #endif // ! SYSTEM_LIBC diff --git a/kaem.run b/kaem.run index 024c268c..1179aa23 100644 --- a/kaem.run +++ b/kaem.run @@ -98,6 +98,8 @@ M2-Planet \ -f lib/linux/fork.c \ -f lib/m2/execve.c \ -f lib/m2/execv.c \ + -f include/sys/resource.h \ + -f lib/linux/wait4.c \ -f lib/linux/waitpid.c \ -f lib/linux/gettimeofday.c \ -f lib/linux/clock_gettime.c \ diff --git a/lib/linux/wait4.c b/lib/linux/wait4.c new file mode 100644 index 00000000..dfb9bb96 --- /dev/null +++ b/lib/linux/wait4.c @@ -0,0 +1,36 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include +#include +#include +#include +#include + +pid_t +wait4 (pid_t pid, int *status_ptr, int options, struct rusage *rusage) +{ + long long_pid = pid; + long long_status_ptr = cast_voidp_to_long (status_ptr); + long long_options = options; + long long_rusage = cast_voidp_to_long (rusage); + return _sys_call4 (SYS_wait4, long_pid, long_status_ptr, long_options, + long_rusage); +} diff --git a/lib/linux/waitpid.c b/lib/linux/waitpid.c index 426a6e72..80d8bbe5 100644 --- a/lib/linux/waitpid.c +++ b/lib/linux/waitpid.c @@ -18,9 +18,11 @@ * along with GNU Mes. If not, see . */ +#include #include #include #include +#include pid_t waitpid (pid_t pid, int *status_ptr, int options) @@ -28,10 +30,10 @@ waitpid (pid_t pid, int *status_ptr, int options) long long_pid = pid; long long_status_ptr = cast_voidp_to_long (status_ptr); long long_options = options; -#if __i386__ +#if defined (SYS_waitpid) return _sys_call3 (SYS_waitpid, long_pid, long_status_ptr, long_options); -#elif __x86_64__ || __arm__ - return _sys_call4 (SYS_wait4, long_pid, long_status_ptr, long_options, 0); +#elif defined (SYS_wait4) + return wait4 (pid, status_ptr, options, 0); #else #error arch not supported #endif diff --git a/simple.make b/simple.make index 847d4baf..4dd3d03c 100644 --- a/simple.make +++ b/simple.make @@ -130,6 +130,7 @@ M2_SOURCES = \ lib/linux/fork.c \ lib/m2/execve.c \ lib/m2/execv.c \ + lib/linux/wait4.c \ lib/linux/waitpid.c \ lib/linux/gettimeofday.c \ lib/linux/clock_gettime.c \ @@ -193,12 +194,14 @@ M2_PLANET_INCLUDES = \ include/linux/x86/syscall.h \ include/time.h \ include/sys/time.h \ + include/m2/types.h \ include/sys/types.h \ include/stdio.h \ include/limits.h \ include/sys/stat.h \ include/fcntl.h \ include/signal.h \ + include/sys/resource.h \ include/mes/mes.h \ include/mes/builtins.h \ include/mes/constants.h \ diff --git a/simple.sh b/simple.sh index 70ddb211..06887251 100755 --- a/simple.sh +++ b/simple.sh @@ -263,6 +263,8 @@ $CC -g -D HAVE_CONFIG_H=1 \ lib/linux/_read.c \ lib/linux/time.c \ lib/linux/unlink.c \ + include/sys/resource.h \ + lib/linux/wait4.c \ lib/linux/waitpid.c \ lib/linux/$mes_cpu-mes-$compiler/syscall.c \ \