xref: /netbsd-src/sys/compat/common/sysv_msg_50.c (revision 1e72df6a037fdd3c6d3014a2679ffff7daab84ca)
1*1e72df6aStsutsui /*	$NetBSD: sysv_msg_50.c,v 1.5 2019/12/15 16:48:26 tsutsui Exp $	*/
2461a86f9Schristos 
3461a86f9Schristos /*-
4461a86f9Schristos  * Copyright (c) 1999 The NetBSD Foundation, Inc.
5461a86f9Schristos  * All rights reserved.
6461a86f9Schristos  *
7461a86f9Schristos  * This code is derived from software contributed to The NetBSD Foundation
8461a86f9Schristos  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9461a86f9Schristos  * NASA Ames Research Center.
10461a86f9Schristos  *
11461a86f9Schristos  * Redistribution and use in source and binary forms, with or without
12461a86f9Schristos  * modification, are permitted provided that the following conditions
13461a86f9Schristos  * are met:
14461a86f9Schristos  * 1. Redistributions of source code must retain the above copyright
15461a86f9Schristos  *    notice, this list of conditions and the following disclaimer.
16461a86f9Schristos  * 2. Redistributions in binary form must reproduce the above copyright
17461a86f9Schristos  *    notice, this list of conditions and the following disclaimer in the
18461a86f9Schristos  *    documentation and/or other materials provided with the distribution.
19461a86f9Schristos  *
20461a86f9Schristos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21461a86f9Schristos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22461a86f9Schristos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23461a86f9Schristos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24461a86f9Schristos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25461a86f9Schristos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26461a86f9Schristos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27461a86f9Schristos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28461a86f9Schristos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29461a86f9Schristos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30461a86f9Schristos  * POSSIBILITY OF SUCH DAMAGE.
31461a86f9Schristos  */
32461a86f9Schristos 
33461a86f9Schristos #include <sys/cdefs.h>
34*1e72df6aStsutsui __KERNEL_RCSID(0, "$NetBSD: sysv_msg_50.c,v 1.5 2019/12/15 16:48:26 tsutsui Exp $");
35d91f98a8Spgoyette 
36d91f98a8Spgoyette #if defined(_KERNEL_OPT)
37d91f98a8Spgoyette #include "opt_compat_netbsd.h"
38d91f98a8Spgoyette #endif
39461a86f9Schristos 
40461a86f9Schristos #include <sys/param.h>
41461a86f9Schristos #include <sys/systm.h>
42461a86f9Schristos #include <sys/signal.h>
43461a86f9Schristos #include <sys/proc.h>
44461a86f9Schristos #include <sys/msg.h>
45461a86f9Schristos 
46461a86f9Schristos #include <compat/sys/msg.h>
47461a86f9Schristos 
48461a86f9Schristos #ifndef SYSVMSG
49461a86f9Schristos #define	SYSVMSG
50461a86f9Schristos #endif
51461a86f9Schristos 
52461a86f9Schristos #include <sys/syscallargs.h>
53461a86f9Schristos 
54461a86f9Schristos int
compat_50_sys___msgctl13(struct lwp * l,const struct compat_50_sys___msgctl13_args * uap,register_t * retval)55461a86f9Schristos compat_50_sys___msgctl13(struct lwp *l, const struct compat_50_sys___msgctl13_args *uap, register_t *retval)
56461a86f9Schristos {
57461a86f9Schristos 	/* {
58461a86f9Schristos 		syscallarg(int) msqid;
59461a86f9Schristos 		syscallarg(int) cmd;
60461a86f9Schristos 		syscallarg(struct msqid_ds13 *) buf;
61461a86f9Schristos 	} */
62461a86f9Schristos 	struct msqid_ds msqbuf;
63461a86f9Schristos 	struct msqid_ds13 omsqbuf;
64461a86f9Schristos 	int cmd, error;
65461a86f9Schristos 
66461a86f9Schristos 	cmd = SCARG(uap, cmd);
67461a86f9Schristos 
68461a86f9Schristos 	if (cmd == IPC_SET) {
69461a86f9Schristos 		error = copyin(SCARG(uap, buf), &omsqbuf, sizeof(omsqbuf));
70461a86f9Schristos 		if (error)
71461a86f9Schristos 			return (error);
72461a86f9Schristos 		__msqid_ds13_to_native(&omsqbuf, &msqbuf);
73461a86f9Schristos 	}
74461a86f9Schristos 
75461a86f9Schristos 	error = msgctl1(l, SCARG(uap, msqid), cmd,
76461a86f9Schristos 	    (cmd == IPC_SET || cmd == IPC_STAT) ? &msqbuf : NULL);
77461a86f9Schristos 
78461a86f9Schristos 	if (error == 0 && cmd == IPC_STAT) {
79461a86f9Schristos 		__native_to_msqid_ds13(&msqbuf, &omsqbuf);
80461a86f9Schristos 		error = copyout(&omsqbuf, SCARG(uap, buf), sizeof(omsqbuf));
81461a86f9Schristos 	}
82461a86f9Schristos 
83461a86f9Schristos 	return (error);
84461a86f9Schristos }
85