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