netbsd32_ioctl.c revision 1.41.10.2 1 1.41.10.2 matt /* $NetBSD: netbsd32_ioctl.c,v 1.41.10.2 2008/07/02 16:45:21 matt Exp $ */
2 1.41.10.2 matt
3 1.41.10.2 matt /*
4 1.41.10.2 matt * Copyright (c) 1998, 2001 Matthew R. Green
5 1.41.10.2 matt * All rights reserved.
6 1.41.10.2 matt *
7 1.41.10.2 matt * Redistribution and use in source and binary forms, with or without
8 1.41.10.2 matt * modification, are permitted provided that the following conditions
9 1.41.10.2 matt * are met:
10 1.41.10.2 matt * 1. Redistributions of source code must retain the above copyright
11 1.41.10.2 matt * notice, this list of conditions and the following disclaimer.
12 1.41.10.2 matt * 2. Redistributions in binary form must reproduce the above copyright
13 1.41.10.2 matt * notice, this list of conditions and the following disclaimer in the
14 1.41.10.2 matt * documentation and/or other materials provided with the distribution.
15 1.41.10.2 matt *
16 1.41.10.2 matt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.41.10.2 matt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.41.10.2 matt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.41.10.2 matt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.41.10.2 matt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.41.10.2 matt * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.41.10.2 matt * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.41.10.2 matt * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.41.10.2 matt * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.41.10.2 matt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.41.10.2 matt * SUCH DAMAGE.
27 1.41.10.2 matt */
28 1.41.10.2 matt
29 1.41.10.2 matt /*
30 1.41.10.2 matt * handle ioctl conversions from netbsd32 -> 64-bit kernel
31 1.41.10.2 matt */
32 1.41.10.2 matt
33 1.41.10.2 matt #include <sys/cdefs.h>
34 1.41.10.2 matt __KERNEL_RCSID(0, "$NetBSD: netbsd32_ioctl.c,v 1.41.10.2 2008/07/02 16:45:21 matt Exp $");
35 1.41.10.2 matt
36 1.41.10.2 matt #include <sys/param.h>
37 1.41.10.2 matt #include <sys/systm.h>
38 1.41.10.2 matt #include <sys/filedesc.h>
39 1.41.10.2 matt #include <sys/ioctl.h>
40 1.41.10.2 matt #include <sys/file.h>
41 1.41.10.2 matt #include <sys/proc.h>
42 1.41.10.2 matt #include <sys/socketvar.h>
43 1.41.10.2 matt #include <sys/audioio.h>
44 1.41.10.2 matt #include <sys/disklabel.h>
45 1.41.10.2 matt #include <sys/dkio.h>
46 1.41.10.2 matt #include <sys/malloc.h>
47 1.41.10.2 matt #include <sys/sockio.h>
48 1.41.10.2 matt #include <sys/socket.h>
49 1.41.10.2 matt #include <sys/ttycom.h>
50 1.41.10.2 matt #include <sys/mount.h>
51 1.41.10.2 matt #include <sys/syscallargs.h>
52 1.41.10.2 matt #include <sys/ktrace.h>
53 1.41.10.2 matt #include <sys/kmem.h>
54 1.41.10.2 matt
55 1.41.10.2 matt #ifdef __sparc__
56 1.41.10.2 matt #include <dev/sun/fbio.h>
57 1.41.10.2 matt #include <machine/openpromio.h>
58 1.41.10.2 matt #endif
59 1.41.10.2 matt
60 1.41.10.2 matt #include <net/if.h>
61 1.41.10.2 matt #include <net/route.h>
62 1.41.10.2 matt
63 1.41.10.2 matt #include <netinet/in.h>
64 1.41.10.2 matt #include <netinet/in_var.h>
65 1.41.10.2 matt #include <netinet/igmp.h>
66 1.41.10.2 matt #include <netinet/igmp_var.h>
67 1.41.10.2 matt #include <netinet/ip_mroute.h>
68 1.41.10.2 matt
69 1.41.10.2 matt #include <compat/sys/sockio.h>
70 1.41.10.2 matt
71 1.41.10.2 matt #include <compat/netbsd32/netbsd32.h>
72 1.41.10.2 matt #include <compat/netbsd32/netbsd32_ioctl.h>
73 1.41.10.2 matt #include <compat/netbsd32/netbsd32_syscallargs.h>
74 1.41.10.2 matt
75 1.41.10.2 matt /* prototypes for the converters */
76 1.41.10.2 matt static inline void netbsd32_to_partinfo(struct netbsd32_partinfo *,
77 1.41.10.2 matt struct partinfo *, u_long);
78 1.41.10.2 matt #if 0
79 1.41.10.2 matt static inline void netbsd32_to_format_op(struct netbsd32_format_op *,
80 1.41.10.2 matt struct format_op *, u_long);
81 1.41.10.2 matt #endif
82 1.41.10.2 matt static inline void netbsd32_to_ifreq(struct netbsd32_ifreq *, struct ifreq *,
83 1.41.10.2 matt u_long cmd);
84 1.41.10.2 matt static inline void netbsd32_to_ifconf(struct netbsd32_ifconf *,
85 1.41.10.2 matt struct ifconf *, u_long);
86 1.41.10.2 matt static inline void netbsd32_to_ifmediareq(struct netbsd32_ifmediareq *,
87 1.41.10.2 matt struct ifmediareq *, u_long);
88 1.41.10.2 matt static inline void netbsd32_to_ifdrv(struct netbsd32_ifdrv *, struct ifdrv *,
89 1.41.10.2 matt u_long);
90 1.41.10.2 matt static inline void netbsd32_to_sioc_vif_req(struct netbsd32_sioc_vif_req *,
91 1.41.10.2 matt struct sioc_vif_req *, u_long);
92 1.41.10.2 matt static inline void netbsd32_to_sioc_sg_req(struct netbsd32_sioc_sg_req *,
93 1.41.10.2 matt struct sioc_sg_req *, u_long);
94 1.41.10.2 matt static inline void netbsd32_from_partinfo(struct partinfo *,
95 1.41.10.2 matt struct netbsd32_partinfo *, u_long);
96 1.41.10.2 matt #if 0
97 1.41.10.2 matt static inline void netbsd32_from_format_op(struct format_op *,
98 1.41.10.2 matt struct netbsd32_format_op *,
99 1.41.10.2 matt u_long);
100 1.41.10.2 matt #endif
101 1.41.10.2 matt static inline void netbsd32_from_ifreq(struct ifreq *,
102 1.41.10.2 matt struct netbsd32_ifreq *, u_long);
103 1.41.10.2 matt static inline void netbsd32_from_ifconf(struct ifconf *,
104 1.41.10.2 matt struct netbsd32_ifconf *, u_long);
105 1.41.10.2 matt static inline void netbsd32_from_ifmediareq(struct ifmediareq *,
106 1.41.10.2 matt struct netbsd32_ifmediareq *,
107 1.41.10.2 matt u_long);
108 1.41.10.2 matt static inline void netbsd32_from_ifdrv(struct ifdrv *,
109 1.41.10.2 matt struct netbsd32_ifdrv *, u_long);
110 1.41.10.2 matt static inline void netbsd32_from_sioc_vif_req(struct sioc_vif_req *,
111 1.41.10.2 matt struct netbsd32_sioc_vif_req *,
112 1.41.10.2 matt u_long);
113 1.41.10.2 matt static inline void netbsd32_from_sioc_sg_req(struct sioc_sg_req *,
114 1.41.10.2 matt struct netbsd32_sioc_sg_req *,
115 1.41.10.2 matt u_long);
116 1.41.10.2 matt
117 1.41.10.2 matt /* convert to/from different structures */
118 1.41.10.2 matt
119 1.41.10.2 matt static inline void
120 1.41.10.2 matt netbsd32_to_partinfo(struct netbsd32_partinfo *s32p, struct partinfo *p, u_long cmd)
121 1.41.10.2 matt {
122 1.41.10.2 matt
123 1.41.10.2 matt p->disklab = (struct disklabel *)NETBSD32PTR64(s32p->disklab);
124 1.41.10.2 matt p->part = (struct partition *)NETBSD32PTR64(s32p->part);
125 1.41.10.2 matt }
126 1.41.10.2 matt
127 1.41.10.2 matt #if 0
128 1.41.10.2 matt static inline void
129 1.41.10.2 matt netbsd32_to_format_op(struct netbsd32_format_op *s32p, struct format_op *p, u_long cmd)
130 1.41.10.2 matt {
131 1.41.10.2 matt
132 1.41.10.2 matt p->df_buf = (char *)NETBSD32PTR64(s32p->df_buf);
133 1.41.10.2 matt p->df_count = s32p->df_count;
134 1.41.10.2 matt p->df_startblk = s32p->df_startblk;
135 1.41.10.2 matt memcpy(p->df_reg, s32p->df_reg, sizeof(s32p->df_reg));
136 1.41.10.2 matt }
137 1.41.10.2 matt #endif
138 1.41.10.2 matt
139 1.41.10.2 matt static inline void
140 1.41.10.2 matt netbsd32_to_ifreq(struct netbsd32_ifreq *s32p, struct ifreq *p, u_long cmd)
141 1.41.10.2 matt {
142 1.41.10.2 matt
143 1.41.10.2 matt memcpy(p, s32p, sizeof *s32p);
144 1.41.10.2 matt /*
145 1.41.10.2 matt * XXX
146 1.41.10.2 matt * struct ifreq says the same, but sometimes the ifr_data
147 1.41.10.2 matt * union member needs to be converted to 64 bits... this
148 1.41.10.2 matt * is very driver specific and so we ignore it for now..
149 1.41.10.2 matt */
150 1.41.10.2 matt if (cmd == SIOCGIFDATA || cmd == SIOCZIFDATA)
151 1.41.10.2 matt p->ifr_data = (void *)NETBSD32PTR64(s32p->ifr_data);
152 1.41.10.2 matt }
153 1.41.10.2 matt
154 1.41.10.2 matt static inline void
155 1.41.10.2 matt netbsd32_to_ifconf(struct netbsd32_ifconf *s32p, struct ifconf *p, u_long cmd)
156 1.41.10.2 matt {
157 1.41.10.2 matt
158 1.41.10.2 matt p->ifc_len = s32p->ifc_len;
159 1.41.10.2 matt /* ifc_buf & ifc_req are the same size so this works */
160 1.41.10.2 matt p->ifc_buf = (void *)NETBSD32PTR64(s32p->ifc_buf);
161 1.41.10.2 matt }
162 1.41.10.2 matt
163 1.41.10.2 matt static inline void
164 1.41.10.2 matt netbsd32_to_ifmediareq(struct netbsd32_ifmediareq *s32p, struct ifmediareq *p, u_long cmd)
165 1.41.10.2 matt {
166 1.41.10.2 matt
167 1.41.10.2 matt memcpy(p, s32p, sizeof *s32p);
168 1.41.10.2 matt p->ifm_ulist = (int *)NETBSD32PTR64(s32p->ifm_ulist);
169 1.41.10.2 matt }
170 1.41.10.2 matt
171 1.41.10.2 matt static inline void
172 1.41.10.2 matt netbsd32_to_ifdrv(struct netbsd32_ifdrv *s32p, struct ifdrv *p, u_long cmd)
173 1.41.10.2 matt {
174 1.41.10.2 matt
175 1.41.10.2 matt memcpy(p, s32p, sizeof *s32p);
176 1.41.10.2 matt p->ifd_data = (void *)NETBSD32PTR64(s32p->ifd_data);
177 1.41.10.2 matt }
178 1.41.10.2 matt
179 1.41.10.2 matt static inline void
180 1.41.10.2 matt netbsd32_to_sioc_vif_req(struct netbsd32_sioc_vif_req *s32p, struct sioc_vif_req *p, u_long cmd)
181 1.41.10.2 matt {
182 1.41.10.2 matt
183 1.41.10.2 matt p->vifi = s32p->vifi;
184 1.41.10.2 matt p->icount = (u_long)s32p->icount;
185 1.41.10.2 matt p->ocount = (u_long)s32p->ocount;
186 1.41.10.2 matt p->ibytes = (u_long)s32p->ibytes;
187 1.41.10.2 matt p->obytes = (u_long)s32p->obytes;
188 1.41.10.2 matt }
189 1.41.10.2 matt
190 1.41.10.2 matt static inline void
191 1.41.10.2 matt netbsd32_to_sioc_sg_req(struct netbsd32_sioc_sg_req *s32p, struct sioc_sg_req *p, u_long cmd)
192 1.41.10.2 matt {
193 1.41.10.2 matt
194 1.41.10.2 matt p->src = s32p->src;
195 1.41.10.2 matt p->grp = s32p->grp;
196 1.41.10.2 matt p->pktcnt = (u_long)s32p->pktcnt;
197 1.41.10.2 matt p->bytecnt = (u_long)s32p->bytecnt;
198 1.41.10.2 matt p->wrong_if = (u_long)s32p->wrong_if;
199 1.41.10.2 matt }
200 1.41.10.2 matt
201 1.41.10.2 matt /*
202 1.41.10.2 matt * handle ioctl conversions from 64-bit kernel -> netbsd32
203 1.41.10.2 matt */
204 1.41.10.2 matt
205 1.41.10.2 matt static inline void
206 1.41.10.2 matt netbsd32_from_partinfo(struct partinfo *p, struct netbsd32_partinfo *s32p, u_long cmd)
207 1.41.10.2 matt {
208 1.41.10.2 matt
209 1.41.10.2 matt NETBSD32PTR32(s32p->disklab, p->disklab);
210 1.41.10.2 matt NETBSD32PTR32(s32p->part, p->part);
211 1.41.10.2 matt }
212 1.41.10.2 matt
213 1.41.10.2 matt #if 0
214 1.41.10.2 matt static inline void
215 1.41.10.2 matt netbsd32_from_format_op(struct format_op *p, struct netbsd32_format_op *s32p, u_long cmd)
216 1.41.10.2 matt {
217 1.41.10.2 matt
218 1.41.10.2 matt /* filled in */
219 1.41.10.2 matt #if 0
220 1.41.10.2 matt s32p->df_buf = (netbsd32_charp)p->df_buf;
221 1.41.10.2 matt #endif
222 1.41.10.2 matt s32p->df_count = p->df_count;
223 1.41.10.2 matt s32p->df_startblk = p->df_startblk;
224 1.41.10.2 matt memcpy(s32p->df_reg, p->df_reg, sizeof(p->df_reg));
225 1.41.10.2 matt }
226 1.41.10.2 matt #endif
227 1.41.10.2 matt
228 1.41.10.2 matt static inline void
229 1.41.10.2 matt netbsd32_from_ifreq(struct ifreq *p, struct netbsd32_ifreq *s32p, u_long cmd)
230 1.41.10.2 matt {
231 1.41.10.2 matt
232 1.41.10.2 matt /*
233 1.41.10.2 matt * XXX
234 1.41.10.2 matt * struct ifreq says the same, but sometimes the ifr_data
235 1.41.10.2 matt * union member needs to be converted to 64 bits... this
236 1.41.10.2 matt * is very driver specific and so we ignore it for now..
237 1.41.10.2 matt */
238 1.41.10.2 matt *s32p->ifr_name = *p->ifr_name;
239 1.41.10.2 matt if (cmd == SIOCGIFDATA || cmd == SIOCZIFDATA)
240 1.41.10.2 matt NETBSD32PTR32(s32p->ifr_data, p->ifr_data);
241 1.41.10.2 matt }
242 1.41.10.2 matt
243 1.41.10.2 matt static inline void
244 1.41.10.2 matt netbsd32_from_ifconf(struct ifconf *p, struct netbsd32_ifconf *s32p, u_long cmd)
245 1.41.10.2 matt {
246 1.41.10.2 matt
247 1.41.10.2 matt s32p->ifc_len = p->ifc_len;
248 1.41.10.2 matt /* ifc_buf & ifc_req are the same size so this works */
249 1.41.10.2 matt NETBSD32PTR32(s32p->ifc_buf, p->ifc_buf);
250 1.41.10.2 matt }
251 1.41.10.2 matt
252 1.41.10.2 matt static inline void
253 1.41.10.2 matt netbsd32_from_ifmediareq(struct ifmediareq *p, struct netbsd32_ifmediareq *s32p, u_long cmd)
254 1.41.10.2 matt {
255 1.41.10.2 matt
256 1.41.10.2 matt memcpy(s32p, p, sizeof *p);
257 1.41.10.2 matt /* filled in? */
258 1.41.10.2 matt #if 0
259 1.41.10.2 matt s32p->ifm_ulist = (netbsd32_intp_t)p->ifm_ulist;
260 1.41.10.2 matt #endif
261 1.41.10.2 matt }
262 1.41.10.2 matt
263 1.41.10.2 matt static inline void
264 1.41.10.2 matt netbsd32_from_ifdrv(struct ifdrv *p, struct netbsd32_ifdrv *s32p, u_long cmd)
265 1.41.10.2 matt {
266 1.41.10.2 matt
267 1.41.10.2 matt memcpy(s32p, p, sizeof *p);
268 1.41.10.2 matt /* filled in? */
269 1.41.10.2 matt #if 0
270 1.41.10.2 matt s32p->ifm_data = (netbsd32_u_longp_t)p->ifm_data;
271 1.41.10.2 matt #endif
272 1.41.10.2 matt }
273 1.41.10.2 matt
274 1.41.10.2 matt static inline void
275 1.41.10.2 matt netbsd32_from_sioc_vif_req(struct sioc_vif_req *p, struct netbsd32_sioc_vif_req *s32p, u_long cmd)
276 1.41.10.2 matt {
277 1.41.10.2 matt
278 1.41.10.2 matt s32p->vifi = p->vifi;
279 1.41.10.2 matt s32p->icount = (netbsd32_u_long)p->icount;
280 1.41.10.2 matt s32p->ocount = (netbsd32_u_long)p->ocount;
281 1.41.10.2 matt s32p->ibytes = (netbsd32_u_long)p->ibytes;
282 1.41.10.2 matt s32p->obytes = (netbsd32_u_long)p->obytes;
283 1.41.10.2 matt }
284 1.41.10.2 matt
285 1.41.10.2 matt static inline void
286 1.41.10.2 matt netbsd32_from_sioc_sg_req(struct sioc_sg_req *p, struct netbsd32_sioc_sg_req *s32p, u_long cmd)
287 1.41.10.2 matt {
288 1.41.10.2 matt
289 1.41.10.2 matt s32p->src = p->src;
290 1.41.10.2 matt s32p->grp = p->grp;
291 1.41.10.2 matt s32p->pktcnt = (netbsd32_u_long)p->pktcnt;
292 1.41.10.2 matt s32p->bytecnt = (netbsd32_u_long)p->bytecnt;
293 1.41.10.2 matt s32p->wrong_if = (netbsd32_u_long)p->wrong_if;
294 1.41.10.2 matt }
295 1.41.10.2 matt
296 1.41.10.2 matt
297 1.41.10.2 matt /*
298 1.41.10.2 matt * main ioctl syscall.
299 1.41.10.2 matt *
300 1.41.10.2 matt * ok, here we are in the biggy. we have to do fix ups depending
301 1.41.10.2 matt * on the ioctl command before and afterwards.
302 1.41.10.2 matt */
303 1.41.10.2 matt int
304 1.41.10.2 matt netbsd32_ioctl(struct lwp *l, const struct netbsd32_ioctl_args *uap, register_t *retval)
305 1.41.10.2 matt {
306 1.41.10.2 matt /* {
307 1.41.10.2 matt syscallarg(int) fd;
308 1.41.10.2 matt syscallarg(netbsd32_u_long) com;
309 1.41.10.2 matt syscallarg(netbsd32_voidp) data;
310 1.41.10.2 matt } */
311 1.41.10.2 matt struct proc *p = l->l_proc;
312 1.41.10.2 matt struct file *fp;
313 1.41.10.2 matt struct filedesc *fdp;
314 1.41.10.2 matt u_long com;
315 1.41.10.2 matt int error = 0;
316 1.41.10.2 matt u_int size, size32;
317 1.41.10.2 matt void *data, *memp = NULL;
318 1.41.10.2 matt void *data32, *memp32 = NULL;
319 1.41.10.2 matt unsigned fd;
320 1.41.10.2 matt fdfile_t *ff;
321 1.41.10.2 matt int tmp;
322 1.41.10.2 matt #define STK_PARAMS 128
323 1.41.10.2 matt u_long stkbuf[STK_PARAMS/sizeof(u_long)];
324 1.41.10.2 matt u_long stkbuf32[STK_PARAMS/sizeof(u_long)];
325 1.41.10.2 matt
326 1.41.10.2 matt /*
327 1.41.10.2 matt * we need to translate some commands (_IOW) before calling sys_ioctl,
328 1.41.10.2 matt * some after (_IOR), and some both (_IOWR).
329 1.41.10.2 matt */
330 1.41.10.2 matt #if 0
331 1.41.10.2 matt {
332 1.41.10.2 matt char *dirs[8] = { "NONE!", "VOID", "OUT", "VOID|OUT!", "IN", "VOID|IN!",
333 1.41.10.2 matt "INOUT", "VOID|IN|OUT!" };
334 1.41.10.2 matt
335 1.41.10.2 matt printf("netbsd32_ioctl(%d, %x, %x): %s group %c base %d len %d\n",
336 1.41.10.2 matt SCARG(uap, fd), SCARG(uap, com), SCARG(uap, data),
337 1.41.10.2 matt dirs[((SCARG(uap, com) & IOC_DIRMASK)>>29)],
338 1.41.10.2 matt IOCGROUP(SCARG(uap, com)), IOCBASECMD(SCARG(uap, com)),
339 1.41.10.2 matt IOCPARM_LEN(SCARG(uap, com)));
340 1.41.10.2 matt }
341 1.41.10.2 matt #endif
342 1.41.10.2 matt
343 1.41.10.2 matt fdp = p->p_fd;
344 1.41.10.2 matt fd = SCARG(uap, fd);
345 1.41.10.2 matt if ((fp = fd_getfile(fd)) == NULL)
346 1.41.10.2 matt return (EBADF);
347 1.41.10.2 matt if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
348 1.41.10.2 matt error = EBADF;
349 1.41.10.2 matt goto out;
350 1.41.10.2 matt }
351 1.41.10.2 matt
352 1.41.10.2 matt ff = fdp->fd_ofiles[SCARG(uap, fd)];
353 1.41.10.2 matt switch (com = SCARG(uap, com)) {
354 1.41.10.2 matt case FIOCLEX:
355 1.41.10.2 matt ff->ff_exclose = true;
356 1.41.10.2 matt fdp->fd_exclose = true;
357 1.41.10.2 matt goto out;
358 1.41.10.2 matt
359 1.41.10.2 matt case FIONCLEX:
360 1.41.10.2 matt ff->ff_exclose = false;
361 1.41.10.2 matt goto out;
362 1.41.10.2 matt }
363 1.41.10.2 matt
364 1.41.10.2 matt /*
365 1.41.10.2 matt * Interpret high order word to find amount of data to be
366 1.41.10.2 matt * copied to/from the user's address space.
367 1.41.10.2 matt */
368 1.41.10.2 matt size = 0;
369 1.41.10.2 matt size32 = IOCPARM_LEN(com);
370 1.41.10.2 matt if (size32 > IOCPARM_MAX) {
371 1.41.10.2 matt error = ENOTTY;
372 1.41.10.2 matt goto out;
373 1.41.10.2 matt }
374 1.41.10.2 matt if (size32 > sizeof(stkbuf)) {
375 1.41.10.2 matt memp32 = kmem_alloc((size_t)size32, KM_SLEEP);
376 1.41.10.2 matt data32 = memp32;
377 1.41.10.2 matt } else
378 1.41.10.2 matt data32 = (void *)stkbuf32;
379 1.41.10.2 matt if (com&IOC_IN) {
380 1.41.10.2 matt if (size32) {
381 1.41.10.2 matt error = copyin(SCARG_P32(uap, data), data32, size32);
382 1.41.10.2 matt if (error) {
383 1.41.10.2 matt if (memp32)
384 1.41.10.2 matt kmem_free(memp32, (size_t)size32);
385 1.41.10.2 matt goto out;
386 1.41.10.2 matt }
387 1.41.10.2 matt ktrgenio(fd, UIO_WRITE, SCARG_P32(uap, data),
388 1.41.10.2 matt size32, 0);
389 1.41.10.2 matt } else
390 1.41.10.2 matt *(void **)data32 = SCARG_P32(uap, data);
391 1.41.10.2 matt } else if ((com&IOC_OUT) && size32)
392 1.41.10.2 matt /*
393 1.41.10.2 matt * Zero the buffer so the user always
394 1.41.10.2 matt * gets back something deterministic.
395 1.41.10.2 matt */
396 1.41.10.2 matt memset(data32, 0, size32);
397 1.41.10.2 matt else if (com&IOC_VOID)
398 1.41.10.2 matt *(void **)data32 = SCARG_P32(uap, data);
399 1.41.10.2 matt
400 1.41.10.2 matt /*
401 1.41.10.2 matt * convert various structures, pointers, and other objects that
402 1.41.10.2 matt * change size from 32 bit -> 64 bit, for all ioctl commands.
403 1.41.10.2 matt */
404 1.41.10.2 matt switch (SCARG(uap, com)) {
405 1.41.10.2 matt case FIONBIO:
406 1.41.10.2 matt mutex_enter(&fp->f_lock);
407 1.41.10.2 matt if ((tmp = *(int *)data32) != 0)
408 1.41.10.2 matt fp->f_flag |= FNONBLOCK;
409 1.41.10.2 matt else
410 1.41.10.2 matt fp->f_flag &= ~FNONBLOCK;
411 1.41.10.2 matt mutex_exit(&fp->f_lock);
412 1.41.10.2 matt error = (*fp->f_ops->fo_ioctl)(fp, FIONBIO, (void *)&tmp);
413 1.41.10.2 matt break;
414 1.41.10.2 matt
415 1.41.10.2 matt case FIOASYNC:
416 1.41.10.2 matt mutex_enter(&fp->f_lock);
417 1.41.10.2 matt if ((tmp = *(int *)data32) != 0)
418 1.41.10.2 matt fp->f_flag |= FASYNC;
419 1.41.10.2 matt else
420 1.41.10.2 matt fp->f_flag &= ~FASYNC;
421 1.41.10.2 matt mutex_exit(&fp->f_lock);
422 1.41.10.2 matt error = (*fp->f_ops->fo_ioctl)(fp, FIOASYNC, (void *)&tmp);
423 1.41.10.2 matt break;
424 1.41.10.2 matt
425 1.41.10.2 matt case DIOCGPART32:
426 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(DIOCGPART, partinfo);
427 1.41.10.2 matt #if 0 /* not implemented by anything */
428 1.41.10.2 matt case DIOCRFORMAT32:
429 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(DIOCRFORMAT, format_op);
430 1.41.10.2 matt case DIOCWFORMAT32:
431 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(DIOCWFORMAT, format_op);
432 1.41.10.2 matt #endif
433 1.41.10.2 matt
434 1.41.10.2 matt /*
435 1.41.10.2 matt * only a few ifreq syscalls need conversion and those are
436 1.41.10.2 matt * all driver specific... XXX
437 1.41.10.2 matt */
438 1.41.10.2 matt #if 0
439 1.41.10.2 matt case SIOCGADDRROM3232:
440 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCGADDRROM32, ifreq);
441 1.41.10.2 matt case SIOCGCHIPID32:
442 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCGCHIPID, ifreq);
443 1.41.10.2 matt case SIOCSIFADDR32:
444 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCSIFADDR, ifreq);
445 1.41.10.2 matt case OSIOCGIFADDR32:
446 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(OSIOCGIFADDR, ifreq);
447 1.41.10.2 matt case SIOCGIFADDR32:
448 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCGIFADDR, ifreq);
449 1.41.10.2 matt case SIOCSIFDSTADDR32:
450 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCSIFDSTADDR, ifreq);
451 1.41.10.2 matt case OSIOCGIFDSTADDR32:
452 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(OSIOCGIFDSTADDR, ifreq);
453 1.41.10.2 matt case SIOCGIFDSTADDR32:
454 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCGIFDSTADDR, ifreq);
455 1.41.10.2 matt case OSIOCGIFBRDADDR32:
456 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(OSIOCGIFBRDADDR, ifreq);
457 1.41.10.2 matt case SIOCGIFBRDADDR32:
458 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCGIFBRDADDR, ifreq);
459 1.41.10.2 matt case SIOCSIFBRDADDR32:
460 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCSIFBRDADDR, ifreq);
461 1.41.10.2 matt case OSIOCGIFNETMASK32:
462 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(OSIOCGIFNETMASK, ifreq);
463 1.41.10.2 matt case SIOCGIFNETMASK32:
464 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCGIFNETMASK, ifreq);
465 1.41.10.2 matt case SIOCSIFNETMASK32:
466 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCSIFNETMASK, ifreq);
467 1.41.10.2 matt case SIOCGIFMETRIC32:
468 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCGIFMETRIC, ifreq);
469 1.41.10.2 matt case SIOCSIFMETRIC32:
470 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCSIFMETRIC, ifreq);
471 1.41.10.2 matt case SIOCDIFADDR32:
472 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCDIFADDR, ifreq);
473 1.41.10.2 matt case SIOCADDMULTI32:
474 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCADDMULTI, ifreq);
475 1.41.10.2 matt case SIOCDELMULTI32:
476 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCDELMULTI, ifreq);
477 1.41.10.2 matt case SIOCSIFMEDIA32:
478 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCSIFMEDIA, ifreq);
479 1.41.10.2 matt case SIOCSIFMTU32:
480 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCSIFMTU, ifreq);
481 1.41.10.2 matt case SIOCGIFMTU32:
482 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCGIFMTU, ifreq);
483 1.41.10.2 matt case BIOCGETIF32:
484 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(BIOCGETIF, ifreq);
485 1.41.10.2 matt case BIOCSETIF32:
486 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(BIOCSETIF, ifreq);
487 1.41.10.2 matt case SIOCPHASE132:
488 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCPHASE1, ifreq);
489 1.41.10.2 matt case SIOCPHASE232:
490 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCPHASE2, ifreq);
491 1.41.10.2 matt #endif
492 1.41.10.2 matt
493 1.41.10.2 matt case OOSIOCGIFCONF32:
494 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(OOSIOCGIFCONF, ifconf);
495 1.41.10.2 matt case OSIOCGIFCONF32:
496 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(OSIOCGIFCONF, ifconf);
497 1.41.10.2 matt case SIOCGIFCONF32:
498 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCGIFCONF, ifconf);
499 1.41.10.2 matt
500 1.41.10.2 matt case SIOCGIFFLAGS32:
501 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCGIFFLAGS, ifreq);
502 1.41.10.2 matt case SIOCSIFFLAGS32:
503 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCSIFFLAGS, ifreq);
504 1.41.10.2 matt
505 1.41.10.2 matt case SIOCGIFMEDIA32:
506 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCGIFMEDIA, ifmediareq);
507 1.41.10.2 matt
508 1.41.10.2 matt case SIOCSDRVSPEC32:
509 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCSDRVSPEC, ifdrv);
510 1.41.10.2 matt
511 1.41.10.2 matt case SIOCGETVIFCNT32:
512 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCGETVIFCNT, sioc_vif_req);
513 1.41.10.2 matt
514 1.41.10.2 matt case SIOCGETSGCNT32:
515 1.41.10.2 matt IOCTL_STRUCT_CONV_TO(SIOCGETSGCNT, sioc_sg_req);
516 1.41.10.2 matt
517 1.41.10.2 matt default:
518 1.41.10.2 matt #ifdef NETBSD32_MD_IOCTL
519 1.41.10.2 matt error = netbsd32_md_ioctl(fp, com, data32, l);
520 1.41.10.2 matt #else
521 1.41.10.2 matt error = (*fp->f_ops->fo_ioctl)(fp, com, data32);
522 1.41.10.2 matt #endif
523 1.41.10.2 matt break;
524 1.41.10.2 matt }
525 1.41.10.2 matt
526 1.41.10.2 matt if (error == EPASSTHROUGH)
527 1.41.10.2 matt error = ENOTTY;
528 1.41.10.2 matt
529 1.41.10.2 matt /*
530 1.41.10.2 matt * Copy any data to user, size was
531 1.41.10.2 matt * already set and checked above.
532 1.41.10.2 matt */
533 1.41.10.2 matt if (error == 0 && (com&IOC_OUT) && size32) {
534 1.41.10.2 matt error = copyout(data32, SCARG_P32(uap, data), size32);
535 1.41.10.2 matt ktrgenio(fd, UIO_READ, SCARG_P32(uap, data),
536 1.41.10.2 matt size32, error);
537 1.41.10.2 matt }
538 1.41.10.2 matt
539 1.41.10.2 matt /* if we malloced data, free it here */
540 1.41.10.2 matt if (memp32)
541 1.41.10.2 matt kmem_free(memp32, (size_t)size32);
542 1.41.10.2 matt if (memp)
543 1.41.10.2 matt kmem_free(memp, (size_t)size);
544 1.41.10.2 matt out:
545 1.41.10.2 matt fd_putfile(fd);
546 1.41.10.2 matt return (error);
547 1.41.10.2 matt }
548