Fri Nov 6 02:26:42 2015 UTC ()
In sysv_sem.c, defer establishment of exithook so we can initialize the
module code from module_init() rather than waiting until after calling
exec_init().  Use a RUN_ONCE routine at entry to each sys_sem* syscall
to establish the exithook, and no longer KASSERT that the hook has
been set before removing it.  (A manually loaded module can be unloaded
before any syscalls have been invoked.)

Remove the conditional calls to the various xxx_init() routines from
init_main.c - we now rely on module_init() to handle initialization.

Let each sub-component's xxx_init() routine handle its own sysctl
sub-tree initialization;  this removes another set of #ifdef ugliness.

Tested both built-in and loadable versions and verified that atf
test kernel/t_sysv passes.


(pgoyette)
diff -r1.472 -r1.473 src/sys/kern/init_main.c
diff -r1.29 -r1.30 src/sys/kern/sysv_ipc.c
diff -r1.69 -r1.70 src/sys/kern/sysv_msg.c
diff -r1.94 -r1.95 src/sys/kern/sysv_sem.c
diff -r1.129 -r1.130 src/sys/kern/sysv_shm.c
diff -r1.25 -r1.26 src/sys/sys/msg.h
diff -r1.31 -r1.32 src/sys/sys/sem.h
diff -r1.50 -r1.51 src/sys/sys/shm.h

cvs diff -r1.472 -r1.473 src/sys/kern/init_main.c (expand / switch to unified diff)

--- src/sys/kern/init_main.c 2015/10/29 00:27:08 1.472
+++ src/sys/kern/init_main.c 2015/11/06 02:26:42 1.473
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: init_main.c,v 1.472 2015/10/29 00:27:08 mrg Exp $ */ 1/* $NetBSD: init_main.c,v 1.473 2015/11/06 02:26:42 pgoyette Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
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.
@@ -87,27 +87,27 @@ @@ -87,27 +87,27 @@
87 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 87 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
88 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 88 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
89 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 89 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
90 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 90 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
91 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 91 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
92 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 92 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
93 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 93 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
94 * SUCH DAMAGE. 94 * SUCH DAMAGE.
95 * 95 *
96 * @(#)init_main.c 8.16 (Berkeley) 5/14/95 96 * @(#)init_main.c 8.16 (Berkeley) 5/14/95
97 */ 97 */
98 98
99#include <sys/cdefs.h> 99#include <sys/cdefs.h>
100__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.472 2015/10/29 00:27:08 mrg Exp $"); 100__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.473 2015/11/06 02:26:42 pgoyette Exp $");
101 101
102#include "opt_ddb.h" 102#include "opt_ddb.h"
103#include "opt_ipsec.h" 103#include "opt_ipsec.h"
104#include "opt_modular.h" 104#include "opt_modular.h"
105#include "opt_ntp.h" 105#include "opt_ntp.h"
106#include "opt_pipe.h" 106#include "opt_pipe.h"
107#include "opt_syscall_debug.h" 107#include "opt_syscall_debug.h"
108#include "opt_sysv.h" 108#include "opt_sysv.h"
109#include "opt_fileassoc.h" 109#include "opt_fileassoc.h"
110#include "opt_ktrace.h" 110#include "opt_ktrace.h"
111#include "opt_pax.h" 111#include "opt_pax.h"
112#include "opt_compat_netbsd.h" 112#include "opt_compat_netbsd.h"
113#include "opt_wapbl.h" 113#include "opt_wapbl.h"
@@ -169,35 +169,26 @@ extern void *_binary_splash_image_end; @@ -169,35 +169,26 @@ extern void *_binary_splash_image_end;
169#include <sys/disk.h> 169#include <sys/disk.h>
170#include <sys/msgbuf.h> 170#include <sys/msgbuf.h>
171#include <sys/module.h> 171#include <sys/module.h>
172#include <sys/event.h> 172#include <sys/event.h>
173#include <sys/lockf.h> 173#include <sys/lockf.h>
174#include <sys/once.h> 174#include <sys/once.h>
175#include <sys/kcpuset.h> 175#include <sys/kcpuset.h>
176#include <sys/ksyms.h> 176#include <sys/ksyms.h>
177#include <sys/uidinfo.h> 177#include <sys/uidinfo.h>
178#include <sys/kprintf.h> 178#include <sys/kprintf.h>
179#ifdef IPSEC 179#ifdef IPSEC
180#include <netipsec/ipsec.h> 180#include <netipsec/ipsec.h>
181#endif 181#endif
182#ifdef SYSVSHM 
183#include <sys/shm.h> 
184#endif 
185#ifdef SYSVSEM 
186#include <sys/sem.h> 
187#endif 
188#ifdef SYSVMSG 
189#include <sys/msg.h> 
190#endif 
191#include <sys/domain.h> 182#include <sys/domain.h>
192#include <sys/namei.h> 183#include <sys/namei.h>
193#include <sys/rnd.h> 184#include <sys/rnd.h>
194#include <sys/pipe.h> 185#include <sys/pipe.h>
195#if NVERIEXEC > 0 186#if NVERIEXEC > 0
196#include <sys/verified_exec.h> 187#include <sys/verified_exec.h>
197#endif /* NVERIEXEC > 0 */ 188#endif /* NVERIEXEC > 0 */
198#ifdef KTRACE 189#ifdef KTRACE
199#include <sys/ktrace.h> 190#include <sys/ktrace.h>
200#endif 191#endif
201#include <sys/kauth.h> 192#include <sys/kauth.h>
202#include <net80211/ieee80211_netbsd.h> 193#include <net80211/ieee80211_netbsd.h>
203#ifdef PTRACE 194#ifdef PTRACE
@@ -515,46 +506,31 @@ main(void) @@ -515,46 +506,31 @@ main(void)
515 kpreempt_enable(); 506 kpreempt_enable();
516 507
517 /* Get the threads going and into any sleeps before continuing. */ 508 /* Get the threads going and into any sleeps before continuing. */
518 yield(); 509 yield();
519 510
520 /* Enable deferred processing of RNG samples */ 511 /* Enable deferred processing of RNG samples */
521 rnd_init_softint(); 512 rnd_init_softint();
522 513
523#ifdef RND_PRINTF 514#ifdef RND_PRINTF
524 /* Enable periodic injection of console output into entropy pool */ 515 /* Enable periodic injection of console output into entropy pool */
525 kprintf_init_callout(); 516 kprintf_init_callout();
526#endif 517#endif
527 518
528#ifdef SYSVSHM 
529 /* Initialize System V style shared memory. */ 
530 shminit(); 
531#endif 
532 
533 vmem_rehash_start(); /* must be before exec_init */ 519 vmem_rehash_start(); /* must be before exec_init */
534 520
535 /* Initialize exec structures */ 521 /* Initialize exec structures */
536 exec_init(1); /* seminit calls exithook_establish() */ 522 exec_init(1); /* seminit calls exithook_establish() */
537 523
538#ifdef SYSVSEM 
539 /* Initialize System V style semaphores. */ 
540 seminit(); 
541#endif 
542 
543#ifdef SYSVMSG 
544 /* Initialize System V style message queues. */ 
545 msginit(); 
546#endif 
547 
548#if NVERIEXEC > 0 524#if NVERIEXEC > 0
549 /* 525 /*
550 * Initialise the Veriexec subsystem. 526 * Initialise the Veriexec subsystem.
551 */ 527 */
552 veriexec_init(); 528 veriexec_init();
553#endif /* NVERIEXEC > 0 */ 529#endif /* NVERIEXEC > 0 */
554 530
555#if defined(PAX_MPROTECT) || defined(PAX_SEGVGUARD) || defined(PAX_ASLR) 531#if defined(PAX_MPROTECT) || defined(PAX_SEGVGUARD) || defined(PAX_ASLR)
556 pax_init(); 532 pax_init();
557#endif /* PAX_MPROTECT || PAX_SEGVGUARD || PAX_ASLR */ 533#endif /* PAX_MPROTECT || PAX_SEGVGUARD || PAX_ASLR */
558 534
559#ifdef IPSEC 535#ifdef IPSEC
560 /* Attach network crypto subsystem */ 536 /* Attach network crypto subsystem */

