Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Define SEM_VALUE_MAX in only one place.



details:   https://anonhg.NetBSD.org/src/rev/8c22095c5005
branches:  trunk
changeset: 344862:8c22095c5005
user:      dholland <dholland%NetBSD.org@localhost>
date:      Sun Apr 24 19:48:29 2016 +0000

description:
Define SEM_VALUE_MAX in only one place.

Adding a whole extra header file just for this is not the optimal
solution... but stuffing it in with anything else exposes things that
otherwise wouldn't be.

Nothing in userland should use <sys/semaphore.h> directly, and if some
foolish third-party software should decide to do so anyway in spite of
the instructions to the contrary I will ruthlessly break it later when
the big kernel includes cleanup finally happens.

Reported by Kamil Rytarowski, and, as it turns out, also by Klaus
Heinz in 2008.

diffstat:

 distrib/sets/lists/comp/mi |   3 ++-
 include/semaphore.h        |   4 ++--
 sys/kern/uipc_sem.c        |   6 +++---
 sys/sys/Makefile           |   6 +++---
 sys/sys/semaphore.h        |  44 ++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 54 insertions(+), 9 deletions(-)

diffs (138 lines):

diff -r 2ce28d8e2cbe -r 8c22095c5005 distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Sun Apr 24 18:24:47 2016 +0000
+++ b/distrib/sets/lists/comp/mi        Sun Apr 24 19:48:29 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: mi,v 1.2031 2016/04/23 23:28:13 christos Exp $
+#      $NetBSD: mi,v 1.2032 2016/04/24 19:48:30 dholland Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 ./etc/mtree/set.comp                           comp-sys-root
@@ -2918,6 +2918,7 @@
 ./usr/include/sys/select.h                     comp-c-include
 ./usr/include/sys/selinfo.h                    comp-c-include
 ./usr/include/sys/sem.h                                comp-c-include
+./usr/include/sys/semaphore.h                  comp-c-include
 ./usr/include/sys/sha1.h                       comp-c-include
 ./usr/include/sys/sha2.h                       comp-c-include
 ./usr/include/sys/shm.h                                comp-c-include
diff -r 2ce28d8e2cbe -r 8c22095c5005 include/semaphore.h
--- a/include/semaphore.h       Sun Apr 24 18:24:47 2016 +0000
+++ b/include/semaphore.h       Sun Apr 24 19:48:29 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: semaphore.h,v 1.4 2012/03/08 21:59:28 joerg Exp $ */
+/* $NetBSD: semaphore.h,v 1.5 2016/04/24 19:48:29 dholland Exp $ */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -38,8 +38,8 @@
 typedef        struct _sem_st *sem_t;
 
 #define        SEM_FAILED      ((sem_t *)0)
-#define        SEM_VALUE_MAX   (~0U)
 
+#include <sys/semaphore.h> /* some kernel-only bits */
 #include <sys/time.h>
 
 __BEGIN_DECLS
diff -r 2ce28d8e2cbe -r 8c22095c5005 sys/kern/uipc_sem.c
--- a/sys/kern/uipc_sem.c       Sun Apr 24 18:24:47 2016 +0000
+++ b/sys/kern/uipc_sem.c       Sun Apr 24 19:48:29 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_sem.c,v 1.44 2015/11/09 01:55:03 pgoyette Exp $   */
+/*     $NetBSD: uipc_sem.c,v 1.45 2016/04/24 19:48:29 dholland Exp $   */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.44 2015/11/09 01:55:03 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.45 2016/04/24 19:48:29 dholland Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -77,6 +77,7 @@
 #include <sys/kauth.h>
 #include <sys/module.h>
 #include <sys/mount.h>
+#include <sys/semaphore.h>
 #include <sys/syscall.h>
 #include <sys/syscallargs.h>
 #include <sys/syscallvar.h>
@@ -85,7 +86,6 @@
 MODULE(MODULE_CLASS_MISC, ksem, NULL);
 
 #define        SEM_MAX_NAMELEN         14
-#define        SEM_VALUE_MAX           (~0U)
 
 #define        KS_UNLINKED             0x01
 
diff -r 2ce28d8e2cbe -r 8c22095c5005 sys/sys/Makefile
--- a/sys/sys/Makefile  Sun Apr 24 18:24:47 2016 +0000
+++ b/sys/sys/Makefile  Sun Apr 24 19:48:29 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.158 2016/04/02 20:38:40 christos Exp $
+#      $NetBSD: Makefile,v 1.159 2016/04/24 19:48:29 dholland Exp $
 
 .include <bsd.own.mk>
 
@@ -34,8 +34,8 @@
        queue.h quota.h quotactl.h \
        ras.h rbtree.h reboot.h radioio.h resource.h resourcevar.h rmd160.h \
        rnd.h rndio.h rwlock.h \
-       scanio.h sched.h scsiio.h sdt.h select.h selinfo.h sem.h sha1.h \
-       sha2.h shm.h siginfo.h signal.h signalvar.h sigtypes.h \
+       scanio.h sched.h scsiio.h sdt.h select.h selinfo.h sem.h semaphore.h \
+       sha1.h sha2.h shm.h siginfo.h signal.h signalvar.h sigtypes.h \
        sleepq.h socket.h \
        socketvar.h sockio.h spawn.h specificdata.h stat.h \
        statvfs.h syscall.h syscallargs.h sysctl.h stdarg.h stdbool.h \
diff -r 2ce28d8e2cbe -r 8c22095c5005 sys/sys/semaphore.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/sys/semaphore.h       Sun Apr 24 19:48:29 2016 +0000
@@ -0,0 +1,44 @@
+/* $NetBSD: semaphore.h,v 1.1 2016/04/24 19:48:29 dholland Exp $ */
+
+/*-
+ * Copyright (c) 2003 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * This file is NOT a public interface. From userland you should
+ * include <semaphore.h>.
+ */
+
+#ifndef _SYS_SEMAPHORE_H_
+#define _SYS_SEMAPHORE_H_
+
+/* POSIX 1003.1b semaphores */
+
+#define        SEM_VALUE_MAX   (~0U)
+
+#endif /* !_SYS_SEMAPHORE_H_ */



Home | Main Index | Thread Index | Old Index