Source-Changes-HG archive

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

[src/trunk]: src/sys Overhaul of the SVID IPC facilities, primarily to use th...



details:   https://anonhg.NetBSD.org/src/rev/dcf4f0d41aff
branches:  trunk
changeset: 475768:dcf4f0d41aff
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Wed Aug 25 05:05:48 1999 +0000

description:
Overhaul of the SVID IPC facilities, primarily to use the types specified
by the Single UNIX Specification version 2, rather than the SVR2-derived
types.  While I was here, I did a namespace sweep to expose the constants
and strucutures, and structure members described by SUSv2; documentation
updates coming shortly.

Fixes kern/8158.

diffstat:

 sys/kern/kern_allocsys.c |    6 +-
 sys/kern/syscalls.master |   38 +++-
 sys/kern/sysv_msg.c      |  418 ++++++++++++++++++++++++++--------------------
 sys/kern/sysv_sem.c      |  280 ++++++++++++++++++------------
 sys/kern/sysv_shm.c      |  117 +++++++++---
 sys/sys/ipc.h            |   35 +++-
 sys/sys/msg.h            |  138 ++++++++++-----
 sys/sys/sem.h            |   99 ++++++++--
 sys/sys/shm.h            |   79 +++++++-
 sys/sys/types.h          |   15 +-
 10 files changed, 803 insertions(+), 422 deletions(-)

diffs (truncated from 2197 to 300 lines):

diff -r 340fe5ff53a8 -r dcf4f0d41aff sys/kern/kern_allocsys.c
--- a/sys/kern/kern_allocsys.c  Wed Aug 25 04:55:53 1999 +0000
+++ b/sys/kern/kern_allocsys.c  Wed Aug 25 05:05:48 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_allocsys.c,v 1.4 1999/06/01 00:40:48 lukem Exp $  */
+/*     $NetBSD: kern_allocsys.c,v 1.5 1999/08/25 05:05:48 thorpej Exp $        */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -139,14 +139,14 @@
 #endif
 #ifdef SYSVSEM
        ALLOCSYS(v, sema, struct semid_ds, seminfo.semmni);
-       ALLOCSYS(v, sem, struct sem, seminfo.semmns);
+       ALLOCSYS(v, sem, struct __sem, seminfo.semmns);
        /* This is pretty disgusting! */
        ALLOCSYS(v, semu, int, (seminfo.semmnu * seminfo.semusz) / sizeof(int));
 #endif
 #ifdef SYSVMSG
        ALLOCSYS(v, msgpool, char, msginfo.msgmax);
        ALLOCSYS(v, msgmaps, struct msgmap, msginfo.msgseg);
-       ALLOCSYS(v, msghdrs, struct msg, msginfo.msgtql);
+       ALLOCSYS(v, msghdrs, struct __msg, msginfo.msgtql);
        ALLOCSYS(v, msqids, struct msqid_ds, msginfo.msgmni);
 #endif
 