cvs diff -r1.29 -r1.30 src/sys/kern/sysv_ipc.c (expand / switch to unified diff)

--- src/sys/kern/sysv_ipc.c 2015/11/06 01:00:41 1.29
+++ src/sys/kern/sysv_ipc.c 2015/11/06 02:26:42 1.30
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sysv_ipc.c,v 1.29 2015/11/06 01:00:41 pgoyette Exp $ */ 1/* $NetBSD: sysv_ipc.c,v 1.30 2015/11/06 02:26:42 pgoyette Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1998, 2007 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998, 2007 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 Charles M. Hannum. 8 * by Charles M. Hannum.
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.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: sysv_ipc.c,v 1.29 2015/11/06 01:00:41 pgoyette Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: sysv_ipc.c,v 1.30 2015/11/06 02:26:42 pgoyette Exp $");
34 34
35#ifdef _KERNEL_OPT 35#ifdef _KERNEL_OPT
36#include "opt_sysv.h" 36#include "opt_sysv.h"
37#endif 37#endif
38 38
39#include <sys/syscall.h> 39#include <sys/syscall.h>
40#include <sys/syscallargs.h> 40#include <sys/syscallargs.h>
41#include <sys/syscallvar.h> 41#include <sys/syscallvar.h>
42#include <sys/param.h> 42#include <sys/param.h>
43#include <sys/kernel.h> 43#include <sys/kernel.h>
44#include <sys/proc.h> 44#include <sys/proc.h>
45#include <sys/ipc.h> 45#include <sys/ipc.h>
46#ifdef SYSVMSG 46#ifdef SYSVMSG
@@ -117,34 +117,29 @@ struct seminfo seminfo = { @@ -117,34 +117,29 @@ struct seminfo seminfo = {
117struct msginfo msginfo = { 117struct msginfo msginfo = {
118 MSGMAX, /* max chars in a message */ 118 MSGMAX, /* max chars in a message */
119 MSGMNI, /* # of message queue identifiers */ 119 MSGMNI, /* # of message queue identifiers */
120 MSGMNB, /* max chars in a queue */ 120 MSGMNB, /* max chars in a queue */
121 MSGTQL, /* max messages in system */ 121 MSGTQL, /* max messages in system */
122 MSGSSZ, /* size of a message segment */ 122 MSGSSZ, /* size of a message segment */
123 /* (must be small power of 2 greater than 4) */ 123 /* (must be small power of 2 greater than 4) */
124 MSGSEG /* number of message segments */ 124 MSGSEG /* number of message segments */
125}; 125};
126#endif 126#endif
127 127
128MODULE(MODULE_CLASS_EXEC, sysv_ipc, NULL); 128MODULE(MODULE_CLASS_EXEC, sysv_ipc, NULL);
129  129
130#ifdef _MODULE 
131SYSCTL_SETUP_PROTO(sysctl_ipc_setup); 130SYSCTL_SETUP_PROTO(sysctl_ipc_setup);
132SYSCTL_SETUP_PROTO(sysctl_ipc_shm_setup); 
133SYSCTL_SETUP_PROTO(sysctl_ipc_sem_setup); 
134SYSCTL_SETUP_PROTO(sysctl_ipc_msg_setup); 
135 131
136static struct sysctllog *sysctl_sysvipc_clog = NULL; 132static struct sysctllog *sysctl_sysvipc_clog = NULL;
137#endif 
138 133
139static const struct syscall_package sysvipc_syscalls[] = { 134static const struct syscall_package sysvipc_syscalls[] = {
140#ifdef SYSVSHM 135#ifdef SYSVSHM
141 { SYS___shmctl50, 0, (sy_call_t *)sys___shmctl50 }, 136 { SYS___shmctl50, 0, (sy_call_t *)sys___shmctl50 },
142 { SYS_shmat, 0, (sy_call_t *)sys_shmat }, 137 { SYS_shmat, 0, (sy_call_t *)sys_shmat },
143 { SYS_shmdt, 0, (sy_call_t *)sys_shmdt }, 138 { SYS_shmdt, 0, (sy_call_t *)sys_shmdt },
144 { SYS_shmget, 0, (sy_call_t *)sys_shmget }, 139 { SYS_shmget, 0, (sy_call_t *)sys_shmget },
145#endif 140#endif
146#ifdef SYSVSEM 141#ifdef SYSVSEM
147 { SYS_____semctl50, 0, (sy_call_t *)sys_____semctl50 }, 142 { SYS_____semctl50, 0, (sy_call_t *)sys_____semctl50 },
148 { SYS_semget, 0, (sy_call_t *)sys_semget }, 143 { SYS_semget, 0, (sy_call_t *)sys_semget },
149 { SYS_semop, 0, (sy_call_t *)sys_semop }, 144 { SYS_semop, 0, (sy_call_t *)sys_semop },
150 { SYS_semconfig, 0, (sy_call_t *)sys_semconfig }, 145 { SYS_semconfig, 0, (sy_call_t *)sys_semconfig },
@@ -155,99 +150,99 @@ static const struct syscall_package sysv @@ -155,99 +150,99 @@ static const struct syscall_package sysv
155 { SYS_msgsnd, 0, (sy_call_t *)sys_msgsnd }, 150 { SYS_msgsnd, 0, (sy_call_t *)sys_msgsnd },
156 { SYS_msgrcv, 0, (sy_call_t *)sys_msgrcv }, 151 { SYS_msgrcv, 0, (sy_call_t *)sys_msgrcv },
157#endif 152#endif
158 { 0, 0, NULL } 153 { 0, 0, NULL }
159}; 154};
160 155
161static int 156static int
162sysv_ipc_modcmd(modcmd_t cmd, void *arg) 157sysv_ipc_modcmd(modcmd_t cmd, void *arg)
163{ 158{
164 int error = 0; 159 int error = 0;
165 160
166 switch (cmd) { 161 switch (cmd) {
167 case MODULE_CMD_INIT: 162 case MODULE_CMD_INIT:
168 /* Link the system calls */ 163 /* Set up the kauth listener */
169 error = syscall_establish(NULL, sysvipc_syscalls); 164 sysvipcinit();
170 165
171 /* Initialize all sysctl sub-trees */ 
172#ifdef _MODULE 166#ifdef _MODULE
 167 /* Set up the common sysctl tree */
173 sysctl_ipc_setup(&sysctl_sysvipc_clog); 168 sysctl_ipc_setup(&sysctl_sysvipc_clog);
174#ifdef SYSVMSG 
175 sysctl_ipc_msg_setup(&sysctl_sysvipc_clog); 
176#endif 
177#ifdef SYSVSHM 
178 sysctl_ipc_shm_setup(&sysctl_sysvipc_clog); 
179#endif 
180#ifdef SYSVSEM 
181 sysctl_ipc_sem_setup(&sysctl_sysvipc_clog); 
182#endif 169#endif
 170
 171 /* Link the system calls */
 172 error = syscall_establish(NULL, sysvipc_syscalls);
 173 if (error)
 174 sysvipcfini();
 175
183 /* Assume no compat sysctl routine for now */ 176 /* Assume no compat sysctl routine for now */
184 kern_sysvipc50_sysctl_p = NULL; 177 kern_sysvipc50_sysctl_p = NULL;
185 178
186 /* Initialize each sub-component */ 179 /*
 180 * Initialize each sub-component, including their
 181 * sysctl data
 182 */
187#ifdef SYSVSHM 183#ifdef SYSVSHM
188 shminit(); 184 shminit(&sysctl_sysvipc_clog);
189#endif 185#endif
190#ifdef SYSVSEM 186#ifdef SYSVSEM
191 seminit(); 187 seminit(&sysctl_sysvipc_clog);
192#endif 188#endif
193#ifdef SYSVMSG 189#ifdef SYSVMSG
194 msginit(); 190 msginit(&sysctl_sysvipc_clog);
195#endif 191#endif
196#endif /* _MODULE */ 
197 break; 192 break;
198 case MODULE_CMD_FINI: 193 case MODULE_CMD_FINI:
199 /* 194 /*
200 * Make sure no subcomponents are active. Each one 195 * Make sure no subcomponents are active. Each one
201 * tells us if it is busy, and if it was _not_ busy, 196 * tells us if it is busy, and if it was _not_ busy,
202 * we assume it has already done its own clean-up. 197 * we assume it has already done its own clean-up.
203 * So we might need to re-init any components that 198 * So we might need to re-init any components that
204 * are successfully fini'd if we find one that is  199 * are successfully fini'd if we find one that is
205 * still busy. 200 * still busy.
206 */ 201 */
207#ifdef SYSVSHM 202#ifdef SYSVSHM
208 if (shmfini()) { 203 if (shmfini()) {
209 return EBUSY; 204 return EBUSY;
210 } 205 }
211#endif 206#endif
212#ifdef SYSVSEM 207#ifdef SYSVSEM
213 if (semfini()) { 208 if (semfini()) {
214#ifdef SYSVSHM 209#ifdef SYSVSHM
215 shminit(); 210 shminit(NULL);
216#endif 211#endif
217 return EBUSY; 212 return EBUSY;
218 } 213 }
219#endif 214#endif
220#ifdef SYSVMSG 215#ifdef SYSVMSG
221 if (msgfini()) { 216 if (msgfini()) {
222#ifdef SYSVSEM 217#ifdef SYSVSEM
223 seminit(); 218 seminit(NULL);
224#endif 219#endif
225#ifdef SYSVSHM 220#ifdef SYSVSHM
226 shminit(); 221 shminit(NULL);
227#endif 222#endif
228 return EBUSY; 223 return EBUSY;
229 } 224 }
230#endif 225#endif
231 226
232 /* Unlink the system calls. */ 227 /* Unlink the system calls. */
233 error = syscall_disestablish(NULL, sysvipc_syscalls); 228 error = syscall_disestablish(NULL, sysvipc_syscalls);
234 if (error) 229 if (error)
235 return error; 230 return error;
236 231
237#ifdef _MODULE 232#ifdef _MODULE
238 /* Remove the sysctl sub-trees */ 233 /* Remove the sysctl sub-trees */
239 sysctl_teardown(&sysctl_sysvipc_clog); 234 sysctl_teardown(&sysctl_sysvipc_clog);
240#endif  235#endif
241 236
242 /* Remove the kauth listener */ 237 /* Remove the kauth listener */
243 sysvipcfini(); 238 sysvipcfini();
244 break; 239 break;
245 default: 240 default:
246 return ENOTTY; 241 return ENOTTY;
247 } 242 }
248 return error; 243 return error;
249} 244}
250 245
251void 246void
252sysvipc50_set_compat_sysctl(int (*compat_sysctl)(SYSCTLFN_PROTO)) 247sysvipc50_set_compat_sysctl(int (*compat_sysctl)(SYSCTLFN_PROTO))
253{ 248{
@@ -335,28 +330,27 @@ ipcperm(kauth_cred_t cred, struct ipc_pe @@ -335,28 +330,27 @@ ipcperm(kauth_cred_t cred, struct ipc_pe
335 330
336void 331void
337sysvipcfini(void) 332sysvipcfini(void)
338{ 333{
339 334
340 KASSERT(sysvipc_listener != NULL); 335 KASSERT(sysvipc_listener != NULL);
341 kauth_unlisten_scope(sysvipc_listener); 336 kauth_unlisten_scope(sysvipc_listener);
342} 337}
343 338
344void 339void
345sysvipcinit(void) 340sysvipcinit(void)
346{ 341{
347 342
348 if (sysvipc_listener != NULL) 343 KASSERT(sysvipc_listener == NULL);
349 return; 
350 344
351 sysvipc_listener = kauth_listen_scope(KAUTH_SCOPE_SYSTEM, 345 sysvipc_listener = kauth_listen_scope(KAUTH_SCOPE_SYSTEM,
352 sysvipc_listener_cb, NULL); 346 sysvipc_listener_cb, NULL);
353} 347}
354 348
355static int 349static int
356sysctl_kern_sysvipc(SYSCTLFN_ARGS) 350sysctl_kern_sysvipc(SYSCTLFN_ARGS)
357{ 351{
358 void *where = oldp; 352 void *where = oldp;
359 size_t sz, *sizep = oldlenp; 353 size_t sz, *sizep = oldlenp;
360#ifdef SYSVMSG 354#ifdef SYSVMSG
361 struct msg_sysctl_info *msgsi = NULL; 355 struct msg_sysctl_info *msgsi = NULL;
362#endif 356#endif

cvs diff -r1.69 -r1.70 src/sys/kern/sysv_msg.c (expand / switch to unified diff)

--- src/sys/kern/sysv_msg.c 2015/05/13 01:16:15 1.69
+++ src/sys/kern/sysv_msg.c 2015/11/06 02:26:42 1.70
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sysv_msg.c,v 1.69 2015/05/13 01:16:15 pgoyette Exp $ */ 1/* $NetBSD: sysv_msg.c,v 1.70 2015/11/06 02:26:42 pgoyette Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2006, 2007 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999, 2006, 2007 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
@@ -40,27 +40,27 @@ @@ -40,27 +40,27 @@
40 * This system call was implemented by Daniel Boulet under contract from RTMX. 40 * This system call was implemented by Daniel Boulet under contract from RTMX.
41 * 41 *
42 * Redistribution and use in source forms, with and without modification, 42 * Redistribution and use in source forms, with and without modification,
43 * are permitted provided that this entire comment appears intact. 43 * are permitted provided that this entire comment appears intact.
44 * 44 *
45 * Redistribution in binary form may occur without any restrictions. 45 * Redistribution in binary form may occur without any restrictions.
46 * Obviously, it would be nice if you gave credit where credit is due 46 * Obviously, it would be nice if you gave credit where credit is due
47 * but requiring it would be too onerous. 47 * but requiring it would be too onerous.
48 * 48 *
49 * This software is provided ``AS IS'' without any warranties of any kind. 49 * This software is provided ``AS IS'' without any warranties of any kind.
50 */ 50 */
51 51
52#include <sys/cdefs.h> 52#include <sys/cdefs.h>
53__KERNEL_RCSID(0, "$NetBSD: sysv_msg.c,v 1.69 2015/05/13 01:16:15 pgoyette Exp $"); 53__KERNEL_RCSID(0, "$NetBSD: sysv_msg.c,v 1.70 2015/11/06 02:26:42 pgoyette Exp $");
54 54
55#ifdef _KERNEL_OPT 55#ifdef _KERNEL_OPT
56#include "opt_sysv.h" 56#include "opt_sysv.h"
57#endif 57#endif
58 58
59#include <sys/param.h> 59#include <sys/param.h>
60#include <sys/kernel.h> 60#include <sys/kernel.h>
61#include <sys/msg.h> 61#include <sys/msg.h>
62#include <sys/sysctl.h> 62#include <sys/sysctl.h>
63#include <sys/mount.h> /* XXX for <sys/syscallargs.h> */ 63#include <sys/mount.h> /* XXX for <sys/syscallargs.h> */
64#include <sys/syscallargs.h> 64#include <sys/syscallargs.h>
65#include <sys/kauth.h> 65#include <sys/kauth.h>
66 66
@@ -81,28 +81,30 @@ static struct msgmap *msgmaps; /* MSGSEG @@ -81,28 +81,30 @@ static struct msgmap *msgmaps; /* MSGSEG
81static struct __msg *msghdrs; /* MSGTQL msg headers */ 81static struct __msg *msghdrs; /* MSGTQL msg headers */
82 82
83kmsq_t *msqs; /* MSGMNI msqid_ds struct's */ 83kmsq_t *msqs; /* MSGMNI msqid_ds struct's */
84kmutex_t msgmutex; /* subsystem lock */ 84kmutex_t msgmutex; /* subsystem lock */
85 85
86static u_int msg_waiters = 0; /* total number of msgrcv waiters */ 86static u_int msg_waiters = 0; /* total number of msgrcv waiters */
87static bool msg_realloc_state; 87static bool msg_realloc_state;
88static kcondvar_t msg_realloc_cv; 88static kcondvar_t msg_realloc_cv;
89 89
90static void msg_freehdr(struct __msg *); 90static void msg_freehdr(struct __msg *);
91 91
92extern int kern_has_sysvmsg; 92extern int kern_has_sysvmsg;
93 93
 94SYSCTL_SETUP_PROTO(sysctl_ipc_msg_setup);
 95
94void 96void
95msginit(void) 97msginit(struct sysctllog **clog)
96{ 98{
97 int i, sz; 99 int i, sz;
98 vaddr_t v; 100 vaddr_t v;
99 101
100 /* 102 /*
101 * msginfo.msgssz should be a power of two for efficiency reasons. 103 * msginfo.msgssz should be a power of two for efficiency reasons.
102 * It is also pretty silly if msginfo.msgssz is less than 8 104 * It is also pretty silly if msginfo.msgssz is less than 8
103 * or greater than about 256 so ... 105 * or greater than about 256 so ...
104 */ 106 */
105 107
106 i = 8; 108 i = 8;
107 while (i < 1024 && i != msginfo.msgssz) 109 while (i < 1024 && i != msginfo.msgssz)
108 i <<= 1; 110 i <<= 1;
@@ -151,27 +153,30 @@ msginit(void) @@ -151,27 +153,30 @@ msginit(void)
151 cv_init(&msqs[i].msq_cv, "msgwait"); 153 cv_init(&msqs[i].msq_cv, "msgwait");
152 /* Implies entry is available */ 154 /* Implies entry is available */
153 msqs[i].msq_u.msg_qbytes = 0; 155 msqs[i].msq_u.msg_qbytes = 0;
154 /* Reset to a known value */ 156 /* Reset to a known value */
155 msqs[i].msq_u.msg_perm._seq = 0; 157 msqs[i].msq_u.msg_perm._seq = 0;
156 } 158 }
157 159
158 mutex_init(&msgmutex, MUTEX_DEFAULT, IPL_NONE); 160 mutex_init(&msgmutex, MUTEX_DEFAULT, IPL_NONE);
159 cv_init(&msg_realloc_cv, "msgrealc"); 161 cv_init(&msg_realloc_cv, "msgrealc");
160 msg_realloc_state = false; 162 msg_realloc_state = false;
161 163
162 kern_has_sysvmsg = 1; 164 kern_has_sysvmsg = 1;
163 165
164 sysvipcinit(); 166#ifdef _MODULE
 167 if (clog)
 168 sysctl_ipc_msg_setup(clog);
 169#endif
165} 170}
166 171
167int 172int
168msgfini(void) 173msgfini(void)
169{ 174{
170 int i, sz; 175 int i, sz;
171 vaddr_t v = (vaddr_t)msgpool; 176 vaddr_t v = (vaddr_t)msgpool;
172 177
173 mutex_enter(&msgmutex); 178 mutex_enter(&msgmutex);
174 for (i = 0; i < msginfo.msgmni; i++) { 179 for (i = 0; i < msginfo.msgmni; i++) {
175 if (msqs[i].msq_u.msg_qbytes != 0) { 180 if (msqs[i].msq_u.msg_qbytes != 0) {
176 mutex_exit(&msgmutex); 181 mutex_exit(&msgmutex);
177 return 1; /* queue not available, prevent unload! */ 182 return 1; /* queue not available, prevent unload! */

cvs diff -r1.94 -r1.95 src/sys/kern/sysv_sem.c (expand / switch to unified diff)

--- src/sys/kern/sysv_sem.c 2015/05/13 01:16:15 1.94
+++ src/sys/kern/sysv_sem.c 2015/11/06 02:26:42 1.95
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sysv_sem.c,v 1.94 2015/05/13 01:16:15 pgoyette Exp $ */ 1/* $NetBSD: sysv_sem.c,v 1.95 2015/11/06 02:26:42 pgoyette Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2007 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999, 2007 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
@@ -29,40 +29,41 @@ @@ -29,40 +29,41 @@
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 * Implementation of SVID semaphores 34 * Implementation of SVID semaphores
35 * 35 *
36 * Author: Daniel Boulet 36 * Author: Daniel Boulet
37 * 37 *
38 * This software is provided ``AS IS'' without any warranties of any kind. 38 * This software is provided ``AS IS'' without any warranties of any kind.
39 */ 39 */
40 40
41#include <sys/cdefs.h> 41#include <sys/cdefs.h>
42__KERNEL_RCSID(0, "$NetBSD: sysv_sem.c,v 1.94 2015/05/13 01:16:15 pgoyette Exp $"); 42__KERNEL_RCSID(0, "$NetBSD: sysv_sem.c,v 1.95 2015/11/06 02:26:42 pgoyette Exp $");
43 43
44#ifdef _KERNEL_OPT 44#ifdef _KERNEL_OPT
45#include "opt_sysv.h" 45#include "opt_sysv.h"
46#endif 46#endif
47 47
48#include <sys/param.h> 48#include <sys/param.h>
49#include <sys/kernel.h> 49#include <sys/kernel.h>
50#include <sys/sem.h> 50#include <sys/sem.h>
51#include <sys/sysctl.h> 51#include <sys/sysctl.h>
52#include <sys/kmem.h> 52#include <sys/kmem.h>
53#include <sys/mount.h> /* XXX for <sys/syscallargs.h> */ 53#include <sys/mount.h> /* XXX for <sys/syscallargs.h> */
54#include <sys/syscallargs.h> 54#include <sys/syscallargs.h>
55#include <sys/kauth.h> 55#include <sys/kauth.h>
 56#include <sys/once.h>
56 57
57/*  58/*
58 * Memory areas: 59 * Memory areas:
59 * 1st: Pool of semaphore identifiers 60 * 1st: Pool of semaphore identifiers
60 * 2nd: Semaphores 61 * 2nd: Semaphores
61 * 3rd: Conditional variables 62 * 3rd: Conditional variables
62 * 4th: Undo structures 63 * 4th: Undo structures
63 */ 64 */
64struct semid_ds * sema __read_mostly; 65struct semid_ds * sema __read_mostly;
65static struct __sem * sem __read_mostly; 66static struct __sem * sem __read_mostly;
66static kcondvar_t * semcv __read_mostly; 67static kcondvar_t * semcv __read_mostly;
67static int * semu __read_mostly; 68static int * semu __read_mostly;
68 69
@@ -81,32 +82,37 @@ static u_int sem_waiters __cacheline_a @@ -81,32 +82,37 @@ static u_int sem_waiters __cacheline_a
81/* Macro to find a particular sem_undo vector */ 82/* Macro to find a particular sem_undo vector */
82#define SEMU(s, ix) ((struct sem_undo *)(((long)s) + ix * seminfo.semusz)) 83#define SEMU(s, ix) ((struct sem_undo *)(((long)s) + ix * seminfo.semusz))
83 84
84#ifdef SEM_DEBUG 85#ifdef SEM_DEBUG
85#define SEM_PRINTF(a) printf a 86#define SEM_PRINTF(a) printf a
86#else 87#else
87#define SEM_PRINTF(a) 88#define SEM_PRINTF(a)
88#endif 89#endif
89 90
90void *hook; /* cookie from exithook_establish() */ 91void *hook; /* cookie from exithook_establish() */
91 92
92extern int kern_has_sysvsem; 93extern int kern_has_sysvsem;
93 94
 95SYSCTL_SETUP_PROTO(sysctl_ipc_sem_setup);
 96
94struct sem_undo *semu_alloc(struct proc *); 97struct sem_undo *semu_alloc(struct proc *);
95int semundo_adjust(struct proc *, struct sem_undo **, int, int, int); 98int semundo_adjust(struct proc *, struct sem_undo **, int, int, int);
96void semundo_clear(int, int); 99void semundo_clear(int, int);
97 100
 101static ONCE_DECL(exithook_control);
 102static int seminit_exithook(void);
 103
98void 104void
99seminit(void) 105seminit(struct sysctllog **clog)
100{ 106{
101 int i, sz; 107 int i, sz;
102 vaddr_t v; 108 vaddr_t v;
103 109
104 mutex_init(&semlock, MUTEX_DEFAULT, IPL_NONE); 110 mutex_init(&semlock, MUTEX_DEFAULT, IPL_NONE);
105 cv_init(&sem_realloc_cv, "semrealc"); 111 cv_init(&sem_realloc_cv, "semrealc");
106 sem_realloc_state = false; 112 sem_realloc_state = false;
107 semtot = 0; 113 semtot = 0;
108 sem_waiters = 0; 114 sem_waiters = 0;
109 115
110 /* Allocate the wired memory for our structures */ 116 /* Allocate the wired memory for our structures */
111 sz = ALIGN(seminfo.semmni * sizeof(struct semid_ds)) + 117 sz = ALIGN(seminfo.semmni * sizeof(struct semid_ds)) +
112 ALIGN(seminfo.semmns * sizeof(struct __sem)) + 118 ALIGN(seminfo.semmns * sizeof(struct __sem)) +
@@ -124,50 +130,59 @@ seminit(void) @@ -124,50 +130,59 @@ seminit(void)
124 semu = (void *)((uintptr_t)semcv + 130 semu = (void *)((uintptr_t)semcv +
125 ALIGN(seminfo.semmni * sizeof(kcondvar_t))); 131 ALIGN(seminfo.semmni * sizeof(kcondvar_t)));
126 132
127 for (i = 0; i < seminfo.semmni; i++) { 133 for (i = 0; i < seminfo.semmni; i++) {
128 sema[i]._sem_base = 0; 134 sema[i]._sem_base = 0;
129 sema[i].sem_perm.mode = 0; 135 sema[i].sem_perm.mode = 0;
130 cv_init(&semcv[i], "semwait"); 136 cv_init(&semcv[i], "semwait");
131 } 137 }
132 for (i = 0; i < seminfo.semmnu; i++) { 138 for (i = 0; i < seminfo.semmnu; i++) {
133 struct sem_undo *suptr = SEMU(semu, i); 139 struct sem_undo *suptr = SEMU(semu, i);
134 suptr->un_proc = NULL; 140 suptr->un_proc = NULL;
135 } 141 }
136 semu_list = NULL; 142 semu_list = NULL;
137 hook = exithook_establish(semexit, NULL); 
138 143
139 kern_has_sysvsem = 1; 144 kern_has_sysvsem = 1;
140 145
141 kern_has_sysvsem = 1; 146#ifdef _MODULE
 147 if (clog)
 148 sysctl_ipc_sem_setup(clog);
 149#endif
 150}
142 151
143 sysvipcinit(); 152static int
 153seminit_exithook(void)
 154{
 155
 156 hook = exithook_establish(semexit, NULL);
 157 return 0;
144} 158}
145 159
146int 160int
147semfini(void) 161semfini(void)
148{ 162{
149 int i, sz; 163 int i, sz;
150 vaddr_t v = (vaddr_t)sema; 164 vaddr_t v = (vaddr_t)sema;
151 165
152 /* Don't allow module unload if we're busy */ 166 /* Don't allow module unload if we're busy */
153 mutex_enter(&semlock); 167 mutex_enter(&semlock);
154 if (semtot) { 168 if (semtot) {
155 mutex_exit(&semlock); 169 mutex_exit(&semlock);
156 return 1; 170 return 1;
157 } 171 }
158 172
159 /* Remove the exit hook */ 173 /* Remove the exit hook */
160 exithook_disestablish(hook); 174 if (hook)
 175 exithook_disestablish(hook);
161 176
162 /* Destroy all our condvars */ 177 /* Destroy all our condvars */
163 for (i = 0; i < seminfo.semmni; i++) { 178 for (i = 0; i < seminfo.semmni; i++) {
164 cv_destroy(&semcv[i]); 179 cv_destroy(&semcv[i]);
165 } 180 }
166 181
167 /* Free the wired memory that we allocated */ 182 /* Free the wired memory that we allocated */
168 sz = ALIGN(seminfo.semmni * sizeof(struct semid_ds)) + 183 sz = ALIGN(seminfo.semmni * sizeof(struct semid_ds)) +
169 ALIGN(seminfo.semmns * sizeof(struct __sem)) + 184 ALIGN(seminfo.semmns * sizeof(struct __sem)) +
170 ALIGN(seminfo.semmni * sizeof(kcondvar_t)) + 185 ALIGN(seminfo.semmni * sizeof(kcondvar_t)) +
171 ALIGN(seminfo.semmnu * seminfo.semusz); 186 ALIGN(seminfo.semmnu * seminfo.semusz);
172 sz = round_page(sz); 187 sz = round_page(sz);
173 uvm_km_free(kernel_map, v, sz, UVM_KMF_WIRED); 188 uvm_km_free(kernel_map, v, sz, UVM_KMF_WIRED);
@@ -322,26 +337,28 @@ semrealloc(int newsemmni, int newsemmns, @@ -322,26 +337,28 @@ semrealloc(int newsemmni, int newsemmns,
322 337
323 uvm_km_free(kernel_map, (vaddr_t)old_sema, sz, UVM_KMF_WIRED); 338 uvm_km_free(kernel_map, (vaddr_t)old_sema, sz, UVM_KMF_WIRED);
324 return 0; 339 return 0;
325} 340}
326 341
327/* 342/*
328 * Placebo. 343 * Placebo.
329 */ 344 */
330 345
331int 346int
332sys_semconfig(struct lwp *l, const struct sys_semconfig_args *uap, register_t *retval) 347sys_semconfig(struct lwp *l, const struct sys_semconfig_args *uap, register_t *retval)
333{ 348{
334 349
 350 RUN_ONCE(&exithook_control, seminit_exithook);
 351
335 *retval = 0; 352 *retval = 0;
336 return 0; 353 return 0;
337} 354}
338 355
339/* 356/*
340 * Allocate a new sem_undo structure for a process. 357 * Allocate a new sem_undo structure for a process.
341 * => Returns NULL on failure. 358 * => Returns NULL on failure.
342 */ 359 */
343struct sem_undo * 360struct sem_undo *
344semu_alloc(struct proc *p) 361semu_alloc(struct proc *p)
345{ 362{
346 struct sem_undo *suptr, **supptr; 363 struct sem_undo *suptr, **supptr;
347 bool attempted = false; 364 bool attempted = false;
@@ -479,26 +496,28 @@ sys_____semctl50(struct lwp *l, const st @@ -479,26 +496,28 @@ sys_____semctl50(struct lwp *l, const st
479 register_t *retval) 496 register_t *retval)
480{ 497{
481 /* { 498 /* {
482 syscallarg(int) semid; 499 syscallarg(int) semid;
483 syscallarg(int) semnum; 500 syscallarg(int) semnum;
484 syscallarg(int) cmd; 501 syscallarg(int) cmd;
485 syscallarg(union __semun *) arg; 502 syscallarg(union __semun *) arg;
486 } */ 503 } */
487 struct semid_ds sembuf; 504 struct semid_ds sembuf;
488 int cmd, error; 505 int cmd, error;
489 void *pass_arg; 506 void *pass_arg;
490 union __semun karg; 507 union __semun karg;
491 508
 509 RUN_ONCE(&exithook_control, seminit_exithook);
 510
492 cmd = SCARG(uap, cmd); 511 cmd = SCARG(uap, cmd);
493 512
494 pass_arg = get_semctl_arg(cmd, &sembuf, &karg); 513 pass_arg = get_semctl_arg(cmd, &sembuf, &karg);
495 514
496 if (pass_arg) { 515 if (pass_arg) {
497 error = copyin(SCARG(uap, arg), &karg, sizeof(karg)); 516 error = copyin(SCARG(uap, arg), &karg, sizeof(karg));
498 if (error) 517 if (error)
499 return error; 518 return error;
500 if (cmd == IPC_SET) { 519 if (cmd == IPC_SET) {
501 error = copyin(karg.buf, &sembuf, sizeof(sembuf)); 520 error = copyin(karg.buf, &sembuf, sizeof(sembuf));
502 if (error) 521 if (error)
503 return (error); 522 return (error);
504 } 523 }
@@ -680,26 +699,28 @@ int @@ -680,26 +699,28 @@ int
680sys_semget(struct lwp *l, const struct sys_semget_args *uap, register_t *retval) 699sys_semget(struct lwp *l, const struct sys_semget_args *uap, register_t *retval)
681{ 700{
682 /* { 701 /* {
683 syscallarg(key_t) key; 702 syscallarg(key_t) key;
684 syscallarg(int) nsems; 703 syscallarg(int) nsems;
685 syscallarg(int) semflg; 704 syscallarg(int) semflg;
686 } */ 705 } */
687 int semid, error = 0; 706 int semid, error = 0;
688 int key = SCARG(uap, key); 707 int key = SCARG(uap, key);
689 int nsems = SCARG(uap, nsems); 708 int nsems = SCARG(uap, nsems);
690 int semflg = SCARG(uap, semflg); 709 int semflg = SCARG(uap, semflg);
691 kauth_cred_t cred = l->l_cred; 710 kauth_cred_t cred = l->l_cred;
692 711
 712 RUN_ONCE(&exithook_control, seminit_exithook);
 713
693 SEM_PRINTF(("semget(0x%x, %d, 0%o)\n", key, nsems, semflg)); 714 SEM_PRINTF(("semget(0x%x, %d, 0%o)\n", key, nsems, semflg));
694 715
695 mutex_enter(&semlock); 716 mutex_enter(&semlock);
696 717
697 if (key != IPC_PRIVATE) { 718 if (key != IPC_PRIVATE) {
698 for (semid = 0; semid < seminfo.semmni; semid++) { 719 for (semid = 0; semid < seminfo.semmni; semid++) {
699 if ((sema[semid].sem_perm.mode & SEM_ALLOC) && 720 if ((sema[semid].sem_perm.mode & SEM_ALLOC) &&
700 sema[semid].sem_perm._key == key) 721 sema[semid].sem_perm._key == key)
701 break; 722 break;
702 } 723 }
703 if (semid < seminfo.semmni) { 724 if (semid < seminfo.semmni) {
704 SEM_PRINTF(("found public key\n")); 725 SEM_PRINTF(("found public key\n"));
705 if ((error = ipcperm(cred, &sema[semid].sem_perm, 726 if ((error = ipcperm(cred, &sema[semid].sem_perm,
@@ -787,26 +808,28 @@ sys_semop(struct lwp *l, const struct sy @@ -787,26 +808,28 @@ sys_semop(struct lwp *l, const struct sy
787 struct proc *p = l->l_proc; 808 struct proc *p = l->l_proc;
788 int semid = SCARG(uap, semid), seq; 809 int semid = SCARG(uap, semid), seq;
789 size_t nsops = SCARG(uap, nsops); 810 size_t nsops = SCARG(uap, nsops);
790 struct sembuf small_sops[SMALL_SOPS]; 811 struct sembuf small_sops[SMALL_SOPS];
791 struct sembuf *sops; 812 struct sembuf *sops;
792 struct semid_ds *semaptr; 813 struct semid_ds *semaptr;
793 struct sembuf *sopptr = NULL; 814 struct sembuf *sopptr = NULL;
794 struct __sem *semptr = NULL; 815 struct __sem *semptr = NULL;
795 struct sem_undo *suptr = NULL; 816 struct sem_undo *suptr = NULL;
796 kauth_cred_t cred = l->l_cred; 817 kauth_cred_t cred = l->l_cred;
797 int i, error; 818 int i, error;
798 int do_wakeup, do_undos; 819 int do_wakeup, do_undos;
799 820
 821 RUN_ONCE(&exithook_control, seminit_exithook);
 822
800 SEM_PRINTF(("call to semop(%d, %p, %zd)\n", semid, SCARG(uap,sops), nsops)); 823 SEM_PRINTF(("call to semop(%d, %p, %zd)\n", semid, SCARG(uap,sops), nsops));
801 824
802 if (__predict_false((p->p_flag & PK_SYSVSEM) == 0)) { 825 if (__predict_false((p->p_flag & PK_SYSVSEM) == 0)) {
803 mutex_enter(p->p_lock); 826 mutex_enter(p->p_lock);
804 p->p_flag |= PK_SYSVSEM; 827 p->p_flag |= PK_SYSVSEM;
805 mutex_exit(p->p_lock); 828 mutex_exit(p->p_lock);
806 } 829 }
807 830
808restart: 831restart:
809 if (nsops <= SMALL_SOPS) { 832 if (nsops <= SMALL_SOPS) {
810 sops = small_sops; 833 sops = small_sops;
811 } else if (nsops <= seminfo.semopm) { 834 } else if (nsops <= seminfo.semopm) {
812 sops = kmem_alloc(nsops * sizeof(*sops), KM_SLEEP); 835 sops = kmem_alloc(nsops * sizeof(*sops), KM_SLEEP);
@@ -1102,27 +1125,26 @@ semexit(struct proc *p, void *v) @@ -1102,27 +1125,26 @@ semexit(struct proc *p, void *v)
1102 * If there are any active undo elements then process them. 1125 * If there are any active undo elements then process them.
1103 */ 1126 */
1104 if (suptr->un_cnt > 0) { 1127 if (suptr->un_cnt > 0) {
1105 int ix; 1128 int ix;
1106 1129
1107 for (ix = 0; ix < suptr->un_cnt; ix++) { 1130 for (ix = 0; ix < suptr->un_cnt; ix++) {
1108 int semid = suptr->un_ent[ix].un_id; 1131 int semid = suptr->un_ent[ix].un_id;
1109 int semnum = suptr->un_ent[ix].un_num; 1132 int semnum = suptr->un_ent[ix].un_num;
1110 int adjval = suptr->un_ent[ix].un_adjval; 1133 int adjval = suptr->un_ent[ix].un_adjval;
1111 struct semid_ds *semaptr; 1134 struct semid_ds *semaptr;
1112 1135
1113 semaptr = &sema[semid]; 1136 semaptr = &sema[semid];
1114 if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0) 1137 if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0)
1115 panic("semexit - semid not allocated"); 
1116 if (semnum >= semaptr->sem_nsems) 1138 if (semnum >= semaptr->sem_nsems)
1117 panic("semexit - semnum out of range"); 1139 panic("semexit - semnum out of range");
1118 1140
1119 SEM_PRINTF(("semexit: %p id=%d num=%d(adj=%d) ; " 1141 SEM_PRINTF(("semexit: %p id=%d num=%d(adj=%d) ; "
1120 "sem=%d\n", 1142 "sem=%d\n",
1121 suptr->un_proc, suptr->un_ent[ix].un_id, 1143 suptr->un_proc, suptr->un_ent[ix].un_id,
1122 suptr->un_ent[ix].un_num, 1144 suptr->un_ent[ix].un_num,
1123 suptr->un_ent[ix].un_adjval, 1145 suptr->un_ent[ix].un_adjval,
1124 semaptr->_sem_base[semnum].semval)); 1146 semaptr->_sem_base[semnum].semval));
1125 1147
1126 if (adjval < 0 && 1148 if (adjval < 0 &&
1127 semaptr->_sem_base[semnum].semval < -adjval) 1149 semaptr->_sem_base[semnum].semval < -adjval)
1128 semaptr->_sem_base[semnum].semval = 0; 1150 semaptr->_sem_base[semnum].semval = 0;

cvs diff -r1.129 -r1.130 src/sys/kern/sysv_shm.c (expand / switch to unified diff)

--- src/sys/kern/sysv_shm.c 2015/11/05 00:10:47 1.129
+++ src/sys/kern/sysv_shm.c 2015/11/06 02:26:42 1.130
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sysv_shm.c,v 1.129 2015/11/05 00:10:47 pgoyette Exp $ */ 1/* $NetBSD: sysv_shm.c,v 1.130 2015/11/06 02:26:42 pgoyette Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2007 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999, 2007 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 Mindaugas Rasiukevicius. 9 * NASA Ames Research Center, and by Mindaugas Rasiukevicius.
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
@@ -51,27 +51,27 @@ @@ -51,27 +51,27 @@
51 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 51 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
52 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 52 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
53 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 53 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
54 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 54 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
55 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 55 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
56 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
60 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 */ 61 */
62 62
63#include <sys/cdefs.h> 63#include <sys/cdefs.h>
64__KERNEL_RCSID(0, "$NetBSD: sysv_shm.c,v 1.129 2015/11/05 00:10:47 pgoyette Exp $"); 64__KERNEL_RCSID(0, "$NetBSD: sysv_shm.c,v 1.130 2015/11/06 02:26:42 pgoyette Exp $");
65 65
66#ifdef _KERNEL_OPT 66#ifdef _KERNEL_OPT
67#include "opt_sysv.h" 67#include "opt_sysv.h"
68#endif 68#endif
69 69
70#include <sys/param.h> 70#include <sys/param.h>
71#include <sys/kernel.h> 71#include <sys/kernel.h>
72#include <sys/kmem.h> 72#include <sys/kmem.h>
73#include <sys/shm.h> 73#include <sys/shm.h>
74#include <sys/mutex.h> 74#include <sys/mutex.h>
75#include <sys/mman.h> 75#include <sys/mman.h>
76#include <sys/stat.h> 76#include <sys/stat.h>
77#include <sys/sysctl.h> 77#include <sys/sysctl.h>
@@ -100,26 +100,28 @@ static int shm_use_phys __read_mostly; @@ -100,26 +100,28 @@ static int shm_use_phys __read_mostly;
100 100
101static kcondvar_t shm_realloc_cv; 101static kcondvar_t shm_realloc_cv;
102static bool shm_realloc_state; 102static bool shm_realloc_state;
103static u_int shm_realloc_disable; 103static u_int shm_realloc_disable;
104 104
105struct shmmap_state { 105struct shmmap_state {
106 unsigned int nitems; 106 unsigned int nitems;
107 unsigned int nrefs; 107 unsigned int nrefs;
108 SLIST_HEAD(, shmmap_entry) entries; 108 SLIST_HEAD(, shmmap_entry) entries;
109}; 109};
110 110
111extern int kern_has_sysvshm; 111extern int kern_has_sysvshm;
112 112
 113SYSCTL_SETUP_PROTO(sysctl_ipc_shm_setup);
 114
113#ifdef SHMDEBUG 115#ifdef SHMDEBUG
114#define SHMPRINTF(a) printf a 116#define SHMPRINTF(a) printf a
115#else 117#else
116#define SHMPRINTF(a) 118#define SHMPRINTF(a)
117#endif 119#endif
118 120
119static int shmrealloc(int); 121static int shmrealloc(int);
120 122
121/* 123/*
122 * Find the shared memory segment by the identifier. 124 * Find the shared memory segment by the identifier.
123 * => must be called with shm_lock held; 125 * => must be called with shm_lock held;
124 */ 126 */
125static struct shmid_ds * 127static struct shmid_ds *
@@ -941,27 +943,27 @@ shmrealloc(int newshmni) @@ -941,27 +943,27 @@ shmrealloc(int newshmni)
941 ALIGN(oldshmni * sizeof(struct shmid_ds))); 943 ALIGN(oldshmni * sizeof(struct shmid_ds)));
942 for (i = 0; i < oldshmni; i++) 944 for (i = 0; i < oldshmni; i++)
943 cv_destroy(&oldshm_cv[i]); 945 cv_destroy(&oldshm_cv[i]);
944 946
945 sz = ALIGN(oldshmni * sizeof(struct shmid_ds)) + 947 sz = ALIGN(oldshmni * sizeof(struct shmid_ds)) +
946 ALIGN(oldshmni * sizeof(kcondvar_t)); 948 ALIGN(oldshmni * sizeof(kcondvar_t));
947 sz = round_page(sz); 949 sz = round_page(sz);
948 uvm_km_free(kernel_map, (vaddr_t)oldshmsegs, sz, UVM_KMF_WIRED); 950 uvm_km_free(kernel_map, (vaddr_t)oldshmsegs, sz, UVM_KMF_WIRED);
949 951
950 return 0; 952 return 0;
951} 953}
952 954
953void 955void
954shminit(void) 956shminit(struct sysctllog **clog)
955{ 957{
956 vaddr_t v; 958 vaddr_t v;
957 size_t sz; 959 size_t sz;
958 int i; 960 int i;
959 961
960 mutex_init(&shm_lock, MUTEX_DEFAULT, IPL_NONE); 962 mutex_init(&shm_lock, MUTEX_DEFAULT, IPL_NONE);
961 cv_init(&shm_realloc_cv, "shmrealc"); 963 cv_init(&shm_realloc_cv, "shmrealc");
962 964
963 /* Allocate the wired memory for our structures */ 965 /* Allocate the wired memory for our structures */
964 sz = ALIGN(shminfo.shmmni * sizeof(struct shmid_ds)) + 966 sz = ALIGN(shminfo.shmmni * sizeof(struct shmid_ds)) +
965 ALIGN(shminfo.shmmni * sizeof(kcondvar_t)); 967 ALIGN(shminfo.shmmni * sizeof(kcondvar_t));
966 sz = round_page(sz); 968 sz = round_page(sz);
967 v = uvm_km_alloc(kernel_map, sz, 0, UVM_KMF_WIRED|UVM_KMF_ZERO); 969 v = uvm_km_alloc(kernel_map, sz, 0, UVM_KMF_WIRED|UVM_KMF_ZERO);
@@ -984,27 +986,30 @@ shminit(void) @@ -984,27 +986,30 @@ shminit(void)
984 } 986 }
985 shm_last_free = 0; 987 shm_last_free = 0;
986 shm_nused = 0; 988 shm_nused = 0;
987 shm_committed = 0; 989 shm_committed = 0;
988 shm_realloc_disable = 0; 990 shm_realloc_disable = 0;
989 shm_realloc_state = false; 991 shm_realloc_state = false;
990 992
991 kern_has_sysvshm = 1; 993 kern_has_sysvshm = 1;
992 994
993 /* Load the callback function pointers for the uvm subsystem */ 995 /* Load the callback function pointers for the uvm subsystem */
994 uvm_shmexit = shmexit; 996 uvm_shmexit = shmexit;
995 uvm_shmfork = shmfork; 997 uvm_shmfork = shmfork;
996 998
997 sysvipcinit(); 999#ifdef _MODULE
 1000 if (clog)
 1001 sysctl_ipc_shm_setup(clog);
 1002#endif
998} 1003}
999 1004
1000int 1005int
1001shmfini(void) 1006shmfini(void)
1002{ 1007{
1003 size_t sz; 1008 size_t sz;
1004 int i; 1009 int i;
1005 vaddr_t v = (vaddr_t)shmsegs; 1010 vaddr_t v = (vaddr_t)shmsegs;
1006 1011
1007 mutex_enter(&shm_lock); 1012 mutex_enter(&shm_lock);
1008 if (shm_nused) { 1013 if (shm_nused) {
1009 mutex_exit(&shm_lock); 1014 mutex_exit(&shm_lock);
1010 return 1; 1015 return 1;

cvs diff -r1.25 -r1.26 src/sys/sys/msg.h (expand / switch to unified diff)

--- src/sys/sys/msg.h 2015/05/13 01:16:15 1.25
+++ src/sys/sys/msg.h 2015/11/06 02:26:42 1.26
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: msg.h,v 1.25 2015/05/13 01:16:15 pgoyette Exp $ */ 1/* $NetBSD: msg.h,v 1.26 2015/11/06 02:26:42 pgoyette Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2007 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999, 2007 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
@@ -199,23 +199,23 @@ extern kmutex_t msgmutex; @@ -199,23 +199,23 @@ extern kmutex_t msgmutex;
199#include <sys/cdefs.h> 199#include <sys/cdefs.h>
200 200
201__BEGIN_DECLS 201__BEGIN_DECLS
202int msgctl(int, int, struct msqid_ds *) __RENAME(__msgctl50); 202int msgctl(int, int, struct msqid_ds *) __RENAME(__msgctl50);
203int msgget(key_t, int); 203int msgget(key_t, int);
204int msgsnd(int, const void *, size_t, int); 204int msgsnd(int, const void *, size_t, int);
205ssize_t msgrcv(int, void *, size_t, long, int); 205ssize_t msgrcv(int, void *, size_t, long, int);
206__END_DECLS 206__END_DECLS
207#else 207#else
208#include <sys/systm.h> 208#include <sys/systm.h>
209 209
210struct proc; 210struct proc;
211 211
212void msginit(void); 212void msginit(struct sysctllog **);
213int msgfini(void); 213int msgfini(void);
214int msgctl1(struct lwp *, int, int, struct msqid_ds *); 214int msgctl1(struct lwp *, int, int, struct msqid_ds *);
215int msgsnd1(struct lwp *, int, const char *, size_t, int, size_t, 215int msgsnd1(struct lwp *, int, const char *, size_t, int, size_t,
216 copyin_t); 216 copyin_t);
217int msgrcv1(struct lwp *, int, char *, size_t, long, int, size_t, 217int msgrcv1(struct lwp *, int, char *, size_t, long, int, size_t,
218 copyout_t, register_t *); 218 copyout_t, register_t *);
219#endif /* !_KERNEL */ 219#endif /* !_KERNEL */
220 220
221#endif /* !_SYS_MSG_H_ */ 221#endif /* !_SYS_MSG_H_ */

cvs diff -r1.31 -r1.32 src/sys/sys/sem.h (expand / switch to unified diff)

--- src/sys/sys/sem.h 2015/05/13 01:16:15 1.31
+++ src/sys/sys/sem.h 2015/11/06 02:26:42 1.32
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sem.h,v 1.31 2015/05/13 01:16:15 pgoyette Exp $ */ 1/* $NetBSD: sem.h,v 1.32 2015/11/06 02:26:42 pgoyette Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999 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. 9 * 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
@@ -212,25 +212,25 @@ extern struct semid_ds *sema; /* semaph @@ -212,25 +212,25 @@ extern struct semid_ds *sema; /* semaph
212#include <sys/cdefs.h> 212#include <sys/cdefs.h>
213 213
214__BEGIN_DECLS 214__BEGIN_DECLS
215#ifndef __LIBC12_SOURCE__ 215#ifndef __LIBC12_SOURCE__
216int semctl(int, int, int, ...) __RENAME(__semctl50); 216int semctl(int, int, int, ...) __RENAME(__semctl50);
217#endif 217#endif
218int semget(key_t, int, int); 218int semget(key_t, int, int);
219int semop(int, struct sembuf *, size_t); 219int semop(int, struct sembuf *, size_t);
220#if defined(_NETBSD_SOURCE) 220#if defined(_NETBSD_SOURCE)
221int semconfig(int); 221int semconfig(int);
222#endif 222#endif
223__END_DECLS 223__END_DECLS
224#else 224#else
225void seminit(void); 225void seminit(struct sysctllog **);
226int semfini(void); 226int semfini(void);
227void semexit(struct proc *, void *); 227void semexit(struct proc *, void *);
228 228
229int semctl1(struct lwp *, int, int, int, void *, register_t *); 229int semctl1(struct lwp *, int, int, int, void *, register_t *);
230#define get_semctl_arg(cmd, sembuf, arg) \ 230#define get_semctl_arg(cmd, sembuf, arg) \
231 ((cmd) == IPC_SET || (cmd) == IPC_STAT ? (void *)sembuf \ 231 ((cmd) == IPC_SET || (cmd) == IPC_STAT ? (void *)sembuf \
232 : (cmd) == GETALL || (cmd) == SETVAL || (cmd) == SETALL ? (void *)arg \ 232 : (cmd) == GETALL || (cmd) == SETVAL || (cmd) == SETALL ? (void *)arg \
233 : NULL) 233 : NULL)
234#endif /* !_KERNEL */ 234#endif /* !_KERNEL */
235 235
236#endif /* !_SYS_SEM_H_ */ 236#endif /* !_SYS_SEM_H_ */

cvs diff -r1.50 -r1.51 src/sys/sys/shm.h (expand / switch to unified diff)

--- src/sys/sys/shm.h 2015/11/05 00:10:48 1.50
+++ src/sys/sys/shm.h 2015/11/06 02:26:42 1.51
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: shm.h,v 1.50 2015/11/05 00:10:48 pgoyette Exp $ */ 1/* $NetBSD: shm.h,v 1.51 2015/11/06 02:26:42 pgoyette Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999 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. 9 * 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
@@ -162,27 +162,27 @@ struct shm_sysctl_info { @@ -162,27 +162,27 @@ struct shm_sysctl_info {
162extern struct shminfo shminfo; 162extern struct shminfo shminfo;
163extern struct shmid_ds *shmsegs; 163extern struct shmid_ds *shmsegs;
164extern int shm_nused; 164extern int shm_nused;
165 165
166#define SHMSEG_FREE 0x0200 166#define SHMSEG_FREE 0x0200
167#define SHMSEG_REMOVED 0x0400 167#define SHMSEG_REMOVED 0x0400
168#define SHMSEG_ALLOCATED 0x0800 168#define SHMSEG_ALLOCATED 0x0800
169#define SHMSEG_WANTED 0x1000 169#define SHMSEG_WANTED 0x1000
170#define SHMSEG_RMLINGER 0x2000 170#define SHMSEG_RMLINGER 0x2000
171#define SHMSEG_WIRED 0x4000 171#define SHMSEG_WIRED 0x4000
172 172
173struct vmspace; 173struct vmspace;
174 174
175void shminit(void); 175void shminit(struct sysctllog **);
176int shmfini(void); 176int shmfini(void);
177void shmfork(struct vmspace *, struct vmspace *); 177void shmfork(struct vmspace *, struct vmspace *);
178void shmexit(struct vmspace *); 178void shmexit(struct vmspace *);
179int shmctl1(struct lwp *, int, int, struct shmid_ds *); 179int shmctl1(struct lwp *, int, int, struct shmid_ds *);
180 180
181extern void (*uvm_shmexit)(struct vmspace *); 181extern void (*uvm_shmexit)(struct vmspace *);
182extern void (*uvm_shmfork)(struct vmspace *, struct vmspace *); 182extern void (*uvm_shmfork)(struct vmspace *, struct vmspace *);
183 183
184#define SYSCTL_FILL_SHM(src, dst) do { \ 184#define SYSCTL_FILL_SHM(src, dst) do { \
185 SYSCTL_FILL_PERM((src).shm_perm, (dst).shm_perm); \ 185 SYSCTL_FILL_PERM((src).shm_perm, (dst).shm_perm); \
186 (dst).shm_segsz = (src).shm_segsz; \ 186 (dst).shm_segsz = (src).shm_segsz; \
187 (dst).shm_lpid = (src).shm_lpid; \ 187 (dst).shm_lpid = (src).shm_lpid; \
188 (dst).shm_cpid = (src).shm_cpid; \ 188 (dst).shm_cpid = (src).shm_cpid; \