svr4_ipc.c revision 160187
143412Snewton/*- 243412Snewton * Copyright (c) 1995 The NetBSD Foundation, Inc. 343412Snewton * All rights reserved. 443412Snewton * 543412Snewton * This code is derived from software contributed to The NetBSD Foundation 643412Snewton * by Christos Zoulas. 743412Snewton * 843412Snewton * Redistribution and use in source and binary forms, with or without 943412Snewton * modification, are permitted provided that the following conditions 1043412Snewton * are met: 1143412Snewton * 1. Redistributions of source code must retain the above copyright 1243412Snewton * notice, this list of conditions and the following disclaimer. 1343412Snewton * 2. Redistributions in binary form must reproduce the above copyright 1443412Snewton * notice, this list of conditions and the following disclaimer in the 1543412Snewton * documentation and/or other materials provided with the distribution. 1643412Snewton * 3. All advertising materials mentioning features or use of this software 1743412Snewton * must display the following acknowledgement: 1843412Snewton * This product includes software developed by the NetBSD 1943412Snewton * Foundation, Inc. and its contributors. 2043412Snewton * 4. Neither the name of The NetBSD Foundation nor the names of its 2143412Snewton * contributors may be used to endorse or promote products derived 2243412Snewton * from this software without specific prior written permission. 2343412Snewton * 2443412Snewton * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2543412Snewton * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2643412Snewton * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2743412Snewton * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2843412Snewton * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2943412Snewton * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3043412Snewton * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3143412Snewton * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3243412Snewton * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3343412Snewton * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3443412Snewton * POSSIBILITY OF SUCH DAMAGE. 3543412Snewton */ 36139743Simp/*- 3743412Snewton * Portions of this code have been derived from software contributed 3843412Snewton * to the FreeBSD Project by Mark Newton. 3943412Snewton * 4043412Snewton * Copyright (c) 1999 Mark Newton 4143412Snewton * All rights reserved. 4243412Snewton * 4343412Snewton * Redistribution and use in source and binary forms, with or without 4443412Snewton * modification, are permitted provided that the following conditions 4543412Snewton * are met: 4643412Snewton * 1. Redistributions of source code must retain the above copyright 4743412Snewton * notice, this list of conditions and the following disclaimer. 4843412Snewton * 2. Redistributions in binary form must reproduce the above copyright 4943412Snewton * notice, this list of conditions and the following disclaimer in the 5043412Snewton * documentation and/or other materials provided with the distribution. 5143412Snewton * 3. The name of the author may not be used to endorse or promote products 5243412Snewton * derived from this software without specific prior written permission 5343412Snewton * 5443412Snewton * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 5543412Snewton * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 5643412Snewton * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 5743412Snewton * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 5843412Snewton * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 5943412Snewton * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 6043412Snewton * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 6143412Snewton * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 6243412Snewton * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 6343412Snewton * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 6443412Snewton * 6543412Snewton * XXX- This code is presently a no-op on FreeBSD (and isn't compiled due 6643412Snewton * to preprocessor conditionals). A nice project for a kernel hacking 6743412Snewton * novice might be to MakeItGo, but I have more important fish to fry 6843412Snewton * at present. 6943412Snewton * 70116174Sobrien * Derived from: $NetBSD: svr4_ipc.c,v 1.7 1998/10/19 22:43:00 tron Exp $ 7143412Snewton */ 7243412Snewton 73116174Sobrien#include <sys/cdefs.h> 74116174Sobrien__FBSDID("$FreeBSD: head/sys/compat/svr4/svr4_ipc.c 160187 2006-07-08 19:51:38Z jhb $"); 75116174Sobrien 76147817Sjhb#include "opt_sysvipc.h" 77147817Sjhb 7843412Snewton#include <sys/param.h> 79147817Sjhb#include <sys/ipc.h> 80147817Sjhb#include <sys/msg.h> 8143412Snewton#include <sys/proc.h> 82147817Sjhb#include <sys/sem.h> 83147817Sjhb#include <sys/shm.h> 84147817Sjhb#include <sys/syscallsubr.h> 85147817Sjhb#include <sys/sysproto.h> 86147817Sjhb#include <sys/systm.h> 8743412Snewton#include <sys/time.h> 8843412Snewton 8965302Sobrien#include <compat/svr4/svr4.h> 9065302Sobrien#include <compat/svr4/svr4_types.h> 9165302Sobrien#include <compat/svr4/svr4_signal.h> 9265302Sobrien#include <compat/svr4/svr4_proto.h> 9365302Sobrien#include <compat/svr4/svr4_util.h> 9465302Sobrien#include <compat/svr4/svr4_ipc.h> 9543412Snewton 9643412Snewton#if defined(SYSVMSG) || defined(SYSVSHM) || defined(SYSVSEM) 9792761Salfredstatic void svr4_to_bsd_ipc_perm(const struct svr4_ipc_perm *, 9892761Salfred struct ipc_perm *); 9992761Salfredstatic void bsd_to_svr4_ipc_perm(const struct ipc_perm *, 10092761Salfred struct svr4_ipc_perm *); 10143412Snewton#endif 10243412Snewton 10343412Snewton#ifdef SYSVSEM 10492761Salfredstatic void bsd_to_svr4_semid_ds(const struct semid_ds *, 10592761Salfred struct svr4_semid_ds *); 10692761Salfredstatic void svr4_to_bsd_semid_ds(const struct svr4_semid_ds *, 10792761Salfred struct semid_ds *); 108147817Sjhbstatic int svr4_semop(struct thread *, void *); 109147817Sjhbstatic int svr4_semget(struct thread *, void *); 110147817Sjhbstatic int svr4_semctl(struct thread *, void *); 11143412Snewton#endif 11243412Snewton 11343412Snewton#ifdef SYSVMSG 11492761Salfredstatic void bsd_to_svr4_msqid_ds(const struct msqid_ds *, 11592761Salfred struct svr4_msqid_ds *); 11692761Salfredstatic void svr4_to_bsd_msqid_ds(const struct svr4_msqid_ds *, 11792761Salfred struct msqid_ds *); 118147817Sjhbstatic int svr4_msgsnd(struct thread *, void *); 119147817Sjhbstatic int svr4_msgrcv(struct thread *, void *); 120147817Sjhbstatic int svr4_msgget(struct thread *, void *); 121147817Sjhbstatic int svr4_msgctl(struct thread *, void *); 12243412Snewton#endif 12343412Snewton 12443412Snewton#ifdef SYSVSHM 12592761Salfredstatic void bsd_to_svr4_shmid_ds(const struct shmid_ds *, 12692761Salfred struct svr4_shmid_ds *); 12792761Salfredstatic void svr4_to_bsd_shmid_ds(const struct svr4_shmid_ds *, 12892761Salfred struct shmid_ds *); 129147817Sjhbstatic int svr4_shmat(struct thread *, void *); 130147817Sjhbstatic int svr4_shmdt(struct thread *, void *); 131147817Sjhbstatic int svr4_shmget(struct thread *, void *); 132147817Sjhbstatic int svr4_shmctl(struct thread *, void *); 13343412Snewton#endif 13443412Snewton 13543412Snewton#if defined(SYSVMSG) || defined(SYSVSHM) || defined(SYSVSEM) 13643412Snewton 13743412Snewtonstatic void 13843412Snewtonsvr4_to_bsd_ipc_perm(spp, bpp) 13943412Snewton const struct svr4_ipc_perm *spp; 14043412Snewton struct ipc_perm *bpp; 14143412Snewton{ 14243412Snewton bpp->key = spp->key; 14343412Snewton bpp->uid = spp->uid; 14443412Snewton bpp->gid = spp->gid; 14543412Snewton bpp->cuid = spp->cuid; 14643412Snewton bpp->cgid = spp->cgid; 14743412Snewton bpp->mode = spp->mode; 14843412Snewton bpp->seq = spp->seq; 14943412Snewton} 15043412Snewton 15143412Snewtonstatic void 15243412Snewtonbsd_to_svr4_ipc_perm(bpp, spp) 15343412Snewton const struct ipc_perm *bpp; 15443412Snewton struct svr4_ipc_perm *spp; 15543412Snewton{ 15643412Snewton spp->key = bpp->key; 15743412Snewton spp->uid = bpp->uid; 15843412Snewton spp->gid = bpp->gid; 15943412Snewton spp->cuid = bpp->cuid; 16043412Snewton spp->cgid = bpp->cgid; 16143412Snewton spp->mode = bpp->mode; 16243412Snewton spp->seq = bpp->seq; 16343412Snewton} 16443412Snewton#endif 16543412Snewton 16643412Snewton#ifdef SYSVSEM 16743412Snewtonstatic void 16843412Snewtonbsd_to_svr4_semid_ds(bds, sds) 16943412Snewton const struct semid_ds *bds; 17043412Snewton struct svr4_semid_ds *sds; 17143412Snewton{ 17243412Snewton bsd_to_svr4_ipc_perm(&bds->sem_perm, &sds->sem_perm); 17343412Snewton sds->sem_base = (struct svr4_sem *) bds->sem_base; 17443412Snewton sds->sem_nsems = bds->sem_nsems; 17543412Snewton sds->sem_otime = bds->sem_otime; 17643412Snewton sds->sem_pad1 = bds->sem_pad1; 17743412Snewton sds->sem_ctime = bds->sem_ctime; 17843412Snewton sds->sem_pad2 = bds->sem_pad2; 17943412Snewton} 18043412Snewton 18143412Snewtonstatic void 18243412Snewtonsvr4_to_bsd_semid_ds(sds, bds) 18343412Snewton const struct svr4_semid_ds *sds; 18443412Snewton struct semid_ds *bds; 18543412Snewton{ 18643412Snewton svr4_to_bsd_ipc_perm(&sds->sem_perm, &bds->sem_perm); 18743412Snewton bds->sem_base = (struct sem *) bds->sem_base; 18843412Snewton bds->sem_nsems = sds->sem_nsems; 18943412Snewton bds->sem_otime = sds->sem_otime; 19043412Snewton bds->sem_pad1 = sds->sem_pad1; 19143412Snewton bds->sem_ctime = sds->sem_ctime; 19243412Snewton bds->sem_pad2 = sds->sem_pad2; 19343412Snewton} 19443412Snewton 19543412Snewtonstruct svr4_sys_semctl_args { 196147817Sjhb int what; 197147817Sjhb int semid; 198147817Sjhb int semnum; 199147817Sjhb int cmd; 200147817Sjhb union semun arg; 20143412Snewton}; 20243412Snewton 20343412Snewtonstatic int 204147817Sjhbsvr4_semctl(td, v) 205147817Sjhb struct thread *td; 20643412Snewton void *v; 20743412Snewton{ 20843412Snewton struct svr4_sys_semctl_args *uap = v; 20943412Snewton struct svr4_semid_ds ss; 210159991Sjhb struct semid_ds bs; 211159991Sjhb union semun semun; 212160187Sjhb register_t rval; 213159991Sjhb int cmd, error; 21443412Snewton 215107849Salfred switch (uap->cmd) { 21643412Snewton case SVR4_SEM_GETZCNT: 217159991Sjhb cmd = GETZCNT; 218159991Sjhb break; 219159991Sjhb 22043412Snewton case SVR4_SEM_GETNCNT: 221159991Sjhb cmd = GETNCNT; 222159991Sjhb break; 223159991Sjhb 22443412Snewton case SVR4_SEM_GETPID: 225159991Sjhb cmd = GETPID; 226159991Sjhb break; 227159991Sjhb 22843412Snewton case SVR4_SEM_GETVAL: 229159991Sjhb cmd = GETVAL; 230159991Sjhb break; 23143412Snewton 23243412Snewton case SVR4_SEM_SETVAL: 233159991Sjhb cmd = SETVAL; 234159991Sjhb break; 23543412Snewton 23643412Snewton case SVR4_SEM_GETALL: 237159991Sjhb cmd = GETVAL; 238159991Sjhb break; 23943412Snewton 24043412Snewton case SVR4_SEM_SETALL: 241159991Sjhb cmd = SETVAL; 242159991Sjhb break; 24343412Snewton 24443412Snewton case SVR4_IPC_STAT: 245159991Sjhb cmd = IPC_STAT; 246159991Sjhb semun.buf = &bs; 247159991Sjhb error = kern_semctl(td, uap->semid, uap->semnum, cmd, &semun, 248160187Sjhb &rval); 24943412Snewton if (error) 250160187Sjhb return (error); 25143412Snewton bsd_to_svr4_semid_ds(&bs, &ss); 252160187Sjhb error = copyout(&ss, uap->arg.buf, sizeof(ss)); 253160187Sjhb if (error == 0) 254160187Sjhb td->td_retval[0] = rval; 255160187Sjhb return (error); 25643412Snewton 25743412Snewton case SVR4_IPC_SET: 258159991Sjhb cmd = IPC_SET; 259107849Salfred error = copyin(uap->arg.buf, (caddr_t) &ss, sizeof ss); 26043412Snewton if (error) 261160187Sjhb return (error); 26243412Snewton svr4_to_bsd_semid_ds(&ss, &bs); 263159991Sjhb semun.buf = &bs; 264160187Sjhb return (kern_semctl(td, uap->semid, uap->semnum, cmd, &semun, 265160187Sjhb td->td_retval)); 26643412Snewton 26743412Snewton case SVR4_IPC_RMID: 268159991Sjhb cmd = IPC_RMID; 269159991Sjhb break; 27043412Snewton 27143412Snewton default: 27243412Snewton return EINVAL; 27343412Snewton } 274159991Sjhb 275160187Sjhb return (kern_semctl(td, uap->semid, uap->semnum, cmd, &uap->arg, 276160187Sjhb td->td_retval)); 27743412Snewton} 27843412Snewton 27943412Snewtonstruct svr4_sys_semget_args { 280147817Sjhb int what; 281147817Sjhb svr4_key_t key; 282147817Sjhb int nsems; 283147817Sjhb int semflg; 28443412Snewton}; 28543412Snewton 28643412Snewtonstatic int 287147817Sjhbsvr4_semget(td, v) 288147817Sjhb struct thread *td; 28943412Snewton void *v; 29043412Snewton{ 29143412Snewton struct svr4_sys_semget_args *uap = v; 292147817Sjhb struct semget_args ap; 29343412Snewton 294107849Salfred ap.key = uap->key; 295107849Salfred ap.nsems = uap->nsems; 296107849Salfred ap.semflg = uap->semflg; 29743412Snewton 298147817Sjhb return semget(td, &ap); 29943412Snewton} 30043412Snewton 30143412Snewtonstruct svr4_sys_semop_args { 302147817Sjhb int what; 303147817Sjhb int semid; 304147817Sjhb struct svr4_sembuf * sops; 305147817Sjhb u_int nsops; 30643412Snewton}; 30743412Snewton 30843412Snewtonstatic int 309147817Sjhbsvr4_semop(td, v) 310147817Sjhb struct thread *td; 31143412Snewton void *v; 31243412Snewton{ 31343412Snewton struct svr4_sys_semop_args *uap = v; 314147817Sjhb struct semop_args ap; 31543412Snewton 316107849Salfred ap.semid = uap->semid; 31743412Snewton /* These are the same */ 318107849Salfred ap.sops = (struct sembuf *) uap->sops; 319107849Salfred ap.nsops = uap->nsops; 32043412Snewton 321147817Sjhb return semop(td, &ap); 32243412Snewton} 32343412Snewton 32443412Snewtonint 325147817Sjhbsvr4_sys_semsys(td, uap) 326147817Sjhb struct thread *td; 327147817Sjhb struct svr4_sys_semsys_args *uap; 32843412Snewton{ 32943412Snewton 330107849Salfred DPRINTF(("svr4_semsys(%d)\n", uap->what)); 33143412Snewton 332107849Salfred switch (uap->what) { 33343412Snewton case SVR4_semctl: 334147817Sjhb return svr4_semctl(td, uap); 33543412Snewton case SVR4_semget: 336147817Sjhb return svr4_semget(td, uap); 33743412Snewton case SVR4_semop: 338147817Sjhb return svr4_semop(td, uap); 33943412Snewton default: 34043412Snewton return EINVAL; 34143412Snewton } 34243412Snewton} 343148541Sjhb 344148541SjhbMODULE_DEPEND(svr4elf, sysvsem, 1, 1, 1); 34543412Snewton#endif 34643412Snewton 34743412Snewton#ifdef SYSVMSG 34843412Snewtonstatic void 34943412Snewtonbsd_to_svr4_msqid_ds(bds, sds) 35043412Snewton const struct msqid_ds *bds; 35143412Snewton struct svr4_msqid_ds *sds; 35243412Snewton{ 35343412Snewton bsd_to_svr4_ipc_perm(&bds->msg_perm, &sds->msg_perm); 35443412Snewton sds->msg_first = (struct svr4_msg *) bds->msg_first; 35543412Snewton sds->msg_last = (struct svr4_msg *) bds->msg_last; 35643412Snewton sds->msg_cbytes = bds->msg_cbytes; 35743412Snewton sds->msg_qnum = bds->msg_qnum; 35843412Snewton sds->msg_qbytes = bds->msg_qbytes; 35943412Snewton sds->msg_lspid = bds->msg_lspid; 36043412Snewton sds->msg_lrpid = bds->msg_lrpid; 36143412Snewton sds->msg_stime = bds->msg_stime; 36243412Snewton sds->msg_pad1 = bds->msg_pad1; 36343412Snewton sds->msg_rtime = bds->msg_rtime; 36443412Snewton sds->msg_pad2 = bds->msg_pad2; 36543412Snewton sds->msg_ctime = bds->msg_ctime; 36643412Snewton sds->msg_pad3 = bds->msg_pad3; 36743412Snewton 36843412Snewton /* use the padding for the rest of the fields */ 36943412Snewton { 37043412Snewton const short *pad = (const short *) bds->msg_pad4; 37143412Snewton sds->msg_cv = pad[0]; 37243412Snewton sds->msg_qnum_cv = pad[1]; 37343412Snewton } 37443412Snewton} 37543412Snewton 37643412Snewtonstatic void 37743412Snewtonsvr4_to_bsd_msqid_ds(sds, bds) 37843412Snewton const struct svr4_msqid_ds *sds; 37943412Snewton struct msqid_ds *bds; 38043412Snewton{ 38143412Snewton svr4_to_bsd_ipc_perm(&sds->msg_perm, &bds->msg_perm); 38243412Snewton bds->msg_first = (struct msg *) sds->msg_first; 38343412Snewton bds->msg_last = (struct msg *) sds->msg_last; 38443412Snewton bds->msg_cbytes = sds->msg_cbytes; 38543412Snewton bds->msg_qnum = sds->msg_qnum; 38643412Snewton bds->msg_qbytes = sds->msg_qbytes; 38743412Snewton bds->msg_lspid = sds->msg_lspid; 38843412Snewton bds->msg_lrpid = sds->msg_lrpid; 38943412Snewton bds->msg_stime = sds->msg_stime; 39043412Snewton bds->msg_pad1 = sds->msg_pad1; 39143412Snewton bds->msg_rtime = sds->msg_rtime; 39243412Snewton bds->msg_pad2 = sds->msg_pad2; 39343412Snewton bds->msg_ctime = sds->msg_ctime; 39443412Snewton bds->msg_pad3 = sds->msg_pad3; 39543412Snewton 39643412Snewton /* use the padding for the rest of the fields */ 39743412Snewton { 39843412Snewton short *pad = (short *) bds->msg_pad4; 39943412Snewton pad[0] = sds->msg_cv; 40043412Snewton pad[1] = sds->msg_qnum_cv; 40143412Snewton } 40243412Snewton} 40343412Snewton 40443412Snewtonstruct svr4_sys_msgsnd_args { 405147817Sjhb int what; 406147817Sjhb int msqid; 407147817Sjhb void * msgp; 408147817Sjhb size_t msgsz; 409147817Sjhb int msgflg; 41043412Snewton}; 41143412Snewton 41243412Snewtonstatic int 413147817Sjhbsvr4_msgsnd(td, v) 414147817Sjhb struct thread *td; 41543412Snewton void *v; 41643412Snewton{ 41743412Snewton struct svr4_sys_msgsnd_args *uap = v; 418147817Sjhb struct msgsnd_args ap; 41943412Snewton 420107849Salfred ap.msqid = uap->msqid; 421107849Salfred ap.msgp = uap->msgp; 422107849Salfred ap.msgsz = uap->msgsz; 423107849Salfred ap.msgflg = uap->msgflg; 42443412Snewton 425147817Sjhb return msgsnd(td, &ap); 42643412Snewton} 42743412Snewton 42843412Snewtonstruct svr4_sys_msgrcv_args { 429147817Sjhb int what; 430147817Sjhb int msqid; 431147817Sjhb void * msgp; 432147817Sjhb size_t msgsz; 433147817Sjhb long msgtyp; 434147817Sjhb int msgflg; 43543412Snewton}; 43643412Snewton 43743412Snewtonstatic int 438147817Sjhbsvr4_msgrcv(td, v) 439147817Sjhb struct thread *td; 44043412Snewton void *v; 44143412Snewton{ 44243412Snewton struct svr4_sys_msgrcv_args *uap = v; 443147817Sjhb struct msgrcv_args ap; 44443412Snewton 445107849Salfred ap.msqid = uap->msqid; 446107849Salfred ap.msgp = uap->msgp; 447107849Salfred ap.msgsz = uap->msgsz; 448107849Salfred ap.msgtyp = uap->msgtyp; 449107849Salfred ap.msgflg = uap->msgflg; 45043412Snewton 451147817Sjhb return msgrcv(td, &ap); 45243412Snewton} 45343412Snewton 45443412Snewtonstruct svr4_sys_msgget_args { 455147817Sjhb int what; 456147817Sjhb svr4_key_t key; 457147817Sjhb int msgflg; 45843412Snewton}; 45943412Snewton 46043412Snewtonstatic int 461147817Sjhbsvr4_msgget(td, v) 462147817Sjhb struct thread *td; 46343412Snewton void *v; 46443412Snewton{ 46543412Snewton struct svr4_sys_msgget_args *uap = v; 466147817Sjhb struct msgget_args ap; 46743412Snewton 468107849Salfred ap.key = uap->key; 469107849Salfred ap.msgflg = uap->msgflg; 47043412Snewton 471147817Sjhb return msgget(td, &ap); 47243412Snewton} 47343412Snewton 47443412Snewtonstruct svr4_sys_msgctl_args { 475147817Sjhb int what; 476147817Sjhb int msqid; 477147817Sjhb int cmd; 478147817Sjhb struct svr4_msqid_ds * buf; 47943412Snewton}; 48043412Snewton 48143412Snewtonstatic int 482147817Sjhbsvr4_msgctl(td, v) 483147817Sjhb struct thread *td; 48443412Snewton void *v; 48543412Snewton{ 48643412Snewton struct svr4_sys_msgctl_args *uap = v; 48743412Snewton struct svr4_msqid_ds ss; 48843412Snewton struct msqid_ds bs; 489141486Sjhb int error; 49043412Snewton 491107849Salfred switch (uap->cmd) { 49243412Snewton case SVR4_IPC_STAT: 493141486Sjhb error = kern_msgctl(td, uap->msqid, IPC_STAT, &bs); 49443412Snewton if (error) 49543412Snewton return error; 49643412Snewton bsd_to_svr4_msqid_ds(&bs, &ss); 497107849Salfred return copyout(&ss, uap->buf, sizeof ss); 49843412Snewton 49943412Snewton case SVR4_IPC_SET: 500107849Salfred error = copyin(uap->buf, &ss, sizeof ss); 50143412Snewton if (error) 50243412Snewton return error; 50343412Snewton svr4_to_bsd_msqid_ds(&ss, &bs); 504141486Sjhb return (kern_msgctl(td, uap->msqid, IPC_SET, &bs)); 50543412Snewton 50643412Snewton case SVR4_IPC_RMID: 507160141Sjhb return (kern_msgctl(td, uap->msqid, IPC_RMID, NULL)); 50843412Snewton 50943412Snewton default: 51043412Snewton return EINVAL; 51143412Snewton } 51243412Snewton} 51343412Snewton 51443412Snewtonint 515147817Sjhbsvr4_sys_msgsys(td, uap) 516147817Sjhb struct thread *td; 517147817Sjhb struct svr4_sys_msgsys_args *uap; 51843412Snewton{ 51943412Snewton 520107849Salfred DPRINTF(("svr4_msgsys(%d)\n", uap->what)); 52143412Snewton 522107849Salfred switch (uap->what) { 52343412Snewton case SVR4_msgsnd: 524147817Sjhb return svr4_msgsnd(td, uap); 52543412Snewton case SVR4_msgrcv: 526147817Sjhb return svr4_msgrcv(td, uap); 52743412Snewton case SVR4_msgget: 528147817Sjhb return svr4_msgget(td, uap); 52943412Snewton case SVR4_msgctl: 530147817Sjhb return svr4_msgctl(td, uap); 53143412Snewton default: 53243412Snewton return EINVAL; 53343412Snewton } 53443412Snewton} 535148541Sjhb 536148541SjhbMODULE_DEPEND(svr4elf, sysvmsg, 1, 1, 1); 53743412Snewton#endif 53843412Snewton 53943412Snewton#ifdef SYSVSHM 54043412Snewton 54143412Snewtonstatic void 54243412Snewtonbsd_to_svr4_shmid_ds(bds, sds) 54343412Snewton const struct shmid_ds *bds; 54443412Snewton struct svr4_shmid_ds *sds; 54543412Snewton{ 54643412Snewton bsd_to_svr4_ipc_perm(&bds->shm_perm, &sds->shm_perm); 54743412Snewton sds->shm_segsz = bds->shm_segsz; 54843412Snewton sds->shm_lkcnt = 0; 54943412Snewton sds->shm_lpid = bds->shm_lpid; 55043412Snewton sds->shm_cpid = bds->shm_cpid; 55143412Snewton sds->shm_amp = bds->shm_internal; 55243412Snewton sds->shm_nattch = bds->shm_nattch; 55343412Snewton sds->shm_cnattch = 0; 55443412Snewton sds->shm_atime = bds->shm_atime; 55543412Snewton sds->shm_pad1 = 0; 55643412Snewton sds->shm_dtime = bds->shm_dtime; 55743412Snewton sds->shm_pad2 = 0; 55843412Snewton sds->shm_ctime = bds->shm_ctime; 55943412Snewton sds->shm_pad3 = 0; 56043412Snewton} 56143412Snewton 56243412Snewtonstatic void 56343412Snewtonsvr4_to_bsd_shmid_ds(sds, bds) 56443412Snewton const struct svr4_shmid_ds *sds; 56543412Snewton struct shmid_ds *bds; 56643412Snewton{ 56743412Snewton svr4_to_bsd_ipc_perm(&sds->shm_perm, &bds->shm_perm); 56843412Snewton bds->shm_segsz = sds->shm_segsz; 56943412Snewton bds->shm_lpid = sds->shm_lpid; 57043412Snewton bds->shm_cpid = sds->shm_cpid; 57143412Snewton bds->shm_internal = sds->shm_amp; 57243412Snewton bds->shm_nattch = sds->shm_nattch; 57343412Snewton bds->shm_atime = sds->shm_atime; 57443412Snewton bds->shm_dtime = sds->shm_dtime; 57543412Snewton bds->shm_ctime = sds->shm_ctime; 57643412Snewton} 57743412Snewton 57843412Snewtonstruct svr4_sys_shmat_args { 579147817Sjhb int what; 580147817Sjhb int shmid; 581147817Sjhb void * shmaddr; 582147817Sjhb int shmflg; 58343412Snewton}; 58443412Snewton 58543412Snewtonstatic int 586147817Sjhbsvr4_shmat(td, v) 587147817Sjhb struct thread *td; 58843412Snewton void *v; 58943412Snewton{ 59043412Snewton struct svr4_sys_shmat_args *uap = v; 591147817Sjhb struct shmat_args ap; 59243412Snewton 593107849Salfred ap.shmid = uap->shmid; 594107849Salfred ap.shmaddr = uap->shmaddr; 595107849Salfred ap.shmflg = uap->shmflg; 59643412Snewton 597147817Sjhb return shmat(td, &ap); 59843412Snewton} 59943412Snewton 60043412Snewtonstruct svr4_sys_shmdt_args { 601147817Sjhb int what; 602147817Sjhb void * shmaddr; 60343412Snewton}; 60443412Snewton 60543412Snewtonstatic int 606147817Sjhbsvr4_shmdt(td, v) 607147817Sjhb struct thread *td; 60843412Snewton void *v; 60943412Snewton{ 61043412Snewton struct svr4_sys_shmdt_args *uap = v; 611147817Sjhb struct shmdt_args ap; 61243412Snewton 613107849Salfred ap.shmaddr = uap->shmaddr; 61443412Snewton 615147817Sjhb return shmdt(td, &ap); 61643412Snewton} 61743412Snewton 61843412Snewtonstruct svr4_sys_shmget_args { 619147817Sjhb int what; 620147817Sjhb key_t key; 621147817Sjhb int size; 622147817Sjhb int shmflg; 62343412Snewton}; 62443412Snewton 62543412Snewtonstatic int 626147817Sjhbsvr4_shmget(td, v) 627147817Sjhb struct thread *td; 62843412Snewton void *v; 62943412Snewton{ 63043412Snewton struct svr4_sys_shmget_args *uap = v; 631147817Sjhb struct shmget_args ap; 63243412Snewton 633107849Salfred ap.key = uap->key; 634107849Salfred ap.size = uap->size; 635107849Salfred ap.shmflg = uap->shmflg; 63643412Snewton 637147817Sjhb return shmget(td, &ap); 63843412Snewton} 63943412Snewton 64043412Snewtonstruct svr4_sys_shmctl_args { 641147817Sjhb int what; 642147817Sjhb int shmid; 643147817Sjhb int cmd; 644147817Sjhb struct svr4_shmid_ds * buf; 64543412Snewton}; 64643412Snewton 64743412Snewtonint 648147817Sjhbsvr4_shmctl(td, v) 649147817Sjhb struct thread *td; 65043412Snewton void *v; 65143412Snewton{ 65243412Snewton struct svr4_sys_shmctl_args *uap = v; 65343412Snewton struct shmid_ds bs; 65443412Snewton struct svr4_shmid_ds ss; 655159993Sjhb size_t bufsize; 656159993Sjhb int cmd, error; 65743412Snewton 658107849Salfred if (uap->buf != NULL) { 659107849Salfred switch (uap->cmd) { 66043412Snewton case SVR4_IPC_SET: 66143412Snewton case SVR4_SHM_LOCK: 66243412Snewton case SVR4_SHM_UNLOCK: 663159993Sjhb error = copyin(uap->buf, &ss, sizeof(ss)); 66443412Snewton if (error) 665159993Sjhb return (error); 66643412Snewton svr4_to_bsd_shmid_ds(&ss, &bs); 66743412Snewton break; 66843412Snewton default: 669159993Sjhb return (EINVAL); 67043412Snewton } 67143412Snewton } 67243412Snewton 673107849Salfred switch (uap->cmd) { 67443412Snewton case SVR4_IPC_STAT: 675159993Sjhb cmd = IPC_STAT; 676159993Sjhb break; 67743412Snewton case SVR4_IPC_SET: 678159993Sjhb cmd = IPC_SET; 679159993Sjhb break; 68043412Snewton case SVR4_IPC_RMID: 681159993Sjhb cmd = IPC_RMID; 682159993Sjhb break; 68343412Snewton case SVR4_SHM_LOCK: 684159993Sjhb cmd = SHM_LOCK; 685159993Sjhb break; 68643412Snewton case SVR4_SHM_UNLOCK: 687159993Sjhb cmd = SHM_UNLOCK; 688159993Sjhb break; 689159993Sjhb default: 690159993Sjhb return (EINVAL); 691159993Sjhb } 692159993Sjhb 693159993Sjhb error = kern_shmctl(td, uap->shmid, cmd, &bs, &bufsize); 694159993Sjhb if (error) 695159993Sjhb return (error); 696159993Sjhb 697159993Sjhb switch (uap->cmd) { 698159993Sjhb case SVR4_IPC_STAT: 699159993Sjhb if (uap->buf != NULL) { 700159993Sjhb bsd_to_svr4_shmid_ds(&bs, &ss); 701159993Sjhb error = copyout(&ss, uap->buf, sizeof(ss)); 70243412Snewton } 703159993Sjhb break; 704159993Sjhb } 70543412Snewton 706159993Sjhb return (error); 70743412Snewton} 70843412Snewton 70943412Snewtonint 710147817Sjhbsvr4_sys_shmsys(td, uap) 711147817Sjhb struct thread *td; 712147817Sjhb struct svr4_sys_shmsys_args *uap; 71343412Snewton{ 71443412Snewton 715107849Salfred DPRINTF(("svr4_shmsys(%d)\n", uap->what)); 71643412Snewton 717107849Salfred switch (uap->what) { 71843412Snewton case SVR4_shmat: 719147817Sjhb return svr4_shmat(td, uap); 72043412Snewton case SVR4_shmdt: 721147817Sjhb return svr4_shmdt(td, uap); 72243412Snewton case SVR4_shmget: 723147817Sjhb return svr4_shmget(td, uap); 72443412Snewton case SVR4_shmctl: 725147817Sjhb return svr4_shmctl(td, uap); 72643412Snewton default: 72743412Snewton return ENOSYS; 72843412Snewton } 72943412Snewton} 730148541Sjhb 731148541SjhbMODULE_DEPEND(svr4elf, sysvshm, 1, 1, 1); 73243412Snewton#endif /* SYSVSHM */ 733