xref: /netbsd-src/sys/compat/netbsd32/netbsd32_ioctl.c (revision c29d51755812ace2e87aeefdb06cb2b4dac7087a)
1 /*	$NetBSD: netbsd32_ioctl.c,v 1.82 2015/08/02 07:37:57 maxv Exp $	*/
2 
3 /*
4  * Copyright (c) 1998, 2001 Matthew R. Green
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 /*
30  * handle ioctl conversions from netbsd32 -> 64-bit kernel
31  */
32 
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: netbsd32_ioctl.c,v 1.82 2015/08/02 07:37:57 maxv Exp $");
35 
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/filedesc.h>
39 #include <sys/ioctl.h>
40 #include <sys/file.h>
41 #include <sys/proc.h>
42 #include <sys/socketvar.h>
43 #include <sys/audioio.h>
44 #include <sys/disklabel.h>
45 #include <sys/dkio.h>
46 #include <sys/ataio.h>
47 #include <sys/sockio.h>
48 #include <sys/socket.h>
49 #include <sys/ttycom.h>
50 #include <sys/mount.h>
51 #include <sys/syscallargs.h>
52 #include <sys/ktrace.h>
53 #include <sys/kmem.h>
54 #include <sys/envsys.h>
55 #include <sys/wdog.h>
56 #include <sys/clockctl.h>
57 #include <sys/exec_elf.h>
58 #include <sys/ksyms.h>
59 
60 #ifdef __sparc__
61 #include <dev/sun/fbio.h>
62 #include <machine/openpromio.h>
63 #endif
64 
65 #include <net/if.h>
66 #include <net/route.h>
67 
68 #include <net/if_pppoe.h>
69 #include <net/if_sppp.h>
70 
71 #include <net/npf/npf.h>
72 
73 #include <net/bpf.h>
74 #include <netinet/in.h>
75 #include <netinet/in_var.h>
76 #include <netinet/igmp.h>
77 #include <netinet/igmp_var.h>
78 #include <netinet/ip_mroute.h>
79 
80 #include <compat/sys/sockio.h>
81 
82 #include <compat/netbsd32/netbsd32.h>
83 #include <compat/netbsd32/netbsd32_ioctl.h>
84 #include <compat/netbsd32/netbsd32_syscallargs.h>
85 
86 #include <dev/vndvar.h>
87 
88 /* convert to/from different structures */
89 
90 static inline void
91 netbsd32_to_partinfo(struct netbsd32_partinfo *s32p, struct partinfo *p, u_long cmd)
92 {
93 
94 	p->disklab = (struct disklabel *)NETBSD32PTR64(s32p->disklab);
95 	p->part = (struct partition *)NETBSD32PTR64(s32p->part);
96 }
97 
98 #if 0
99 static inline void
100 netbsd32_to_format_op(struct netbsd32_format_op *s32p, struct format_op *p, u_long cmd)
101 {
102 
103 	p->df_buf = (char *)NETBSD32PTR64(s32p->df_buf);
104 	p->df_count = s32p->df_count;
105 	p->df_startblk = s32p->df_startblk;
106 	memcpy(p->df_reg, s32p->df_reg, sizeof(s32p->df_reg));
107 }
108 #endif
109 
110 static inline void
111 netbsd32_to_ifreq(struct netbsd32_ifreq *s32p, struct ifreq *p, u_long cmd)
112 {
113 
114 	memcpy(p, s32p, sizeof *s32p);
115 	/*
116 	 * XXX
117 	 * struct ifreq says the same, but sometimes the ifr_data
118 	 * union member needs to be converted to 64 bits... this
119 	 * is very driver specific and so we ignore it for now..
120 	 */
121 	if (cmd == SIOCGIFDATA || cmd == SIOCZIFDATA)
122 		p->ifr_data = (void *)NETBSD32PTR64(s32p->ifr_data);
123 }
124 
125 static inline void
126 netbsd32_to_oifreq(struct netbsd32_oifreq *s32p, struct oifreq *p, u_long cmd)
127 {
128 
129 	memcpy(p, s32p, sizeof *s32p);
130 	/*
131 	 * XXX
132 	 * struct ifreq says the same, but sometimes the ifr_data
133 	 * union member needs to be converted to 64 bits... this
134 	 * is very driver specific and so we ignore it for now..
135 	 */
136 	if (cmd == SIOCGIFDATA || cmd == SIOCZIFDATA)
137 		p->ifr_data = (void *)NETBSD32PTR64(s32p->ifr_data);
138 }
139 
140 static inline void
141 netbsd32_to_if_addrprefreq(const struct netbsd32_if_addrprefreq *ifap32,
142 	struct if_addrprefreq *ifap, u_long cmd)
143 {
144 	strlcpy(ifap->ifap_name, ifap32->ifap_name, sizeof(ifap->ifap_name));
145 	ifap->ifap_preference = ifap32->ifap_preference;
146 	memcpy(&ifap->ifap_addr, &ifap32->ifap_addr,
147 	    min(ifap32->ifap_addr.ss_len, _SS_MAXSIZE));
148 }
149 
150 static inline void
151 netbsd32_to_ifconf(struct netbsd32_ifconf *s32p, struct ifconf *p, u_long cmd)
152 {
153 
154 	p->ifc_len = s32p->ifc_len;
155 	/* ifc_buf & ifc_req are the same size so this works */
156 	p->ifc_buf = (void *)NETBSD32PTR64(s32p->ifc_buf);
157 }
158 
159 static inline void
160 netbsd32_to_ifmediareq(struct netbsd32_ifmediareq *s32p, struct ifmediareq *p, u_long cmd)
161 {
162 
163 	memcpy(p, s32p, sizeof *s32p);
164 	p->ifm_ulist = (int *)NETBSD32PTR64(s32p->ifm_ulist);
165 }
166 
167 static inline void
168 netbsd32_to_pppoediscparms(struct netbsd32_pppoediscparms *s32p,
169     struct pppoediscparms *p, u_long cmd)
170 {
171 
172 	memcpy(p->ifname, s32p->ifname, sizeof p->ifname);
173 	memcpy(p->eth_ifname, s32p->eth_ifname, sizeof p->eth_ifname);
174 	p->ac_name = (char *)NETBSD32PTR64(s32p->ac_name);
175 	p->ac_name_len = s32p->ac_name_len;
176 	p->service_name = (char *)NETBSD32PTR64(s32p->service_name);
177 	p->service_name_len = s32p->service_name_len;
178 }
179 
180 static inline void
181 netbsd32_to_spppauthcfg(struct netbsd32_spppauthcfg *s32p,
182     struct spppauthcfg *p, u_long cmd)
183 {
184 
185 	memcpy(p->ifname, s32p->ifname, sizeof p->ifname);
186 	p->hisauth = s32p->hisauth;
187 	p->myauth = s32p->myauth;
188 	p->myname_length = s32p->myname_length;
189 	p->mysecret_length = s32p->mysecret_length;
190 	p->hisname_length = s32p->hisname_length;
191 	p->hissecret_length = s32p->hissecret_length;
192 	p->myauthflags = s32p->myauthflags;
193 	p->hisauthflags = s32p->hisauthflags;
194 	p->myname = (char *)NETBSD32PTR64(s32p->myname);
195 	p->mysecret = (char *)NETBSD32PTR64(s32p->mysecret);
196 	p->hisname = (char *)NETBSD32PTR64(s32p->hisname);
197 	p->hissecret = (char *)NETBSD32PTR64(s32p->hissecret);
198 }
199 
200 static inline void
201 netbsd32_to_ifdrv(struct netbsd32_ifdrv *s32p, struct ifdrv *p, u_long cmd)
202 {
203 
204 	memcpy(p->ifd_name, s32p->ifd_name, sizeof p->ifd_name);
205 	p->ifd_cmd = s32p->ifd_cmd;
206 	p->ifd_len = s32p->ifd_len;
207 	p->ifd_data = (void *)NETBSD32PTR64(s32p->ifd_data);
208 }
209 
210 static inline void
211 netbsd32_to_sioc_vif_req(struct netbsd32_sioc_vif_req *s32p, struct sioc_vif_req *p, u_long cmd)
212 {
213 
214 	p->vifi = s32p->vifi;
215 	p->icount = (u_long)s32p->icount;
216 	p->ocount = (u_long)s32p->ocount;
217 	p->ibytes = (u_long)s32p->ibytes;
218 	p->obytes = (u_long)s32p->obytes;
219 }
220 
221 static inline void
222 netbsd32_to_sioc_sg_req(struct netbsd32_sioc_sg_req *s32p, struct sioc_sg_req *p, u_long cmd)
223 {
224 
225 	p->src = s32p->src;
226 	p->grp = s32p->grp;
227 	p->pktcnt = (u_long)s32p->pktcnt;
228 	p->bytecnt = (u_long)s32p->bytecnt;
229 	p->wrong_if = (u_long)s32p->wrong_if;
230 }
231 
232 static inline void
233 netbsd32_to_atareq(struct netbsd32_atareq *s32p, struct atareq *p, u_long cmd)
234 {
235 	p->flags = (u_long)s32p->flags;
236 	p->command = s32p->command;
237 	p->features = s32p->features;
238 	p->sec_count = s32p->sec_count;
239 	p->sec_num = s32p->sec_num;
240 	p->head = s32p->head;
241 	p->cylinder = s32p->cylinder;
242 	p->databuf =  (char *)NETBSD32PTR64(s32p->databuf);
243 	p->datalen = (u_long)s32p->datalen;
244 	p->timeout = s32p->timeout;
245 	p->retsts = s32p->retsts;
246 	p->error = s32p->error;
247 }
248 
249 static inline void
250 netbsd32_to_vnd_ioctl(struct netbsd32_vnd_ioctl *s32p, struct vnd_ioctl *p, u_long cmd)
251 {
252 
253 	p->vnd_file = (char *)NETBSD32PTR64(s32p->vnd_file);
254 	p->vnd_flags = s32p->vnd_flags;
255 	p->vnd_geom = s32p->vnd_geom;
256 	p->vnd_osize = s32p->vnd_osize;
257 	p->vnd_size = s32p->vnd_size;
258 }
259 
260 static inline void
261 netbsd32_to_vnd_user(struct netbsd32_vnd_user *s32p, struct vnd_user *p, u_long cmd)
262 {
263 
264 	p->vnu_unit = s32p->vnu_unit;
265 	p->vnu_dev = s32p->vnu_dev;
266 	p->vnu_ino = s32p->vnu_ino;
267 }
268 
269 static inline void
270 netbsd32_to_vnd_ioctl50(struct netbsd32_vnd_ioctl50 *s32p, struct vnd_ioctl50 *p, u_long cmd)
271 {
272 
273 	p->vnd_file = (char *)NETBSD32PTR64(s32p->vnd_file);
274 	p->vnd_flags = s32p->vnd_flags;
275 	p->vnd_geom = s32p->vnd_geom;
276 	p->vnd_size = s32p->vnd_size;
277 }
278 
279 static inline void
280 netbsd32_to_plistref(struct netbsd32_plistref *s32p, struct plistref *p, u_long cmd)
281 {
282 
283 	p->pref_plist = NETBSD32PTR64(s32p->pref_plist);
284 	p->pref_len = s32p->pref_len;
285 }
286 
287 static inline void
288 netbsd32_to_u_long(netbsd32_u_long *s32p, u_long *p, u_long cmd)
289 {
290 
291 	*p = (u_long)*s32p;
292 }
293 
294 static inline void
295 netbsd32_to_voidp(netbsd32_voidp *s32p, voidp *p, u_long cmd)
296 {
297 
298 	*p = (void *)NETBSD32PTR64(*s32p);
299 }
300 
301 static inline void
302 netbsd32_to_wdog_conf(struct netbsd32_wdog_conf *s32p, struct wdog_conf *p, u_long cmd)
303 {
304 
305 	p->wc_names = (char *)NETBSD32PTR64(s32p->wc_names);
306 	p->wc_count = s32p->wc_count;
307 }
308 
309 static inline void
310 netbsd32_to_bpf_program(struct netbsd32_bpf_program *s32p, struct bpf_program *p, u_long cmd)
311 {
312 
313 	p->bf_insns = (void *)NETBSD32PTR64(s32p->bf_insns);
314 	p->bf_len = s32p->bf_len;
315 }
316 
317 static inline void
318 netbsd32_to_bpf_dltlist(struct netbsd32_bpf_dltlist *s32p, struct bpf_dltlist *p, u_long cmd)
319 {
320 
321 	p->bfl_list = (void *)NETBSD32PTR64(s32p->bfl_list);
322 	p->bfl_len = s32p->bfl_len;
323 }
324 
325 /* wsdisplay stuff */
326 static inline void
327 netbsd32_to_wsdisplay_addscreendata(struct netbsd32_wsdisplay_addscreendata *asd32,
328 					       struct wsdisplay_addscreendata *asd,
329 					       u_long cmd)
330 {
331 	asd->screentype = (char *)NETBSD32PTR64(asd32->screentype);
332 	asd->emul = (char *)NETBSD32PTR64(asd32->emul);
333 	asd->idx = asd32->idx;
334 }
335 
336 static inline void
337 netbsd32_to_ieee80211req(struct netbsd32_ieee80211req *ireq32,
338 			 struct ieee80211req *ireq, u_long cmd)
339 {
340 	strncpy(ireq->i_name, ireq32->i_name, IFNAMSIZ);
341 	ireq->i_type = ireq32->i_type;
342 	ireq->i_val = ireq32->i_val;
343 	ireq->i_len = ireq32->i_len;
344 	ireq->i_data = NETBSD32PTR64(ireq32->i_data);
345 }
346 
347 static inline void
348 netbsd32_to_ieee80211_nwkey(struct netbsd32_ieee80211_nwkey *nwk32,
349 					       struct ieee80211_nwkey *nwk,
350 					       u_long cmd)
351 {
352 	int i;
353 
354 	strncpy(nwk->i_name, nwk32->i_name, IFNAMSIZ);
355 	nwk->i_wepon = nwk32->i_wepon;
356 	nwk->i_defkid = nwk32->i_defkid;
357 	for (i = 0; i < IEEE80211_WEP_NKID; i++) {
358 		nwk->i_key[i].i_keylen = nwk32->i_key[i].i_keylen;
359 		nwk->i_key[i].i_keydat =
360 		    NETBSD32PTR64(nwk32->i_key[i].i_keydat);
361 	}
362 }
363 
364 static inline void
365 netbsd32_to_wsdisplay_cursor(struct netbsd32_wsdisplay_cursor *c32,
366 					       struct wsdisplay_cursor *c,
367 					       u_long cmd)
368 {
369 	c->which = c32->which;
370 	c->enable = c32->enable;
371 	c->pos.x = c32->pos.x;
372 	c->pos.y = c32->pos.y;
373 	c->hot.x = c32->hot.x;
374 	c->hot.y = c32->hot.y;
375 	c->size.x = c32->size.x;
376 	c->size.y = c32->size.y;
377 	c->cmap.index = c32->cmap.index;
378 	c->cmap.count = c32->cmap.count;
379 	c->cmap.red = NETBSD32PTR64(c32->cmap.red);
380 	c->cmap.green = NETBSD32PTR64(c32->cmap.green);
381 	c->cmap.blue = NETBSD32PTR64(c32->cmap.blue);
382 	c->image = NETBSD32PTR64(c32->image);
383 	c->mask = NETBSD32PTR64(c32->mask);
384 }
385 
386 static inline void
387 netbsd32_to_wsdisplay_cmap(struct netbsd32_wsdisplay_cmap *c32,
388 					       struct wsdisplay_cmap *c,
389 					       u_long cmd)
390 {
391 	c->index = c32->index;
392 	c->count = c32->count;
393 	c->red   = NETBSD32PTR64(c32->red);
394 	c->green = NETBSD32PTR64(c32->green);
395 	c->blue  = NETBSD32PTR64(c32->blue);
396 }
397 
398 static inline void
399 netbsd32_to_clockctl_settimeofday(
400     const struct netbsd32_clockctl_settimeofday *s32p,
401     struct clockctl_settimeofday *p,
402     u_long cmd)
403 {
404 
405 	p->tv = NETBSD32PTR64(s32p->tv);
406 	p->tzp = NETBSD32PTR64(s32p->tzp);
407 }
408 
409 static inline void
410 netbsd32_to_clockctl_adjtime(
411     const struct netbsd32_clockctl_adjtime *s32p,
412     struct clockctl_adjtime *p,
413     u_long cmd)
414 {
415 
416 	p->delta = NETBSD32PTR64(s32p->delta);
417 	p->olddelta = NETBSD32PTR64(s32p->olddelta);
418 }
419 
420 static inline void
421 netbsd32_to_clockctl_clock_settime(
422     const struct netbsd32_clockctl_clock_settime *s32p,
423     struct clockctl_clock_settime *p,
424     u_long cmd)
425 {
426 
427 	p->clock_id = s32p->clock_id;
428 	p->tp = NETBSD32PTR64(s32p->tp);
429 }
430 
431 static inline void
432 netbsd32_to_clockctl_ntp_adjtime(
433     const struct netbsd32_clockctl_ntp_adjtime *s32p,
434     struct clockctl_ntp_adjtime *p,
435     u_long cmd)
436 {
437 
438 	p->tp = NETBSD32PTR64(s32p->tp);
439 	p->retval = s32p->retval;
440 }
441 
442 static inline void
443 netbsd32_to_ksyms_gsymbol(
444     const struct netbsd32_ksyms_gsymbol *s32p,
445     struct ksyms_gsymbol *p,
446     u_long cmd)
447 {
448 
449 	p->kg_name = NETBSD32PTR64(s32p->kg_name);
450 }
451 
452 static inline void
453 netbsd32_to_ksyms_gvalue(
454     const struct netbsd32_ksyms_gvalue *s32p,
455     struct ksyms_gvalue *p,
456     u_long cmd)
457 {
458 
459 	p->kv_name = NETBSD32PTR64(s32p->kv_name);
460 }
461 
462 static inline void
463 netbsd32_to_npf_ioctl_table(
464     const struct netbsd32_npf_ioctl_table *s32p,
465     struct npf_ioctl_table *p,
466     u_long cmd)
467 {
468 
469 	p->nct_cmd = s32p->nct_cmd;
470 	p->nct_name = NETBSD32PTR64(s32p->nct_name);
471 	switch (s32p->nct_cmd) {
472 	case NPF_CMD_TABLE_LOOKUP:
473 	case NPF_CMD_TABLE_ADD:
474 	case NPF_CMD_TABLE_REMOVE:
475 		p->nct_data.ent.alen = s32p->nct_data.ent.alen;
476 		p->nct_data.ent.addr = s32p->nct_data.ent.addr;
477 		p->nct_data.ent.mask = s32p->nct_data.ent.mask;
478 		break;
479 	case NPF_CMD_TABLE_LIST:
480 		p->nct_data.buf.buf = NETBSD32PTR64(s32p->nct_data.buf.buf);
481 		p->nct_data.buf.len = s32p->nct_data.buf.len;
482 		break;
483 	}
484 }
485 
486 /*
487  * handle ioctl conversions from 64-bit kernel -> netbsd32
488  */
489 
490 static inline void
491 netbsd32_from_partinfo(struct partinfo *p, struct netbsd32_partinfo *s32p, u_long cmd)
492 {
493 
494 	NETBSD32PTR32(s32p->disklab, p->disklab);
495 	NETBSD32PTR32(s32p->part, p->part);
496 }
497 
498 #if 0
499 static inline void
500 netbsd32_from_format_op(struct format_op *p, struct netbsd32_format_op *s32p, u_long cmd)
501 {
502 
503 /* filled in */
504 #if 0
505 	s32p->df_buf = (netbsd32_charp)p->df_buf;
506 #endif
507 	s32p->df_count = p->df_count;
508 	s32p->df_startblk = p->df_startblk;
509 	memcpy(s32p->df_reg, p->df_reg, sizeof(p->df_reg));
510 }
511 #endif
512 
513 static inline void
514 netbsd32_from_ifreq(struct ifreq *p, struct netbsd32_ifreq *s32p, u_long cmd)
515 {
516 
517 	/*
518 	 * XXX
519 	 * struct ifreq says the same, but sometimes the ifr_data
520 	 * union member needs to be converted to 64 bits... this
521 	 * is very driver specific and so we ignore it for now..
522 	 */
523 	memcpy(s32p, p, sizeof *s32p);
524 	if (cmd == SIOCGIFDATA || cmd == SIOCZIFDATA)
525 		NETBSD32PTR32(s32p->ifr_data, p->ifr_data);
526 }
527 
528 static inline void
529 netbsd32_from_oifreq(struct oifreq *p, struct netbsd32_oifreq *s32p, u_long cmd)
530 {
531 
532 	/*
533 	 * XXX
534 	 * struct ifreq says the same, but sometimes the ifr_data
535 	 * union member needs to be converted to 64 bits... this
536 	 * is very driver specific and so we ignore it for now..
537 	 */
538 	memcpy(s32p, p, sizeof *s32p);
539 	if (cmd == SIOCGIFDATA || cmd == SIOCZIFDATA)
540 		NETBSD32PTR32(s32p->ifr_data, p->ifr_data);
541 }
542 
543 static inline void
544 netbsd32_from_if_addrprefreq(const struct if_addrprefreq *ifap,
545 	struct netbsd32_if_addrprefreq *ifap32, u_long cmd)
546 {
547 	strlcpy(ifap32->ifap_name, ifap->ifap_name, sizeof(ifap32->ifap_name));
548 	ifap32->ifap_preference = ifap->ifap_preference;
549 	memcpy(&ifap32->ifap_addr, &ifap->ifap_addr,
550 	    min(ifap->ifap_addr.ss_len, _SS_MAXSIZE));
551 }
552 
553 static inline void
554 netbsd32_from_ifconf(struct ifconf *p, struct netbsd32_ifconf *s32p, u_long cmd)
555 {
556 
557 	s32p->ifc_len = p->ifc_len;
558 	/* ifc_buf & ifc_req are the same size so this works */
559 	NETBSD32PTR32(s32p->ifc_buf, p->ifc_buf);
560 }
561 
562 static inline void
563 netbsd32_from_ifmediareq(struct ifmediareq *p, struct netbsd32_ifmediareq *s32p, u_long cmd)
564 {
565 
566 	memcpy(s32p, p, sizeof *p);
567 /* filled in? */
568 #if 0
569 	s32p->ifm_ulist = (netbsd32_intp_t)p->ifm_ulist;
570 #endif
571 }
572 
573 static inline void
574 netbsd32_from_pppoediscparms(struct pppoediscparms *p,
575     struct netbsd32_pppoediscparms *s32p, u_long cmd)
576 {
577 
578 	memcpy(s32p->ifname, p->ifname, sizeof s32p->ifname);
579 	memcpy(s32p->eth_ifname, p->eth_ifname, sizeof s32p->eth_ifname);
580 	NETBSD32PTR32(s32p->ac_name, p->ac_name);
581 	s32p->ac_name_len = p->ac_name_len;
582 	NETBSD32PTR32(s32p->service_name, p->service_name);
583 	s32p->service_name_len = p->service_name_len;
584 }
585 
586 static inline void
587 netbsd32_from_spppauthcfg(struct spppauthcfg *p,
588     struct netbsd32_spppauthcfg *s32p, u_long cmd)
589 {
590 
591 	memcpy(s32p->ifname, p->ifname, sizeof s32p->ifname);
592 	s32p->hisauth = p->hisauth;
593 	s32p->myauth = p->myauth;
594 	s32p->myname_length = p->myname_length;
595 	s32p->mysecret_length = p->mysecret_length;
596 	s32p->hisname_length = p->hisname_length;
597 	s32p->hissecret_length = p->hissecret_length;
598 	s32p->myauthflags = p->myauthflags;
599 	s32p->hisauthflags = p->hisauthflags;
600 	NETBSD32PTR32(s32p->myname, p->myname);
601 	NETBSD32PTR32(s32p->mysecret, p->mysecret);
602 	NETBSD32PTR32(s32p->hisname, p->hisname);
603 	NETBSD32PTR32(s32p->hissecret, p->hissecret);
604 }
605 
606 static inline void
607 netbsd32_from_ifdrv(struct ifdrv *p, struct netbsd32_ifdrv *s32p, u_long cmd)
608 {
609 
610 	memcpy(s32p->ifd_name, p->ifd_name, sizeof s32p->ifd_name);
611 	s32p->ifd_cmd = p->ifd_cmd;
612 	s32p->ifd_len = p->ifd_len;
613 	NETBSD32PTR32(s32p->ifd_data, p->ifd_data);
614 }
615 
616 static inline void
617 netbsd32_from_sioc_vif_req(struct sioc_vif_req *p, struct netbsd32_sioc_vif_req *s32p, u_long cmd)
618 {
619 
620 	s32p->vifi = p->vifi;
621 	s32p->icount = (netbsd32_u_long)p->icount;
622 	s32p->ocount = (netbsd32_u_long)p->ocount;
623 	s32p->ibytes = (netbsd32_u_long)p->ibytes;
624 	s32p->obytes = (netbsd32_u_long)p->obytes;
625 }
626 
627 static inline void
628 netbsd32_from_sioc_sg_req(struct sioc_sg_req *p, struct netbsd32_sioc_sg_req *s32p, u_long cmd)
629 {
630 
631 	s32p->src = p->src;
632 	s32p->grp = p->grp;
633 	s32p->pktcnt = (netbsd32_u_long)p->pktcnt;
634 	s32p->bytecnt = (netbsd32_u_long)p->bytecnt;
635 	s32p->wrong_if = (netbsd32_u_long)p->wrong_if;
636 }
637 
638 static inline void
639 netbsd32_from_atareq(struct atareq *p, struct netbsd32_atareq *s32p, u_long cmd)
640 {
641 	s32p->flags = (netbsd32_u_long)p->flags;
642 	s32p->command = p->command;
643 	s32p->features = p->features;
644 	s32p->sec_count = p->sec_count;
645 	s32p->sec_num = p->sec_num;
646 	s32p->head = p->head;
647 	s32p->cylinder = p->cylinder;
648 	NETBSD32PTR32(s32p->databuf, p->databuf);
649 	s32p->datalen = (netbsd32_u_long)p->datalen;
650 	s32p->timeout = p->timeout;
651 	s32p->retsts = p->retsts;
652 	s32p->error = p->error;
653 }
654 
655 static inline void
656 netbsd32_from_vnd_ioctl(struct vnd_ioctl *p, struct netbsd32_vnd_ioctl *s32p, u_long cmd)
657 {
658 
659 	s32p->vnd_flags = p->vnd_flags;
660 	s32p->vnd_geom = p->vnd_geom;
661 	s32p->vnd_osize = p->vnd_osize;
662 	s32p->vnd_size = p->vnd_size;
663 }
664 
665 static inline void
666 netbsd32_from_vnd_user(struct vnd_user *p, struct netbsd32_vnd_user *s32p, u_long cmd)
667 {
668 
669 	s32p->vnu_unit = p->vnu_unit;
670 	s32p->vnu_dev = p->vnu_dev;
671 	s32p->vnu_ino = p->vnu_ino;
672 }
673 
674 static inline void
675 netbsd32_from_vnd_ioctl50(struct vnd_ioctl50 *p, struct netbsd32_vnd_ioctl50 *s32p, u_long cmd)
676 {
677 
678 	s32p->vnd_flags = p->vnd_flags;
679 	s32p->vnd_geom = p->vnd_geom;
680 	s32p->vnd_size = p->vnd_size;
681 }
682 
683 static inline void
684 netbsd32_from_plistref(struct plistref *p, struct netbsd32_plistref *s32p, u_long cmd)
685 {
686 
687 	NETBSD32PTR32(s32p->pref_plist, p->pref_plist);
688 	s32p->pref_len = p->pref_len;
689 }
690 
691 static inline void
692 netbsd32_from_wdog_conf(struct wdog_conf *p, struct netbsd32_wdog_conf *s32p, u_long cmd)
693 {
694 
695 	NETBSD32PTR32(s32p->wc_names, p->wc_names);
696 	s32p->wc_count = p->wc_count;
697 }
698 
699 /* wsdisplay stuff */
700 static inline void
701 netbsd32_from_wsdisplay_addscreendata(struct wsdisplay_addscreendata *asd,
702 					struct netbsd32_wsdisplay_addscreendata *asd32,
703 					u_long cmd)
704 {
705 	NETBSD32PTR32(asd32->screentype, asd->screentype);
706 	NETBSD32PTR32(asd32->emul, asd->emul);
707 	asd32->idx = asd->idx;
708 }
709 
710 static inline void
711 netbsd32_from_wsdisplay_cursor(struct wsdisplay_cursor *c,
712 					       struct netbsd32_wsdisplay_cursor *c32,
713 					       u_long cmd)
714 {
715 	c32->which = c->which;
716 	c32->enable = c->enable;
717 	c32->pos.x = c->pos.x;
718 	c32->pos.y = c->pos.y;
719 	c32->hot.x = c->hot.x;
720 	c32->hot.y = c->hot.y;
721 	c32->size.x = c->size.x;
722 	c32->size.y = c->size.y;
723 	c32->cmap.index = c->cmap.index;
724 	c32->cmap.count = c->cmap.count;
725 	NETBSD32PTR32(c32->cmap.red, c->cmap.red);
726 	NETBSD32PTR32(c32->cmap.green, c->cmap.green);
727 	NETBSD32PTR32(c32->cmap.blue, c->cmap.blue);
728 	NETBSD32PTR32(c32->image, c->image);
729 	NETBSD32PTR32(c32->mask, c->mask);
730 }
731 
732 static inline void
733 netbsd32_from_wsdisplay_cmap(struct wsdisplay_cmap *c,
734 					   struct netbsd32_wsdisplay_cmap *c32,
735 					   u_long cmd)
736 {
737 	c32->index = c->index;
738 	c32->count = c->count;
739 	NETBSD32PTR32(c32->red, c->red);
740 	NETBSD32PTR32(c32->green, c->green);
741 	NETBSD32PTR32(c32->blue, c->blue);
742 }
743 
744 static inline void
745 netbsd32_from_ieee80211req(struct ieee80211req *ireq,
746 			   struct netbsd32_ieee80211req *ireq32, u_long cmd)
747 {
748 	strncpy(ireq32->i_name, ireq->i_name, IFNAMSIZ);
749 	ireq32->i_type = ireq->i_type;
750 	ireq32->i_val = ireq->i_val;
751 	ireq32->i_len = ireq->i_len;
752 	NETBSD32PTR32(ireq32->i_data, ireq->i_data);
753 }
754 
755 static inline void
756 netbsd32_from_ieee80211_nwkey(struct ieee80211_nwkey *nwk,
757 				struct netbsd32_ieee80211_nwkey *nwk32,
758 				u_long cmd)
759 {
760 	int i;
761 
762 	strncpy(nwk32->i_name, nwk->i_name, IFNAMSIZ);
763 	nwk32->i_wepon = nwk->i_wepon;
764 	nwk32->i_defkid = nwk->i_defkid;
765 	for (i = 0; i < IEEE80211_WEP_NKID; i++) {
766 		nwk32->i_key[i].i_keylen = nwk->i_key[i].i_keylen;
767 		NETBSD32PTR32(nwk32->i_key[i].i_keydat,
768 				nwk->i_key[i].i_keydat);
769 	}
770 }
771 
772 static inline void
773 netbsd32_from_bpf_program(struct bpf_program *p, struct netbsd32_bpf_program *s32p, u_long cmd)
774 {
775 
776 	NETBSD32PTR32(s32p->bf_insns, p->bf_insns);
777 	s32p->bf_len = p->bf_len;
778 }
779 
780 static inline void
781 netbsd32_from_bpf_dltlist(struct bpf_dltlist *p, struct netbsd32_bpf_dltlist *s32p, u_long cmd)
782 {
783 
784 	NETBSD32PTR32(s32p->bfl_list, p->bfl_list);
785 	s32p->bfl_len = p->bfl_len;
786 }
787 
788 static inline void
789 netbsd32_from_u_long(u_long *p, netbsd32_u_long *s32p, u_long cmd)
790 {
791 
792 	*s32p = (netbsd32_u_long)*p;
793 }
794 
795 static inline void
796 netbsd32_from_voidp(voidp *p, netbsd32_voidp *s32p, u_long cmd)
797 {
798 
799 	NETBSD32PTR32(*s32p, *p);
800 }
801 
802 
803 static inline void
804 netbsd32_from_clockctl_settimeofday(
805     const struct clockctl_settimeofday *p,
806     struct netbsd32_clockctl_settimeofday *s32p,
807     u_long cmd)
808 {
809 
810 	NETBSD32PTR32(s32p->tv, p->tv);
811 	NETBSD32PTR32(s32p->tzp, p->tzp);
812 }
813 
814 static inline void
815 netbsd32_from_clockctl_adjtime(
816     const struct clockctl_adjtime *p,
817     struct netbsd32_clockctl_adjtime *s32p,
818     u_long cmd)
819 {
820 
821 	NETBSD32PTR32(s32p->delta, p->delta);
822 	NETBSD32PTR32(s32p->olddelta, p->olddelta);
823 }
824 
825 static inline void
826 netbsd32_from_clockctl_clock_settime(
827     const struct clockctl_clock_settime *p,
828     struct netbsd32_clockctl_clock_settime *s32p,
829     u_long cmd)
830 {
831 
832 	s32p->clock_id = p->clock_id;
833 	NETBSD32PTR32(s32p->tp, p->tp);
834 }
835 
836 static inline void
837 netbsd32_from_clockctl_ntp_adjtime(
838     const struct clockctl_ntp_adjtime *p,
839     struct netbsd32_clockctl_ntp_adjtime *s32p,
840     u_long cmd)
841 {
842 
843 	NETBSD32PTR32(s32p->tp, p->tp);
844 	s32p->retval = p->retval;
845 }
846 
847 static inline void
848 netbsd32_from_ksyms_gsymbol(
849     const struct ksyms_gsymbol *p,
850     struct netbsd32_ksyms_gsymbol *s32p,
851     u_long cmd)
852 {
853 
854 	NETBSD32PTR32(s32p->kg_name, p->kg_name);
855 	s32p->kg_sym = p->kg_sym;
856 }
857 
858 static inline void
859 netbsd32_from_ksyms_gvalue(
860     const struct ksyms_gvalue *p,
861     struct netbsd32_ksyms_gvalue *s32p,
862     u_long cmd)
863 {
864 
865 	NETBSD32PTR32(s32p->kv_name, p->kv_name);
866 	s32p->kv_value = p->kv_value;
867 }
868 
869 static inline void
870 netbsd32_from_npf_ioctl_table(
871     const struct npf_ioctl_table *p,
872     struct netbsd32_npf_ioctl_table *s32p,
873     u_long cmd)
874 {
875 
876 	s32p->nct_cmd = p->nct_cmd;
877 	NETBSD32PTR32(s32p->nct_name, p->nct_name);
878 	switch (p->nct_cmd) {
879 	case NPF_CMD_TABLE_LOOKUP:
880 	case NPF_CMD_TABLE_ADD:
881 	case NPF_CMD_TABLE_REMOVE:
882 		s32p->nct_data.ent.alen = p->nct_data.ent.alen;
883 		s32p->nct_data.ent.addr = p->nct_data.ent.addr;
884 		s32p->nct_data.ent.mask = p->nct_data.ent.mask;
885 		break;
886 	case NPF_CMD_TABLE_LIST:
887 		NETBSD32PTR32(s32p->nct_data.buf.buf, p->nct_data.buf.buf);
888 		s32p->nct_data.buf.len = p->nct_data.buf.len;
889 		break;
890 	}
891 }
892 
893 /*
894  * main ioctl syscall.
895  *
896  * ok, here we are in the biggy.  we have to do fix ups depending
897  * on the ioctl command before and afterwards.
898  */
899 int
900 netbsd32_ioctl(struct lwp *l, const struct netbsd32_ioctl_args *uap, register_t *retval)
901 {
902 	/* {
903 		syscallarg(int) fd;
904 		syscallarg(netbsd32_u_long) com;
905 		syscallarg(netbsd32_voidp) data;
906 	} */
907 	struct proc *p = l->l_proc;
908 	struct file *fp;
909 	struct filedesc *fdp;
910 	u_long com;
911 	int error = 0;
912 	size_t size;
913 	size_t alloc_size32, size32;
914 	void *data, *memp = NULL;
915 	void *data32, *memp32 = NULL;
916 	unsigned int fd;
917 	fdfile_t *ff;
918 	int tmp;
919 #define STK_PARAMS	128
920 	uint64_t stkbuf[STK_PARAMS/sizeof(uint64_t)];
921 	uint64_t stkbuf32[STK_PARAMS/sizeof(uint64_t)];
922 
923 	/*
924 	 * we need to translate some commands (_IOW) before calling sys_ioctl,
925 	 * some after (_IOR), and some both (_IOWR).
926 	 */
927 #if 0
928 	{
929 		const char * const dirs[8] = {
930 		    "NONE!", "VOID", "OUT", "VOID|OUT!", "IN", "VOID|IN!",
931 		    "INOUT", "VOID|IN|OUT!"
932 		};
933 
934 		printf("netbsd32_ioctl(%d, %x, %x): "
935 		    "%s group %c base %d len %d\n",
936 		    SCARG(uap, fd), SCARG(uap, com), SCARG(uap, data).i32,
937 		    dirs[((SCARG(uap, com) & IOC_DIRMASK)>>29)],
938 		    IOCGROUP(SCARG(uap, com)), IOCBASECMD(SCARG(uap, com)),
939 		    IOCPARM_LEN(SCARG(uap, com)));
940 	}
941 #endif
942 
943 	memp = NULL;
944 	memp32 = NULL;
945 	alloc_size32 = 0;
946 	size32 = 0;
947 	size = 0;
948 
949 	fdp = p->p_fd;
950 	fd = SCARG(uap, fd);
951 	if ((fp = fd_getfile(fd)) == NULL)
952 		return (EBADF);
953 	if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
954 		error = EBADF;
955 		goto out;
956 	}
957 
958 	ff = fdp->fd_dt->dt_ff[SCARG(uap, fd)];
959 	switch (com = SCARG(uap, com)) {
960 	case FIOCLEX:
961 		ff->ff_exclose = true;
962 		fdp->fd_exclose = true;
963 		goto out;
964 
965 	case FIONCLEX:
966 		ff->ff_exclose = false;
967 		goto out;
968 	}
969 
970 	/*
971 	 * Interpret high order word to find amount of data to be
972 	 * copied to/from the user's address space.
973 	 */
974 	size32 = IOCPARM_LEN(com);
975 	alloc_size32 = size32;
976 
977 	/*
978 	 * The disklabel is now padded to a multiple of 8 bytes however the old
979 	 * disklabel on 32bit platforms wasn't.  This leaves a difference in
980 	 * size of 4 bytes between the two but are otherwise identical.
981 	 * To deal with this, we allocate enough space for the new disklabel
982 	 * but only copyin/out the smaller amount.
983 	 */
984 	if (IOCGROUP(com) == 'd') {
985 		u_long ncom = com ^ (DIOCGDINFO ^ DIOCGDINFO32);
986 		switch (ncom) {
987 		case DIOCGDINFO:
988 		case DIOCWDINFO:
989 		case DIOCSDINFO:
990 		case DIOCGDEFLABEL:
991 			com = ncom;
992 			if (IOCPARM_LEN(DIOCGDINFO32) < IOCPARM_LEN(DIOCGDINFO))
993 				alloc_size32 = IOCPARM_LEN(DIOCGDINFO);
994 			break;
995 		}
996 	}
997 	if (alloc_size32 > IOCPARM_MAX) {
998 		error = ENOTTY;
999 		goto out;
1000 	}
1001 	if (alloc_size32 > sizeof(stkbuf)) {
1002 		memp32 = kmem_alloc(alloc_size32, KM_SLEEP);
1003 		data32 = memp32;
1004 	} else
1005 		data32 = (void *)stkbuf32;
1006 	if ((com >> IOCPARM_SHIFT) == 0)  {
1007 		/* UNIX-style ioctl. */
1008 		data32 = SCARG_P32(uap, data);
1009 	} else {
1010 		if (com&IOC_IN) {
1011 			if (size32) {
1012 				error = copyin(SCARG_P32(uap, data), data32,
1013 				    size32);
1014 				if (error) {
1015 					goto out;
1016 				}
1017 				/*
1018 				 * The data between size and alloc_size has
1019 				 * not been overwritten.  It shouldn't matter
1020 				 * but let's clear that anyway.
1021 				 */
1022 				if (__predict_false(size32 < alloc_size32)) {
1023 					memset((char *)data32+size32, 0,
1024 					    alloc_size32 - size32);
1025 				}
1026 				ktrgenio(fd, UIO_WRITE, SCARG_P32(uap, data),
1027 				    size32, 0);
1028 			} else
1029 				*(void **)data32 = SCARG_P32(uap, data);
1030 		} else if ((com&IOC_OUT) && size32) {
1031 			/*
1032 			 * Zero the buffer so the user always
1033 			 * gets back something deterministic.
1034 			 */
1035 			memset(data32, 0, alloc_size32);
1036 		} else if (com&IOC_VOID) {
1037 			*(void **)data32 = SCARG_P32(uap, data);
1038 		}
1039 	}
1040 
1041 	/*
1042 	 * convert various structures, pointers, and other objects that
1043 	 * change size from 32 bit -> 64 bit, for all ioctl commands.
1044 	 */
1045 	switch (SCARG(uap, com)) {
1046 	case FIONBIO:
1047 		mutex_enter(&fp->f_lock);
1048 		if ((tmp = *(int *)data32) != 0)
1049 			fp->f_flag |= FNONBLOCK;
1050 		else
1051 			fp->f_flag &= ~FNONBLOCK;
1052 		mutex_exit(&fp->f_lock);
1053 		error = (*fp->f_ops->fo_ioctl)(fp, FIONBIO, (void *)&tmp);
1054 		break;
1055 
1056 	case FIOASYNC:
1057 		mutex_enter(&fp->f_lock);
1058 		if ((tmp = *(int *)data32) != 0)
1059 			fp->f_flag |= FASYNC;
1060 		else
1061 			fp->f_flag &= ~FASYNC;
1062 		mutex_exit(&fp->f_lock);
1063 		error = (*fp->f_ops->fo_ioctl)(fp, FIOASYNC, (void *)&tmp);
1064 		break;
1065 
1066 	case AUDIO_WSEEK32:
1067 		IOCTL_CONV_TO(AUDIO_WSEEK, u_long);
1068 
1069 	case DIOCGPART32:
1070 		IOCTL_STRUCT_CONV_TO(DIOCGPART, partinfo);
1071 #if 0	/* not implemented by anything */
1072 	case DIOCRFORMAT32:
1073 		IOCTL_STRUCT_CONV_TO(DIOCRFORMAT, format_op);
1074 	case DIOCWFORMAT32:
1075 		IOCTL_STRUCT_CONV_TO(DIOCWFORMAT, format_op);
1076 #endif
1077 
1078 	case ATAIOCCOMMAND32:
1079 		IOCTL_STRUCT_CONV_TO(ATAIOCCOMMAND, atareq);
1080 
1081 	case SIOCIFGCLONERS32:
1082 		{
1083 			struct netbsd32_if_clonereq *req =
1084 			    (struct netbsd32_if_clonereq *)data32;
1085 			char *buf = NETBSD32PTR64(req->ifcr_buffer);
1086 
1087 			error = if_clone_list(req->ifcr_count,
1088 			    buf, &req->ifcr_total);
1089 			break;
1090 		}
1091 
1092 /*
1093  * only a few ifreq syscalls need conversion and those are
1094  * all driver specific... XXX
1095  */
1096 #if 0
1097 	case SIOCGADDRROM3232:
1098 		IOCTL_STRUCT_CONV_TO(SIOCGADDRROM32, ifreq);
1099 	case SIOCGCHIPID32:
1100 		IOCTL_STRUCT_CONV_TO(SIOCGCHIPID, ifreq);
1101 	case SIOCSIFADDR32:
1102 		IOCTL_STRUCT_CONV_TO(SIOCSIFADDR, ifreq);
1103 	case OSIOCGIFADDR32:
1104 		IOCTL_STRUCT_CONV_TO(OSIOCGIFADDR, ifreq);
1105 	case SIOCGIFADDR32:
1106 		IOCTL_STRUCT_CONV_TO(SIOCGIFADDR, ifreq);
1107 	case SIOCSIFDSTADDR32:
1108 		IOCTL_STRUCT_CONV_TO(SIOCSIFDSTADDR, ifreq);
1109 	case OSIOCGIFDSTADDR32:
1110 		IOCTL_STRUCT_CONV_TO(OSIOCGIFDSTADDR, ifreq);
1111 	case SIOCGIFDSTADDR32:
1112 		IOCTL_STRUCT_CONV_TO(SIOCGIFDSTADDR, ifreq);
1113 	case OSIOCGIFBRDADDR32:
1114 		IOCTL_STRUCT_CONV_TO(OSIOCGIFBRDADDR, ifreq);
1115 	case SIOCGIFBRDADDR32:
1116 		IOCTL_STRUCT_CONV_TO(SIOCGIFBRDADDR, ifreq);
1117 	case SIOCSIFBRDADDR32:
1118 		IOCTL_STRUCT_CONV_TO(SIOCSIFBRDADDR, ifreq);
1119 	case OSIOCGIFNETMASK32:
1120 		IOCTL_STRUCT_CONV_TO(OSIOCGIFNETMASK, ifreq);
1121 	case SIOCGIFNETMASK32:
1122 		IOCTL_STRUCT_CONV_TO(SIOCGIFNETMASK, ifreq);
1123 	case SIOCSIFNETMASK32:
1124 		IOCTL_STRUCT_CONV_TO(SIOCSIFNETMASK, ifreq);
1125 	case SIOCGIFMETRIC32:
1126 		IOCTL_STRUCT_CONV_TO(SIOCGIFMETRIC, ifreq);
1127 	case SIOCSIFMETRIC32:
1128 		IOCTL_STRUCT_CONV_TO(SIOCSIFMETRIC, ifreq);
1129 	case SIOCDIFADDR32:
1130 		IOCTL_STRUCT_CONV_TO(SIOCDIFADDR, ifreq);
1131 	case SIOCADDMULTI32:
1132 		IOCTL_STRUCT_CONV_TO(SIOCADDMULTI, ifreq);
1133 	case SIOCDELMULTI32:
1134 		IOCTL_STRUCT_CONV_TO(SIOCDELMULTI, ifreq);
1135 	case SIOCSIFMEDIA32:
1136 		IOCTL_STRUCT_CONV_TO(SIOCSIFMEDIA, ifreq);
1137 	case SIOCSIFMTU32:
1138 		IOCTL_STRUCT_CONV_TO(SIOCSIFMTU, ifreq);
1139 	case SIOCGIFMTU32:
1140 		IOCTL_STRUCT_CONV_TO(SIOCGIFMTU, ifreq);
1141 	case BIOCGETIF32:
1142 		IOCTL_STRUCT_CONV_TO(BIOCGETIF, ifreq);
1143 	case BIOCSETIF32:
1144 		IOCTL_STRUCT_CONV_TO(BIOCSETIF, ifreq);
1145 	case SIOCPHASE132:
1146 		IOCTL_STRUCT_CONV_TO(SIOCPHASE1, ifreq);
1147 	case SIOCPHASE232:
1148 		IOCTL_STRUCT_CONV_TO(SIOCPHASE2, ifreq);
1149 #endif
1150 
1151 	case OOSIOCGIFCONF32:
1152 		IOCTL_STRUCT_CONV_TO(OOSIOCGIFCONF, ifconf);
1153 	case OSIOCGIFCONF32:
1154 		IOCTL_STRUCT_CONV_TO(OSIOCGIFCONF, ifconf);
1155 	case SIOCGIFCONF32:
1156 		IOCTL_STRUCT_CONV_TO(SIOCGIFCONF, ifconf);
1157 
1158 	case SIOCGIFFLAGS32:
1159 		IOCTL_STRUCT_CONV_TO(SIOCGIFFLAGS, ifreq);
1160 	case SIOCSIFFLAGS32:
1161 		IOCTL_STRUCT_CONV_TO(SIOCSIFFLAGS, ifreq);
1162 
1163 	case SIOCGIFADDRPREF32:
1164 		IOCTL_STRUCT_CONV_TO(SIOCGIFADDRPREF, if_addrprefreq);
1165 	case SIOCSIFADDRPREF32:
1166 		IOCTL_STRUCT_CONV_TO(SIOCSIFADDRPREF, if_addrprefreq);
1167 
1168 
1169 	case OSIOCGIFFLAGS32:
1170 		IOCTL_STRUCT_CONV_TO(OSIOCGIFFLAGS, oifreq);
1171 	case OSIOCSIFFLAGS32:
1172 		IOCTL_STRUCT_CONV_TO(OSIOCSIFFLAGS, oifreq);
1173 
1174 	case SIOCGIFMEDIA32:
1175 		IOCTL_STRUCT_CONV_TO(SIOCGIFMEDIA, ifmediareq);
1176 
1177 	case PPPOESETPARMS32:
1178 		IOCTL_STRUCT_CONV_TO(PPPOESETPARMS, pppoediscparms);
1179 	case PPPOEGETPARMS32:
1180 		IOCTL_STRUCT_CONV_TO(PPPOEGETPARMS, pppoediscparms);
1181 	case SPPPGETAUTHCFG32:
1182 		IOCTL_STRUCT_CONV_TO(SPPPGETAUTHCFG, spppauthcfg);
1183 	case SPPPSETAUTHCFG32:
1184 		IOCTL_STRUCT_CONV_TO(SPPPSETAUTHCFG, spppauthcfg);
1185 
1186 	case SIOCSDRVSPEC32:
1187 		IOCTL_STRUCT_CONV_TO(SIOCSDRVSPEC, ifdrv);
1188 	case SIOCGDRVSPEC32:
1189 		IOCTL_STRUCT_CONV_TO(SIOCGDRVSPEC, ifdrv);
1190 
1191 	case SIOCGETVIFCNT32:
1192 		IOCTL_STRUCT_CONV_TO(SIOCGETVIFCNT, sioc_vif_req);
1193 
1194 	case SIOCGETSGCNT32:
1195 		IOCTL_STRUCT_CONV_TO(SIOCGETSGCNT, sioc_sg_req);
1196 
1197 	case VNDIOCSET32:
1198 		IOCTL_STRUCT_CONV_TO(VNDIOCSET, vnd_ioctl);
1199 
1200 	case VNDIOCCLR32:
1201 		IOCTL_STRUCT_CONV_TO(VNDIOCCLR, vnd_ioctl);
1202 
1203 	case VNDIOCGET32:
1204 		IOCTL_STRUCT_CONV_TO(VNDIOCGET, vnd_user);
1205 
1206 	case VNDIOCSET5032:
1207 		IOCTL_STRUCT_CONV_TO(VNDIOCSET50, vnd_ioctl50);
1208 
1209 	case VNDIOCCLR5032:
1210 		IOCTL_STRUCT_CONV_TO(VNDIOCCLR50, vnd_ioctl50);
1211 
1212 	case ENVSYS_GETDICTIONARY32:
1213 		IOCTL_STRUCT_CONV_TO(ENVSYS_GETDICTIONARY, plistref);
1214 	case ENVSYS_SETDICTIONARY32:
1215 		IOCTL_STRUCT_CONV_TO(ENVSYS_SETDICTIONARY, plistref);
1216 	case ENVSYS_REMOVEPROPS32:
1217 		IOCTL_STRUCT_CONV_TO(ENVSYS_REMOVEPROPS, plistref);
1218 
1219 	case WDOGIOC_GWDOGS32:
1220 		IOCTL_STRUCT_CONV_TO(WDOGIOC_GWDOGS, wdog_conf);
1221 
1222 	case BIOCSETF32:
1223 		IOCTL_STRUCT_CONV_TO(BIOCSETF, bpf_program);
1224 	case BIOCSTCPF32:
1225 		IOCTL_STRUCT_CONV_TO(BIOCSTCPF, bpf_program);
1226 	case BIOCSUDPF32:
1227 		IOCTL_STRUCT_CONV_TO(BIOCSUDPF, bpf_program);
1228 	case BIOCGDLTLIST32:
1229 		IOCTL_STRUCT_CONV_TO(BIOCGDLTLIST, bpf_dltlist);
1230 
1231 	case WSDISPLAYIO_ADDSCREEN32:
1232 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_ADDSCREEN, wsdisplay_addscreendata);
1233 
1234 	case WSDISPLAYIO_GCURSOR32:
1235 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_GCURSOR, wsdisplay_cursor);
1236 	case WSDISPLAYIO_SCURSOR32:
1237 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_SCURSOR, wsdisplay_cursor);
1238 
1239 	case WSDISPLAYIO_GETCMAP32:
1240 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_GETCMAP, wsdisplay_cmap);
1241 	case WSDISPLAYIO_PUTCMAP32:
1242 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_PUTCMAP, wsdisplay_cmap);
1243 
1244 	case SIOCS8021132:
1245 		IOCTL_STRUCT_CONV_TO(SIOCS80211, ieee80211req);
1246 	case SIOCG8021132:
1247 		IOCTL_STRUCT_CONV_TO(SIOCG80211, ieee80211req);
1248 	case SIOCS80211NWKEY32:
1249 		IOCTL_STRUCT_CONV_TO(SIOCS80211NWKEY, ieee80211_nwkey);
1250 	case SIOCG80211NWKEY32:
1251 		IOCTL_STRUCT_CONV_TO(SIOCG80211NWKEY, ieee80211_nwkey);
1252 
1253 	case POWER_EVENT_RECVDICT32:
1254 		IOCTL_STRUCT_CONV_TO(POWER_EVENT_RECVDICT, plistref);
1255 
1256 	case CLOCKCTL_SETTIMEOFDAY32:
1257 		IOCTL_STRUCT_CONV_TO(CLOCKCTL_SETTIMEOFDAY,
1258 		    clockctl_settimeofday);
1259 	case CLOCKCTL_ADJTIME32:
1260 		IOCTL_STRUCT_CONV_TO(CLOCKCTL_ADJTIME, clockctl_adjtime);
1261 	case CLOCKCTL_CLOCK_SETTIME32:
1262 		IOCTL_STRUCT_CONV_TO(CLOCKCTL_CLOCK_SETTIME,
1263 		    clockctl_clock_settime);
1264 	case CLOCKCTL_NTP_ADJTIME32:
1265 		IOCTL_STRUCT_CONV_TO(CLOCKCTL_NTP_ADJTIME,
1266 		    clockctl_ntp_adjtime);
1267 
1268 	case KIOCGSYMBOL32:
1269 		IOCTL_STRUCT_CONV_TO(KIOCGSYMBOL, ksyms_gsymbol);
1270 	case KIOCGVALUE32:
1271 		IOCTL_STRUCT_CONV_TO(KIOCGVALUE, ksyms_gvalue);
1272 
1273 	case IOC_NPF_LOAD32:
1274 		IOCTL_STRUCT_CONV_TO(IOC_NPF_LOAD, plistref);
1275 	case IOC_NPF_TABLE32:
1276 		IOCTL_STRUCT_CONV_TO(IOC_NPF_TABLE, npf_ioctl_table);
1277 	case IOC_NPF_STATS32:
1278 		IOCTL_CONV_TO(IOC_NPF_STATS, voidp);
1279 	case IOC_NPF_SAVE32:
1280 		IOCTL_STRUCT_CONV_TO(IOC_NPF_SAVE, plistref);
1281 	case IOC_NPF_RULE32:
1282 		IOCTL_STRUCT_CONV_TO(IOC_NPF_RULE, plistref);
1283 
1284 	default:
1285 #ifdef NETBSD32_MD_IOCTL
1286 		error = netbsd32_md_ioctl(fp, com, data32, l);
1287 #else
1288 		error = (*fp->f_ops->fo_ioctl)(fp, com, data32);
1289 #endif
1290 		break;
1291 	}
1292 
1293 	if (error == EPASSTHROUGH)
1294 		error = ENOTTY;
1295 
1296 	/*
1297 	 * Copy any data to user, size was
1298 	 * already set and checked above.
1299 	 */
1300 	if (error == 0 && (com&IOC_OUT) && size32) {
1301 		error = copyout(data32, SCARG_P32(uap, data), size32);
1302 		ktrgenio(fd, UIO_READ, SCARG_P32(uap, data),
1303 		    size32, error);
1304 	}
1305 
1306  out:
1307 	/* If we allocated data, free it here. */
1308 	if (memp32)
1309 		kmem_free(memp32, alloc_size32);
1310 	if (memp)
1311 		kmem_free(memp, size);
1312 	fd_putfile(fd);
1313 	return (error);
1314 }
1315