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 * 1743412Snewton * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1843412Snewton * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1943412Snewton * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2043412Snewton * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2143412Snewton * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2243412Snewton * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2343412Snewton * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2443412Snewton * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2543412Snewton * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2643412Snewton * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2743412Snewton * POSSIBILITY OF SUCH DAMAGE. 2843412Snewton */ 29139743Simp/*- 3043412Snewton * Portions of this code have been derived from software contributed 3143412Snewton * to the FreeBSD Project by Mark Newton. 3243412Snewton * 3343412Snewton * Copyright (c) 1999 Mark Newton 3443412Snewton * All rights reserved. 3543412Snewton * 3643412Snewton * Redistribution and use in source and binary forms, with or without 3743412Snewton * modification, are permitted provided that the following conditions 3843412Snewton * are met: 3943412Snewton * 1. Redistributions of source code must retain the above copyright 4043412Snewton * notice, this list of conditions and the following disclaimer. 4143412Snewton * 2. Redistributions in binary form must reproduce the above copyright 4243412Snewton * notice, this list of conditions and the following disclaimer in the 4343412Snewton * documentation and/or other materials provided with the distribution. 4443412Snewton * 3. The name of the author may not be used to endorse or promote products 4543412Snewton * derived from this software without specific prior written permission 4643412Snewton * 4743412Snewton * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 4843412Snewton * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 4943412Snewton * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 5043412Snewton * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 5143412Snewton * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 5243412Snewton * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 5343412Snewton * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 5443412Snewton * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 5543412Snewton * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 5643412Snewton * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 5743412Snewton * 5843412Snewton * XXX- This code is presently a no-op on FreeBSD (and isn't compiled due 5943412Snewton * to preprocessor conditionals). A nice project for a kernel hacking 6043412Snewton * novice might be to MakeItGo, but I have more important fish to fry 6143412Snewton * at present. 6243412Snewton * 63116174Sobrien * Derived from: $NetBSD: svr4_ipc.c,v 1.7 1998/10/19 22:43:00 tron Exp $ 6443412Snewton */ 6543412Snewton 66116174Sobrien#include <sys/cdefs.h> 67116174Sobrien__FBSDID("$FreeBSD: releng/10.3/sys/compat/svr4/svr4_ipc.c 263687 2014-03-24 13:48:04Z emaste $"); 68116174Sobrien 69147817Sjhb#include "opt_sysvipc.h" 70147817Sjhb 7143412Snewton#include <sys/param.h> 72147817Sjhb#include <sys/ipc.h> 73147817Sjhb#include <sys/msg.h> 7443412Snewton#include <sys/proc.h> 75147817Sjhb#include <sys/sem.h> 76147817Sjhb#include <sys/shm.h> 77147817Sjhb#include <sys/syscallsubr.h> 78147817Sjhb#include <sys/sysproto.h> 79147817Sjhb#include <sys/systm.h> 8043412Snewton#include <sys/time.h> 8143412Snewton 8265302Sobrien#include <compat/svr4/svr4.h> 8365302Sobrien#include <compat/svr4/svr4_types.h> 8465302Sobrien#include <compat/svr4/svr4_signal.h> 8565302Sobrien#include <compat/svr4/svr4_proto.h> 8665302Sobrien#include <compat/svr4/svr4_util.h> 8765302Sobrien#include <compat/svr4/svr4_ipc.h> 8843412Snewton 8943412Snewton#if defined(SYSVMSG) || defined(SYSVSHM) || defined(SYSVSEM) 9092761Salfredstatic void svr4_to_bsd_ipc_perm(const struct svr4_ipc_perm *, 9192761Salfred struct ipc_perm *); 9292761Salfredstatic void bsd_to_svr4_ipc_perm(const struct ipc_perm *, 9392761Salfred struct svr4_ipc_perm *); 9443412Snewton#endif 9543412Snewton 9643412Snewton#ifdef SYSVSEM 9792761Salfredstatic void bsd_to_svr4_semid_ds(const struct semid_ds *, 9892761Salfred struct svr4_semid_ds *); 9992761Salfredstatic void svr4_to_bsd_semid_ds(const struct svr4_semid_ds *, 10092761Salfred struct semid_ds *); 101147817Sjhbstatic int svr4_semop(struct thread *, void *); 102147817Sjhbstatic int svr4_semget(struct thread *, void *); 103147817Sjhbstatic int svr4_semctl(struct thread *, void *); 10443412Snewton#endif 10543412Snewton 10643412Snewton#ifdef SYSVMSG 10792761Salfredstatic void bsd_to_svr4_msqid_ds(const struct msqid_ds *, 10892761Salfred struct svr4_msqid_ds *); 10992761Salfredstatic void svr4_to_bsd_msqid_ds(const struct svr4_msqid_ds *, 11092761Salfred struct msqid_ds *); 111147817Sjhbstatic int svr4_msgsnd(struct thread *, void *); 112147817Sjhbstatic int svr4_msgrcv(struct thread *, void *); 113147817Sjhbstatic int svr4_msgget(struct thread *, void *); 114147817Sjhbstatic int svr4_msgctl(struct thread *, void *); 11543412Snewton#endif 11643412Snewton 11743412Snewton#ifdef SYSVSHM 11892761Salfredstatic void bsd_to_svr4_shmid_ds(const struct shmid_ds *, 11992761Salfred struct svr4_shmid_ds *); 12092761Salfredstatic void svr4_to_bsd_shmid_ds(const struct svr4_shmid_ds *, 12192761Salfred struct shmid_ds *); 122147817Sjhbstatic int svr4_shmat(struct thread *, void *); 123147817Sjhbstatic int svr4_shmdt(struct thread *, void *); 124147817Sjhbstatic int svr4_shmget(struct thread *, void *); 125147817Sjhbstatic int svr4_shmctl(struct thread *, void *); 12643412Snewton#endif 12743412Snewton 12843412Snewton#if defined(SYSVMSG) || defined(SYSVSHM) || defined(SYSVSEM) 12943412Snewton 13043412Snewtonstatic void 13143412Snewtonsvr4_to_bsd_ipc_perm(spp, bpp) 13243412Snewton const struct svr4_ipc_perm *spp; 13343412Snewton struct ipc_perm *bpp; 13443412Snewton{ 13543412Snewton bpp->key = spp->key; 13643412Snewton bpp->uid = spp->uid; 13743412Snewton bpp->gid = spp->gid; 13843412Snewton bpp->cuid = spp->cuid; 13943412Snewton bpp->cgid = spp->cgid; 14043412Snewton bpp->mode = spp->mode; 14143412Snewton bpp->seq = spp->seq; 14243412Snewton} 14343412Snewton 14443412Snewtonstatic void 14543412Snewtonbsd_to_svr4_ipc_perm(bpp, spp) 14643412Snewton const struct ipc_perm *bpp; 14743412Snewton struct svr4_ipc_perm *spp; 14843412Snewton{ 14943412Snewton spp->key = bpp->key; 15043412Snewton spp->uid = bpp->uid; 15143412Snewton spp->gid = bpp->gid; 15243412Snewton spp->cuid = bpp->cuid; 15343412Snewton spp->cgid = bpp->cgid; 15443412Snewton spp->mode = bpp->mode; 15543412Snewton spp->seq = bpp->seq; 15643412Snewton} 15743412Snewton#endif 15843412Snewton 15943412Snewton#ifdef SYSVSEM 16043412Snewtonstatic void 16143412Snewtonbsd_to_svr4_semid_ds(bds, sds) 16243412Snewton const struct semid_ds *bds; 16343412Snewton struct svr4_semid_ds *sds; 16443412Snewton{ 165194910Sjhb bzero(sds, sizeof(*sds)); 16643412Snewton bsd_to_svr4_ipc_perm(&bds->sem_perm, &sds->sem_perm); 16743412Snewton sds->sem_base = (struct svr4_sem *) bds->sem_base; 16843412Snewton sds->sem_nsems = bds->sem_nsems; 16943412Snewton sds->sem_otime = bds->sem_otime; 17043412Snewton sds->sem_ctime = bds->sem_ctime; 17143412Snewton} 17243412Snewton 17343412Snewtonstatic void 17443412Snewtonsvr4_to_bsd_semid_ds(sds, bds) 17543412Snewton const struct svr4_semid_ds *sds; 17643412Snewton struct semid_ds *bds; 17743412Snewton{ 17843412Snewton svr4_to_bsd_ipc_perm(&sds->sem_perm, &bds->sem_perm); 17943412Snewton bds->sem_base = (struct sem *) bds->sem_base; 18043412Snewton bds->sem_nsems = sds->sem_nsems; 18143412Snewton bds->sem_otime = sds->sem_otime; 18243412Snewton bds->sem_ctime = sds->sem_ctime; 18343412Snewton} 18443412Snewton 18543412Snewtonstruct svr4_sys_semctl_args { 186147817Sjhb int what; 187147817Sjhb int semid; 188147817Sjhb int semnum; 189147817Sjhb int cmd; 190147817Sjhb union semun arg; 19143412Snewton}; 19243412Snewton 19343412Snewtonstatic int 194147817Sjhbsvr4_semctl(td, v) 195147817Sjhb struct thread *td; 19643412Snewton void *v; 19743412Snewton{ 19843412Snewton struct svr4_sys_semctl_args *uap = v; 19943412Snewton struct svr4_semid_ds ss; 200159991Sjhb struct semid_ds bs; 201159991Sjhb union semun semun; 202160187Sjhb register_t rval; 203159991Sjhb int cmd, error; 20443412Snewton 205107849Salfred switch (uap->cmd) { 20643412Snewton case SVR4_SEM_GETZCNT: 207159991Sjhb cmd = GETZCNT; 208159991Sjhb break; 209159991Sjhb 21043412Snewton case SVR4_SEM_GETNCNT: 211159991Sjhb cmd = GETNCNT; 212159991Sjhb break; 213159991Sjhb 21443412Snewton case SVR4_SEM_GETPID: 215159991Sjhb cmd = GETPID; 216159991Sjhb break; 217159991Sjhb 21843412Snewton case SVR4_SEM_GETVAL: 219159991Sjhb cmd = GETVAL; 220159991Sjhb break; 22143412Snewton 22243412Snewton case SVR4_SEM_SETVAL: 223159991Sjhb cmd = SETVAL; 224159991Sjhb break; 22543412Snewton 22643412Snewton case SVR4_SEM_GETALL: 227159991Sjhb cmd = GETVAL; 228159991Sjhb break; 22943412Snewton 23043412Snewton case SVR4_SEM_SETALL: 231159991Sjhb cmd = SETVAL; 232159991Sjhb break; 23343412Snewton 23443412Snewton case SVR4_IPC_STAT: 235159991Sjhb cmd = IPC_STAT; 236159991Sjhb semun.buf = &bs; 237159991Sjhb error = kern_semctl(td, uap->semid, uap->semnum, cmd, &semun, 238160187Sjhb &rval); 23943412Snewton if (error) 240160187Sjhb return (error); 24143412Snewton bsd_to_svr4_semid_ds(&bs, &ss); 242160187Sjhb error = copyout(&ss, uap->arg.buf, sizeof(ss)); 243160187Sjhb if (error == 0) 244160187Sjhb td->td_retval[0] = rval; 245160187Sjhb return (error); 24643412Snewton 24743412Snewton case SVR4_IPC_SET: 248159991Sjhb cmd = IPC_SET; 249107849Salfred error = copyin(uap->arg.buf, (caddr_t) &ss, sizeof ss); 25043412Snewton if (error) 251160187Sjhb return (error); 25243412Snewton svr4_to_bsd_semid_ds(&ss, &bs); 253159991Sjhb semun.buf = &bs; 254160187Sjhb return (kern_semctl(td, uap->semid, uap->semnum, cmd, &semun, 255160187Sjhb td->td_retval)); 25643412Snewton 25743412Snewton case SVR4_IPC_RMID: 258159991Sjhb cmd = IPC_RMID; 259159991Sjhb break; 26043412Snewton 26143412Snewton default: 26243412Snewton return EINVAL; 26343412Snewton } 264159991Sjhb 265160187Sjhb return (kern_semctl(td, uap->semid, uap->semnum, cmd, &uap->arg, 266160187Sjhb td->td_retval)); 26743412Snewton} 26843412Snewton 26943412Snewtonstruct svr4_sys_semget_args { 270147817Sjhb int what; 271147817Sjhb svr4_key_t key; 272147817Sjhb int nsems; 273147817Sjhb int semflg; 27443412Snewton}; 27543412Snewton 27643412Snewtonstatic int 277147817Sjhbsvr4_semget(td, v) 278147817Sjhb struct thread *td; 27943412Snewton void *v; 28043412Snewton{ 28143412Snewton struct svr4_sys_semget_args *uap = v; 282147817Sjhb struct semget_args ap; 28343412Snewton 284107849Salfred ap.key = uap->key; 285107849Salfred ap.nsems = uap->nsems; 286107849Salfred ap.semflg = uap->semflg; 28743412Snewton 288225617Skmacy return sys_semget(td, &ap); 28943412Snewton} 29043412Snewton 29143412Snewtonstruct svr4_sys_semop_args { 292147817Sjhb int what; 293147817Sjhb int semid; 294147817Sjhb struct svr4_sembuf * sops; 295147817Sjhb u_int nsops; 29643412Snewton}; 29743412Snewton 29843412Snewtonstatic int 299147817Sjhbsvr4_semop(td, v) 300147817Sjhb struct thread *td; 30143412Snewton void *v; 30243412Snewton{ 30343412Snewton struct svr4_sys_semop_args *uap = v; 304147817Sjhb struct semop_args ap; 30543412Snewton 306107849Salfred ap.semid = uap->semid; 30743412Snewton /* These are the same */ 308107849Salfred ap.sops = (struct sembuf *) uap->sops; 309107849Salfred ap.nsops = uap->nsops; 31043412Snewton 311225617Skmacy return sys_semop(td, &ap); 31243412Snewton} 31343412Snewton 31443412Snewtonint 315147817Sjhbsvr4_sys_semsys(td, uap) 316147817Sjhb struct thread *td; 317147817Sjhb struct svr4_sys_semsys_args *uap; 31843412Snewton{ 31943412Snewton 320107849Salfred DPRINTF(("svr4_semsys(%d)\n", uap->what)); 32143412Snewton 322107849Salfred switch (uap->what) { 32343412Snewton case SVR4_semctl: 324147817Sjhb return svr4_semctl(td, uap); 32543412Snewton case SVR4_semget: 326147817Sjhb return svr4_semget(td, uap); 32743412Snewton case SVR4_semop: 328147817Sjhb return svr4_semop(td, uap); 32943412Snewton default: 33043412Snewton return EINVAL; 33143412Snewton } 33243412Snewton} 333148541Sjhb 334148541SjhbMODULE_DEPEND(svr4elf, sysvsem, 1, 1, 1); 33543412Snewton#endif 33643412Snewton 33743412Snewton#ifdef SYSVMSG 33843412Snewtonstatic void 33943412Snewtonbsd_to_svr4_msqid_ds(bds, sds) 34043412Snewton const struct msqid_ds *bds; 34143412Snewton struct svr4_msqid_ds *sds; 34243412Snewton{ 343194910Sjhb bzero(sds, sizeof(*sds)); 34443412Snewton bsd_to_svr4_ipc_perm(&bds->msg_perm, &sds->msg_perm); 34543412Snewton sds->msg_first = (struct svr4_msg *) bds->msg_first; 34643412Snewton sds->msg_last = (struct svr4_msg *) bds->msg_last; 34743412Snewton sds->msg_cbytes = bds->msg_cbytes; 34843412Snewton sds->msg_qnum = bds->msg_qnum; 34943412Snewton sds->msg_qbytes = bds->msg_qbytes; 35043412Snewton sds->msg_lspid = bds->msg_lspid; 35143412Snewton sds->msg_lrpid = bds->msg_lrpid; 35243412Snewton sds->msg_stime = bds->msg_stime; 35343412Snewton sds->msg_rtime = bds->msg_rtime; 35443412Snewton sds->msg_ctime = bds->msg_ctime; 35543412Snewton} 35643412Snewton 35743412Snewtonstatic void 35843412Snewtonsvr4_to_bsd_msqid_ds(sds, bds) 35943412Snewton const struct svr4_msqid_ds *sds; 36043412Snewton struct msqid_ds *bds; 36143412Snewton{ 36243412Snewton svr4_to_bsd_ipc_perm(&sds->msg_perm, &bds->msg_perm); 36343412Snewton bds->msg_first = (struct msg *) sds->msg_first; 36443412Snewton bds->msg_last = (struct msg *) sds->msg_last; 36543412Snewton bds->msg_cbytes = sds->msg_cbytes; 36643412Snewton bds->msg_qnum = sds->msg_qnum; 36743412Snewton bds->msg_qbytes = sds->msg_qbytes; 36843412Snewton bds->msg_lspid = sds->msg_lspid; 36943412Snewton bds->msg_lrpid = sds->msg_lrpid; 37043412Snewton bds->msg_stime = sds->msg_stime; 37143412Snewton bds->msg_rtime = sds->msg_rtime; 37243412Snewton bds->msg_ctime = sds->msg_ctime; 37343412Snewton} 37443412Snewton 37543412Snewtonstruct svr4_sys_msgsnd_args { 376147817Sjhb int what; 377147817Sjhb int msqid; 378147817Sjhb void * msgp; 379147817Sjhb size_t msgsz; 380147817Sjhb int msgflg; 38143412Snewton}; 38243412Snewton 38343412Snewtonstatic int 384147817Sjhbsvr4_msgsnd(td, v) 385147817Sjhb struct thread *td; 38643412Snewton void *v; 38743412Snewton{ 38843412Snewton struct svr4_sys_msgsnd_args *uap = v; 389147817Sjhb struct msgsnd_args ap; 39043412Snewton 391107849Salfred ap.msqid = uap->msqid; 392107849Salfred ap.msgp = uap->msgp; 393107849Salfred ap.msgsz = uap->msgsz; 394107849Salfred ap.msgflg = uap->msgflg; 39543412Snewton 396225617Skmacy return sys_msgsnd(td, &ap); 39743412Snewton} 39843412Snewton 39943412Snewtonstruct svr4_sys_msgrcv_args { 400147817Sjhb int what; 401147817Sjhb int msqid; 402147817Sjhb void * msgp; 403147817Sjhb size_t msgsz; 404147817Sjhb long msgtyp; 405147817Sjhb int msgflg; 40643412Snewton}; 40743412Snewton 40843412Snewtonstatic int 409147817Sjhbsvr4_msgrcv(td, v) 410147817Sjhb struct thread *td; 41143412Snewton void *v; 41243412Snewton{ 41343412Snewton struct svr4_sys_msgrcv_args *uap = v; 414147817Sjhb struct msgrcv_args ap; 41543412Snewton 416107849Salfred ap.msqid = uap->msqid; 417107849Salfred ap.msgp = uap->msgp; 418107849Salfred ap.msgsz = uap->msgsz; 419107849Salfred ap.msgtyp = uap->msgtyp; 420107849Salfred ap.msgflg = uap->msgflg; 42143412Snewton 422225617Skmacy return sys_msgrcv(td, &ap); 42343412Snewton} 42443412Snewton 42543412Snewtonstruct svr4_sys_msgget_args { 426147817Sjhb int what; 427147817Sjhb svr4_key_t key; 428147817Sjhb int msgflg; 42943412Snewton}; 43043412Snewton 43143412Snewtonstatic int 432147817Sjhbsvr4_msgget(td, v) 433147817Sjhb struct thread *td; 43443412Snewton void *v; 43543412Snewton{ 43643412Snewton struct svr4_sys_msgget_args *uap = v; 437147817Sjhb struct msgget_args ap; 43843412Snewton 439107849Salfred ap.key = uap->key; 440107849Salfred ap.msgflg = uap->msgflg; 44143412Snewton 442225617Skmacy return sys_msgget(td, &ap); 44343412Snewton} 44443412Snewton 44543412Snewtonstruct svr4_sys_msgctl_args { 446147817Sjhb int what; 447147817Sjhb int msqid; 448147817Sjhb int cmd; 449147817Sjhb struct svr4_msqid_ds * buf; 45043412Snewton}; 45143412Snewton 45243412Snewtonstatic int 453147817Sjhbsvr4_msgctl(td, v) 454147817Sjhb struct thread *td; 45543412Snewton void *v; 45643412Snewton{ 45743412Snewton struct svr4_sys_msgctl_args *uap = v; 45843412Snewton struct svr4_msqid_ds ss; 45943412Snewton struct msqid_ds bs; 460141486Sjhb int error; 46143412Snewton 462107849Salfred switch (uap->cmd) { 46343412Snewton case SVR4_IPC_STAT: 464141486Sjhb error = kern_msgctl(td, uap->msqid, IPC_STAT, &bs); 46543412Snewton if (error) 46643412Snewton return error; 46743412Snewton bsd_to_svr4_msqid_ds(&bs, &ss); 468107849Salfred return copyout(&ss, uap->buf, sizeof ss); 46943412Snewton 47043412Snewton case SVR4_IPC_SET: 471107849Salfred error = copyin(uap->buf, &ss, sizeof ss); 47243412Snewton if (error) 47343412Snewton return error; 47443412Snewton svr4_to_bsd_msqid_ds(&ss, &bs); 475141486Sjhb return (kern_msgctl(td, uap->msqid, IPC_SET, &bs)); 47643412Snewton 47743412Snewton case SVR4_IPC_RMID: 478160141Sjhb return (kern_msgctl(td, uap->msqid, IPC_RMID, NULL)); 47943412Snewton 48043412Snewton default: 48143412Snewton return EINVAL; 48243412Snewton } 48343412Snewton} 48443412Snewton 48543412Snewtonint 486147817Sjhbsvr4_sys_msgsys(td, uap) 487147817Sjhb struct thread *td; 488147817Sjhb struct svr4_sys_msgsys_args *uap; 48943412Snewton{ 49043412Snewton 491107849Salfred DPRINTF(("svr4_msgsys(%d)\n", uap->what)); 49243412Snewton 493107849Salfred switch (uap->what) { 49443412Snewton case SVR4_msgsnd: 495147817Sjhb return svr4_msgsnd(td, uap); 49643412Snewton case SVR4_msgrcv: 497147817Sjhb return svr4_msgrcv(td, uap); 49843412Snewton case SVR4_msgget: 499147817Sjhb return svr4_msgget(td, uap); 50043412Snewton case SVR4_msgctl: 501147817Sjhb return svr4_msgctl(td, uap); 50243412Snewton default: 50343412Snewton return EINVAL; 50443412Snewton } 50543412Snewton} 506148541Sjhb 507148541SjhbMODULE_DEPEND(svr4elf, sysvmsg, 1, 1, 1); 50843412Snewton#endif 50943412Snewton 51043412Snewton#ifdef SYSVSHM 51143412Snewton 51243412Snewtonstatic void 51343412Snewtonbsd_to_svr4_shmid_ds(bds, sds) 51443412Snewton const struct shmid_ds *bds; 51543412Snewton struct svr4_shmid_ds *sds; 51643412Snewton{ 517194910Sjhb bzero(sds, sizeof(*sds)); 51843412Snewton bsd_to_svr4_ipc_perm(&bds->shm_perm, &sds->shm_perm); 51943412Snewton sds->shm_segsz = bds->shm_segsz; 52043412Snewton sds->shm_lkcnt = 0; 52143412Snewton sds->shm_lpid = bds->shm_lpid; 52243412Snewton sds->shm_cpid = bds->shm_cpid; 523194910Sjhb sds->shm_amp = 0; 52443412Snewton sds->shm_nattch = bds->shm_nattch; 52543412Snewton sds->shm_cnattch = 0; 52643412Snewton sds->shm_atime = bds->shm_atime; 52743412Snewton sds->shm_dtime = bds->shm_dtime; 52843412Snewton sds->shm_ctime = bds->shm_ctime; 52943412Snewton} 53043412Snewton 53143412Snewtonstatic void 53243412Snewtonsvr4_to_bsd_shmid_ds(sds, bds) 53343412Snewton const struct svr4_shmid_ds *sds; 53443412Snewton struct shmid_ds *bds; 53543412Snewton{ 53643412Snewton svr4_to_bsd_ipc_perm(&sds->shm_perm, &bds->shm_perm); 53743412Snewton bds->shm_segsz = sds->shm_segsz; 53843412Snewton bds->shm_lpid = sds->shm_lpid; 53943412Snewton bds->shm_cpid = sds->shm_cpid; 54043412Snewton bds->shm_nattch = sds->shm_nattch; 54143412Snewton bds->shm_atime = sds->shm_atime; 54243412Snewton bds->shm_dtime = sds->shm_dtime; 54343412Snewton bds->shm_ctime = sds->shm_ctime; 54443412Snewton} 54543412Snewton 54643412Snewtonstruct svr4_sys_shmat_args { 547147817Sjhb int what; 548147817Sjhb int shmid; 549147817Sjhb void * shmaddr; 550147817Sjhb int shmflg; 55143412Snewton}; 55243412Snewton 55343412Snewtonstatic int 554147817Sjhbsvr4_shmat(td, v) 555147817Sjhb struct thread *td; 55643412Snewton void *v; 55743412Snewton{ 55843412Snewton struct svr4_sys_shmat_args *uap = v; 559147817Sjhb struct shmat_args ap; 56043412Snewton 561107849Salfred ap.shmid = uap->shmid; 562107849Salfred ap.shmaddr = uap->shmaddr; 563107849Salfred ap.shmflg = uap->shmflg; 56443412Snewton 565225617Skmacy return sys_shmat(td, &ap); 56643412Snewton} 56743412Snewton 56843412Snewtonstruct svr4_sys_shmdt_args { 569147817Sjhb int what; 570147817Sjhb void * shmaddr; 57143412Snewton}; 57243412Snewton 57343412Snewtonstatic int 574147817Sjhbsvr4_shmdt(td, v) 575147817Sjhb struct thread *td; 57643412Snewton void *v; 57743412Snewton{ 57843412Snewton struct svr4_sys_shmdt_args *uap = v; 579147817Sjhb struct shmdt_args ap; 58043412Snewton 581107849Salfred ap.shmaddr = uap->shmaddr; 58243412Snewton 583225617Skmacy return sys_shmdt(td, &ap); 58443412Snewton} 58543412Snewton 58643412Snewtonstruct svr4_sys_shmget_args { 587147817Sjhb int what; 588147817Sjhb key_t key; 589147817Sjhb int size; 590147817Sjhb int shmflg; 59143412Snewton}; 59243412Snewton 59343412Snewtonstatic int 594147817Sjhbsvr4_shmget(td, v) 595147817Sjhb struct thread *td; 59643412Snewton void *v; 59743412Snewton{ 59843412Snewton struct svr4_sys_shmget_args *uap = v; 599147817Sjhb struct shmget_args ap; 60043412Snewton 601107849Salfred ap.key = uap->key; 602107849Salfred ap.size = uap->size; 603107849Salfred ap.shmflg = uap->shmflg; 60443412Snewton 605225617Skmacy return sys_shmget(td, &ap); 60643412Snewton} 60743412Snewton 60843412Snewtonstruct svr4_sys_shmctl_args { 609147817Sjhb int what; 610147817Sjhb int shmid; 611147817Sjhb int cmd; 612147817Sjhb struct svr4_shmid_ds * buf; 61343412Snewton}; 61443412Snewton 61543412Snewtonint 616147817Sjhbsvr4_shmctl(td, v) 617147817Sjhb struct thread *td; 61843412Snewton void *v; 61943412Snewton{ 62043412Snewton struct svr4_sys_shmctl_args *uap = v; 62143412Snewton struct shmid_ds bs; 62243412Snewton struct svr4_shmid_ds ss; 623159993Sjhb size_t bufsize; 624159993Sjhb int cmd, error; 62543412Snewton 626107849Salfred if (uap->buf != NULL) { 627107849Salfred switch (uap->cmd) { 62843412Snewton case SVR4_IPC_SET: 62943412Snewton case SVR4_SHM_LOCK: 63043412Snewton case SVR4_SHM_UNLOCK: 631159993Sjhb error = copyin(uap->buf, &ss, sizeof(ss)); 63243412Snewton if (error) 633159993Sjhb return (error); 63443412Snewton svr4_to_bsd_shmid_ds(&ss, &bs); 63543412Snewton break; 63643412Snewton default: 637159993Sjhb return (EINVAL); 63843412Snewton } 63943412Snewton } 64043412Snewton 641107849Salfred switch (uap->cmd) { 64243412Snewton case SVR4_IPC_STAT: 643159993Sjhb cmd = IPC_STAT; 644159993Sjhb break; 64543412Snewton case SVR4_IPC_SET: 646159993Sjhb cmd = IPC_SET; 647159993Sjhb break; 64843412Snewton case SVR4_IPC_RMID: 649159993Sjhb cmd = IPC_RMID; 650159993Sjhb break; 65143412Snewton case SVR4_SHM_LOCK: 652159993Sjhb cmd = SHM_LOCK; 653159993Sjhb break; 65443412Snewton case SVR4_SHM_UNLOCK: 655159993Sjhb cmd = SHM_UNLOCK; 656159993Sjhb break; 657159993Sjhb default: 658159993Sjhb return (EINVAL); 659159993Sjhb } 660159993Sjhb 661159993Sjhb error = kern_shmctl(td, uap->shmid, cmd, &bs, &bufsize); 662159993Sjhb if (error) 663159993Sjhb return (error); 664159993Sjhb 665159993Sjhb switch (uap->cmd) { 666159993Sjhb case SVR4_IPC_STAT: 667159993Sjhb if (uap->buf != NULL) { 668159993Sjhb bsd_to_svr4_shmid_ds(&bs, &ss); 669159993Sjhb error = copyout(&ss, uap->buf, sizeof(ss)); 67043412Snewton } 671159993Sjhb break; 672159993Sjhb } 67343412Snewton 674159993Sjhb return (error); 67543412Snewton} 67643412Snewton 67743412Snewtonint 678147817Sjhbsvr4_sys_shmsys(td, uap) 679147817Sjhb struct thread *td; 680147817Sjhb struct svr4_sys_shmsys_args *uap; 68143412Snewton{ 68243412Snewton 683107849Salfred DPRINTF(("svr4_shmsys(%d)\n", uap->what)); 68443412Snewton 685107849Salfred switch (uap->what) { 68643412Snewton case SVR4_shmat: 687147817Sjhb return svr4_shmat(td, uap); 68843412Snewton case SVR4_shmdt: 689147817Sjhb return svr4_shmdt(td, uap); 69043412Snewton case SVR4_shmget: 691147817Sjhb return svr4_shmget(td, uap); 69243412Snewton case SVR4_shmctl: 693147817Sjhb return svr4_shmctl(td, uap); 69443412Snewton default: 69543412Snewton return ENOSYS; 69643412Snewton } 69743412Snewton} 698148541Sjhb 699148541SjhbMODULE_DEPEND(svr4elf, sysvshm, 1, 1, 1); 70043412Snewton#endif /* SYSVSHM */ 701