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