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