GSoC 2016: Charles Cui: add SEM_NSEMS_MAXdiff -r1.36 -r1.37 src/include/limits.h
(christos)
--- src/include/limits.h 2016/03/08 05:02:55 1.36
+++ src/include/limits.h 2016/06/10 23:24:33 1.37
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: limits.h,v 1.36 2016/03/08 05:02:55 christos Exp $ */ | 1 | /* $NetBSD: limits.h,v 1.37 2016/06/10 23:24:33 christos Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1988, 1993 | 4 | * Copyright (c) 1988, 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 | * 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. | |
@@ -83,26 +83,27 @@ | @@ -83,26 +83,27 @@ | |||
83 | #define _POSIX_THREAD_THREADS_MAX 64 | 83 | #define _POSIX_THREAD_THREADS_MAX 64 | |
84 | 84 | |||
85 | /* | 85 | /* | |
86 | * These are the correct names, defined in terms of the above | 86 | * These are the correct names, defined in terms of the above | |
87 | * except for PTHREAD_KEYS_MAX which is bigger than standard | 87 | * except for PTHREAD_KEYS_MAX which is bigger than standard | |
88 | * mandated minimum value _POSIX_THREAD_KEYS_MAX. | 88 | * mandated minimum value _POSIX_THREAD_KEYS_MAX. | |
89 | */ | 89 | */ | |
90 | #define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS | 90 | #define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS | |
91 | #define PTHREAD_KEYS_MAX 256 | 91 | #define PTHREAD_KEYS_MAX 256 | |
92 | /* Not yet: PTHREAD_STACK_MIN */ | 92 | /* Not yet: PTHREAD_STACK_MIN */ | |
93 | #define PTHREAD_THREADS_MAX _POSIX_THREAD_THREADS_MAX | 93 | #define PTHREAD_THREADS_MAX _POSIX_THREAD_THREADS_MAX | |
94 | 94 | |||
95 | #define _POSIX_TIMER_MAX 32 | 95 | #define _POSIX_TIMER_MAX 32 | |
96 | #define _POSIX_SEM_NSEMS_MAX 256 | |||
96 | #define _POSIX_TTY_NAME_MAX 9 | 97 | #define _POSIX_TTY_NAME_MAX 9 | |
97 | #define _POSIX_TZNAME_MAX 6 | 98 | #define _POSIX_TZNAME_MAX 6 | |
98 | 99 | |||
99 | #define _POSIX2_BC_BASE_MAX 99 | 100 | #define _POSIX2_BC_BASE_MAX 99 | |
100 | #define _POSIX2_BC_DIM_MAX 2048 | 101 | #define _POSIX2_BC_DIM_MAX 2048 | |
101 | #define _POSIX2_BC_SCALE_MAX 99 | 102 | #define _POSIX2_BC_SCALE_MAX 99 | |
102 | #define _POSIX2_BC_STRING_MAX 1000 | 103 | #define _POSIX2_BC_STRING_MAX 1000 | |
103 | #define _POSIX2_CHARCLASS_NAME_MAX 14 | 104 | #define _POSIX2_CHARCLASS_NAME_MAX 14 | |
104 | #define _POSIX2_COLL_WEIGHTS_MAX 2 | 105 | #define _POSIX2_COLL_WEIGHTS_MAX 2 | |
105 | #define _POSIX2_EXPR_NEST_MAX 32 | 106 | #define _POSIX2_EXPR_NEST_MAX 32 | |
106 | #define _POSIX2_LINE_MAX 2048 | 107 | #define _POSIX2_LINE_MAX 2048 | |
107 | #define _POSIX2_RE_DUP_MAX 255 | 108 | #define _POSIX2_RE_DUP_MAX 255 | |
108 | 109 |
--- src/lib/libc/gen/sysconf.3 2016/02/26 17:13:01 1.45
+++ src/lib/libc/gen/sysconf.3 2016/06/10 23:24:33 1.46
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | .\" $NetBSD: sysconf.3,v 1.45 2016/02/26 17:13:01 christos Exp $ | 1 | .\" $NetBSD: sysconf.3,v 1.46 2016/06/10 23:24:33 christos Exp $ | |
2 | .\" | 2 | .\" | |
3 | .\" Copyright (c) 1993 | 3 | .\" Copyright (c) 1993 | |
4 | .\" The Regents of the University of California. All rights reserved. | 4 | .\" The Regents of the University of California. 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. Neither the name of the University nor the names of its contributors | 14 | .\" 3. Neither the name of the University nor the names of its contributors | |
@@ -139,26 +139,29 @@ Read-Write Locks | @@ -139,26 +139,29 @@ Read-Write Locks | |||
139 | option to which the system attempts to conform, | 139 | option to which the system attempts to conform, | |
140 | otherwise \-1. | 140 | otherwise \-1. | |
141 | .It Li _SC_REGEXP | 141 | .It Li _SC_REGEXP | |
142 | Return 1 if | 142 | Return 1 if | |
143 | .Tn POSIX | 143 | .Tn POSIX | |
144 | regular expressions are available on this system, otherwise \-1. | 144 | regular expressions are available on this system, otherwise \-1. | |
145 | .It Li _SC_SEMAPHORES | 145 | .It Li _SC_SEMAPHORES | |
146 | The version of | 146 | The version of | |
147 | .St -p1003.1 | 147 | .St -p1003.1 | |
148 | and its | 148 | and its | |
149 | Semaphores | 149 | Semaphores | |
150 | option to which the system attempts to conform, | 150 | option to which the system attempts to conform, | |
151 | otherwise \-1. | 151 | otherwise \-1. | |
152 | .It Li _SC_SEM_NSEMS_MAX | |||
153 | The maximum number of semaphores that one process can have open at a time, | |||
154 | otherwise \-1. | |||
152 | .It Li _SC_SHELL | 155 | .It Li _SC_SHELL | |
153 | Return 1 if | 156 | Return 1 if | |
154 | .Tn POSIX | 157 | .Tn POSIX | |
155 | shell is available on this system, otherwise \-1. | 158 | shell is available on this system, otherwise \-1. | |
156 | .It Li _SC_SPIN_LOCKS | 159 | .It Li _SC_SPIN_LOCKS | |
157 | The version of | 160 | The version of | |
158 | .St -p1003.1 | 161 | .St -p1003.1 | |
159 | and its | 162 | and its | |
160 | Spin Locks | 163 | Spin Locks | |
161 | option to which the system attempts to conform, | 164 | option to which the system attempts to conform, | |
162 | otherwise \-1. | 165 | otherwise \-1. | |
163 | .It Li _SC_STREAM_MAX | 166 | .It Li _SC_STREAM_MAX | |
164 | The minimum maximum number of streams that a process may have open | 167 | The minimum maximum number of streams that a process may have open |
--- src/lib/libc/gen/sysconf.c 2016/02/26 17:13:01 1.37
+++ src/lib/libc/gen/sysconf.c 2016/06/10 23:24:33 1.38
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: sysconf.c,v 1.37 2016/02/26 17:13:01 christos Exp $ */ | 1 | /* $NetBSD: sysconf.c,v 1.38 2016/06/10 23:24:33 christos 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 | * Sean Eric Fagan of Cygnus Support. | 8 | * Sean Eric Fagan of Cygnus Support. | |
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. | |
@@ -27,27 +27,27 @@ | @@ -27,27 +27,27 @@ | |||
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
32 | * SUCH DAMAGE. | 32 | * SUCH DAMAGE. | |
33 | */ | 33 | */ | |
34 | 34 | |||
35 | #include <sys/cdefs.h> | 35 | #include <sys/cdefs.h> | |
36 | #if defined(LIBC_SCCS) && !defined(lint) | 36 | #if defined(LIBC_SCCS) && !defined(lint) | |
37 | #if 0 | 37 | #if 0 | |
38 | static char sccsid[] = "@(#)sysconf.c 8.2 (Berkeley) 3/20/94"; | 38 | static char sccsid[] = "@(#)sysconf.c 8.2 (Berkeley) 3/20/94"; | |
39 | #else | 39 | #else | |
40 | __RCSID("$NetBSD: sysconf.c,v 1.37 2016/02/26 17:13:01 christos Exp $"); | 40 | __RCSID("$NetBSD: sysconf.c,v 1.38 2016/06/10 23:24:33 christos Exp $"); | |
41 | #endif | 41 | #endif | |
42 | #endif /* LIBC_SCCS and not lint */ | 42 | #endif /* LIBC_SCCS and not lint */ | |
43 | 43 | |||
44 | #include "namespace.h" | 44 | #include "namespace.h" | |
45 | #include <sys/param.h> | 45 | #include <sys/param.h> | |
46 | #include <sys/sysctl.h> | 46 | #include <sys/sysctl.h> | |
47 | #include <sys/time.h> | 47 | #include <sys/time.h> | |
48 | #include <sys/resource.h> | 48 | #include <sys/resource.h> | |
49 | 49 | |||
50 | #include <errno.h> | 50 | #include <errno.h> | |
51 | #include <limits.h> | 51 | #include <limits.h> | |
52 | #include <time.h> | 52 | #include <time.h> | |
53 | #include <unistd.h> | 53 | #include <unistd.h> | |
@@ -410,19 +410,21 @@ yesno: if (sysctl(mib, mib_len, &value, | @@ -410,19 +410,21 @@ yesno: if (sysctl(mib, mib_len, &value, | |||
410 | case _SC_THREAD_ATTR_STACKSIZE: | 410 | case _SC_THREAD_ATTR_STACKSIZE: | |
411 | return _POSIX_THREAD_ATTR_STACKSIZE; | 411 | return _POSIX_THREAD_ATTR_STACKSIZE; | |
412 | case _SC_THREAD_SAFE_FUNCTIONS: | 412 | case _SC_THREAD_SAFE_FUNCTIONS: | |
413 | return _POSIX_THREAD_SAFE_FUNCTIONS; | 413 | return _POSIX_THREAD_SAFE_FUNCTIONS; | |
414 | case _SC_THREAD_PRIORITY_SCHEDULING: | 414 | case _SC_THREAD_PRIORITY_SCHEDULING: | |
415 | case _SC_THREAD_PRIO_INHERIT: | 415 | case _SC_THREAD_PRIO_INHERIT: | |
416 | case _SC_THREAD_PRIO_PROTECT: | 416 | case _SC_THREAD_PRIO_PROTECT: | |
417 | case _SC_THREAD_PROCESS_SHARED: | 417 | case _SC_THREAD_PROCESS_SHARED: | |
418 | return -1; | 418 | return -1; | |
419 | case _SC_TTY_NAME_MAX: | 419 | case _SC_TTY_NAME_MAX: | |
420 | return pathconf(_PATH_DEV, _PC_NAME_MAX); | 420 | return pathconf(_PATH_DEV, _PC_NAME_MAX); | |
421 | case _SC_TIMER_MAX: | 421 | case _SC_TIMER_MAX: | |
422 | return _POSIX_TIMER_MAX; | 422 | return _POSIX_TIMER_MAX; | |
423 | case _SC_SEM_NSEMS_MAX: | |||
424 | return _POSIX_SEM_NSEMS_MAX; | |||
423 | default: | 425 | default: | |
424 | errno = EINVAL; | 426 | errno = EINVAL; | |
425 | return (-1); | 427 | return (-1); | |
426 | } | 428 | } | |
427 | return (sysctl(mib, mib_len, &value, &len, NULL, 0) == -1 ? -1 : value); | 429 | return (sysctl(mib, mib_len, &value, &len, NULL, 0) == -1 ? -1 : value); | |
428 | } | 430 | } |
--- src/sys/kern/uipc_sem.c 2016/04/24 19:48:29 1.45
+++ src/sys/kern/uipc_sem.c 2016/06/10 23:24:33 1.46
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: uipc_sem.c,v 1.45 2016/04/24 19:48:29 dholland Exp $ */ | 1 | /* $NetBSD: uipc_sem.c,v 1.46 2016/06/10 23:24:33 christos Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2011 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 Mindaugas Rasiukevicius. | 8 | * by Mindaugas Rasiukevicius. | |
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. | |
@@ -50,53 +50,54 @@ | @@ -50,53 +50,54 @@ | |||
50 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 50 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
51 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 51 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
52 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 52 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
53 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 53 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
54 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 54 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
55 | * SUCH DAMAGE. | 55 | * SUCH DAMAGE. | |
56 | */ | 56 | */ | |
57 | 57 | |||
58 | /* | 58 | /* | |
59 | * Implementation of POSIX semaphore. | 59 | * Implementation of POSIX semaphore. | |
60 | */ | 60 | */ | |
61 | 61 | |||
62 | #include <sys/cdefs.h> | 62 | #include <sys/cdefs.h> | |
63 | __KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.45 2016/04/24 19:48:29 dholland Exp $"); | 63 | __KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.46 2016/06/10 23:24:33 christos Exp $"); | |
64 | 64 | |||
65 | #include <sys/param.h> | 65 | #include <sys/param.h> | |
66 | #include <sys/kernel.h> | 66 | #include <sys/kernel.h> | |
67 | 67 | |||
68 | #include <sys/atomic.h> | 68 | #include <sys/atomic.h> | |
69 | #include <sys/proc.h> | 69 | #include <sys/proc.h> | |
70 | #include <sys/ksem.h> | 70 | #include <sys/ksem.h> | |
71 | #include <sys/syscall.h> | 71 | #include <sys/syscall.h> | |
72 | #include <sys/stat.h> | 72 | #include <sys/stat.h> | |
73 | #include <sys/kmem.h> | 73 | #include <sys/kmem.h> | |
74 | #include <sys/fcntl.h> | 74 | #include <sys/fcntl.h> | |
75 | #include <sys/file.h> | 75 | #include <sys/file.h> | |
76 | #include <sys/filedesc.h> | 76 | #include <sys/filedesc.h> | |
77 | #include <sys/kauth.h> | 77 | #include <sys/kauth.h> | |
78 | #include <sys/module.h> | 78 | #include <sys/module.h> | |
79 | #include <sys/mount.h> | 79 | #include <sys/mount.h> | |
80 | #include <sys/semaphore.h> | 80 | #include <sys/semaphore.h> | |
81 | #include <sys/syscall.h> | 81 | #include <sys/syscall.h> | |
82 | #include <sys/syscallargs.h> | 82 | #include <sys/syscallargs.h> | |
83 | #include <sys/syscallvar.h> | 83 | #include <sys/syscallvar.h> | |
84 | #include <sys/sysctl.h> | 84 | #include <sys/sysctl.h> | |
85 | 85 | |||
86 | MODULE(MODULE_CLASS_MISC, ksem, NULL); | 86 | MODULE(MODULE_CLASS_MISC, ksem, NULL); | |
87 | 87 | |||
88 | #define SEM_MAX_NAMELEN 14 | 88 | #define SEM_MAX_NAMELEN 14 | |
89 | 89 | |||
90 | #define SEM_NSEMS_MAX 256 | |||
90 | #define KS_UNLINKED 0x01 | 91 | #define KS_UNLINKED 0x01 | |
91 | 92 | |||
92 | static kmutex_t ksem_lock __cacheline_aligned; | 93 | static kmutex_t ksem_lock __cacheline_aligned; | |
93 | static LIST_HEAD(,ksem) ksem_head __cacheline_aligned; | 94 | static LIST_HEAD(,ksem) ksem_head __cacheline_aligned; | |
94 | static u_int nsems_total __cacheline_aligned; | 95 | static u_int nsems_total __cacheline_aligned; | |
95 | static u_int nsems __cacheline_aligned; | 96 | static u_int nsems __cacheline_aligned; | |
96 | 97 | |||
97 | static kauth_listener_t ksem_listener; | 98 | static kauth_listener_t ksem_listener; | |
98 | 99 | |||
99 | static int ksem_sysinit(void); | 100 | static int ksem_sysinit(void); | |
100 | static int ksem_sysfini(bool); | 101 | static int ksem_sysfini(bool); | |
101 | static int ksem_modcmd(modcmd_t, void *); | 102 | static int ksem_modcmd(modcmd_t, void *); | |
102 | static int ksem_close_fop(file_t *); | 103 | static int ksem_close_fop(file_t *); | |
@@ -323,26 +324,31 @@ ksem_create(lwp_t *l, const char *name, | @@ -323,26 +324,31 @@ ksem_create(lwp_t *l, const char *name, | |||
323 | return ENAMETOOLONG; | 324 | return ENAMETOOLONG; | |
324 | } | 325 | } | |
325 | /* Name must start with a '/' but not contain one. */ | 326 | /* Name must start with a '/' but not contain one. */ | |
326 | if (*name != '/' || len < 2 || strchr(name + 1, '/') != NULL) { | 327 | if (*name != '/' || len < 2 || strchr(name + 1, '/') != NULL) { | |
327 | return EINVAL; | 328 | return EINVAL; | |
328 | } | 329 | } | |
329 | kname = kmem_alloc(++len, KM_SLEEP); | 330 | kname = kmem_alloc(++len, KM_SLEEP); | |
330 | strlcpy(kname, name, len); | 331 | strlcpy(kname, name, len); | |
331 | } else { | 332 | } else { | |
332 | kname = NULL; | 333 | kname = NULL; | |
333 | len = 0; | 334 | len = 0; | |
334 | } | 335 | } | |
335 | 336 | |||
337 | if (atomic_inc_uint_nv(&l->l_proc->p_nsems) > SEM_NSEMS_MAX) { | |||
338 | atomic_dec_uint(&l->l_proc->p_nsems); | |||
339 | return -1; | |||
340 | } | |||
341 | ||||
336 | ks = kmem_zalloc(sizeof(ksem_t), KM_SLEEP); | 342 | ks = kmem_zalloc(sizeof(ksem_t), KM_SLEEP); | |
337 | mutex_init(&ks->ks_lock, MUTEX_DEFAULT, IPL_NONE); | 343 | mutex_init(&ks->ks_lock, MUTEX_DEFAULT, IPL_NONE); | |
338 | cv_init(&ks->ks_cv, "psem"); | 344 | cv_init(&ks->ks_cv, "psem"); | |
339 | ks->ks_name = kname; | 345 | ks->ks_name = kname; | |
340 | ks->ks_namelen = len; | 346 | ks->ks_namelen = len; | |
341 | ks->ks_mode = mode; | 347 | ks->ks_mode = mode; | |
342 | ks->ks_value = val; | 348 | ks->ks_value = val; | |
343 | ks->ks_ref = 1; | 349 | ks->ks_ref = 1; | |
344 | 350 | |||
345 | uc = l->l_cred; | 351 | uc = l->l_cred; | |
346 | ks->ks_uid = kauth_cred_geteuid(uc); | 352 | ks->ks_uid = kauth_cred_geteuid(uc); | |
347 | ks->ks_gid = kauth_cred_getegid(uc); | 353 | ks->ks_gid = kauth_cred_getegid(uc); | |
348 | 354 | |||
@@ -356,26 +362,27 @@ ksem_free(ksem_t *ks) | @@ -356,26 +362,27 @@ ksem_free(ksem_t *ks) | |||
356 | { | 362 | { | |
357 | 363 | |||
358 | KASSERT(!cv_has_waiters(&ks->ks_cv)); | 364 | KASSERT(!cv_has_waiters(&ks->ks_cv)); | |
359 | 365 | |||
360 | if (ks->ks_name) { | 366 | if (ks->ks_name) { | |
361 | KASSERT(ks->ks_namelen > 0); | 367 | KASSERT(ks->ks_namelen > 0); | |
362 | kmem_free(ks->ks_name, ks->ks_namelen); | 368 | kmem_free(ks->ks_name, ks->ks_namelen); | |
363 | } | 369 | } | |
364 | mutex_destroy(&ks->ks_lock); | 370 | mutex_destroy(&ks->ks_lock); | |
365 | cv_destroy(&ks->ks_cv); | 371 | cv_destroy(&ks->ks_cv); | |
366 | kmem_free(ks, sizeof(ksem_t)); | 372 | kmem_free(ks, sizeof(ksem_t)); | |
367 | 373 | |||
368 | atomic_dec_uint(&nsems_total); | 374 | atomic_dec_uint(&nsems_total); | |
375 | atomic_dec_uint(&curproc->p_nsems); | |||
369 | } | 376 | } | |
370 | 377 | |||
371 | int | 378 | int | |
372 | sys__ksem_init(struct lwp *l, const struct sys__ksem_init_args *uap, | 379 | sys__ksem_init(struct lwp *l, const struct sys__ksem_init_args *uap, | |
373 | register_t *retval) | 380 | register_t *retval) | |
374 | { | 381 | { | |
375 | /* { | 382 | /* { | |
376 | unsigned int value; | 383 | unsigned int value; | |
377 | intptr_t *idp; | 384 | intptr_t *idp; | |
378 | } */ | 385 | } */ | |
379 | 386 | |||
380 | return do_ksem_init(l, SCARG(uap, value), SCARG(uap, idp), copyout); | 387 | return do_ksem_init(l, SCARG(uap, value), SCARG(uap, idp), copyout); | |
381 | } | 388 | } |
--- src/sys/sys/proc.h 2016/04/27 21:15:40 1.330
+++ src/sys/sys/proc.h 2016/06/10 23:24:33 1.331
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: proc.h,v 1.330 2016/04/27 21:15:40 christos Exp $ */ | 1 | /* $NetBSD: proc.h,v 1.331 2016/06/10 23:24:33 christos Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2006, 2007, 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 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. | |
@@ -295,26 +295,27 @@ struct proc { | @@ -295,26 +295,27 @@ struct proc { | |||
295 | void *p_tracep; /* k: Trace private data */ | 295 | void *p_tracep; /* k: Trace private data */ | |
296 | struct vnode *p_textvp; /* :: Vnode of executable */ | 296 | struct vnode *p_textvp; /* :: Vnode of executable */ | |
297 | 297 | |||
298 | struct emul *p_emul; /* :: emulation information */ | 298 | struct emul *p_emul; /* :: emulation information */ | |
299 | void *p_emuldata; /* :: per-proc emul data, or NULL */ | 299 | void *p_emuldata; /* :: per-proc emul data, or NULL */ | |
300 | const struct execsw *p_execsw; /* :: exec package information */ | 300 | const struct execsw *p_execsw; /* :: exec package information */ | |
301 | struct klist p_klist; /* p: knotes attached to proc */ | 301 | struct klist p_klist; /* p: knotes attached to proc */ | |
302 | 302 | |||
303 | LIST_HEAD(, lwp) p_sigwaiters; /* p: LWPs waiting for signals */ | 303 | LIST_HEAD(, lwp) p_sigwaiters; /* p: LWPs waiting for signals */ | |
304 | sigpend_t p_sigpend; /* p: pending signals */ | 304 | sigpend_t p_sigpend; /* p: pending signals */ | |
305 | struct lcproc *p_lwpctl; /* p, a: _lwp_ctl() information */ | 305 | struct lcproc *p_lwpctl; /* p, a: _lwp_ctl() information */ | |
306 | pid_t p_ppid; /* :: cached parent pid */ | 306 | pid_t p_ppid; /* :: cached parent pid */ | |
307 | pid_t p_fpid; /* :: forked pid */ | 307 | pid_t p_fpid; /* :: forked pid */ | |
308 | u_int p_nsems; /* Count of semaphores */ | |||
308 | 309 | |||
309 | /* | 310 | /* | |
310 | * End area that is zeroed on creation | 311 | * End area that is zeroed on creation | |
311 | */ | 312 | */ | |
312 | #define p_endzero p_startcopy | 313 | #define p_endzero p_startcopy | |
313 | 314 | |||
314 | /* | 315 | /* | |
315 | * The following fields are all copied upon creation in fork. | 316 | * The following fields are all copied upon creation in fork. | |
316 | */ | 317 | */ | |
317 | #define p_startcopy p_sigctx | 318 | #define p_startcopy p_sigctx | |
318 | 319 | |||
319 | struct sigctx p_sigctx; /* p: Shared signal state */ | 320 | struct sigctx p_sigctx; /* p: Shared signal state */ | |
320 | 321 |
--- src/sys/sys/unistd.h 2016/02/26 17:10:41 1.56
+++ src/sys/sys/unistd.h 2016/06/10 23:24:33 1.57
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: unistd.h,v 1.56 2016/02/26 17:10:41 christos Exp $ */ | 1 | /* $NetBSD: unistd.h,v 1.57 2016/06/10 23:24:33 christos Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1989, 1993 | 4 | * Copyright (c) 1989, 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 | * 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. | |
@@ -298,27 +298,27 @@ | @@ -298,27 +298,27 @@ | |||
298 | #define _SC_V6_LPBIG_OFFBIG 77 | 298 | #define _SC_V6_LPBIG_OFFBIG 77 | |
299 | #define _SC_2_PBS 80 | 299 | #define _SC_2_PBS 80 | |
300 | #define _SC_2_PBS_ACCOUNTING 81 | 300 | #define _SC_2_PBS_ACCOUNTING 81 | |
301 | #define _SC_2_PBS_CHECKPOINT 82 | 301 | #define _SC_2_PBS_CHECKPOINT 82 | |
302 | #define _SC_2_PBS_LOCATE 83 | 302 | #define _SC_2_PBS_LOCATE 83 | |
303 | #define _SC_2_PBS_MESSAGE 84 | 303 | #define _SC_2_PBS_MESSAGE 84 | |
304 | #define _SC_2_PBS_TRACK 85 | 304 | #define _SC_2_PBS_TRACK 85 | |
305 | 305 | |||
306 | /* These are implemented */ | 306 | /* These are implemented */ | |
307 | #define _SC_SPAWN 86 | 307 | #define _SC_SPAWN 86 | |
308 | #define _SC_SHARED_MEMORY_OBJECTS 87 | 308 | #define _SC_SHARED_MEMORY_OBJECTS 87 | |
309 | 309 | |||
310 | #define _SC_TIMER_MAX 88 | 310 | #define _SC_TIMER_MAX 88 | |
311 | 311 | #define _SC_SEM_NSEMS_MAX 89 | ||
312 | 312 | |||
313 | /* Extensions found in Solaris and Linux. */ | 313 | /* Extensions found in Solaris and Linux. */ | |
314 | #define _SC_PHYS_PAGES 121 | 314 | #define _SC_PHYS_PAGES 121 | |
315 | 315 | |||
316 | #ifdef _NETBSD_SOURCE | 316 | #ifdef _NETBSD_SOURCE | |
317 | /* Commonly provided sysconf() extensions */ | 317 | /* Commonly provided sysconf() extensions */ | |
318 | #define _SC_NPROCESSORS_CONF 1001 | 318 | #define _SC_NPROCESSORS_CONF 1001 | |
319 | #define _SC_NPROCESSORS_ONLN 1002 | 319 | #define _SC_NPROCESSORS_ONLN 1002 | |
320 | /* Native variables */ | 320 | /* Native variables */ | |
321 | #define _SC_SCHED_RT_TS 2001 | 321 | #define _SC_SCHED_RT_TS 2001 | |
322 | #define _SC_SCHED_PRI_MIN 2002 | 322 | #define _SC_SCHED_PRI_MIN 2002 | |
323 | #define _SC_SCHED_PRI_MAX 2003 | 323 | #define _SC_SCHED_PRI_MAX 2003 | |
324 | #endif /* _NETBSD_SOURCE */ | 324 | #endif /* _NETBSD_SOURCE */ |