1*d91f98a8Spgoyette /* $NetBSD: sysv_msg_14.c,v 1.20 2019/01/27 02:08:39 pgoyette Exp $ */
29244fc5bSthorpej
39244fc5bSthorpej /*-
49244fc5bSthorpej * Copyright (c) 1999 The NetBSD Foundation, Inc.
59244fc5bSthorpej * All rights reserved.
69244fc5bSthorpej *
79244fc5bSthorpej * This code is derived from software contributed to The NetBSD Foundation
89244fc5bSthorpej * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
99244fc5bSthorpej * NASA Ames Research Center.
109244fc5bSthorpej *
119244fc5bSthorpej * Redistribution and use in source and binary forms, with or without
129244fc5bSthorpej * modification, are permitted provided that the following conditions
139244fc5bSthorpej * are met:
149244fc5bSthorpej * 1. Redistributions of source code must retain the above copyright
159244fc5bSthorpej * notice, this list of conditions and the following disclaimer.
169244fc5bSthorpej * 2. Redistributions in binary form must reproduce the above copyright
179244fc5bSthorpej * notice, this list of conditions and the following disclaimer in the
189244fc5bSthorpej * documentation and/or other materials provided with the distribution.
199244fc5bSthorpej *
209244fc5bSthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
219244fc5bSthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
229244fc5bSthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
239244fc5bSthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
249244fc5bSthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
259244fc5bSthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
269244fc5bSthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
279244fc5bSthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
289244fc5bSthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
299244fc5bSthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
309244fc5bSthorpej * POSSIBILITY OF SUCH DAMAGE.
319244fc5bSthorpej */
329244fc5bSthorpej
33dab6ef8bSlukem #include <sys/cdefs.h>
34*d91f98a8Spgoyette __KERNEL_RCSID(0, "$NetBSD: sysv_msg_14.c,v 1.20 2019/01/27 02:08:39 pgoyette Exp $");
35*d91f98a8Spgoyette
36*d91f98a8Spgoyette #if defined(_KERNEL_OPT)
37*d91f98a8Spgoyette #include "opt_compat_netbsd.h"
38*d91f98a8Spgoyette #endif
39dab6ef8bSlukem
409244fc5bSthorpej #include <sys/param.h>
419244fc5bSthorpej #include <sys/systm.h>
429244fc5bSthorpej #include <sys/signal.h>
439244fc5bSthorpej #include <sys/proc.h>
449244fc5bSthorpej #include <sys/msg.h>
459244fc5bSthorpej
4688056ee1Schristos #include <compat/sys/msg.h>
4788056ee1Schristos
480d8b0305Sjdolecek #ifndef SYSVMSG
499244fc5bSthorpej #define SYSVMSG
500d8b0305Sjdolecek #endif
519244fc5bSthorpej
529244fc5bSthorpej #include <sys/syscallargs.h>
539244fc5bSthorpej
549244fc5bSthorpej int
compat_14_sys_msgctl(struct lwp * l,const struct compat_14_sys_msgctl_args * uap,register_t * retval)557e2790cfSdsl compat_14_sys_msgctl(struct lwp *l, const struct compat_14_sys_msgctl_args *uap, register_t *retval)
569244fc5bSthorpej {
577e2790cfSdsl /* {
589244fc5bSthorpej syscallarg(int) msqid;
599244fc5bSthorpej syscallarg(int) cmd;
609244fc5bSthorpej syscallarg(struct msqid_ds14 *) buf;
617e2790cfSdsl } */
629244fc5bSthorpej struct msqid_ds msqbuf;
639244fc5bSthorpej struct msqid_ds14 omsqbuf;
649244fc5bSthorpej int cmd, error;
659244fc5bSthorpej
669244fc5bSthorpej cmd = SCARG(uap, cmd);
679244fc5bSthorpej
689244fc5bSthorpej if (cmd == IPC_SET) {
699244fc5bSthorpej error = copyin(SCARG(uap, buf), &omsqbuf, sizeof(omsqbuf));
709244fc5bSthorpej if (error)
719244fc5bSthorpej return (error);
72461a86f9Schristos __msqid_ds14_to_native(&omsqbuf, &msqbuf);
739244fc5bSthorpej }
749244fc5bSthorpej
75f474dcebSad error = msgctl1(l, SCARG(uap, msqid), cmd,
769244fc5bSthorpej (cmd == IPC_SET || cmd == IPC_STAT) ? &msqbuf : NULL);
779244fc5bSthorpej
789244fc5bSthorpej if (error == 0 && cmd == IPC_STAT) {
79461a86f9Schristos __native_to_msqid_ds14(&msqbuf, &omsqbuf);
809244fc5bSthorpej error = copyout(&omsqbuf, SCARG(uap, buf), sizeof(omsqbuf));
819244fc5bSthorpej }
829244fc5bSthorpej
839244fc5bSthorpej return (error);
849244fc5bSthorpej }
85