- Only increment nprocs when we're creating a new process, not just when allocating a PID. - Per above, proc_free_pid() no longer decrements nprocs. It's now done in proc_free() right after proc_free_pid(). - Ensure nprocs is accessed using atomics everywhere.diff -r1.247 -r1.248 src/sys/compat/linux/common/linux_misc.c
(thorpej)
--- src/sys/compat/linux/common/linux_misc.c 2019/12/31 13:07:13 1.247
+++ src/sys/compat/linux/common/linux_misc.c 2020/04/19 20:31:59 1.248
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: linux_misc.c,v 1.247 2019/12/31 13:07:13 ad Exp $ */ | 1 | /* $NetBSD: linux_misc.c,v 1.248 2020/04/19 20:31:59 thorpej Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1995, 1998, 1999, 2008 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1995, 1998, 1999, 2008 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Frank van der Linden and Eric Haszlakiewicz; by Jason R. Thorpe | 8 | * by Frank van der Linden and Eric Haszlakiewicz; by Jason R. Thorpe | |
9 | * of the Numerical Aerospace Simulation Facility, NASA Ames Research Center. | 9 | * of the Numerical Aerospace Simulation Facility, NASA Ames Research Center. | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | 12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | 13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
@@ -47,27 +47,27 @@ | @@ -47,27 +47,27 @@ | |||
47 | * linux_sys_readdir : linux_misc_notalpha.c | 47 | * linux_sys_readdir : linux_misc_notalpha.c | |
48 | * linux_sys_setresgid : linux_misc_notalpha.c | 48 | * linux_sys_setresgid : linux_misc_notalpha.c | |
49 | * linux_sys_time : linux_misc_notalpha.c | 49 | * linux_sys_time : linux_misc_notalpha.c | |
50 | * linux_sys_utime : linux_misc_notalpha.c | 50 | * linux_sys_utime : linux_misc_notalpha.c | |
51 | * linux_sys_waitpid : linux_misc_notalpha.c | 51 | * linux_sys_waitpid : linux_misc_notalpha.c | |
52 | * linux_sys_old_mmap : linux_oldmmap.c | 52 | * linux_sys_old_mmap : linux_oldmmap.c | |
53 | * linux_sys_oldolduname : linux_oldolduname.c | 53 | * linux_sys_oldolduname : linux_oldolduname.c | |
54 | * linux_sys_oldselect : linux_oldselect.c | 54 | * linux_sys_oldselect : linux_oldselect.c | |
55 | * linux_sys_olduname : linux_olduname.c | 55 | * linux_sys_olduname : linux_olduname.c | |
56 | * linux_sys_pipe : linux_pipe.c | 56 | * linux_sys_pipe : linux_pipe.c | |
57 | */ | 57 | */ | |
58 | 58 | |||
59 | #include <sys/cdefs.h> | 59 | #include <sys/cdefs.h> | |
60 | __KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.247 2019/12/31 13:07:13 ad Exp $"); | 60 | __KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.248 2020/04/19 20:31:59 thorpej Exp $"); | |
61 | 61 | |||
62 | #include <sys/param.h> | 62 | #include <sys/param.h> | |
63 | #include <sys/systm.h> | 63 | #include <sys/systm.h> | |
64 | #include <sys/namei.h> | 64 | #include <sys/namei.h> | |
65 | #include <sys/proc.h> | 65 | #include <sys/proc.h> | |
66 | #include <sys/dirent.h> | 66 | #include <sys/dirent.h> | |
67 | #include <sys/file.h> | 67 | #include <sys/file.h> | |
68 | #include <sys/stat.h> | 68 | #include <sys/stat.h> | |
69 | #include <sys/filedesc.h> | 69 | #include <sys/filedesc.h> | |
70 | #include <sys/ioctl.h> | 70 | #include <sys/ioctl.h> | |
71 | #include <sys/kernel.h> | 71 | #include <sys/kernel.h> | |
72 | #include <sys/malloc.h> | 72 | #include <sys/malloc.h> | |
73 | #include <sys/mbuf.h> | 73 | #include <sys/mbuf.h> | |
@@ -1350,27 +1350,27 @@ linux_sys_sysinfo(struct lwp *l, const s | @@ -1350,27 +1350,27 @@ linux_sys_sysinfo(struct lwp *l, const s | |||
1350 | memset(&si, 0, sizeof(si)); | 1350 | memset(&si, 0, sizeof(si)); | |
1351 | si.uptime = time_uptime; | 1351 | si.uptime = time_uptime; | |
1352 | la = &averunnable; | 1352 | la = &averunnable; | |
1353 | si.loads[0] = la->ldavg[0] * LINUX_SYSINFO_LOADS_SCALE / la->fscale; | 1353 | si.loads[0] = la->ldavg[0] * LINUX_SYSINFO_LOADS_SCALE / la->fscale; | |
1354 | si.loads[1] = la->ldavg[1] * LINUX_SYSINFO_LOADS_SCALE / la->fscale; | 1354 | si.loads[1] = la->ldavg[1] * LINUX_SYSINFO_LOADS_SCALE / la->fscale; | |
1355 | si.loads[2] = la->ldavg[2] * LINUX_SYSINFO_LOADS_SCALE / la->fscale; | 1355 | si.loads[2] = la->ldavg[2] * LINUX_SYSINFO_LOADS_SCALE / la->fscale; | |
1356 | si.totalram = ctob((u_long)physmem); | 1356 | si.totalram = ctob((u_long)physmem); | |
1357 | si.freeram = (u_long)uvm_availmem() * uvmexp.pagesize; | 1357 | si.freeram = (u_long)uvm_availmem() * uvmexp.pagesize; | |
1358 | si.sharedram = 0; /* XXX */ | 1358 | si.sharedram = 0; /* XXX */ | |
1359 | si.bufferram = (u_long)uvmexp.filepages * uvmexp.pagesize; | 1359 | si.bufferram = (u_long)uvmexp.filepages * uvmexp.pagesize; | |
1360 | si.totalswap = (u_long)uvmexp.swpages * uvmexp.pagesize; | 1360 | si.totalswap = (u_long)uvmexp.swpages * uvmexp.pagesize; | |
1361 | si.freeswap = | 1361 | si.freeswap = | |
1362 | (u_long)(uvmexp.swpages - uvmexp.swpginuse) * uvmexp.pagesize; | 1362 | (u_long)(uvmexp.swpages - uvmexp.swpginuse) * uvmexp.pagesize; | |
1363 | si.procs = nprocs; | 1363 | si.procs = atomic_load_relaxed(&nprocs); | |
1364 | 1364 | |||
1365 | /* The following are only present in newer Linux kernels. */ | 1365 | /* The following are only present in newer Linux kernels. */ | |
1366 | si.totalbig = 0; | 1366 | si.totalbig = 0; | |
1367 | si.freebig = 0; | 1367 | si.freebig = 0; | |
1368 | si.mem_unit = 1; | 1368 | si.mem_unit = 1; | |
1369 | 1369 | |||
1370 | return (copyout(&si, SCARG(uap, arg), sizeof si)); | 1370 | return (copyout(&si, SCARG(uap, arg), sizeof si)); | |
1371 | } | 1371 | } | |
1372 | 1372 | |||
1373 | int | 1373 | int | |
1374 | linux_sys_getrlimit(struct lwp *l, const struct linux_sys_getrlimit_args *uap, register_t *retval) | 1374 | linux_sys_getrlimit(struct lwp *l, const struct linux_sys_getrlimit_args *uap, register_t *retval) | |
1375 | { | 1375 | { | |
1376 | /* { | 1376 | /* { |
--- src/sys/compat/linux/common/linux_sched.c 2019/11/23 19:42:52 1.73
+++ src/sys/compat/linux/common/linux_sched.c 2020/04/19 20:31:59 1.74
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: linux_sched.c,v 1.73 2019/11/23 19:42:52 ad Exp $ */ | 1 | /* $NetBSD: linux_sched.c,v 1.74 2020/04/19 20:31:59 thorpej Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1999, 2019 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1999, 2019 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, | 8 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, | |
9 | * NASA Ames Research Center; by Matthias Scheler. | 9 | * NASA Ames Research Center; by Matthias Scheler. | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | 12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | 13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
@@ -25,27 +25,27 @@ | @@ -25,27 +25,27 @@ | |||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
30 | * POSSIBILITY OF SUCH DAMAGE. | 30 | * POSSIBILITY OF SUCH DAMAGE. | |
31 | */ | 31 | */ | |
32 | 32 | |||
33 | /* | 33 | /* | |
34 | * Linux compatibility module. Try to deal with scheduler related syscalls. | 34 | * Linux compatibility module. Try to deal with scheduler related syscalls. | |
35 | */ | 35 | */ | |
36 | 36 | |||
37 | #include <sys/cdefs.h> | 37 | #include <sys/cdefs.h> | |
38 | __KERNEL_RCSID(0, "$NetBSD: linux_sched.c,v 1.73 2019/11/23 19:42:52 ad Exp $"); | 38 | __KERNEL_RCSID(0, "$NetBSD: linux_sched.c,v 1.74 2020/04/19 20:31:59 thorpej Exp $"); | |
39 | 39 | |||
40 | #include <sys/param.h> | 40 | #include <sys/param.h> | |
41 | #include <sys/mount.h> | 41 | #include <sys/mount.h> | |
42 | #include <sys/proc.h> | 42 | #include <sys/proc.h> | |
43 | #include <sys/systm.h> | 43 | #include <sys/systm.h> | |
44 | #include <sys/sysctl.h> | 44 | #include <sys/sysctl.h> | |
45 | #include <sys/syscallargs.h> | 45 | #include <sys/syscallargs.h> | |
46 | #include <sys/wait.h> | 46 | #include <sys/wait.h> | |
47 | #include <sys/kauth.h> | 47 | #include <sys/kauth.h> | |
48 | #include <sys/ptrace.h> | 48 | #include <sys/ptrace.h> | |
49 | #include <sys/atomic.h> | 49 | #include <sys/atomic.h> | |
50 | 50 | |||
51 | #include <sys/cpu.h> | 51 | #include <sys/cpu.h> | |
@@ -172,54 +172,44 @@ linux_clone_nptl(struct lwp *l, const st | @@ -172,54 +172,44 @@ linux_clone_nptl(struct lwp *l, const st | |||
172 | /* { | 172 | /* { | |
173 | syscallarg(int) flags; | 173 | syscallarg(int) flags; | |
174 | syscallarg(void *) stack; | 174 | syscallarg(void *) stack; | |
175 | syscallarg(void *) parent_tidptr; | 175 | syscallarg(void *) parent_tidptr; | |
176 | syscallarg(void *) tls; | 176 | syscallarg(void *) tls; | |
177 | syscallarg(void *) child_tidptr; | 177 | syscallarg(void *) child_tidptr; | |
178 | } */ | 178 | } */ | |
179 | struct proc *p; | 179 | struct proc *p; | |
180 | struct lwp *l2; | 180 | struct lwp *l2; | |
181 | struct linux_emuldata *led; | 181 | struct linux_emuldata *led; | |
182 | void *parent_tidptr, *tls, *child_tidptr; | 182 | void *parent_tidptr, *tls, *child_tidptr; | |
183 | vaddr_t uaddr; | 183 | vaddr_t uaddr; | |
184 | lwpid_t lid; | 184 | lwpid_t lid; | |
185 | int flags, tnprocs, error; | 185 | int flags, error; | |
186 | 186 | |||
187 | p = l->l_proc; | 187 | p = l->l_proc; | |
188 | flags = SCARG(uap, flags); | 188 | flags = SCARG(uap, flags); | |
189 | parent_tidptr = SCARG(uap, parent_tidptr); | 189 | parent_tidptr = SCARG(uap, parent_tidptr); | |
190 | tls = SCARG(uap, tls); | 190 | tls = SCARG(uap, tls); | |
191 | child_tidptr = SCARG(uap, child_tidptr); | 191 | child_tidptr = SCARG(uap, child_tidptr); | |
192 | 192 | |||
193 | tnprocs = atomic_inc_uint_nv(&nprocs); | |||
194 | if (__predict_false(tnprocs >= maxproc) || | |||
195 | kauth_authorize_process(l->l_cred, KAUTH_PROCESS_FORK, p, | |||
196 | KAUTH_ARG(tnprocs), NULL, NULL) != 0) { | |||
197 | atomic_dec_uint(&nprocs); | |||
198 | return EAGAIN; | |||
199 | } | |||
200 | ||||
201 | uaddr = uvm_uarea_alloc(); | 193 | uaddr = uvm_uarea_alloc(); | |
202 | if (__predict_false(uaddr == 0)) { | 194 | if (__predict_false(uaddr == 0)) { | |
203 | atomic_dec_uint(&nprocs); | |||
204 | return ENOMEM; | 195 | return ENOMEM; | |
205 | } | 196 | } | |
206 | 197 | |||
207 | error = lwp_create(l, p, uaddr, LWP_DETACHED | LWP_PIDLID, | 198 | error = lwp_create(l, p, uaddr, LWP_DETACHED | LWP_PIDLID, | |
208 | SCARG(uap, stack), 0, child_return, NULL, &l2, l->l_class, | 199 | SCARG(uap, stack), 0, child_return, NULL, &l2, l->l_class, | |
209 | &l->l_sigmask, &l->l_sigstk); | 200 | &l->l_sigmask, &l->l_sigstk); | |
210 | if (__predict_false(error)) { | 201 | if (__predict_false(error)) { | |
211 | DPRINTF(("%s: lwp_create error=%d\n", __func__, error)); | 202 | DPRINTF(("%s: lwp_create error=%d\n", __func__, error)); | |
212 | atomic_dec_uint(&nprocs); | |||
213 | uvm_uarea_free(uaddr); | 203 | uvm_uarea_free(uaddr); | |
214 | return error; | 204 | return error; | |
215 | } | 205 | } | |
216 | lid = l2->l_lid; | 206 | lid = l2->l_lid; | |
217 | 207 | |||
218 | /* LINUX_CLONE_CHILD_CLEARTID: clear TID in child's memory on exit() */ | 208 | /* LINUX_CLONE_CHILD_CLEARTID: clear TID in child's memory on exit() */ | |
219 | if (flags & LINUX_CLONE_CHILD_CLEARTID) { | 209 | if (flags & LINUX_CLONE_CHILD_CLEARTID) { | |
220 | led = l2->l_emuldata; | 210 | led = l2->l_emuldata; | |
221 | led->led_clear_tid = child_tidptr; | 211 | led->led_clear_tid = child_tidptr; | |
222 | } | 212 | } | |
223 | 213 | |||
224 | /* LINUX_CLONE_PARENT_SETTID: store child's TID in parent's memory */ | 214 | /* LINUX_CLONE_PARENT_SETTID: store child's TID in parent's memory */ | |
225 | if (flags & LINUX_CLONE_PARENT_SETTID) { | 215 | if (flags & LINUX_CLONE_PARENT_SETTID) { |
--- src/sys/compat/linux32/common/linux32_sysinfo.c 2019/12/31 13:07:13 1.10
+++ src/sys/compat/linux32/common/linux32_sysinfo.c 2020/04/19 20:31:59 1.11
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: linux32_sysinfo.c,v 1.10 2019/12/31 13:07:13 ad Exp $ */ | 1 | /* $NetBSD: linux32_sysinfo.c,v 1.11 2020/04/19 20:31:59 thorpej Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved. | 4 | * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved. | |
5 | * | 5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | 6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions | 7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | 8 | * are met: | |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. | |
14 | * 3. All advertising materials mentioning features or use of this software | 14 | * 3. All advertising materials mentioning features or use of this software | |
@@ -23,27 +23,27 @@ | @@ -23,27 +23,27 @@ | |||
23 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 23 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
24 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS | 24 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS | |
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
31 | * POSSIBILITY OF SUCH DAMAGE. | 31 | * POSSIBILITY OF SUCH DAMAGE. | |
32 | */ | 32 | */ | |
33 | 33 | |||
34 | #include <sys/cdefs.h> | 34 | #include <sys/cdefs.h> | |
35 | 35 | |||
36 | __KERNEL_RCSID(0, "$NetBSD: linux32_sysinfo.c,v 1.10 2019/12/31 13:07:13 ad Exp $"); | 36 | __KERNEL_RCSID(0, "$NetBSD: linux32_sysinfo.c,v 1.11 2020/04/19 20:31:59 thorpej Exp $"); | |
37 | 37 | |||
38 | #include <sys/types.h> | 38 | #include <sys/types.h> | |
39 | #include <sys/param.h> | 39 | #include <sys/param.h> | |
40 | #include <sys/kernel.h> | 40 | #include <sys/kernel.h> | |
41 | #include <sys/dirent.h> | 41 | #include <sys/dirent.h> | |
42 | #include <sys/proc.h> | 42 | #include <sys/proc.h> | |
43 | 43 | |||
44 | #include <sys/syscallargs.h> | 44 | #include <sys/syscallargs.h> | |
45 | 45 | |||
46 | #include <uvm/uvm_extern.h> | 46 | #include <uvm/uvm_extern.h> | |
47 | 47 | |||
48 | #include <compat/netbsd32/netbsd32.h> | 48 | #include <compat/netbsd32/netbsd32.h> | |
49 | #include <compat/netbsd32/netbsd32_conv.h> | 49 | #include <compat/netbsd32/netbsd32_conv.h> | |
@@ -73,23 +73,23 @@ linux32_sys_sysinfo(struct lwp *l, const | @@ -73,23 +73,23 @@ linux32_sys_sysinfo(struct lwp *l, const | |||
73 | memset(&si, 0, sizeof(si)); | 73 | memset(&si, 0, sizeof(si)); | |
74 | si.uptime = time_uptime; | 74 | si.uptime = time_uptime; | |
75 | la = &averunnable; | 75 | la = &averunnable; | |
76 | si.loads[0] = la->ldavg[0] * LINUX_SYSINFO_LOADS_SCALE / la->fscale; | 76 | si.loads[0] = la->ldavg[0] * LINUX_SYSINFO_LOADS_SCALE / la->fscale; | |
77 | si.loads[1] = la->ldavg[1] * LINUX_SYSINFO_LOADS_SCALE / la->fscale; | 77 | si.loads[1] = la->ldavg[1] * LINUX_SYSINFO_LOADS_SCALE / la->fscale; | |
78 | si.loads[2] = la->ldavg[2] * LINUX_SYSINFO_LOADS_SCALE / la->fscale; | 78 | si.loads[2] = la->ldavg[2] * LINUX_SYSINFO_LOADS_SCALE / la->fscale; | |
79 | si.totalram = ctob((u_long)physmem); | 79 | si.totalram = ctob((u_long)physmem); | |
80 | si.freeram = (u_long)uvm_availmem() * uvmexp.pagesize; | 80 | si.freeram = (u_long)uvm_availmem() * uvmexp.pagesize; | |
81 | si.sharedram = 0; /* XXX */ | 81 | si.sharedram = 0; /* XXX */ | |
82 | si.bufferram = (u_long)uvmexp.filepages * uvmexp.pagesize; | 82 | si.bufferram = (u_long)uvmexp.filepages * uvmexp.pagesize; | |
83 | si.totalswap = (u_long)uvmexp.swpages * uvmexp.pagesize; | 83 | si.totalswap = (u_long)uvmexp.swpages * uvmexp.pagesize; | |
84 | si.freeswap = | 84 | si.freeswap = | |
85 | (u_long)(uvmexp.swpages - uvmexp.swpginuse) * uvmexp.pagesize; | 85 | (u_long)(uvmexp.swpages - uvmexp.swpginuse) * uvmexp.pagesize; | |
86 | si.procs = nprocs; | 86 | si.procs = atomic_load_relaxed(&nprocs); | |
87 | 87 | |||
88 | /* The following are only present in newer Linux kernels. */ | 88 | /* The following are only present in newer Linux kernels. */ | |
89 | si.totalbig = 0; | 89 | si.totalbig = 0; | |
90 | si.freebig = 0; | 90 | si.freebig = 0; | |
91 | si.mem_unit = 1; | 91 | si.mem_unit = 1; | |
92 | 92 | |||
93 | return (copyout(&si, SCARG_P32(uap, arg), sizeof si)); | 93 | return (copyout(&si, SCARG_P32(uap, arg), sizeof si)); | |
94 | } | 94 | } | |
95 | 95 |
--- src/sys/compat/netbsd32/netbsd32_execve.c 2019/09/17 15:19:27 1.41
+++ src/sys/compat/netbsd32/netbsd32_execve.c 2020/04/19 20:31:59 1.42
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: netbsd32_execve.c,v 1.41 2019/09/17 15:19:27 christos Exp $ */ | 1 | /* $NetBSD: netbsd32_execve.c,v 1.42 2020/04/19 20:31:59 thorpej Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1998, 2001 Matthew R. Green | 4 | * Copyright (c) 1998, 2001 Matthew R. Green | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -18,27 +18,27 @@ | @@ -18,27 +18,27 @@ | |||
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | |
23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
26 | * SUCH DAMAGE. | 26 | * SUCH DAMAGE. | |
27 | */ | 27 | */ | |
28 | 28 | |||
29 | #include <sys/cdefs.h> | 29 | #include <sys/cdefs.h> | |
30 | 30 | |||
31 | __KERNEL_RCSID(0, "$NetBSD: netbsd32_execve.c,v 1.41 2019/09/17 15:19:27 christos Exp $"); | 31 | __KERNEL_RCSID(0, "$NetBSD: netbsd32_execve.c,v 1.42 2020/04/19 20:31:59 thorpej Exp $"); | |
32 | 32 | |||
33 | #include <sys/param.h> | 33 | #include <sys/param.h> | |
34 | #include <sys/systm.h> | 34 | #include <sys/systm.h> | |
35 | #include <sys/atomic.h> | 35 | #include <sys/atomic.h> | |
36 | #include <sys/mount.h> | 36 | #include <sys/mount.h> | |
37 | #include <sys/namei.h> | 37 | #include <sys/namei.h> | |
38 | #include <sys/stat.h> | 38 | #include <sys/stat.h> | |
39 | #include <sys/spawn.h> | 39 | #include <sys/spawn.h> | |
40 | #include <sys/uidinfo.h> | 40 | #include <sys/uidinfo.h> | |
41 | #include <sys/vnode.h> | 41 | #include <sys/vnode.h> | |
42 | #include <sys/file.h> | 42 | #include <sys/file.h> | |
43 | #include <sys/filedesc.h> | 43 | #include <sys/filedesc.h> | |
44 | #include <sys/syscallargs.h> | 44 | #include <sys/syscallargs.h> | |
@@ -172,26 +172,27 @@ netbsd32_posix_spawn(struct lwp *l, | @@ -172,26 +172,27 @@ netbsd32_posix_spawn(struct lwp *l, | |||
172 | syscallarg(const netbsd32_posix_spawnattrp) attrp; | 172 | syscallarg(const netbsd32_posix_spawnattrp) attrp; | |
173 | syscallarg(netbsd32_charpp) argv; | 173 | syscallarg(netbsd32_charpp) argv; | |
174 | syscallarg(netbsd32_charpp) envp; | 174 | syscallarg(netbsd32_charpp) envp; | |
175 | } */ | 175 | } */ | |
176 | 176 | |||
177 | int error; | 177 | int error; | |
178 | struct posix_spawn_file_actions *fa = NULL; | 178 | struct posix_spawn_file_actions *fa = NULL; | |
179 | struct posix_spawnattr *sa = NULL; | 179 | struct posix_spawnattr *sa = NULL; | |
180 | pid_t pid; | 180 | pid_t pid; | |
181 | bool child_ok = false; | 181 | bool child_ok = false; | |
182 | rlim_t max_fileactions; | 182 | rlim_t max_fileactions; | |
183 | proc_t *p = l->l_proc; | 183 | proc_t *p = l->l_proc; | |
184 | 184 | |||
185 | /* check_posix_spawn() increments nprocs for us. */ | |||
185 | error = check_posix_spawn(l); | 186 | error = check_posix_spawn(l); | |
186 | if (error) { | 187 | if (error) { | |
187 | *retval = error; | 188 | *retval = error; | |
188 | return 0; | 189 | return 0; | |
189 | } | 190 | } | |
190 | 191 | |||
191 | /* copy in file_actions struct */ | 192 | /* copy in file_actions struct */ | |
192 | if (SCARG_P32(uap, file_actions) != NULL) { | 193 | if (SCARG_P32(uap, file_actions) != NULL) { | |
193 | max_fileactions = 2 * uimin(p->p_rlimit[RLIMIT_NOFILE].rlim_cur, | 194 | max_fileactions = 2 * uimin(p->p_rlimit[RLIMIT_NOFILE].rlim_cur, | |
194 | maxfiles); | 195 | maxfiles); | |
195 | error = netbsd32_posix_spawn_fa_alloc(&fa, | 196 | error = netbsd32_posix_spawn_fa_alloc(&fa, | |
196 | SCARG_P32(uap, file_actions), max_fileactions); | 197 | SCARG_P32(uap, file_actions), max_fileactions); | |
197 | if (error) | 198 | if (error) |
--- src/sys/kern/kern_exec.c 2020/04/14 22:42:18 1.496
+++ src/sys/kern/kern_exec.c 2020/04/19 20:31:59 1.497
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: kern_exec.c,v 1.496 2020/04/14 22:42:18 kamil Exp $ */ | 1 | /* $NetBSD: kern_exec.c,v 1.497 2020/04/19 20:31:59 thorpej Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2008, 2019, 2020 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2008, 2019, 2020 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Andrew Doran. | 8 | * by Andrew Doran. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -52,27 +52,27 @@ | @@ -52,27 +52,27 @@ | |||
52 | * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR | 52 | * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR | |
53 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 53 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
54 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 54 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
55 | * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 55 | * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
56 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 56 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
57 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 57 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | |
58 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | 58 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
59 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 59 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
60 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 60 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
61 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 61 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
62 | */ | 62 | */ | |
63 | 63 | |||
64 | #include <sys/cdefs.h> | 64 | #include <sys/cdefs.h> | |
65 | __KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.496 2020/04/14 22:42:18 kamil Exp $"); | 65 | __KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.497 2020/04/19 20:31:59 thorpej Exp $"); | |
66 | 66 | |||
67 | #include "opt_exec.h" | 67 | #include "opt_exec.h" | |
68 | #include "opt_execfmt.h" | 68 | #include "opt_execfmt.h" | |
69 | #include "opt_ktrace.h" | 69 | #include "opt_ktrace.h" | |
70 | #include "opt_modular.h" | 70 | #include "opt_modular.h" | |
71 | #include "opt_syscall_debug.h" | 71 | #include "opt_syscall_debug.h" | |
72 | #include "veriexec.h" | 72 | #include "veriexec.h" | |
73 | #include "opt_pax.h" | 73 | #include "opt_pax.h" | |
74 | 74 | |||
75 | #include <sys/param.h> | 75 | #include <sys/param.h> | |
76 | #include <sys/systm.h> | 76 | #include <sys/systm.h> | |
77 | #include <sys/filedesc.h> | 77 | #include <sys/filedesc.h> | |
78 | #include <sys/kernel.h> | 78 | #include <sys/kernel.h> | |
@@ -2387,26 +2387,30 @@ posix_spawn_fa_alloc(struct posix_spawn_ | @@ -2387,26 +2387,30 @@ posix_spawn_fa_alloc(struct posix_spawn_ | |||
2387 | memcpy(fae->fae_path, pbuf, fal); | 2387 | memcpy(fae->fae_path, pbuf, fal); | |
2388 | } | 2388 | } | |
2389 | PNBUF_PUT(pbuf); | 2389 | PNBUF_PUT(pbuf); | |
2390 | 2390 | |||
2391 | *fap = fa; | 2391 | *fap = fa; | |
2392 | return 0; | 2392 | return 0; | |
2393 | out: | 2393 | out: | |
2394 | if (pbuf) | 2394 | if (pbuf) | |
2395 | PNBUF_PUT(pbuf); | 2395 | PNBUF_PUT(pbuf); | |
2396 | posix_spawn_fa_free(fa, i); | 2396 | posix_spawn_fa_free(fa, i); | |
2397 | return error; | 2397 | return error; | |
2398 | } | 2398 | } | |
2399 | 2399 | |||
2400 | /* | |||
2401 | * N.B. increments nprocs upon success. Callers need to drop nprocs if | |||
2402 | * they fail for some other reason. | |||
2403 | */ | |||
2400 | int | 2404 | int | |
2401 | check_posix_spawn(struct lwp *l1) | 2405 | check_posix_spawn(struct lwp *l1) | |
2402 | { | 2406 | { | |
2403 | int error, tnprocs, count; | 2407 | int error, tnprocs, count; | |
2404 | uid_t uid; | 2408 | uid_t uid; | |
2405 | struct proc *p1; | 2409 | struct proc *p1; | |
2406 | 2410 | |||
2407 | p1 = l1->l_proc; | 2411 | p1 = l1->l_proc; | |
2408 | uid = kauth_cred_getuid(l1->l_cred); | 2412 | uid = kauth_cred_getuid(l1->l_cred); | |
2409 | tnprocs = atomic_inc_uint_nv(&nprocs); | 2413 | tnprocs = atomic_inc_uint_nv(&nprocs); | |
2410 | 2414 | |||
2411 | /* | 2415 | /* | |
2412 | * Although process entries are dynamically created, we still keep | 2416 | * Although process entries are dynamically created, we still keep | |
@@ -2741,26 +2745,27 @@ sys_posix_spawn(struct lwp *l1, const st | @@ -2741,26 +2745,27 @@ sys_posix_spawn(struct lwp *l1, const st | |||
2741 | syscallarg(const struct posix_spawnattr *) attrp; | 2745 | syscallarg(const struct posix_spawnattr *) attrp; | |
2742 | syscallarg(char *const *) argv; | 2746 | syscallarg(char *const *) argv; | |
2743 | syscallarg(char *const *) envp; | 2747 | syscallarg(char *const *) envp; | |
2744 | } */ | 2748 | } */ | |
2745 | 2749 | |||
2746 | int error; | 2750 | int error; | |
2747 | struct posix_spawn_file_actions *fa = NULL; | 2751 | struct posix_spawn_file_actions *fa = NULL; | |
2748 | struct posix_spawnattr *sa = NULL; | 2752 | struct posix_spawnattr *sa = NULL; | |
2749 | pid_t pid; | 2753 | pid_t pid; | |
2750 | bool child_ok = false; | 2754 | bool child_ok = false; | |
2751 | rlim_t max_fileactions; | 2755 | rlim_t max_fileactions; | |
2752 | proc_t *p = l1->l_proc; | 2756 | proc_t *p = l1->l_proc; | |
2753 | 2757 | |||
2758 | /* check_posix_spawn() increments nprocs for us. */ | |||
2754 | error = check_posix_spawn(l1); | 2759 | error = check_posix_spawn(l1); | |
2755 | if (error) { | 2760 | if (error) { | |
2756 | *retval = error; | 2761 | *retval = error; | |
2757 | return 0; | 2762 | return 0; | |
2758 | } | 2763 | } | |
2759 | 2764 | |||
2760 | /* copy in file_actions struct */ | 2765 | /* copy in file_actions struct */ | |
2761 | if (SCARG(uap, file_actions) != NULL) { | 2766 | if (SCARG(uap, file_actions) != NULL) { | |
2762 | max_fileactions = 2 * uimin(p->p_rlimit[RLIMIT_NOFILE].rlim_cur, | 2767 | max_fileactions = 2 * uimin(p->p_rlimit[RLIMIT_NOFILE].rlim_cur, | |
2763 | maxfiles); | 2768 | maxfiles); | |
2764 | error = posix_spawn_fa_alloc(&fa, SCARG(uap, file_actions), | 2769 | error = posix_spawn_fa_alloc(&fa, SCARG(uap, file_actions), | |
2765 | max_fileactions); | 2770 | max_fileactions); | |
2766 | if (error) | 2771 | if (error) |
--- src/sys/kern/kern_exit.c 2020/04/04 20:20:12 1.287
+++ src/sys/kern/kern_exit.c 2020/04/19 20:31:59 1.288
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: kern_exit.c,v 1.287 2020/04/04 20:20:12 thorpej Exp $ */ | 1 | /* $NetBSD: kern_exit.c,v 1.288 2020/04/19 20:31:59 thorpej Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1998, 1999, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1998, 1999, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, | 8 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, | |
9 | * NASA Ames Research Center, and by Andrew Doran. | 9 | * NASA Ames Research Center, and by Andrew Doran. | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | 12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | 13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
@@ -57,27 +57,27 @@ | @@ -57,27 +57,27 @@ | |||
57 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 57 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
58 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 58 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
59 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 59 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
60 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 60 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
61 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 61 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
62 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 62 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
63 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 63 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
64 | * SUCH DAMAGE. | 64 | * SUCH DAMAGE. | |
65 | * | 65 | * | |
66 | * @(#)kern_exit.c 8.10 (Berkeley) 2/23/95 | 66 | * @(#)kern_exit.c 8.10 (Berkeley) 2/23/95 | |
67 | */ | 67 | */ | |
68 | 68 | |||
69 | #include <sys/cdefs.h> | 69 | #include <sys/cdefs.h> | |
70 | __KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.287 2020/04/04 20:20:12 thorpej Exp $"); | 70 | __KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.288 2020/04/19 20:31:59 thorpej Exp $"); | |
71 | 71 | |||
72 | #include "opt_ktrace.h" | 72 | #include "opt_ktrace.h" | |
73 | #include "opt_dtrace.h" | 73 | #include "opt_dtrace.h" | |
74 | #include "opt_sysv.h" | 74 | #include "opt_sysv.h" | |
75 | 75 | |||
76 | #include <sys/param.h> | 76 | #include <sys/param.h> | |
77 | #include <sys/systm.h> | 77 | #include <sys/systm.h> | |
78 | #include <sys/ioctl.h> | 78 | #include <sys/ioctl.h> | |
79 | #include <sys/tty.h> | 79 | #include <sys/tty.h> | |
80 | #include <sys/time.h> | 80 | #include <sys/time.h> | |
81 | #include <sys/resource.h> | 81 | #include <sys/resource.h> | |
82 | #include <sys/kernel.h> | 82 | #include <sys/kernel.h> | |
83 | #include <sys/proc.h> | 83 | #include <sys/proc.h> | |
@@ -1206,26 +1206,27 @@ proc_free(struct proc *p, struct wrusage | @@ -1206,26 +1206,27 @@ proc_free(struct proc *p, struct wrusage | |||
1206 | * If anyone tries to access the proc structure after here they will | 1206 | * If anyone tries to access the proc structure after here they will | |
1207 | * get a shock - bits are missing. Attempt to make it hard! We | 1207 | * get a shock - bits are missing. Attempt to make it hard! We | |
1208 | * don't bother with any further locking past this point. | 1208 | * don't bother with any further locking past this point. | |
1209 | */ | 1209 | */ | |
1210 | p->p_stat = SIDL; /* not even a zombie any more */ | 1210 | p->p_stat = SIDL; /* not even a zombie any more */ | |
1211 | LIST_REMOVE(p, p_list); /* off zombproc */ | 1211 | LIST_REMOVE(p, p_list); /* off zombproc */ | |
1212 | parent->p_nstopchild--; | 1212 | parent->p_nstopchild--; | |
1213 | LIST_REMOVE(p, p_sibling); | 1213 | LIST_REMOVE(p, p_sibling); | |
1214 | 1214 | |||
1215 | /* | 1215 | /* | |
1216 | * Let pid be reallocated. | 1216 | * Let pid be reallocated. | |
1217 | */ | 1217 | */ | |
1218 | proc_free_pid(p->p_pid); | 1218 | proc_free_pid(p->p_pid); | |
1219 | atomic_dec_uint(&nprocs); | |||
1219 | 1220 | |||
1220 | /* | 1221 | /* | |
1221 | * Unlink process from its process group. | 1222 | * Unlink process from its process group. | |
1222 | * Releases the proc_lock. | 1223 | * Releases the proc_lock. | |
1223 | */ | 1224 | */ | |
1224 | proc_leavepgrp(p); | 1225 | proc_leavepgrp(p); | |
1225 | 1226 | |||
1226 | /* | 1227 | /* | |
1227 | * Delay release until after lwp_free. | 1228 | * Delay release until after lwp_free. | |
1228 | */ | 1229 | */ | |
1229 | cred2 = l->l_cred; | 1230 | cred2 = l->l_cred; | |
1230 | 1231 | |||
1231 | /* | 1232 | /* |
--- src/sys/kern/kern_proc.c 2020/04/06 08:20:05 1.243
+++ src/sys/kern/kern_proc.c 2020/04/19 20:31:59 1.244
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: kern_proc.c,v 1.243 2020/04/06 08:20:05 kamil Exp $ */ | 1 | /* $NetBSD: kern_proc.c,v 1.244 2020/04/19 20:31:59 thorpej Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1999, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1999, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, | 8 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, | |
9 | * NASA Ames Research Center, and by Andrew Doran. | 9 | * NASA Ames Research Center, and by Andrew Doran. | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | 12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | 13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
@@ -52,27 +52,27 @@ | @@ -52,27 +52,27 @@ | |||
52 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 52 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
53 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 53 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
54 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 54 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
55 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 55 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
56 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 56 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
57 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 57 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
59 | * SUCH DAMAGE. | 59 | * SUCH DAMAGE. | |
60 | * | 60 | * | |
61 | * @(#)kern_proc.c 8.7 (Berkeley) 2/14/95 | 61 | * @(#)kern_proc.c 8.7 (Berkeley) 2/14/95 | |
62 | */ | 62 | */ | |
63 | 63 | |||
64 | #include <sys/cdefs.h> | 64 | #include <sys/cdefs.h> | |
65 | __KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.243 2020/04/06 08:20:05 kamil Exp $"); | 65 | __KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.244 2020/04/19 20:31:59 thorpej Exp $"); | |
66 | 66 | |||
67 | #ifdef _KERNEL_OPT | 67 | #ifdef _KERNEL_OPT | |
68 | #include "opt_kstack.h" | 68 | #include "opt_kstack.h" | |
69 | #include "opt_maxuprc.h" | 69 | #include "opt_maxuprc.h" | |
70 | #include "opt_dtrace.h" | 70 | #include "opt_dtrace.h" | |
71 | #include "opt_compat_netbsd32.h" | 71 | #include "opt_compat_netbsd32.h" | |
72 | #include "opt_kaslr.h" | 72 | #include "opt_kaslr.h" | |
73 | #endif | 73 | #endif | |
74 | 74 | |||
75 | #if defined(__HAVE_COMPAT_NETBSD32) && !defined(COMPAT_NETBSD32) \ | 75 | #if defined(__HAVE_COMPAT_NETBSD32) && !defined(COMPAT_NETBSD32) \ | |
76 | && !defined(_RUMPKERNEL) | 76 | && !defined(_RUMPKERNEL) | |
77 | #define COMPAT_NETBSD32 | 77 | #define COMPAT_NETBSD32 | |
78 | #endif | 78 | #endif | |
@@ -856,28 +856,26 @@ proc_free_pid(pid_t pid) | @@ -856,28 +856,26 @@ proc_free_pid(pid_t pid) | |||
856 | pt->pt_proc = P_FREE(pid & ~pid_tbl_mask); | 856 | pt->pt_proc = P_FREE(pid & ~pid_tbl_mask); | |
857 | KASSERT(pt->pt_pid == pid); | 857 | KASSERT(pt->pt_pid == pid); | |
858 | pt->pt_pid = 0; | 858 | pt->pt_pid = 0; | |
859 | 859 | |||
860 | if (pt->pt_pgrp == NULL) { | 860 | if (pt->pt_pgrp == NULL) { | |
861 | /* link last freed entry onto ours */ | 861 | /* link last freed entry onto ours */ | |
862 | pid &= pid_tbl_mask; | 862 | pid &= pid_tbl_mask; | |
863 | pt = &pid_table[last_free_pt]; | 863 | pt = &pid_table[last_free_pt]; | |
864 | pt->pt_proc = P_FREE(P_NEXT(pt->pt_proc) | pid); | 864 | pt->pt_proc = P_FREE(P_NEXT(pt->pt_proc) | pid); | |
865 | pt->pt_pid = 0; | 865 | pt->pt_pid = 0; | |
866 | last_free_pt = pid; | 866 | last_free_pt = pid; | |
867 | pid_alloc_cnt--; | 867 | pid_alloc_cnt--; | |
868 | } | 868 | } | |
869 | ||||
870 | atomic_dec_uint(&nprocs); | |||
871 | } | 869 | } | |
872 | 870 | |||
873 | void | 871 | void | |
874 | proc_free_mem(struct proc *p) | 872 | proc_free_mem(struct proc *p) | |
875 | { | 873 | { | |
876 | 874 | |||
877 | kdtrace_proc_dtor(NULL, p); | 875 | kdtrace_proc_dtor(NULL, p); | |
878 | pool_cache_put(proc_cache, p); | 876 | pool_cache_put(proc_cache, p); | |
879 | } | 877 | } | |
880 | 878 | |||
881 | /* | 879 | /* | |
882 | * proc_enterpgrp: move p to a new or existing process group (and session). | 880 | * proc_enterpgrp: move p to a new or existing process group (and session). | |
883 | * | 881 | * |
--- src/sys/miscfs/procfs/procfs_linux.c 2020/01/02 15:42:27 1.80
+++ src/sys/miscfs/procfs/procfs_linux.c 2020/04/19 20:31:59 1.81
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: procfs_linux.c,v 1.80 2020/01/02 15:42:27 thorpej Exp $ */ | 1 | /* $NetBSD: procfs_linux.c,v 1.81 2020/04/19 20:31:59 thorpej Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2001 Wasabi Systems, Inc. | 4 | * Copyright (c) 2001 Wasabi Systems, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Written by Frank van der Linden for Wasabi Systems, Inc. | 7 | * Written by Frank van der Linden for Wasabi Systems, Inc. | |
8 | * | 8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | 11 | * are met: | |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright | |
@@ -26,27 +26,27 @@ | @@ -26,27 +26,27 @@ | |||
26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
27 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 27 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
28 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC | 28 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC | |
29 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 29 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
35 | * POSSIBILITY OF SUCH DAMAGE. | 35 | * POSSIBILITY OF SUCH DAMAGE. | |
36 | */ | 36 | */ | |
37 | 37 | |||
38 | #include <sys/cdefs.h> | 38 | #include <sys/cdefs.h> | |
39 | __KERNEL_RCSID(0, "$NetBSD: procfs_linux.c,v 1.80 2020/01/02 15:42:27 thorpej Exp $"); | 39 | __KERNEL_RCSID(0, "$NetBSD: procfs_linux.c,v 1.81 2020/04/19 20:31:59 thorpej Exp $"); | |
40 | 40 | |||
41 | #include <sys/param.h> | 41 | #include <sys/param.h> | |
42 | #include <sys/systm.h> | 42 | #include <sys/systm.h> | |
43 | #include <sys/time.h> | 43 | #include <sys/time.h> | |
44 | #include <sys/cpu.h> | 44 | #include <sys/cpu.h> | |
45 | #include <sys/kernel.h> | 45 | #include <sys/kernel.h> | |
46 | #include <sys/proc.h> | 46 | #include <sys/proc.h> | |
47 | #include <sys/vnode.h> | 47 | #include <sys/vnode.h> | |
48 | #include <sys/exec.h> | 48 | #include <sys/exec.h> | |
49 | #include <sys/resource.h> | 49 | #include <sys/resource.h> | |
50 | #include <sys/resourcevar.h> | 50 | #include <sys/resourcevar.h> | |
51 | #include <sys/signal.h> | 51 | #include <sys/signal.h> | |
52 | #include <sys/signalvar.h> | 52 | #include <sys/signalvar.h> | |
@@ -336,27 +336,27 @@ procfs_doloadavg(struct lwp *curl, struc | @@ -336,27 +336,27 @@ procfs_doloadavg(struct lwp *curl, struc | |||
336 | error = ENAMETOOLONG; | 336 | error = ENAMETOOLONG; | |
337 | bf = malloc(LBFSZ, M_TEMP, M_WAITOK); | 337 | bf = malloc(LBFSZ, M_TEMP, M_WAITOK); | |
338 | 338 | |||
339 | averunnable.fscale = FSCALE; | 339 | averunnable.fscale = FSCALE; | |
340 | len = snprintf(bf, LBFSZ, | 340 | len = snprintf(bf, LBFSZ, | |
341 | "%d.%02d %d.%02d %d.%02d %d/%d %d\n", | 341 | "%d.%02d %d.%02d %d.%02d %d/%d %d\n", | |
342 | (int)(averunnable.ldavg[0] / averunnable.fscale), | 342 | (int)(averunnable.ldavg[0] / averunnable.fscale), | |
343 | (int)(averunnable.ldavg[0] * 100 / averunnable.fscale % 100), | 343 | (int)(averunnable.ldavg[0] * 100 / averunnable.fscale % 100), | |
344 | (int)(averunnable.ldavg[1] / averunnable.fscale), | 344 | (int)(averunnable.ldavg[1] / averunnable.fscale), | |
345 | (int)(averunnable.ldavg[1] * 100 / averunnable.fscale % 100), | 345 | (int)(averunnable.ldavg[1] * 100 / averunnable.fscale % 100), | |
346 | (int)(averunnable.ldavg[2] / averunnable.fscale), | 346 | (int)(averunnable.ldavg[2] / averunnable.fscale), | |
347 | (int)(averunnable.ldavg[2] * 100 / averunnable.fscale % 100), | 347 | (int)(averunnable.ldavg[2] * 100 / averunnable.fscale % 100), | |
348 | 1, /* number of ONPROC processes */ | 348 | 1, /* number of ONPROC processes */ | |
349 | nprocs, | 349 | atomic_load_relaxed(&nprocs), | |
350 | 30000); /* last pid */ | 350 | 30000); /* last pid */ | |
351 | if (len == 0) | 351 | if (len == 0) | |
352 | goto out; | 352 | goto out; | |
353 | 353 | |||
354 | error = uiomove_frombuf(bf, len, uio); | 354 | error = uiomove_frombuf(bf, len, uio); | |
355 | out: | 355 | out: | |
356 | free(bf, M_TEMP); | 356 | free(bf, M_TEMP); | |
357 | return error; | 357 | return error; | |
358 | } | 358 | } | |
359 | 359 | |||
360 | /* | 360 | /* | |
361 | * Linux compatible /proc/<pid>/statm. Only active when the -o linux | 361 | * Linux compatible /proc/<pid>/statm. Only active when the -o linux | |
362 | * mountflag is used. | 362 | * mountflag is used. |
--- src/sys/miscfs/procfs/procfs_vfsops.c 2020/04/04 20:49:30 1.104
+++ src/sys/miscfs/procfs/procfs_vfsops.c 2020/04/19 20:31:59 1.105
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: procfs_vfsops.c,v 1.104 2020/04/04 20:49:30 ad Exp $ */ | 1 | /* $NetBSD: procfs_vfsops.c,v 1.105 2020/04/19 20:31:59 thorpej Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1993 | 4 | * Copyright (c) 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to Berkeley by | 7 | * This code is derived from software contributed to Berkeley by | |
8 | * Jan-Simon Pendry. | 8 | * Jan-Simon Pendry. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -66,27 +66,27 @@ | @@ -66,27 +66,27 @@ | |||
66 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 66 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
67 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 67 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
68 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 68 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
69 | * SUCH DAMAGE. | 69 | * SUCH DAMAGE. | |
70 | * | 70 | * | |
71 | * @(#)procfs_vfsops.c 8.7 (Berkeley) 5/10/95 | 71 | * @(#)procfs_vfsops.c 8.7 (Berkeley) 5/10/95 | |
72 | */ | 72 | */ | |
73 | 73 | |||
74 | /* | 74 | /* | |
75 | * procfs VFS interface | 75 | * procfs VFS interface | |
76 | */ | 76 | */ | |
77 | 77 | |||
78 | #include <sys/cdefs.h> | 78 | #include <sys/cdefs.h> | |
79 | __KERNEL_RCSID(0, "$NetBSD: procfs_vfsops.c,v 1.104 2020/04/04 20:49:30 ad Exp $"); | 79 | __KERNEL_RCSID(0, "$NetBSD: procfs_vfsops.c,v 1.105 2020/04/19 20:31:59 thorpej Exp $"); | |
80 | 80 | |||
81 | #if defined(_KERNEL_OPT) | 81 | #if defined(_KERNEL_OPT) | |
82 | #include "opt_compat_netbsd.h" | 82 | #include "opt_compat_netbsd.h" | |
83 | #endif | 83 | #endif | |
84 | 84 | |||
85 | #include <sys/param.h> | 85 | #include <sys/param.h> | |
86 | #include <sys/time.h> | 86 | #include <sys/time.h> | |
87 | #include <sys/kernel.h> | 87 | #include <sys/kernel.h> | |
88 | #include <sys/systm.h> | 88 | #include <sys/systm.h> | |
89 | #include <sys/sysctl.h> | 89 | #include <sys/sysctl.h> | |
90 | #include <sys/proc.h> | 90 | #include <sys/proc.h> | |
91 | #include <sys/buf.h> | 91 | #include <sys/buf.h> | |
92 | #include <sys/syslog.h> | 92 | #include <sys/syslog.h> | |
@@ -226,29 +226,29 @@ procfs_start(struct mount *mp, int flags | @@ -226,29 +226,29 @@ procfs_start(struct mount *mp, int flags | |||
226 | /* | 226 | /* | |
227 | * Get file system statistics. | 227 | * Get file system statistics. | |
228 | */ | 228 | */ | |
229 | int | 229 | int | |
230 | procfs_statvfs(struct mount *mp, struct statvfs *sbp) | 230 | procfs_statvfs(struct mount *mp, struct statvfs *sbp) | |
231 | { | 231 | { | |
232 | 232 | |||
233 | genfs_statvfs(mp, sbp); | 233 | genfs_statvfs(mp, sbp); | |
234 | 234 | |||
235 | sbp->f_bsize = PAGE_SIZE; | 235 | sbp->f_bsize = PAGE_SIZE; | |
236 | sbp->f_frsize = PAGE_SIZE; | 236 | sbp->f_frsize = PAGE_SIZE; | |
237 | sbp->f_iosize = PAGE_SIZE; | 237 | sbp->f_iosize = PAGE_SIZE; | |
238 | sbp->f_blocks = 1; | 238 | sbp->f_blocks = 1; | |
239 | sbp->f_files = maxproc; /* approx */ | 239 | sbp->f_files = maxproc; /* approx */ | |
240 | sbp->f_ffree = maxproc - nprocs; /* approx */ | 240 | sbp->f_ffree = maxproc - atomic_load_relaxed(&nprocs); /* approx */ | |
241 | sbp->f_favail = maxproc - nprocs; /* approx */ | 241 | sbp->f_favail = maxproc - atomic_load_relaxed(&nprocs); /* approx */ | |
242 | 242 | |||
243 | return (0); | 243 | return (0); | |
244 | } | 244 | } | |
245 | 245 | |||
246 | /*ARGSUSED*/ | 246 | /*ARGSUSED*/ | |
247 | int | 247 | int | |
248 | procfs_sync( | 248 | procfs_sync( | |
249 | struct mount *mp, | 249 | struct mount *mp, | |
250 | int waitfor, | 250 | int waitfor, | |
251 | kauth_cred_t uc) | 251 | kauth_cred_t uc) | |
252 | { | 252 | { | |
253 | 253 | |||
254 | return (0); | 254 | return (0); |
--- src/sys/rump/librump/rumpkern/lwproc.c 2020/02/15 18:12:15 1.44
+++ src/sys/rump/librump/rumpkern/lwproc.c 2020/04/19 20:32:00 1.45
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: lwproc.c,v 1.44 2020/02/15 18:12:15 ad Exp $ */ | 1 | /* $NetBSD: lwproc.c,v 1.45 2020/04/19 20:32:00 thorpej Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved. | 4 | * Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved. | |
5 | * | 5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | 6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions | 7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | 8 | * are met: | |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. | |
14 | * | 14 | * | |
@@ -18,27 +18,27 @@ | @@ -18,27 +18,27 @@ | |||
18 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 18 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
25 | * SUCH DAMAGE. | 25 | * SUCH DAMAGE. | |
26 | */ | 26 | */ | |
27 | 27 | |||
28 | #define RUMP__CURLWP_PRIVATE | 28 | #define RUMP__CURLWP_PRIVATE | |
29 | 29 | |||
30 | #include <sys/cdefs.h> | 30 | #include <sys/cdefs.h> | |
31 | __KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.44 2020/02/15 18:12:15 ad Exp $"); | 31 | __KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.45 2020/04/19 20:32:00 thorpej Exp $"); | |
32 | 32 | |||
33 | #include <sys/param.h> | 33 | #include <sys/param.h> | |
34 | #include <sys/atomic.h> | 34 | #include <sys/atomic.h> | |
35 | #include <sys/filedesc.h> | 35 | #include <sys/filedesc.h> | |
36 | #include <sys/fstrans.h> | 36 | #include <sys/fstrans.h> | |
37 | #include <sys/kauth.h> | 37 | #include <sys/kauth.h> | |
38 | #include <sys/kmem.h> | 38 | #include <sys/kmem.h> | |
39 | #include <sys/lwp.h> | 39 | #include <sys/lwp.h> | |
40 | #include <sys/ktrace.h> | 40 | #include <sys/ktrace.h> | |
41 | #include <sys/pool.h> | 41 | #include <sys/pool.h> | |
42 | #include <sys/proc.h> | 42 | #include <sys/proc.h> | |
43 | #include <sys/queue.h> | 43 | #include <sys/queue.h> | |
44 | #include <sys/resourcevar.h> | 44 | #include <sys/resourcevar.h> | |
@@ -168,27 +168,28 @@ lwproc_proc_free(struct proc *p) | @@ -168,27 +168,28 @@ lwproc_proc_free(struct proc *p) | |||
168 | /* childranee eunt initus */ | 168 | /* childranee eunt initus */ | |
169 | while ((child = LIST_FIRST(&p->p_children)) != NULL) { | 169 | while ((child = LIST_FIRST(&p->p_children)) != NULL) { | |
170 | LIST_REMOVE(child, p_sibling); | 170 | LIST_REMOVE(child, p_sibling); | |
171 | child->p_pptr = initproc; | 171 | child->p_pptr = initproc; | |
172 | child->p_ppid = 1; | 172 | child->p_ppid = 1; | |
173 | LIST_INSERT_HEAD(&initproc->p_children, child, p_sibling); | 173 | LIST_INSERT_HEAD(&initproc->p_children, child, p_sibling); | |
174 | } | 174 | } | |
175 | 175 | |||
176 | KASSERT(p->p_nlwps == 0); | 176 | KASSERT(p->p_nlwps == 0); | |
177 | KASSERT(LIST_EMPTY(&p->p_lwps)); | 177 | KASSERT(LIST_EMPTY(&p->p_lwps)); | |
178 | 178 | |||
179 | LIST_REMOVE(p, p_list); | 179 | LIST_REMOVE(p, p_list); | |
180 | LIST_REMOVE(p, p_sibling); | 180 | LIST_REMOVE(p, p_sibling); | |
181 | proc_free_pid(p->p_pid); /* decrements nprocs */ | 181 | proc_free_pid(p->p_pid); | |
182 | atomic_dec_uint(&nprocs); | |||
182 | proc_leavepgrp(p); /* releases proc_lock */ | 183 | proc_leavepgrp(p); /* releases proc_lock */ | |
183 | 184 | |||
184 | cred = p->p_cred; | 185 | cred = p->p_cred; | |
185 | chgproccnt(kauth_cred_getuid(cred), -1); | 186 | chgproccnt(kauth_cred_getuid(cred), -1); | |
186 | rump_proc_vfs_release(p); | 187 | rump_proc_vfs_release(p); | |
187 | 188 | |||
188 | doexithooks(p); | 189 | doexithooks(p); | |
189 | lim_free(p->p_limit); | 190 | lim_free(p->p_limit); | |
190 | pstatsfree(p->p_stats); | 191 | pstatsfree(p->p_stats); | |
191 | kauth_cred_free(p->p_cred); | 192 | kauth_cred_free(p->p_cred); | |
192 | proc_finispecific(p); | 193 | proc_finispecific(p); | |
193 | 194 | |||
194 | mutex_obj_free(p->p_lock); | 195 | mutex_obj_free(p->p_lock); |