diff -r 340fe5ff53a8 -r dcf4f0d41aff sys/kern/syscalls.master
--- a/sys/kern/syscalls.master  Wed Aug 25 04:55:53 1999 +0000
+++ b/sys/kern/syscalls.master  Wed Aug 25 05:05:48 1999 +0000
@@ -1,4 +1,4 @@
-       $NetBSD: syscalls.master,v 1.96 1999/07/12 23:01:27 thorpej Exp $
+       $NetBSD: syscalls.master,v 1.97 1999/08/25 05:05:48 thorpej Exp $
 
 ;      @(#)syscalls.master     8.2 (Berkeley) 1/13/94
 
@@ -426,28 +426,28 @@
 #endif /* !LKM */
 ; System calls 220-300 are reserved for use by NetBSD
 #if defined(SYSVSEM) || !defined(_KERNEL)
-220    STD             { int sys___semctl(int semid, int semnum, int cmd, \
-                           union semun *arg); }
+220    COMPAT_14       { int sys___semctl(int semid, int semnum, int cmd, \
+                           union __semun *arg); }
 221    STD             { int sys_semget(key_t key, int nsems, int semflg); }
 222    STD             { int sys_semop(int semid, struct sembuf *sops, \
                            size_t nsops); }
 223    STD             { int sys_semconfig(int flag); }
 #else
-220    EXCL            semctl
+220    EXCL            compat_14_semctl
 221    EXCL            semget
 222    EXCL            semop
 223    EXCL            semconfig
 #endif
 #if defined(SYSVMSG) || !defined(_KERNEL)
-224    STD             { int sys_msgctl(int msqid, int cmd, \
-                           struct msqid_ds *buf); }
+224    COMPAT_14       { int sys_msgctl(int msqid, int cmd, \
+                           struct msqid_ds14 *buf); }
 225    STD             { int sys_msgget(key_t key, int msgflg); }
 226    STD             { int sys_msgsnd(int msqid, const void *msgp, \
                            size_t msgsz, int msgflg); }
 227    STD             { ssize_t sys_msgrcv(int msqid, void *msgp, \
                            size_t msgsz, long msgtyp, int msgflg); }
 #else
-224    EXCL            msgctl
+224    EXCL            compat_14_msgctl
 225    EXCL            msgget
 226    EXCL            msgsnd
 227    EXCL            msgrcv
@@ -455,13 +455,13 @@
 #if defined(SYSVSHM) || !defined(_KERNEL)
 228    STD             { void *sys_shmat(int shmid, const void *shmaddr, \
                            int shmflg); }
-229    STD             { int sys_shmctl(int shmid, int cmd, \
-                           struct shmid_ds *buf); }
+229    COMPAT_14       { int sys_shmctl(int shmid, int cmd, \
+                           struct shmid_ds14 *buf); }
 230    STD             { int sys_shmdt(const void *shmaddr); }
 231    STD             { int sys_shmget(key_t key, size_t size, int shmflg); }
 #else
 228    EXCL            shmat
-229    EXCL            shmctl
+229    EXCL            compat_14_shmctl
 230    EXCL            shmdt
 231    EXCL            shmget
 #endif
@@ -565,3 +565,21 @@
                            struct stat *sb); }
 300    STD             { int sys_fhstatfs(const fhandle_t *fhp, \
                            struct statfs *buf); }
+#if defined(SYSVSEM) || !defined(_KERNEL)
+301    STD             { int sys___semctl13(int semid, int semnum, int cmd, \
+                           union __semun arg); }
+#else
+301    EXCL            __semctl13
+#endif
+#if defined(SYSVMSG) || !defined(_KERNEL)
+302    STD             { int sys___msgctl13(int msqid, int cmd, \
+                           struct msqid_ds *buf); }
+#else
+302    EXCL            __msgctl13
+#endif
+#if defined(SYSVSHM) || !defined(_KERNEL)
+303    STD             { int sys___shmctl13(int shmid, int cmd, \
+                           struct shmid_ds *buf); }
+#else
+303    EXCL            __shmctl13
+#endif
diff -r 340fe5ff53a8 -r dcf4f0d41aff sys/kern/sysv_msg.c
--- a/sys/kern/sysv_msg.c       Wed Aug 25 04:55:53 1999 +0000
+++ b/sys/kern/sysv_msg.c       Wed Aug 25 05:05:48 1999 +0000
@@ -1,9 +1,46 @@
-/*     $NetBSD: sysv_msg.c,v 1.25 1999/04/21 02:31:50 mrg Exp $        */
+/*     $NetBSD: sysv_msg.c,v 1.26 1999/08/25 05:05:49 thorpej Exp $    */
+
+/*-
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
+ * NASA Ames Research Center.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the NetBSD
+ *     Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * 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.
+ */
 
 /*
  * Implementation of SVID messages
  *
- * Author:  Daniel Boulet
+ * Author: Daniel Boulet
  *
  * Copyright 1993 Daniel Boulet and RTMX Inc.
  *
@@ -42,9 +79,9 @@
 
 int nfree_msgmaps;             /* # of free map entries */
 short free_msgmaps;            /* head of linked list of free map entries */
-struct msg *free_msghdrs;      /* list of free msg headers */
+struct __msg *free_msghdrs;    /* list of free msg headers */
 
-static void msg_freehdr __P((struct msg *));
+static void msg_freehdr __P((struct __msg *));
 
 void
 msginit()
@@ -98,13 +135,13 @@
 
        for (i = 0; i < msginfo.msgmni; i++) {
                msqids[i].msg_qbytes = 0;       /* implies entry is available */
-               msqids[i].msg_perm.seq = 0;     /* reset to a known value */
+               msqids[i].msg_perm._seq = 0;    /* reset to a known value */
        }
 }
 
 static void
 msg_freehdr(msghdr)
