Home | History | Annotate | Line # | Download | only in freebsd
freebsd_ipc.c revision 1.11.2.1
      1  1.11.2.1  christos /*	$NetBSD: freebsd_ipc.c,v 1.11.2.1 2005/12/11 10:28:46 christos Exp $	*/
      2       1.1   mycroft 
      3       1.1   mycroft /*
      4       1.3   mycroft  * Copyright (c) 1994 Adam Glass and Charles M. Hannum.  All rights reserved.
      5       1.1   mycroft  *
      6       1.1   mycroft  * Redistribution and use in source and binary forms, with or without
      7       1.1   mycroft  * modification, are permitted provided that the following conditions
      8       1.1   mycroft  * are met:
      9       1.1   mycroft  * 1. Redistributions of source code must retain the above copyright
     10       1.1   mycroft  *    notice, this list of conditions and the following disclaimer.
     11       1.1   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     12       1.1   mycroft  *    notice, this list of conditions and the following disclaimer in the
     13       1.1   mycroft  *    documentation and/or other materials provided with the distribution.
     14       1.1   mycroft  * 3. All advertising materials mentioning features or use of this software
     15       1.1   mycroft  *    must display the following acknowledgement:
     16       1.3   mycroft  *	This product includes software developed by Adam Glass and Charles M.
     17       1.1   mycroft  *	Hannum.
     18       1.1   mycroft  * 4. The names of the authors may not be used to endorse or promote products
     19       1.1   mycroft  *    derived from this software without specific prior written permission.
     20       1.1   mycroft  *
     21       1.1   mycroft  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
     22       1.1   mycroft  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23       1.1   mycroft  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24       1.1   mycroft  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     25       1.1   mycroft  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26       1.1   mycroft  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27       1.1   mycroft  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28       1.1   mycroft  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29       1.1   mycroft  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30       1.1   mycroft  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31       1.1   mycroft  */
     32      1.10     lukem 
     33      1.10     lukem #include <sys/cdefs.h>
     34  1.11.2.1  christos __KERNEL_RCSID(0, "$NetBSD: freebsd_ipc.c,v 1.11.2.1 2005/12/11 10:28:46 christos Exp $");
     35       1.4      tron 
     36       1.9       mrg #if defined(_KERNEL_OPT)
     37       1.4      tron #include "opt_sysv.h"
     38       1.8  jdolecek #endif
     39       1.1   mycroft 
     40       1.1   mycroft #include <sys/param.h>
     41       1.1   mycroft #include <sys/systm.h>
     42       1.1   mycroft #include <sys/kernel.h>
     43       1.1   mycroft #include <sys/proc.h>
     44       1.1   mycroft #include <sys/sem.h>
     45       1.1   mycroft #include <sys/malloc.h>
     46       1.1   mycroft 
     47       1.1   mycroft #include <sys/mount.h>
     48      1.11   thorpej #include <sys/sa.h>
     49       1.1   mycroft #include <sys/syscallargs.h>
     50       1.1   mycroft 
     51  1.11.2.1  christos #include <compat/sys/shm.h>
     52       1.1   mycroft #include <compat/freebsd/freebsd_syscallargs.h>
     53       1.1   mycroft 
     54       1.1   mycroft #ifdef SYSVSEM
     55       1.1   mycroft int
     56      1.11   thorpej freebsd_sys_semsys(l, v, retval)
     57      1.11   thorpej 	struct lwp *l;
     58       1.1   mycroft 	void *v;
     59       1.1   mycroft 	register_t *retval;
     60       1.1   mycroft {
     61       1.1   mycroft 	struct freebsd_sys_semsys_args /* {
     62       1.1   mycroft 		syscallarg(int) which;
     63       1.1   mycroft 		syscallarg(int) a2;
     64       1.1   mycroft 		syscallarg(int) a3;
     65       1.1   mycroft 		syscallarg(int) a4;
     66       1.1   mycroft 		syscallarg(int) a5;
     67       1.1   mycroft 	} */ *uap = v;
     68       1.5   thorpej 	struct compat_14_sys___semctl_args /* {
     69       1.1   mycroft 		syscallarg(int) semid;
     70       1.1   mycroft 		syscallarg(int) semnum;
     71       1.1   mycroft 		syscallarg(int) cmd;
     72       1.5   thorpej 		syscallarg(union __semun *) arg;
     73       1.1   mycroft 	} */ __semctl_args;
     74       1.1   mycroft 	struct sys_semget_args /* {
     75       1.1   mycroft 		syscallarg(key_t) key;
     76       1.1   mycroft 		syscallarg(int) nsems;
     77       1.1   mycroft 		syscallarg(int) semflg;
     78       1.1   mycroft 	} */ semget_args;
     79       1.1   mycroft 	struct sys_semop_args /* {
     80       1.1   mycroft 		syscallarg(int) semid;
     81       1.1   mycroft 		syscallarg(struct sembuf *) sops;
     82       1.1   mycroft 		syscallarg(u_int) nsops;
     83       1.1   mycroft 	} */ semop_args;
     84       1.1   mycroft 	struct sys_semconfig_args /* {
     85       1.1   mycroft 		syscallarg(int) flag;
     86       1.1   mycroft 	} */ semconfig_args;
     87       1.1   mycroft 
     88       1.1   mycroft 	switch (SCARG(uap, which)) {
     89       1.1   mycroft 	case 0:						/* __semctl() */
     90       1.1   mycroft 		SCARG(&__semctl_args, semid) = SCARG(uap, a2);
     91       1.1   mycroft 		SCARG(&__semctl_args, semnum) = SCARG(uap, a3);
     92       1.1   mycroft 		SCARG(&__semctl_args, cmd) = SCARG(uap, a4);
     93       1.5   thorpej 		SCARG(&__semctl_args, arg) = (union __semun *)SCARG(uap, a5);
     94      1.11   thorpej 		return (compat_14_sys___semctl(l, &__semctl_args, retval));
     95       1.1   mycroft 
     96       1.1   mycroft 	case 1:						/* semget() */
     97       1.1   mycroft 		SCARG(&semget_args, key) = SCARG(uap, a2);
     98       1.1   mycroft 		SCARG(&semget_args, nsems) = SCARG(uap, a3);
     99       1.1   mycroft 		SCARG(&semget_args, semflg) = SCARG(uap, a4);
    100      1.11   thorpej 		return (sys_semget(l, &semget_args, retval));
    101       1.1   mycroft 
    102       1.1   mycroft 	case 2:						/* semop() */
    103       1.1   mycroft 		SCARG(&semop_args, semid) = SCARG(uap, a2);
    104       1.1   mycroft 		SCARG(&semop_args, sops) = (struct sembuf *)SCARG(uap, a3);
    105       1.1   mycroft 		SCARG(&semop_args, nsops) = SCARG(uap, a4);
    106      1.11   thorpej 		return (sys_semop(l, &semop_args, retval));
    107       1.1   mycroft 
    108       1.1   mycroft 	case 3:						/* semconfig() */
    109       1.1   mycroft 		SCARG(&semconfig_args, flag) = SCARG(uap, a2);
    110      1.11   thorpej 		return (sys_semconfig(l, &semconfig_args, retval));
    111       1.1   mycroft 
    112       1.1   mycroft 	default:
    113       1.1   mycroft 		return (EINVAL);
    114       1.1   mycroft 	}
    115       1.1   mycroft }
    116       1.1   mycroft #endif
    117       1.1   mycroft 
    118       1.1   mycroft #ifdef SYSVSHM
    119       1.1   mycroft int
    120      1.11   thorpej freebsd_sys_shmsys(l, v, retval)
    121      1.11   thorpej 	struct lwp *l;
    122       1.1   mycroft 	void *v;
    123       1.1   mycroft 	register_t *retval;
    124       1.1   mycroft {
    125       1.1   mycroft 	struct freebsd_sys_shmsys_args /* {
    126       1.1   mycroft 		syscallarg(int) which;
    127       1.1   mycroft 		syscallarg(int) a2;
    128       1.1   mycroft 		syscallarg(int) a3;
    129       1.1   mycroft 		syscallarg(int) a4;
    130       1.1   mycroft 	} */ *uap = v;
    131       1.1   mycroft 	struct sys_shmat_args /* {
    132       1.1   mycroft 		syscallarg(int) shmid;
    133       1.1   mycroft 		syscallarg(void *) shmaddr;
    134       1.1   mycroft 		syscallarg(int) shmflg;
    135       1.1   mycroft 	} */ shmat_args;
    136       1.5   thorpej 	struct compat_14_sys_shmctl_args /* {
    137       1.1   mycroft 		syscallarg(int) shmid;
    138       1.1   mycroft 		syscallarg(int) cmd;
    139       1.5   thorpej 		syscallarg(struct shmid_ds14 *) buf;
    140       1.1   mycroft 	} */ shmctl_args;
    141       1.1   mycroft 	struct sys_shmdt_args /* {
    142       1.1   mycroft 		syscallarg(void *) shmaddr;
    143       1.1   mycroft 	} */ shmdt_args;
    144       1.1   mycroft 	struct sys_shmget_args /* {
    145       1.1   mycroft 		syscallarg(key_t) key;
    146       1.1   mycroft 		syscallarg(int) size;
    147       1.1   mycroft 		syscallarg(int) shmflg;
    148       1.1   mycroft 	} */ shmget_args;
    149       1.1   mycroft 
    150       1.1   mycroft 	switch (SCARG(uap, which)) {
    151       1.1   mycroft 	case 0:						/* shmat() */
    152       1.1   mycroft 		SCARG(&shmat_args, shmid) = SCARG(uap, a2);
    153       1.1   mycroft 		SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a3);
    154       1.1   mycroft 		SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
    155      1.11   thorpej 		return (sys_shmat(l, &shmat_args, retval));
    156       1.1   mycroft 
    157       1.1   mycroft 	case 1:						/* oshmctl() */
    158       1.1   mycroft 		/* XXX Need to translate shmid_ds format. */
    159       1.1   mycroft 		return (EINVAL);
    160       1.1   mycroft 
    161       1.1   mycroft 	case 2:						/* shmdt() */
    162       1.2   mycroft 		SCARG(&shmdt_args, shmaddr) = (void *)SCARG(uap, a2);
    163      1.11   thorpej 		return (sys_shmdt(l, &shmdt_args, retval));
    164       1.1   mycroft 
    165       1.1   mycroft 	case 3:						/* shmget() */
    166       1.1   mycroft 		SCARG(&shmget_args, key) = SCARG(uap, a2);
    167       1.1   mycroft 		SCARG(&shmget_args, size) = SCARG(uap, a3);
    168       1.1   mycroft 		SCARG(&shmget_args, shmflg) = SCARG(uap, a4);
    169      1.11   thorpej 		return (sys_shmget(l, &shmget_args, retval));
    170       1.1   mycroft 
    171       1.1   mycroft 	case 4:						/* shmctl() */
    172       1.1   mycroft 		SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
    173       1.1   mycroft 		SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
    174       1.5   thorpej 		SCARG(&shmctl_args, buf) = (struct shmid_ds14 *)SCARG(uap, a4);
    175      1.11   thorpej 		return (compat_14_sys_shmctl(l, &shmctl_args, retval));
    176       1.1   mycroft 
    177       1.1   mycroft 	default:
    178       1.1   mycroft 		return (EINVAL);
    179       1.1   mycroft 	}
    180       1.1   mycroft }
    181       1.1   mycroft #endif
    182       1.1   mycroft 
    183       1.1   mycroft #ifdef SYSVMSG
    184       1.1   mycroft int
    185      1.11   thorpej freebsd_sys_msgsys(l, v, retval)
    186      1.11   thorpej 	struct lwp *l;
    187       1.1   mycroft 	void *v;
    188       1.1   mycroft 	register_t *retval;
    189       1.1   mycroft {
    190       1.1   mycroft 	struct freebsd_sys_msgsys_args /* {
    191       1.1   mycroft 		syscallarg(int) which;
    192       1.1   mycroft 		syscallarg(int) a2;
    193       1.1   mycroft 		syscallarg(int) a3;
    194       1.1   mycroft 		syscallarg(int) a4;
    195       1.1   mycroft 		syscallarg(int) a5;
    196       1.1   mycroft 		syscallarg(int) a6;
    197       1.1   mycroft 	} */ *uap = v;
    198       1.5   thorpej 	struct compat_14_sys_msgctl_args /* {
    199       1.1   mycroft 		syscallarg(int) msqid;
    200       1.1   mycroft 		syscallarg(int) cmd;
    201       1.5   thorpej 		syscallarg(struct msqid_ds14 *) buf;
    202       1.1   mycroft 	} */ msgctl_args;
    203       1.1   mycroft 	struct sys_msgget_args /* {
    204       1.1   mycroft 		syscallarg(key_t) key;
    205       1.1   mycroft 		syscallarg(int) msgflg;
    206       1.1   mycroft 	} */ msgget_args;
    207       1.1   mycroft 	struct sys_msgsnd_args /* {
    208       1.1   mycroft 		syscallarg(int) msqid;
    209       1.1   mycroft 		syscallarg(void *) msgp;
    210       1.1   mycroft 		syscallarg(size_t) msgsz;
    211       1.1   mycroft 		syscallarg(int) msgflg;
    212       1.1   mycroft 	} */ msgsnd_args;
    213       1.1   mycroft 	struct sys_msgrcv_args /* {
    214       1.1   mycroft 		syscallarg(int) msqid;
    215       1.1   mycroft 		syscallarg(void *) msgp;
    216       1.1   mycroft 		syscallarg(size_t) msgsz;
    217       1.1   mycroft 		syscallarg(long) msgtyp;
    218       1.1   mycroft 		syscallarg(int) msgflg;
    219       1.1   mycroft 	} */ msgrcv_args;
    220       1.1   mycroft 
    221       1.1   mycroft 	switch (SCARG(uap, which)) {
    222       1.1   mycroft 	case 0:					/* msgctl()*/
    223       1.1   mycroft 		SCARG(&msgctl_args, msqid) = SCARG(uap, a2);
    224       1.1   mycroft 		SCARG(&msgctl_args, cmd) = SCARG(uap, a3);
    225       1.1   mycroft 		SCARG(&msgctl_args, buf) =
    226       1.5   thorpej 		    (struct msqid_ds14 *)SCARG(uap, a4);
    227      1.11   thorpej 		return (compat_14_sys_msgctl(l, &msgctl_args, retval));
    228       1.1   mycroft 
    229       1.1   mycroft 	case 1:					/* msgget() */
    230       1.1   mycroft 		SCARG(&msgget_args, key) = SCARG(uap, a2);
    231       1.1   mycroft 		SCARG(&msgget_args, msgflg) = SCARG(uap, a3);
    232      1.11   thorpej 		return (sys_msgget(l, &msgget_args, retval));
    233       1.1   mycroft 
    234       1.1   mycroft 	case 2:					/* msgsnd() */
    235       1.1   mycroft 		SCARG(&msgsnd_args, msqid) = SCARG(uap, a2);
    236       1.1   mycroft 		SCARG(&msgsnd_args, msgp) = (void *)SCARG(uap, a3);
    237       1.1   mycroft 		SCARG(&msgsnd_args, msgsz) = SCARG(uap, a4);
    238       1.1   mycroft 		SCARG(&msgsnd_args, msgflg) = SCARG(uap, a5);
    239      1.11   thorpej 		return (sys_msgsnd(l, &msgsnd_args, retval));
    240       1.1   mycroft 
    241       1.1   mycroft 	case 3:					/* msgrcv() */
    242       1.1   mycroft 		SCARG(&msgrcv_args, msqid) = SCARG(uap, a2);
    243       1.1   mycroft 		SCARG(&msgrcv_args, msgp) = (void *)SCARG(uap, a3);
    244       1.1   mycroft 		SCARG(&msgrcv_args, msgsz) = SCARG(uap, a4);
    245       1.1   mycroft 		SCARG(&msgrcv_args, msgtyp) = SCARG(uap, a5);
    246       1.1   mycroft 		SCARG(&msgrcv_args, msgflg) = SCARG(uap, a6);
    247      1.11   thorpej 		return (sys_msgrcv(l, &msgrcv_args, retval));
    248       1.1   mycroft 
    249       1.1   mycroft 	default:
    250       1.1   mycroft 		return (EINVAL);
    251       1.1   mycroft 	}
    252       1.1   mycroft }
    253       1.1   mycroft #endif
    254