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