-       struct msg *msghdr;
+       struct __msg *msghdr;
 {
        while (msghdr->msg_ts > 0) {
                short next;
@@ -127,121 +164,135 @@
 }
 
 int
-sys_msgctl(p, v, retval)
+sys___msgctl13(p, v, retval)
        struct proc *p;
        void *v;
        register_t *retval;
 {
-       register struct sys_msgctl_args /* {
+       struct sys___msgctl13_args /* {
                syscallarg(int) msqid;
                syscallarg(int) cmd;
                syscallarg(struct msqid_ds *) buf;
        } */ *uap = v;
-       int msqid = SCARG(uap, msqid);
-       int cmd = SCARG(uap, cmd);
-       struct msqid_ds *user_msqptr = SCARG(uap, buf);
-       struct ucred *cred = p->p_ucred;
-       int rval, eval;
        struct msqid_ds msqbuf;
-       register struct msqid_ds *msqptr;
+       int cmd, error;
+
+       cmd = SCARG(uap, cmd);
 
-       MSG_PRINTF(("call to msgctl(%d, %d, %p)\n", msqid, cmd, user_msqptr));
-
-       msqid = IPCID_TO_IX(msqid);
-
-       if (msqid < 0 || msqid >= msginfo.msgmni) {
-               MSG_PRINTF(("msqid (%d) out of range (0<=msqid<%d)\n", msqid,
-                   msginfo.msgmni));
-               return(EINVAL);
+       if (cmd == IPC_SET) {
+               error = copyin(SCARG(uap, buf), &msqbuf, sizeof(msqbuf));
+               if (error)
+                       return (error);
        }
 
-       msqptr = &msqids[msqid];
+       error = msgctl1(p, SCARG(uap, msqid), cmd,
+           (cmd == IPC_SET || cmd == IPC_STAT) ? &msqbuf : NULL);
+
+       if (error == 0 && cmd == IPC_STAT)
+               error = copyout(&msqbuf, SCARG(uap, buf), sizeof(msqbuf));
+
+       return (error);
+}
+
+int
+msgctl1(p, msqid, cmd, msqbuf)
+       struct proc *p;
+       int msqid;
+       int cmd;
+       struct msqid_ds *msqbuf;
+{
+       struct ucred *cred = p->p_ucred;
+       struct msqid_ds *msqptr;
+       int error = 0, ix;
+
+       MSG_PRINTF(("call to msgctl1(%d, %d)\n", msqid, cmd));
+
+       ix = IPCID_TO_IX(msqid);
+
+       if (ix < 0 || ix >= msginfo.msgmni) {
+               MSG_PRINTF(("msqid (%d) out of range (0<=msqid<%d)\n", ix,
+                   msginfo.msgmni));
+               return (EINVAL);
+       }
+
+       msqptr = &msqids[ix];
 
        if (msqptr->msg_qbytes == 0) {
                MSG_PRINTF(("no such msqid\n"));
-               return(EINVAL);
+               return (EINVAL);
        }
-       if (msqptr->msg_perm.seq != IPCID_TO_SEQ(SCARG(uap, msqid))) {
+       if (msqptr->msg_perm._seq != IPCID_TO_SEQ(msqid)) {
                MSG_PRINTF(("wrong sequence number\n"));
-               return(EINVAL);
+               return (EINVAL);
        }
 
-       eval = 0;
-       rval = 0;
-
        switch (cmd) {
-
        case IPC_RMID:
        {
-               struct msg *msghdr;
-               if ((eval = ipcperm(cred, &msqptr->msg_perm, IPC_M)) != 0)
-                       return(eval);
+               struct __msg *msghdr;
+               if ((error = ipcperm(cred, &msqptr->msg_perm, IPC_M)) != 0)
+                       return (error);
                /* Free the message headers */
-               msghdr = msqptr->msg_first;
+               msghdr = msqptr->_msg_first;
                while (msghdr != NULL) {
-                       struct msg *msghdr_tmp;
+                       struct __msg *msghdr_tmp;
 
                        /* Free the segments of each message */
-                       msqptr->msg_cbytes -= msghdr->msg_ts;
+                       msqptr->_msg_cbytes -= msghdr->msg_ts;
                        msqptr->msg_qnum--;
                        msghdr_tmp = msghdr;



Home | Main Index | Thread Index | Old Index