1/* $NetBSD: netbsd32_compat_50_sysv.c,v 1.1 2015/12/03 10:38:21 pgoyette Exp $ */
2
3/*-
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38#include <sys/cdefs.h>
39__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_50_sysv.c,v 1.1 2015/12/03 10:38:21 pgoyette Exp $");
40
41#if defined(_KERNEL_OPT)
42#include "opt_sysv.h"
43#include "opt_compat_netbsd.h"
44#endif
45
46#include <sys/param.h>
47#include <sys/systm.h>
48#include <sys/msg.h>
49#include <sys/sem.h>
50#include <sys/shm.h>
51
52#include <compat/netbsd32/netbsd32.h>
53#include <compat/netbsd32/netbsd32_syscallargs.h>
54#include <compat/netbsd32/netbsd32_conv.h>
55
56#if defined(COMPAT_50)
57
58#if defined(SYSVSEM)
59
60int
61compat_50_netbsd32___semctl14(struct lwp *l, const struct compat_50_netbsd32___semctl14_args *uap, register_t *retval)
62{
63 return do_netbsd32___semctl14(l, uap, retval, NULL);
64}
65
66int
67do_netbsd32___semctl14(struct lwp *l, const struct compat_50_netbsd32___semctl14_args *uap, register_t *retval, void *vkarg)
68{
69 /* {
70 syscallarg(int) semid;
71 syscallarg(int) semnum;
72 syscallarg(int) cmd;
73 syscallarg(netbsd32_semun50p_t) arg;
74 } */
75 struct semid_ds sembuf;
76 struct netbsd32_semid_ds50 sembuf32;
77 int cmd, error;
78 void *pass_arg;
79 union __semun karg;
80 union netbsd32_semun50 karg32;
81
82 cmd = SCARG(uap, cmd);
83
84 switch (cmd) {
85 case IPC_SET:
86 case IPC_STAT:
87 pass_arg = &sembuf;
88 break;
89
90 case GETALL:
91 case SETVAL:
92 case SETALL:
93 pass_arg = &karg;
94 break;
95 default:
96 pass_arg = NULL;
97 break;
98 }
99
100 if (pass_arg) {
101 if (vkarg != NULL)
102 karg32 = *(union netbsd32_semun50 *)vkarg;
103 else {
104 error = copyin(SCARG_P32(uap, arg), &karg32,
105 sizeof(karg32));
106 if (error)
107 return error;
108 }
109 if (pass_arg == &karg) {
110 switch (cmd) {
111 case GETALL:
112 case SETALL:
113 karg.array = NETBSD32PTR64(karg32.array);
114 break;
115 case SETVAL:
116 karg.val = karg32.val;
117 break;
118 }
119 }
120 if (cmd == IPC_SET) {
121 error = copyin(NETBSD32PTR64(karg32.buf), &sembuf32,
122 sizeof(sembuf32));
123 if (error)
124 return (error);
125 netbsd32_to_semid_ds50(&sembuf32, &sembuf);
126 }
127 }
128
129 error = semctl1(l, SCARG(uap, semid), SCARG(uap, semnum), cmd,
130 pass_arg, retval);
131
132 if (error == 0 && cmd == IPC_STAT) {
133 netbsd32_from_semid_ds50(&sembuf, &sembuf32);
134 error = copyout(&sembuf32, NETBSD32PTR64(karg32.buf),
135 sizeof(sembuf32));
136 }
137
138 return (error);
139}
140#endif
141
142#if defined(SYSVMSG)
143
144int
145compat_50_netbsd32___msgctl13(struct lwp *l, const struct compat_50_netbsd32___msgctl13_args *uap, register_t *retval)
146{
147 /* {
148 syscallarg(int) msqid;
149 syscallarg(int) cmd;
150 syscallarg(netbsd32_msqid_ds50p_t) buf;
151 } */
152 struct msqid_ds ds;
153 struct netbsd32_msqid_ds50 ds32;
154 int error, cmd;
155
156 cmd = SCARG(uap, cmd);
157 if (cmd == IPC_SET) {
158 error = copyin(SCARG_P32(uap, buf), &ds32, sizeof(ds32));
159 if (error)
160 return error;
161 netbsd32_to_msqid_ds50(&ds32, &ds);
162 }
163
164 error = msgctl1(l, SCARG(uap, msqid), cmd,
165 (cmd == IPC_SET || cmd == IPC_STAT) ? &ds : NULL);
166
167 if (error == 0 && cmd == IPC_STAT) {
168 netbsd32_from_msqid_ds50(&ds, &ds32);
169 error = copyout(&ds32, SCARG_P32(uap, buf), sizeof(ds32));
170 }
171
172 return error;
173}
174#endif
175
176#if defined(SYSVSHM)
177
178int
179compat_50_netbsd32___shmctl13(struct lwp *l, const struct compat_50_netbsd32___shmctl13_args *uap, register_t *retval)
180{
181 /* {
182 syscallarg(int) shmid;
183 syscallarg(int) cmd;
184 syscallarg(netbsd32_shmid_ds50p_t) buf;
185 } */
186 struct shmid_ds ds;
187 struct netbsd32_shmid_ds50 ds32;
188 int error, cmd;
189
190 cmd = SCARG(uap, cmd);
191 if (cmd == IPC_SET) {
192 error = copyin(SCARG_P32(uap, buf), &ds32, sizeof(ds32));
193 if (error)
194 return error;
195 netbsd32_to_shmid_ds50(&ds32, &ds);
196 }
197
198 error = shmctl1(l, SCARG(uap, shmid), cmd,
199 (cmd == IPC_SET || cmd == IPC_STAT) ? &ds : NULL);
200
201 if (error == 0 && cmd == IPC_STAT) {
202 netbsd32_from_shmid_ds50(&ds, &ds32);
203 error = copyout(&ds32, SCARG_P32(uap, buf), sizeof(ds32));
204 }
205
206 return error;
207}
208#endif
209
210#endif /* COMPAT_50 */
211