Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_ioctl.c revision 1.120
      1 /*	$NetBSD: netbsd32_ioctl.c,v 1.120 2021/12/22 00:21:32 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.120 2021/12/22 00:21:32 roy Exp $");
     35 
     36 #if defined(_KERNEL_OPT)
     37 #include "opt_ntp.h"
     38 #endif
     39 
     40 #include <sys/param.h>
     41 #include <sys/atomic.h>
     42 #include <sys/systm.h>
     43 #include <sys/filedesc.h>
     44 #include <sys/ioctl.h>
     45 #include <sys/file.h>
     46 #include <sys/proc.h>
     47 #include <sys/socketvar.h>
     48 #include <sys/audioio.h>
     49 #include <sys/disklabel.h>
     50 #include <sys/dkio.h>
     51 #include <sys/ataio.h>
     52 #include <sys/sockio.h>
     53 #include <sys/socket.h>
     54 #include <sys/ttycom.h>
     55 #include <sys/mount.h>
     56 #include <sys/syscallargs.h>
     57 #include <sys/ktrace.h>
     58 #include <sys/kmem.h>
     59 #include <sys/envsys.h>
     60 #include <sys/wdog.h>
     61 #include <sys/clockctl.h>
     62 #include <sys/exec_elf.h>
     63 #include <sys/ksyms.h>
     64 #include <sys/drvctlio.h>
     65 #include <sys/compat_stub.h>
     66 
     67 #include <sys/vnode.h>
     68 #include <sys/conf.h>
     69 #include <miscfs/specfs/specdev.h>
     70 
     71 #ifdef __sparc__
     72 #include <dev/sun/fbio.h>
     73 #include <machine/openpromio.h>
     74 #endif
     75 
     76 #include <net/if.h>
     77 #include <net/route.h>
     78 
     79 #include <net/if_pppoe.h>
     80 #include <net/if_sppp.h>
     81 
     82 #include <net/bpf.h>
     83 #include <netinet/in.h>
     84 #include <netinet/in_var.h>
     85 #include <netinet/igmp.h>
     86 #include <netinet/igmp_var.h>
     87 #include <netinet/ip_mroute.h>
     88 
     89 #include <netinet6/nd6.h>
     90 #include <netinet6/in6_var.h>
     91 
     92 #include <compat/sys/sockio.h>
     93 
     94 #include <compat/netbsd32/netbsd32.h>
     95 #include <compat/netbsd32/netbsd32_ioctl.h>
     96 #include <compat/netbsd32/netbsd32_syscallargs.h>
     97 #include <compat/netbsd32/netbsd32_conv.h>
     98 
     99 #include <dev/fssvar.h>
    100 #include <dev/vndvar.h>
    101 
    102 /* convert to/from different structures */
    103 
    104 #if 0
    105 static inline void
    106 netbsd32_to_format_op(struct netbsd32_format_op *s32p,
    107     struct format_op *p, u_long cmd)
    108 {
    109 
    110 	p->df_buf = (char *)NETBSD32PTR64(s32p->df_buf);
    111 	p->df_count = s32p->df_count;
    112 	p->df_startblk = s32p->df_startblk;
    113 	memcpy(p->df_reg, s32p->df_reg, sizeof(s32p->df_reg));
    114 }
    115 #endif
    116 
    117 static inline void
    118 netbsd32_to_ifreq(struct netbsd32_ifreq *s32p, struct ifreq *p, u_long cmd)
    119 {
    120 
    121 	memcpy(p, s32p, sizeof *s32p);
    122 	/*
    123 	 * XXX
    124 	 * struct ifreq says the same, but sometimes the ifr_data
    125 	 * union member needs to be converted to 64 bits... this
    126 	 * is very driver specific and so we ignore it for now..
    127 	 */
    128 	switch (cmd) {
    129 	case SIOCGIFDATA:
    130 	case SIOCZIFDATA:
    131 	case SIOCGIFGENERIC:
    132 	case SIOCSIFGENERIC:
    133 		p->ifr_data = (void *)NETBSD32PTR64(s32p->ifr_data);
    134 		break;
    135 	}
    136 }
    137 
    138 static inline void
    139 netbsd32_to_oifreq(struct netbsd32_oifreq *s32p, struct oifreq *p, u_long cmd)
    140 {
    141 
    142 	memcpy(p, s32p, sizeof *s32p);
    143 	/*
    144 	 * XXX
    145 	 * struct ifreq says the same, but sometimes the ifr_data
    146 	 * union member needs to be converted to 64 bits... this
    147 	 * is very driver specific and so we ignore it for now..
    148 	 */
    149 	if (cmd == SIOCGIFDATA || cmd == SIOCZIFDATA)
    150 		p->ifr_data = (void *)NETBSD32PTR64(s32p->ifr_data);
    151 }
    152 
    153 static inline void
    154 netbsd32_to_if_addrprefreq(const struct netbsd32_if_addrprefreq *ifap32,
    155     struct if_addrprefreq *ifap, u_long cmd)
    156 {
    157 
    158 	memcpy(ifap->ifap_name, ifap32->ifap_name, IFNAMSIZ);
    159 	ifap->ifap_preference = ifap32->ifap_preference;
    160 	memcpy(&ifap->ifap_addr, &ifap32->ifap_addr,
    161 	    uimin(ifap32->ifap_addr.ss_len, _SS_MAXSIZE));
    162 }
    163 
    164 static inline void
    165 netbsd32_to_ifconf(struct netbsd32_ifconf *s32p, struct ifconf *p, u_long cmd)
    166 {
    167 
    168 	p->ifc_len = s32p->ifc_len;
    169 	/* ifc_buf & ifc_req are the same size so this works */
    170 	p->ifc_buf = (void *)NETBSD32PTR64(s32p->ifc_buf);
    171 }
    172 
    173 static inline void
    174 netbsd32_to_ifmediareq(struct netbsd32_ifmediareq *s32p,
    175     struct ifmediareq *p, u_long cmd)
    176 {
    177 
    178 	memcpy(p, s32p, sizeof *s32p);
    179 	p->ifm_ulist = (int *)NETBSD32PTR64(s32p->ifm_ulist);
    180 }
    181 
    182 static inline void
    183 netbsd32_to_in_nbrinfo(struct netbsd32_in_nbrinfo *s32p, struct in_nbrinfo *p,
    184     u_long cmd)
    185 {
    186 
    187 	memcpy(p->ifname, s32p->ifname, sizeof p->ifname);
    188 	memcpy(&p->addr, &s32p->addr, sizeof p->addr);
    189 	p->asked = s32p->asked;
    190 	p->state = s32p->state;
    191 	p->expire = s32p->expire;
    192 }
    193 
    194 static inline void
    195 netbsd32_to_in6_nbrinfo(struct netbsd32_in6_nbrinfo *s32p, struct in6_nbrinfo *p,
    196     u_long cmd)
    197 {
    198 
    199 	memcpy(p->ifname, s32p->ifname, sizeof p->ifname);
    200 	memcpy(&p->addr, &s32p->addr, sizeof p->addr);
    201 	p->asked = s32p->asked;
    202 	p->isrouter = s32p->isrouter;
    203 	p->state = s32p->state;
    204 	p->expire = s32p->expire;
    205 }
    206 
    207 static inline void
    208 netbsd32_to_pppoediscparms(struct netbsd32_pppoediscparms *s32p,
    209     struct pppoediscparms *p, u_long cmd)
    210 {
    211 
    212 	memcpy(p->ifname, s32p->ifname, sizeof p->ifname);
    213 	memcpy(p->eth_ifname, s32p->eth_ifname, sizeof p->eth_ifname);
    214 	p->ac_name = (char *)NETBSD32PTR64(s32p->ac_name);
    215 	p->ac_name_len = s32p->ac_name_len;
    216 	p->service_name = (char *)NETBSD32PTR64(s32p->service_name);
    217 	p->service_name_len = s32p->service_name_len;
    218 }
    219 
    220 static inline void
    221 netbsd32_to_spppauthcfg(struct netbsd32_spppauthcfg *s32p,
    222     struct spppauthcfg *p, u_long cmd)
    223 {
    224 
    225 	memcpy(p->ifname, s32p->ifname, sizeof p->ifname);
    226 	p->hisauth = s32p->hisauth;
    227 	p->myauth = s32p->myauth;
    228 	p->myname_length = s32p->myname_length;
    229 	p->mysecret_length = s32p->mysecret_length;
    230 	p->hisname_length = s32p->hisname_length;
    231 	p->hissecret_length = s32p->hissecret_length;
    232 	p->myauthflags = s32p->myauthflags;
    233 	p->hisauthflags = s32p->hisauthflags;
    234 	p->myname = (char *)NETBSD32PTR64(s32p->myname);
    235 	p->mysecret = (char *)NETBSD32PTR64(s32p->mysecret);
    236 	p->hisname = (char *)NETBSD32PTR64(s32p->hisname);
    237 	p->hissecret = (char *)NETBSD32PTR64(s32p->hissecret);
    238 }
    239 
    240 static inline void
    241 netbsd32_to_ifdrv(struct netbsd32_ifdrv *s32p, struct ifdrv *p, u_long cmd)
    242 {
    243 
    244 	memcpy(p->ifd_name, s32p->ifd_name, sizeof p->ifd_name);
    245 	p->ifd_cmd = s32p->ifd_cmd;
    246 	p->ifd_len = s32p->ifd_len;
    247 	p->ifd_data = (void *)NETBSD32PTR64(s32p->ifd_data);
    248 }
    249 
    250 static inline void
    251 netbsd32_to_sioc_vif_req(struct netbsd32_sioc_vif_req *s32p,
    252     struct sioc_vif_req *p, u_long cmd)
    253 {
    254 
    255 	p->vifi = s32p->vifi;
    256 	p->icount = (u_long)s32p->icount;
    257 	p->ocount = (u_long)s32p->ocount;
    258 	p->ibytes = (u_long)s32p->ibytes;
    259 	p->obytes = (u_long)s32p->obytes;
    260 }
    261 
    262 static inline void
    263 netbsd32_to_sioc_sg_req(struct netbsd32_sioc_sg_req *s32p,
    264     struct sioc_sg_req *p, u_long cmd)
    265 {
    266 
    267 	p->src = s32p->src;
    268 	p->grp = s32p->grp;
    269 	p->pktcnt = (u_long)s32p->pktcnt;
    270 	p->bytecnt = (u_long)s32p->bytecnt;
    271 	p->wrong_if = (u_long)s32p->wrong_if;
    272 }
    273 
    274 static inline void
    275 netbsd32_to_kfilter_mapping(struct netbsd32_kfilter_mapping *s32p,
    276     struct kfilter_mapping *p, u_long cmd)
    277 {
    278 
    279 	p->name = (char *)NETBSD32PTR64(s32p->name);
    280 	p->len = s32p->len;
    281 	p->filter = s32p->filter;
    282 }
    283 
    284 static inline void
    285 netbsd32_to_atareq(struct netbsd32_atareq *s32p, struct atareq *p, u_long cmd)
    286 {
    287 
    288 	p->flags = (u_long)s32p->flags;
    289 	p->command = s32p->command;
    290 	p->features = s32p->features;
    291 	p->sec_count = s32p->sec_count;
    292 	p->sec_num = s32p->sec_num;
    293 	p->head = s32p->head;
    294 	p->cylinder = s32p->cylinder;
    295 	p->databuf =  (char *)NETBSD32PTR64(s32p->databuf);
    296 	p->datalen = (u_long)s32p->datalen;
    297 	p->timeout = s32p->timeout;
    298 	p->retsts = s32p->retsts;
    299 	p->error = s32p->error;
    300 }
    301 
    302 static inline void
    303 netbsd32_to_fss_set(struct netbsd32_fss_set *s32p, struct fss_set *p,
    304     u_long cmd)
    305 {
    306 
    307 	p->fss_mount = (char *)NETBSD32PTR64(s32p->fss_mount);
    308 	p->fss_bstore = (char *)NETBSD32PTR64(s32p->fss_bstore);
    309 	p->fss_csize = s32p->fss_csize;
    310 	p->fss_flags = s32p->fss_flags;
    311 }
    312 
    313 static inline void
    314 netbsd32_to_fss_get(struct netbsd32_fss_get *s32p, struct fss_get *p,
    315     u_long cmd)
    316 {
    317 
    318 	memcpy(p->fsg_mount, s32p->fsg_mount, MNAMELEN);
    319 	netbsd32_to_timeval(&s32p->fsg_time, &p->fsg_time);
    320 	p->fsg_csize = s32p->fsg_csize;
    321 	p->fsg_mount_size = s32p->fsg_mount_size;
    322 	p->fsg_bs_size = s32p->fsg_bs_size;
    323 
    324 }
    325 
    326 static inline void
    327 netbsd32_to_vnd_ioctl(struct netbsd32_vnd_ioctl *s32p,
    328     struct vnd_ioctl *p, u_long cmd)
    329 {
    330 
    331 	p->vnd_file = (char *)NETBSD32PTR64(s32p->vnd_file);
    332 	p->vnd_flags = s32p->vnd_flags;
    333 	p->vnd_geom = s32p->vnd_geom;
    334 	p->vnd_osize = s32p->vnd_osize;
    335 	p->vnd_size = s32p->vnd_size;
    336 }
    337 
    338 static inline void
    339 netbsd32_to_vnd_user(struct netbsd32_vnd_user *s32p,
    340     struct vnd_user *p, u_long cmd)
    341 {
    342 
    343 	p->vnu_unit = s32p->vnu_unit;
    344 	p->vnu_dev = s32p->vnu_dev;
    345 	p->vnu_ino = s32p->vnu_ino;
    346 }
    347 
    348 static inline void
    349 netbsd32_to_vnd_ioctl50(struct netbsd32_vnd_ioctl50 *s32p,
    350     struct vnd_ioctl50 *p, u_long cmd)
    351 {
    352 
    353 	p->vnd_file = (char *)NETBSD32PTR64(s32p->vnd_file);
    354 	p->vnd_flags = s32p->vnd_flags;
    355 	p->vnd_geom = s32p->vnd_geom;
    356 	p->vnd_size = s32p->vnd_size;
    357 }
    358 
    359 static inline void
    360 netbsd32_to_plistref(struct netbsd32_plistref *s32p,
    361     struct plistref *p, u_long cmd)
    362 {
    363 
    364 	p->pref_plist = NETBSD32PTR64(s32p->pref_plist);
    365 	p->pref_len = s32p->pref_len;
    366 }
    367 
    368 static inline void
    369 netbsd32_to_nvlist_ref_t(netbsd32_nvlist_ref_t *s32p,
    370     nvlist_ref_t *p, u_long cmd)
    371 {
    372 
    373 	p->buf = NETBSD32PTR64(s32p->buf);
    374 	p->len = s32p->len;
    375 	p->flags = s32p->flags;
    376 }
    377 
    378 static inline void
    379 netbsd32_to_u_long(netbsd32_u_long *s32p, u_long *p, u_long cmd)
    380 {
    381 
    382 	*p = (u_long)*s32p;
    383 }
    384 
    385 static inline void
    386 netbsd32_to_voidp(netbsd32_voidp *s32p, voidp *p, u_long cmd)
    387 {
    388 
    389 	*p = (void *)NETBSD32PTR64(*s32p);
    390 }
    391 
    392 static inline void
    393 netbsd32_to_wdog_conf(struct netbsd32_wdog_conf *s32p,
    394     struct wdog_conf *p, u_long cmd)
    395 {
    396 
    397 	p->wc_names = (char *)NETBSD32PTR64(s32p->wc_names);
    398 	p->wc_count = s32p->wc_count;
    399 }
    400 
    401 static inline void
    402 netbsd32_to_npf_ioctl_table(const struct netbsd32_npf_ioctl_table *s32p,
    403     struct npf_ioctl_table *p, u_long cmd)
    404 {
    405 
    406        p->nct_cmd = s32p->nct_cmd;
    407        p->nct_name = NETBSD32PTR64(s32p->nct_name);
    408        switch (s32p->nct_cmd) {
    409        case NPF_CMD_TABLE_LOOKUP:
    410        case NPF_CMD_TABLE_ADD:
    411        case NPF_CMD_TABLE_REMOVE:
    412                p->nct_data.ent = s32p->nct_data.ent;
    413                break;
    414        case NPF_CMD_TABLE_LIST:
    415                p->nct_data.buf.buf = NETBSD32PTR64(s32p->nct_data.buf.buf);
    416                p->nct_data.buf.len = s32p->nct_data.buf.len;
    417                break;
    418        }
    419 }
    420 
    421 static inline void
    422 netbsd32_to_bpf_program(struct netbsd32_bpf_program *s32p,
    423     struct bpf_program *p, u_long cmd)
    424 {
    425 
    426 	p->bf_insns = (void *)NETBSD32PTR64(s32p->bf_insns);
    427 	p->bf_len = s32p->bf_len;
    428 }
    429 
    430 static inline void
    431 netbsd32_to_bpf_dltlist(struct netbsd32_bpf_dltlist *s32p,
    432     struct bpf_dltlist *p, u_long cmd)
    433 {
    434 
    435 	p->bfl_list = (void *)NETBSD32PTR64(s32p->bfl_list);
    436 	p->bfl_len = s32p->bfl_len;
    437 }
    438 
    439 /* wsdisplay stuff */
    440 static inline void
    441 netbsd32_to_wsdisplay_addscreendata(
    442     struct netbsd32_wsdisplay_addscreendata *asd32,
    443     struct wsdisplay_addscreendata *asd, u_long cmd)
    444 {
    445 
    446 	asd->screentype = (char *)NETBSD32PTR64(asd32->screentype);
    447 	asd->emul = (char *)NETBSD32PTR64(asd32->emul);
    448 	asd->idx = asd32->idx;
    449 }
    450 
    451 static inline void
    452 netbsd32_to_ieee80211req(struct netbsd32_ieee80211req *ireq32,
    453     struct ieee80211req *ireq, u_long cmd)
    454 {
    455 
    456 	memcpy(ireq->i_name, ireq32->i_name, IFNAMSIZ);
    457 	ireq->i_type = ireq32->i_type;
    458 	ireq->i_val = ireq32->i_val;
    459 	ireq->i_len = ireq32->i_len;
    460 	ireq->i_data = NETBSD32PTR64(ireq32->i_data);
    461 }
    462 
    463 static inline void
    464 netbsd32_to_ieee80211_nwkey(struct netbsd32_ieee80211_nwkey *nwk32,
    465     struct ieee80211_nwkey *nwk, u_long cmd)
    466 {
    467 	int i;
    468 
    469 	memcpy(nwk->i_name, nwk32->i_name, IFNAMSIZ);
    470 	nwk->i_wepon = nwk32->i_wepon;
    471 	nwk->i_defkid = nwk32->i_defkid;
    472 	for (i = 0; i < IEEE80211_WEP_NKID; i++) {
    473 		nwk->i_key[i].i_keylen = nwk32->i_key[i].i_keylen;
    474 		nwk->i_key[i].i_keydat =
    475 		    NETBSD32PTR64(nwk32->i_key[i].i_keydat);
    476 	}
    477 }
    478 
    479 static inline void
    480 netbsd32_to_wsdisplay_cursor(struct netbsd32_wsdisplay_cursor *c32,
    481     struct wsdisplay_cursor *c, u_long cmd)
    482 {
    483 
    484 	c->which = c32->which;
    485 	c->enable = c32->enable;
    486 	c->pos.x = c32->pos.x;
    487 	c->pos.y = c32->pos.y;
    488 	c->hot.x = c32->hot.x;
    489 	c->hot.y = c32->hot.y;
    490 	c->size.x = c32->size.x;
    491 	c->size.y = c32->size.y;
    492 	c->cmap.index = c32->cmap.index;
    493 	c->cmap.count = c32->cmap.count;
    494 	c->cmap.red = NETBSD32PTR64(c32->cmap.red);
    495 	c->cmap.green = NETBSD32PTR64(c32->cmap.green);
    496 	c->cmap.blue = NETBSD32PTR64(c32->cmap.blue);
    497 	c->image = NETBSD32PTR64(c32->image);
    498 	c->mask = NETBSD32PTR64(c32->mask);
    499 }
    500 
    501 static inline void
    502 netbsd32_to_wsdisplay_cmap(struct netbsd32_wsdisplay_cmap *c32,
    503     struct wsdisplay_cmap *c, u_long cmd)
    504 {
    505 
    506 	c->index = c32->index;
    507 	c->count = c32->count;
    508 	c->red   = NETBSD32PTR64(c32->red);
    509 	c->green = NETBSD32PTR64(c32->green);
    510 	c->blue  = NETBSD32PTR64(c32->blue);
    511 }
    512 
    513 static inline void
    514 netbsd32_to_wsdisplay_font(struct netbsd32_wsdisplay_font *f32,
    515     struct wsdisplay_font *f, u_long cmd)
    516 {
    517 
    518 	f->name = NETBSD32PTR64(f32->name);
    519 	f->firstchar = f32->firstchar;
    520 	f->numchars = f32->numchars;
    521 	f->encoding = f32->encoding;
    522 	f->fontwidth = f32->fontwidth;
    523 	f->fontheight = f32->fontheight;
    524 	f->stride = f32->stride;
    525 	f->bitorder = f32->bitorder;
    526 	f->byteorder = f32->byteorder;
    527 	f->data = NETBSD32PTR64(f32->data);
    528 }
    529 
    530 static inline void
    531 netbsd32_to_wsdisplay_usefontdata(struct netbsd32_wsdisplay_usefontdata *f32,
    532     struct wsdisplay_usefontdata *f, u_long cmd)
    533 {
    534 
    535 	f->name = NETBSD32PTR64(f32->name);
    536 }
    537 
    538 static inline void
    539 netbsd32_to_clockctl_settimeofday(
    540     const struct netbsd32_clockctl_settimeofday *s32p,
    541     struct clockctl_settimeofday *p, u_long cmd)
    542 {
    543 
    544 	p->tv = NETBSD32PTR64(s32p->tv);
    545 	p->tzp = NETBSD32PTR64(s32p->tzp);
    546 }
    547 
    548 static inline void
    549 netbsd32_to_clockctl_adjtime(
    550     const struct netbsd32_clockctl_adjtime *s32p,
    551     struct clockctl_adjtime *p, u_long cmd)
    552 {
    553 
    554 	p->delta = NETBSD32PTR64(s32p->delta);
    555 	p->olddelta = NETBSD32PTR64(s32p->olddelta);
    556 }
    557 
    558 static inline void
    559 netbsd32_to_clockctl_clock_settime(
    560     const struct netbsd32_clockctl_clock_settime *s32p,
    561     struct clockctl_clock_settime *p, u_long cmd)
    562 {
    563 
    564 	p->clock_id = s32p->clock_id;
    565 	p->tp = NETBSD32PTR64(s32p->tp);
    566 }
    567 
    568 #ifdef NTP
    569 static inline void
    570 netbsd32_to_clockctl_ntp_adjtime(
    571     const struct netbsd32_clockctl_ntp_adjtime *s32p,
    572     struct clockctl_ntp_adjtime *p, u_long cmd)
    573 {
    574 
    575 	p->tp = NETBSD32PTR64(s32p->tp);
    576 	p->retval = s32p->retval;
    577 }
    578 #endif
    579 
    580 static inline void
    581 netbsd32_to_ksyms_gsymbol(const struct netbsd32_ksyms_gsymbol *s32p,
    582     struct ksyms_gsymbol *p, u_long cmd)
    583 {
    584 
    585 	p->kg_name = NETBSD32PTR64(s32p->kg_name);
    586 }
    587 
    588 static inline void
    589 netbsd32_to_ksyms_gvalue(const struct netbsd32_ksyms_gvalue *s32p,
    590     struct ksyms_gvalue *p, u_long cmd)
    591 {
    592 
    593 	p->kv_name = NETBSD32PTR64(s32p->kv_name);
    594 }
    595 
    596 static inline void
    597 netbsd32_to_devlistargs(const struct netbsd32_devlistargs *s32p,
    598     struct devlistargs *p, u_long cmd)
    599 {
    600 
    601 	memcpy(p->l_devname, s32p->l_devname, sizeof(p->l_devname));
    602 	p->l_children = s32p->l_children;
    603 	p->l_childname = NETBSD32PTR64(s32p->l_childname);
    604 }
    605 
    606 static inline void
    607 netbsd32_to_devrescanargs(const struct netbsd32_devrescanargs *s32p,
    608     struct devrescanargs *p, u_long cmd)
    609 {
    610 
    611 	memcpy(p->busname, s32p->busname, sizeof(p->busname));
    612 	memcpy(p->ifattr, s32p->ifattr, sizeof(p->ifattr));
    613 	p->numlocators = s32p->numlocators;
    614 	p->locators = NETBSD32PTR64(s32p->locators);
    615 }
    616 
    617 static inline void
    618 netbsd32_to_disk_strategy(const struct netbsd32_disk_strategy *s32p,
    619     struct disk_strategy *p, u_long cmd)
    620 {
    621 
    622 	memcpy(p->dks_name, s32p->dks_name, sizeof(p->dks_name));
    623 	p->dks_param = NETBSD32PTR64(s32p->dks_param);
    624 	p->dks_paramlen = s32p->dks_paramlen;
    625 }
    626 
    627 static inline void
    628 netbsd32_to_dkwedge_list(const struct netbsd32_dkwedge_list *s32p,
    629     struct dkwedge_list *p, u_long cmd)
    630 {
    631 
    632 	p->dkwl_buf = NETBSD32PTR64(s32p->dkwl_buf);
    633 	p->dkwl_bufsize = s32p->dkwl_bufsize;
    634 	p->dkwl_nwedges = s32p->dkwl_nwedges;
    635 	p->dkwl_ncopied = s32p->dkwl_ncopied;
    636 }
    637 
    638 /*
    639  * handle ioctl conversions from 64-bit kernel -> netbsd32
    640  */
    641 
    642 #if 0
    643 static inline void
    644 netbsd32_from_format_op(struct format_op *p,
    645     struct netbsd32_format_op *s32p, u_long cmd)
    646 {
    647 
    648 /* filled in */
    649 #if 0
    650 	s32p->df_buf = (netbsd32_charp)p->df_buf;
    651 #endif
    652 	s32p->df_count = p->df_count;
    653 	s32p->df_startblk = p->df_startblk;
    654 	memcpy(s32p->df_reg, p->df_reg, sizeof(p->df_reg));
    655 }
    656 #endif
    657 
    658 static inline void
    659 netbsd32_from_ifreq(struct ifreq *p, struct netbsd32_ifreq *s32p, u_long cmd)
    660 {
    661 
    662 	/*
    663 	 * XXX
    664 	 * struct ifreq says the same, but sometimes the ifr_data
    665 	 * union member needs to be converted to 64 bits... this
    666 	 * is very driver specific and so we ignore it for now..
    667 	 */
    668 	memcpy(s32p, p, sizeof *s32p);
    669 	switch (cmd) {
    670 	case SIOCGIFDATA:
    671 	case SIOCZIFDATA:
    672 	case SIOCGIFGENERIC:
    673 	case SIOCSIFGENERIC:
    674 		NETBSD32PTR32(s32p->ifr_data, p->ifr_data);
    675 		break;
    676 	}
    677 }
    678 
    679 static inline void
    680 netbsd32_from_oifreq(struct oifreq *p,
    681     struct netbsd32_oifreq *s32p, u_long cmd)
    682 {
    683 
    684 	/*
    685 	 * XXX
    686 	 * struct ifreq says the same, but sometimes the ifr_data
    687 	 * union member needs to be converted to 64 bits... this
    688 	 * is very driver specific and so we ignore it for now..
    689 	 */
    690 	memcpy(s32p, p, sizeof *s32p);
    691 	if (cmd == SIOCGIFDATA || cmd == SIOCZIFDATA)
    692 		NETBSD32PTR32(s32p->ifr_data, p->ifr_data);
    693 }
    694 
    695 static inline void
    696 netbsd32_from_if_addrprefreq(const struct if_addrprefreq *ifap,
    697     struct netbsd32_if_addrprefreq *ifap32, u_long cmd)
    698 {
    699 
    700 	memcpy(ifap32->ifap_name, ifap->ifap_name, IFNAMSIZ);
    701 	ifap32->ifap_preference = ifap->ifap_preference;
    702 	memcpy(&ifap32->ifap_addr, &ifap->ifap_addr,
    703 	    uimin(ifap->ifap_addr.ss_len, _SS_MAXSIZE));
    704 }
    705 
    706 static inline void
    707 netbsd32_from_ifconf(struct ifconf *p,
    708     struct netbsd32_ifconf *s32p, u_long cmd)
    709 {
    710 
    711 	s32p->ifc_len = p->ifc_len;
    712 	/* ifc_buf & ifc_req are the same size so this works */
    713 	NETBSD32PTR32(s32p->ifc_buf, p->ifc_buf);
    714 }
    715 
    716 static inline void
    717 netbsd32_from_ifmediareq(struct ifmediareq *p,
    718     struct netbsd32_ifmediareq *s32p, u_long cmd)
    719 {
    720 
    721 	memcpy(s32p, p, sizeof *p);
    722 /* filled in? */
    723 #if 0
    724 	s32p->ifm_ulist = (netbsd32_intp_t)p->ifm_ulist;
    725 #endif
    726 }
    727 
    728 static inline void
    729 netbsd32_from_in_nbrinfo(struct in_nbrinfo *p, struct netbsd32_in_nbrinfo *s32p,
    730     u_long cmd)
    731 {
    732 
    733 	memcpy(s32p->ifname, p->ifname, sizeof s32p->ifname);
    734 	memcpy(&s32p->addr, &p->addr, sizeof s32p->addr);
    735 	s32p->asked = p->asked;
    736 	s32p->state = p->state;
    737 	s32p->expire = p->expire;
    738 }
    739 
    740 static inline void
    741 netbsd32_from_in6_nbrinfo(struct in6_nbrinfo *p, struct netbsd32_in6_nbrinfo *s32p,
    742     u_long cmd)
    743 {
    744 
    745 	memcpy(s32p->ifname, p->ifname, sizeof s32p->ifname);
    746 	memcpy(&s32p->addr, &p->addr, sizeof s32p->addr);
    747 	s32p->asked = p->asked;
    748 	s32p->isrouter = p->isrouter;
    749 	s32p->state = p->state;
    750 	s32p->expire = p->expire;
    751 }
    752 
    753 static inline void
    754 netbsd32_from_pppoediscparms(struct pppoediscparms *p,
    755     struct netbsd32_pppoediscparms *s32p, u_long cmd)
    756 {
    757 
    758 	memcpy(s32p->ifname, p->ifname, sizeof s32p->ifname);
    759 	memcpy(s32p->eth_ifname, p->eth_ifname, sizeof s32p->eth_ifname);
    760 	NETBSD32PTR32(s32p->ac_name, p->ac_name);
    761 	s32p->ac_name_len = p->ac_name_len;
    762 	NETBSD32PTR32(s32p->service_name, p->service_name);
    763 	s32p->service_name_len = p->service_name_len;
    764 }
    765 
    766 static inline void
    767 netbsd32_from_spppauthcfg(struct spppauthcfg *p,
    768     struct netbsd32_spppauthcfg *s32p, u_long cmd)
    769 {
    770 
    771 	memcpy(s32p->ifname, p->ifname, sizeof s32p->ifname);
    772 	s32p->hisauth = p->hisauth;
    773 	s32p->myauth = p->myauth;
    774 	s32p->myname_length = p->myname_length;
    775 	s32p->mysecret_length = p->mysecret_length;
    776 	s32p->hisname_length = p->hisname_length;
    777 	s32p->hissecret_length = p->hissecret_length;
    778 	s32p->myauthflags = p->myauthflags;
    779 	s32p->hisauthflags = p->hisauthflags;
    780 	NETBSD32PTR32(s32p->myname, p->myname);
    781 	NETBSD32PTR32(s32p->mysecret, p->mysecret);
    782 	NETBSD32PTR32(s32p->hisname, p->hisname);
    783 	NETBSD32PTR32(s32p->hissecret, p->hissecret);
    784 }
    785 
    786 static inline void
    787 netbsd32_from_ifdrv(struct ifdrv *p, struct netbsd32_ifdrv *s32p, u_long cmd)
    788 {
    789 
    790 	memcpy(s32p->ifd_name, p->ifd_name, sizeof s32p->ifd_name);
    791 	s32p->ifd_cmd = p->ifd_cmd;
    792 	s32p->ifd_len = p->ifd_len;
    793 	NETBSD32PTR32(s32p->ifd_data, p->ifd_data);
    794 }
    795 
    796 static inline void
    797 netbsd32_from_sioc_vif_req(struct sioc_vif_req *p,
    798     struct netbsd32_sioc_vif_req *s32p, u_long cmd)
    799 {
    800 
    801 	s32p->vifi = p->vifi;
    802 	s32p->icount = (netbsd32_u_long)p->icount;
    803 	s32p->ocount = (netbsd32_u_long)p->ocount;
    804 	s32p->ibytes = (netbsd32_u_long)p->ibytes;
    805 	s32p->obytes = (netbsd32_u_long)p->obytes;
    806 }
    807 
    808 static inline void
    809 netbsd32_from_sioc_sg_req(struct sioc_sg_req *p,
    810     struct netbsd32_sioc_sg_req *s32p, u_long cmd)
    811 {
    812 
    813 	s32p->src = p->src;
    814 	s32p->grp = p->grp;
    815 	s32p->pktcnt = (netbsd32_u_long)p->pktcnt;
    816 	s32p->bytecnt = (netbsd32_u_long)p->bytecnt;
    817 	s32p->wrong_if = (netbsd32_u_long)p->wrong_if;
    818 }
    819 
    820 static inline void
    821 netbsd32_from_kfilter_mapping(struct kfilter_mapping *p,
    822     struct netbsd32_kfilter_mapping *s32p, u_long cmd)
    823 {
    824 
    825 	NETBSD32PTR32(s32p->name, p->name);
    826 	s32p->len = p->len;
    827 	s32p->filter = p->filter;
    828 }
    829 
    830 static inline void
    831 netbsd32_from_atareq(struct atareq *p,
    832     struct netbsd32_atareq *s32p, u_long cmd)
    833 {
    834 
    835 	s32p->flags = (netbsd32_u_long)p->flags;
    836 	s32p->command = p->command;
    837 	s32p->features = p->features;
    838 	s32p->sec_count = p->sec_count;
    839 	s32p->sec_num = p->sec_num;
    840 	s32p->head = p->head;
    841 	s32p->cylinder = p->cylinder;
    842 	NETBSD32PTR32(s32p->databuf, p->databuf);
    843 	s32p->datalen = (netbsd32_u_long)p->datalen;
    844 	s32p->timeout = p->timeout;
    845 	s32p->retsts = p->retsts;
    846 	s32p->error = p->error;
    847 }
    848 
    849 static inline void
    850 netbsd32_from_fss_set(struct fss_set *p, struct netbsd32_fss_set *s32p,
    851     u_long cmd)
    852 {
    853 
    854 	NETBSD32PTR32(s32p->fss_mount, p->fss_mount);
    855 	NETBSD32PTR32(s32p->fss_bstore, p->fss_bstore);
    856 	s32p->fss_csize = p->fss_csize;
    857 	s32p->fss_flags = p->fss_flags;
    858 }
    859 
    860 static inline void
    861 netbsd32_from_fss_get(struct fss_get *p, struct netbsd32_fss_get *s32p,
    862     u_long cmd)
    863 {
    864 
    865 	memcpy(s32p->fsg_mount, p->fsg_mount, MNAMELEN);
    866 	netbsd32_from_timeval(&p->fsg_time, &s32p->fsg_time);
    867 	s32p->fsg_csize = p->fsg_csize;
    868 	s32p->fsg_mount_size = p->fsg_mount_size;
    869 	s32p->fsg_bs_size = p->fsg_bs_size;
    870 
    871 }
    872 
    873 static inline void
    874 netbsd32_from_vnd_ioctl(struct vnd_ioctl *p,
    875     struct netbsd32_vnd_ioctl *s32p, u_long cmd)
    876 {
    877 
    878 	s32p->vnd_flags = p->vnd_flags;
    879 	s32p->vnd_geom = p->vnd_geom;
    880 	s32p->vnd_osize = p->vnd_osize;
    881 	s32p->vnd_size = p->vnd_size;
    882 }
    883 
    884 static inline void
    885 netbsd32_from_vnd_user(struct vnd_user *p,
    886     struct netbsd32_vnd_user *s32p, u_long cmd)
    887 {
    888 
    889 	s32p->vnu_unit = p->vnu_unit;
    890 	s32p->vnu_dev = p->vnu_dev;
    891 	s32p->vnu_ino = p->vnu_ino;
    892 }
    893 
    894 static inline void
    895 netbsd32_from_vnd_ioctl50(struct vnd_ioctl50 *p,
    896     struct netbsd32_vnd_ioctl50 *s32p, u_long cmd)
    897 {
    898 
    899 	s32p->vnd_flags = p->vnd_flags;
    900 	s32p->vnd_geom = p->vnd_geom;
    901 	s32p->vnd_size = p->vnd_size;
    902 }
    903 
    904 static inline void
    905 netbsd32_from_plistref(struct plistref *p,
    906     struct netbsd32_plistref *s32p, u_long cmd)
    907 {
    908 
    909 	NETBSD32PTR32(s32p->pref_plist, p->pref_plist);
    910 	s32p->pref_len = p->pref_len;
    911 }
    912 
    913 static inline void
    914 netbsd32_from_nvlist_ref_t(nvlist_ref_t *p,
    915     netbsd32_nvlist_ref_t *s32p, u_long cmd)
    916 {
    917 
    918 	NETBSD32PTR32(s32p->buf, p->buf);
    919 	s32p->len = p->len;
    920 	s32p->flags = p->flags;
    921 }
    922 
    923 static inline void
    924 netbsd32_from_wdog_conf(struct wdog_conf *p,
    925     struct netbsd32_wdog_conf *s32p, u_long cmd)
    926 {
    927 
    928 	NETBSD32PTR32(s32p->wc_names, p->wc_names);
    929 	s32p->wc_count = p->wc_count;
    930 }
    931 
    932 /* wsdisplay stuff */
    933 static inline void
    934 netbsd32_from_wsdisplay_addscreendata(struct wsdisplay_addscreendata *asd,
    935     struct netbsd32_wsdisplay_addscreendata *asd32, u_long cmd)
    936 {
    937 
    938 	NETBSD32PTR32(asd32->screentype, asd->screentype);
    939 	NETBSD32PTR32(asd32->emul, asd->emul);
    940 	asd32->idx = asd->idx;
    941 }
    942 
    943 static inline void
    944 netbsd32_from_wsdisplay_cursor(struct wsdisplay_cursor *c,
    945     struct netbsd32_wsdisplay_cursor *c32, u_long cmd)
    946 {
    947 
    948 	c32->which = c->which;
    949 	c32->enable = c->enable;
    950 	c32->pos.x = c->pos.x;
    951 	c32->pos.y = c->pos.y;
    952 	c32->hot.x = c->hot.x;
    953 	c32->hot.y = c->hot.y;
    954 	c32->size.x = c->size.x;
    955 	c32->size.y = c->size.y;
    956 	c32->cmap.index = c->cmap.index;
    957 	c32->cmap.count = c->cmap.count;
    958 	NETBSD32PTR32(c32->cmap.red, c->cmap.red);
    959 	NETBSD32PTR32(c32->cmap.green, c->cmap.green);
    960 	NETBSD32PTR32(c32->cmap.blue, c->cmap.blue);
    961 	NETBSD32PTR32(c32->image, c->image);
    962 	NETBSD32PTR32(c32->mask, c->mask);
    963 }
    964 
    965 static inline void
    966 netbsd32_from_wsdisplay_cmap(struct wsdisplay_cmap *c,
    967     struct netbsd32_wsdisplay_cmap *c32, u_long cmd)
    968 {
    969 
    970 	c32->index = c->index;
    971 	c32->count = c->count;
    972 	NETBSD32PTR32(c32->red, c->red);
    973 	NETBSD32PTR32(c32->green, c->green);
    974 	NETBSD32PTR32(c32->blue, c->blue);
    975 }
    976 
    977 static inline void
    978 netbsd32_from_wsdisplay_font(struct wsdisplay_font *f,
    979     struct netbsd32_wsdisplay_font *f32, u_long cmd)
    980 {
    981 }
    982 
    983 static inline void
    984 netbsd32_from_wsdisplay_usefontdata(struct wsdisplay_usefontdata *f,
    985     struct netbsd32_wsdisplay_usefontdata *f32, u_long cmd)
    986 {
    987 }
    988 
    989 static inline void
    990 netbsd32_from_ieee80211req(struct ieee80211req *ireq,
    991     struct netbsd32_ieee80211req *ireq32, u_long cmd)
    992 {
    993 
    994 	memcpy(ireq32->i_name, ireq->i_name, IFNAMSIZ);
    995 	ireq32->i_type = ireq->i_type;
    996 	ireq32->i_val = ireq->i_val;
    997 	ireq32->i_len = ireq->i_len;
    998 	NETBSD32PTR32(ireq32->i_data, ireq->i_data);
    999 }
   1000 
   1001 static inline void
   1002 netbsd32_from_ieee80211_nwkey(struct ieee80211_nwkey *nwk,
   1003     struct netbsd32_ieee80211_nwkey *nwk32, u_long cmd)
   1004 {
   1005 	int i;
   1006 
   1007 	memcpy(nwk32->i_name, nwk->i_name, IFNAMSIZ);
   1008 	nwk32->i_wepon = nwk->i_wepon;
   1009 	nwk32->i_defkid = nwk->i_defkid;
   1010 	for (i = 0; i < IEEE80211_WEP_NKID; i++) {
   1011 		nwk32->i_key[i].i_keylen = nwk->i_key[i].i_keylen;
   1012 		NETBSD32PTR32(nwk32->i_key[i].i_keydat,
   1013 				nwk->i_key[i].i_keydat);
   1014 	}
   1015 }
   1016 
   1017 static inline void
   1018 netbsd32_from_bpf_program(struct bpf_program *p,
   1019     struct netbsd32_bpf_program *s32p, u_long cmd)
   1020 {
   1021 
   1022 	NETBSD32PTR32(s32p->bf_insns, p->bf_insns);
   1023 	s32p->bf_len = p->bf_len;
   1024 }
   1025 
   1026 static inline void
   1027 netbsd32_from_bpf_dltlist(struct bpf_dltlist *p,
   1028     struct netbsd32_bpf_dltlist *s32p, u_long cmd)
   1029 {
   1030 
   1031 	NETBSD32PTR32(s32p->bfl_list, p->bfl_list);
   1032 	s32p->bfl_len = p->bfl_len;
   1033 }
   1034 
   1035 static inline void
   1036 netbsd32_from_u_long(u_long *p, netbsd32_u_long *s32p, u_long cmd)
   1037 {
   1038 
   1039 	*s32p = (netbsd32_u_long)*p;
   1040 }
   1041 
   1042 static inline void
   1043 netbsd32_from_voidp(voidp *p, netbsd32_voidp *s32p, u_long cmd)
   1044 {
   1045 
   1046 	NETBSD32PTR32(*s32p, *p);
   1047 }
   1048 
   1049 static inline void
   1050 netbsd32_from_clockctl_settimeofday(const struct clockctl_settimeofday *p,
   1051     struct netbsd32_clockctl_settimeofday *s32p, u_long cmd)
   1052 {
   1053 
   1054 	NETBSD32PTR32(s32p->tv, p->tv);
   1055 	NETBSD32PTR32(s32p->tzp, p->tzp);
   1056 }
   1057 
   1058 static inline void
   1059 netbsd32_from_clockctl_adjtime(const struct clockctl_adjtime *p,
   1060     struct netbsd32_clockctl_adjtime *s32p, u_long cmd)
   1061 {
   1062 
   1063 	NETBSD32PTR32(s32p->delta, p->delta);
   1064 	NETBSD32PTR32(s32p->olddelta, p->olddelta);
   1065 }
   1066 
   1067 static inline void
   1068 netbsd32_from_clockctl_clock_settime(const struct clockctl_clock_settime *p,
   1069     struct netbsd32_clockctl_clock_settime *s32p, u_long cmd)
   1070 {
   1071 
   1072 	s32p->clock_id = p->clock_id;
   1073 	NETBSD32PTR32(s32p->tp, p->tp);
   1074 }
   1075 
   1076 #ifdef NTP
   1077 static inline void
   1078 netbsd32_from_clockctl_ntp_adjtime(const struct clockctl_ntp_adjtime *p,
   1079     struct netbsd32_clockctl_ntp_adjtime *s32p, u_long cmd)
   1080 {
   1081 
   1082 	NETBSD32PTR32(s32p->tp, p->tp);
   1083 	s32p->retval = p->retval;
   1084 }
   1085 #endif
   1086 
   1087 static inline void
   1088 netbsd32_from_ksyms_gsymbol( const struct ksyms_gsymbol *p,
   1089     struct netbsd32_ksyms_gsymbol *s32p, u_long cmd)
   1090 {
   1091 
   1092 	NETBSD32PTR32(s32p->kg_name, p->kg_name);
   1093 	s32p->kg_sym = p->kg_sym;
   1094 }
   1095 
   1096 static inline void
   1097 netbsd32_from_ksyms_gvalue(
   1098     const struct ksyms_gvalue *p,
   1099     struct netbsd32_ksyms_gvalue *s32p, u_long cmd)
   1100 {
   1101 
   1102 	NETBSD32PTR32(s32p->kv_name, p->kv_name);
   1103 	s32p->kv_value = p->kv_value;
   1104 }
   1105 
   1106 static inline void
   1107 netbsd32_from_npf_ioctl_table(const struct npf_ioctl_table *p,
   1108     struct netbsd32_npf_ioctl_table *s32p, u_long cmd)
   1109 {
   1110 
   1111        s32p->nct_cmd = p->nct_cmd;
   1112        NETBSD32PTR32(s32p->nct_name, p->nct_name);
   1113        switch (p->nct_cmd) {
   1114        case NPF_CMD_TABLE_LOOKUP:
   1115        case NPF_CMD_TABLE_ADD:
   1116        case NPF_CMD_TABLE_REMOVE:
   1117                s32p->nct_data.ent = p->nct_data.ent;
   1118                break;
   1119        case NPF_CMD_TABLE_LIST:
   1120                NETBSD32PTR32(s32p->nct_data.buf.buf, p->nct_data.buf.buf);
   1121                s32p->nct_data.buf.len = p->nct_data.buf.len;
   1122                break;
   1123        }
   1124 }
   1125 
   1126 static inline void
   1127 netbsd32_from_devlistargs(const struct devlistargs *p,
   1128     struct netbsd32_devlistargs *s32p, u_long cmd)
   1129 {
   1130 
   1131 	memcpy(s32p->l_devname, p->l_devname, sizeof(s32p->l_devname));
   1132 	s32p->l_children = p->l_children;
   1133 	NETBSD32PTR32(s32p->l_childname, p->l_childname);
   1134 }
   1135 
   1136 static inline void
   1137 netbsd32_from_devrescanargs(const struct devrescanargs *p,
   1138     struct netbsd32_devrescanargs *s32p, u_long cmd)
   1139 {
   1140 
   1141 	memcpy(s32p->busname, p->busname, sizeof(s32p->busname));
   1142 	memcpy(s32p->ifattr, p->ifattr, sizeof(s32p->ifattr));
   1143 	s32p->numlocators = p->numlocators;
   1144 	NETBSD32PTR32(s32p->locators, p->locators);
   1145 }
   1146 
   1147 static inline void
   1148 netbsd32_from_disk_strategy(const struct disk_strategy *p,
   1149     struct netbsd32_disk_strategy *s32p, u_long cmd)
   1150 {
   1151 
   1152 	memcpy(s32p->dks_name, p->dks_name, sizeof(p->dks_name));
   1153 	NETBSD32PTR32(s32p->dks_param, p->dks_param);
   1154 	s32p->dks_paramlen = p->dks_paramlen;
   1155 }
   1156 
   1157 static inline void
   1158 netbsd32_from_dkwedge_list(const struct dkwedge_list *p,
   1159     struct netbsd32_dkwedge_list *s32p, u_long cmd)
   1160 {
   1161 
   1162 	NETBSD32PTR32(s32p->dkwl_buf, p->dkwl_buf);
   1163 	s32p->dkwl_bufsize = p->dkwl_bufsize;
   1164 	s32p->dkwl_nwedges = p->dkwl_nwedges;
   1165 	s32p->dkwl_ncopied = p->dkwl_ncopied;
   1166 }
   1167 
   1168 static inline void
   1169 netbsd32_to_lsenable(struct netbsd32_lsenable *le32, struct lsenable *le,
   1170     u_long cmd)
   1171 {
   1172 
   1173 	le->le_csstart = le32->le_csstart;
   1174 	le->le_csend = le32->le_csend;
   1175 	le->le_lockstart = le32->le_lockstart;
   1176 	le->le_lockend = le32->le_lockend;
   1177 	le->le_nbufs = le32->le_nbufs;
   1178 	le->le_flags = le32->le_flags;
   1179 	le->le_mask = le32->le_mask;
   1180 }
   1181 
   1182 static inline void
   1183 netbsd32_from_lsenable(struct lsenable *le, struct netbsd32_lsenable *le32,
   1184     u_long cmd)
   1185 {
   1186 
   1187 	le32->le_csstart = le->le_csstart;
   1188 	le32->le_csend = le->le_csend;
   1189 	le32->le_lockstart = le->le_lockstart;
   1190 	le32->le_lockend = le->le_lockend;
   1191 	le32->le_nbufs = le->le_nbufs;
   1192 	le32->le_flags = le->le_flags;
   1193 	le32->le_mask = le->le_mask;
   1194 }
   1195 
   1196 static inline void
   1197 netbsd32_to_lsdisable(struct netbsd32_lsdisable *ld32, struct lsdisable *ld,
   1198     u_long cmd)
   1199 {
   1200 
   1201 	ld->ld_size = ld32->ld_size;
   1202 	netbsd32_to_timespec(&ld32->ld_time, &ld->ld_time);
   1203 	memcpy(&ld->ld_time, &ld32->ld_time, sizeof(ld->ld_time));
   1204 }
   1205 
   1206 static inline void
   1207 netbsd32_from_lsdisable(struct lsdisable *ld, struct netbsd32_lsdisable *ld32,
   1208     u_long cmd)
   1209 {
   1210 
   1211 	ld->ld_size = ld32->ld_size;
   1212 	netbsd32_from_timespec(&ld->ld_time, &ld32->ld_time);
   1213 	memcpy(&ld->ld_time, &ld32->ld_time, sizeof(ld->ld_time));
   1214 }
   1215 
   1216 #ifdef NTP
   1217 static int
   1218 netbsd32_do_clockctl_ntp_adjtime(struct file *fp,
   1219     struct clockctl_ntp_adjtime *args)
   1220 {
   1221 	struct vnode *vp;
   1222 	struct specnode *sn;
   1223 	const char *name;
   1224 
   1225 	struct netbsd32_timex ntv32;
   1226 	struct timex ntv;
   1227 	int error;
   1228 
   1229 	/* Verify that the file descriptor is is to the clockctl device */
   1230 	if (fp->f_type != DTYPE_VNODE)
   1231 		return EINVAL;
   1232 
   1233 	vp = fp->f_vnode;
   1234 	if (vp->v_type != VCHR)
   1235 		return EINVAL;
   1236 
   1237 	sn = vp->v_specnode;
   1238 	name = cdevsw_getname(major(sn->sn_rdev));
   1239 	if (name == NULL || strcmp(name, "clockctl") != 0)
   1240 		return EINVAL;
   1241 
   1242 	if (vec_ntp_adjtime1 == NULL)
   1243 		return EINVAL;
   1244 
   1245 	error = copyin(args->tp, &ntv32, sizeof(ntv32));
   1246 	if (error)
   1247 		return error;
   1248 
   1249 	netbsd32_to_timex(&ntv32, &ntv);
   1250 	(*vec_ntp_adjtime1)(&ntv);
   1251 	netbsd32_from_timex(&ntv, &ntv32);
   1252 
   1253 	error = copyout(&ntv32, args->tp, sizeof(ntv32));
   1254 	if (error == 0)
   1255 		args->retval = ntp_timestatus();
   1256 
   1257 	return error;
   1258 }
   1259 #endif
   1260 
   1261 /*
   1262  * main ioctl syscall.
   1263  *
   1264  * ok, here we are in the biggy.  we have to do fix ups depending
   1265  * on the ioctl command before and afterwards.
   1266  */
   1267 int
   1268 netbsd32_ioctl(struct lwp *l,
   1269     const struct netbsd32_ioctl_args *uap, register_t *retval)
   1270 {
   1271 	/* {
   1272 		syscallarg(int) fd;
   1273 		syscallarg(netbsd32_u_long) com;
   1274 		syscallarg(netbsd32_voidp) data;
   1275 	} */
   1276 	struct proc *p = l->l_proc;
   1277 	struct file *fp;
   1278 	struct filedesc *fdp;
   1279 	u_long com;
   1280 	int error = 0;
   1281 	size_t size;
   1282 	size_t alloc_size32, size32;
   1283 	void *data, *memp = NULL;
   1284 	void *data32, *memp32 = NULL;
   1285 	unsigned int fd;
   1286 	fdfile_t *ff;
   1287 	int tmp;
   1288 #define STK_PARAMS	128
   1289 	uint64_t stkbuf[STK_PARAMS/sizeof(uint64_t)];
   1290 	uint64_t stkbuf32[STK_PARAMS/sizeof(uint64_t)];
   1291 
   1292 	/*
   1293 	 * we need to translate some commands (_IOW) before calling sys_ioctl,
   1294 	 * some after (_IOR), and some both (_IOWR).
   1295 	 */
   1296 #if 0
   1297 	{
   1298 		const char * const dirs[8] = {
   1299 		    "NONE!", "VOID", "OUT", "VOID|OUT!", "IN", "VOID|IN!",
   1300 		    "INOUT", "VOID|IN|OUT!"
   1301 		};
   1302 
   1303 		printf("netbsd32_ioctl(%d, %x, %x): "
   1304 		    "%s group %c base %d len %d\n",
   1305 		    SCARG(uap, fd), SCARG(uap, com), SCARG(uap, data).i32,
   1306 		    dirs[((SCARG(uap, com) & IOC_DIRMASK)>>29)],
   1307 		    IOCGROUP(SCARG(uap, com)), IOCBASECMD(SCARG(uap, com)),
   1308 		    IOCPARM_LEN(SCARG(uap, com)));
   1309 	}
   1310 #endif
   1311 
   1312 	memp = NULL;
   1313 	memp32 = NULL;
   1314 	alloc_size32 = 0;
   1315 	size32 = 0;
   1316 	size = 0;
   1317 
   1318 	fdp = p->p_fd;
   1319 	fd = SCARG(uap, fd);
   1320 	if ((fp = fd_getfile(fd)) == NULL)
   1321 		return EBADF;
   1322 	if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
   1323 		error = EBADF;
   1324 		goto out;
   1325 	}
   1326 
   1327 	ff = atomic_load_consume(&fdp->fd_dt)->dt_ff[SCARG(uap, fd)];
   1328 	switch (com = SCARG(uap, com)) {
   1329 	case FIOCLEX:
   1330 		ff->ff_exclose = true;
   1331 		fdp->fd_exclose = true;
   1332 		goto out;
   1333 
   1334 	case FIONCLEX:
   1335 		ff->ff_exclose = false;
   1336 		goto out;
   1337 	}
   1338 
   1339 	/*
   1340 	 * Interpret high order word to find amount of data to be
   1341 	 * copied to/from the user's address space.
   1342 	 */
   1343 	size32 = IOCPARM_LEN(com);
   1344 	alloc_size32 = size32;
   1345 
   1346 	/*
   1347 	 * The disklabel is now padded to a multiple of 8 bytes however the old
   1348 	 * disklabel on 32bit platforms wasn't.  This leaves a difference in
   1349 	 * size of 4 bytes between the two but are otherwise identical.
   1350 	 * To deal with this, we allocate enough space for the new disklabel
   1351 	 * but only copyin/out the smaller amount.
   1352 	 */
   1353 	if (IOCGROUP(com) == 'd') {
   1354 		u_long ncom = com ^ (DIOCGDINFO ^ DIOCGDINFO32);
   1355 		switch (ncom) {
   1356 		case DIOCGDINFO:
   1357 		case DIOCWDINFO:
   1358 		case DIOCSDINFO:
   1359 		case DIOCGDEFLABEL:
   1360 			com = ncom;
   1361 			if (IOCPARM_LEN(DIOCGDINFO32) < IOCPARM_LEN(DIOCGDINFO))
   1362 				alloc_size32 = IOCPARM_LEN(DIOCGDINFO);
   1363 			break;
   1364 		}
   1365 	}
   1366 	if (alloc_size32 > IOCPARM_MAX) {
   1367 		error = ENOTTY;
   1368 		goto out;
   1369 	}
   1370 	if (alloc_size32 > sizeof(stkbuf)) {
   1371 		memp32 = kmem_alloc(alloc_size32, KM_SLEEP);
   1372 		data32 = memp32;
   1373 	} else
   1374 		data32 = (void *)stkbuf32;
   1375 	if ((com >> IOCPARM_SHIFT) == 0)  {
   1376 		/* UNIX-style ioctl. */
   1377 		data32 = SCARG_P32(uap, data);
   1378 	} else {
   1379 		if (com&IOC_IN) {
   1380 			if (size32) {
   1381 				error = copyin(SCARG_P32(uap, data), data32,
   1382 				    size32);
   1383 				if (error) {
   1384 					goto out;
   1385 				}
   1386 				/*
   1387 				 * The data between size and alloc_size has
   1388 				 * not been overwritten.  It shouldn't matter
   1389 				 * but let's clear that anyway.
   1390 				 */
   1391 				if (__predict_false(size32 < alloc_size32)) {
   1392 					memset((char *)data32+size32, 0,
   1393 					    alloc_size32 - size32);
   1394 				}
   1395 				ktrgenio(fd, UIO_WRITE, SCARG_P32(uap, data),
   1396 				    size32, 0);
   1397 			} else
   1398 				*(void **)data32 = SCARG_P32(uap, data);
   1399 		} else if ((com&IOC_OUT) && size32) {
   1400 			/*
   1401 			 * Zero the buffer so the user always
   1402 			 * gets back something deterministic.
   1403 			 */
   1404 			memset(data32, 0, alloc_size32);
   1405 		} else if (com&IOC_VOID) {
   1406 			*(void **)data32 = SCARG_P32(uap, data);
   1407 		}
   1408 	}
   1409 
   1410 	/*
   1411 	 * convert various structures, pointers, and other objects that
   1412 	 * change size from 32 bit -> 64 bit, for all ioctl commands.
   1413 	 */
   1414 	switch (SCARG(uap, com)) {
   1415 	case FIONBIO:
   1416 		mutex_enter(&fp->f_lock);
   1417 		if ((tmp = *(int *)data32) != 0)
   1418 			fp->f_flag |= FNONBLOCK;
   1419 		else
   1420 			fp->f_flag &= ~FNONBLOCK;
   1421 		mutex_exit(&fp->f_lock);
   1422 		error = (*fp->f_ops->fo_ioctl)(fp, FIONBIO, (void *)&tmp);
   1423 		break;
   1424 
   1425 	case FIOASYNC:
   1426 		mutex_enter(&fp->f_lock);
   1427 		if ((tmp = *(int *)data32) != 0)
   1428 			fp->f_flag |= FASYNC;
   1429 		else
   1430 			fp->f_flag &= ~FASYNC;
   1431 		mutex_exit(&fp->f_lock);
   1432 		error = (*fp->f_ops->fo_ioctl)(fp, FIOASYNC, (void *)&tmp);
   1433 		break;
   1434 
   1435 	case AUDIO_WSEEK32:
   1436 		IOCTL_CONV_TO(AUDIO_WSEEK, u_long);
   1437 
   1438 #if 0	/* not implemented by anything */
   1439 	case DIOCRFORMAT32:
   1440 		IOCTL_STRUCT_CONV_TO(DIOCRFORMAT, format_op);
   1441 	case DIOCWFORMAT32:
   1442 		IOCTL_STRUCT_CONV_TO(DIOCWFORMAT, format_op);
   1443 #endif
   1444 
   1445 	case KFILTER_BYFILTER32:
   1446 		IOCTL_STRUCT_CONV_TO(KFILTER_BYFILTER, kfilter_mapping);
   1447 	case KFILTER_BYNAME32:
   1448 		IOCTL_STRUCT_CONV_TO(KFILTER_BYNAME, kfilter_mapping);
   1449 
   1450 	case ATAIOCCOMMAND32:
   1451 		IOCTL_STRUCT_CONV_TO(ATAIOCCOMMAND, atareq);
   1452 
   1453 	case SIOCIFGCLONERS32:
   1454 		{
   1455 			struct netbsd32_if_clonereq *req =
   1456 			    (struct netbsd32_if_clonereq *)data32;
   1457 			char *buf = NETBSD32PTR64(req->ifcr_buffer);
   1458 
   1459 			error = if_clone_list(req->ifcr_count,
   1460 			    buf, &req->ifcr_total);
   1461 			break;
   1462 		}
   1463 
   1464 /*
   1465  * only a few ifreq syscalls need conversion and those are
   1466  * all driver specific... XXX
   1467  */
   1468 #if 0
   1469 	case SIOCGADDRROM3232:
   1470 		IOCTL_STRUCT_CONV_TO(SIOCGADDRROM32, ifreq);
   1471 	case SIOCGCHIPID32:
   1472 		IOCTL_STRUCT_CONV_TO(SIOCGCHIPID, ifreq);
   1473 	case SIOCSIFADDR32:
   1474 		IOCTL_STRUCT_CONV_TO(SIOCSIFADDR, ifreq);
   1475 	case OSIOCGIFADDR32:
   1476 		IOCTL_STRUCT_CONV_TO(OSIOCGIFADDR, ifreq);
   1477 	case SIOCGIFADDR32:
   1478 		IOCTL_STRUCT_CONV_TO(SIOCGIFADDR, ifreq);
   1479 	case SIOCSIFDSTADDR32:
   1480 		IOCTL_STRUCT_CONV_TO(SIOCSIFDSTADDR, ifreq);
   1481 	case OSIOCGIFDSTADDR32:
   1482 		IOCTL_STRUCT_CONV_TO(OSIOCGIFDSTADDR, ifreq);
   1483 	case SIOCGIFDSTADDR32:
   1484 		IOCTL_STRUCT_CONV_TO(SIOCGIFDSTADDR, ifreq);
   1485 	case OSIOCGIFBRDADDR32:
   1486 		IOCTL_STRUCT_CONV_TO(OSIOCGIFBRDADDR, ifreq);
   1487 	case SIOCGIFBRDADDR32:
   1488 		IOCTL_STRUCT_CONV_TO(SIOCGIFBRDADDR, ifreq);
   1489 	case SIOCSIFBRDADDR32:
   1490 		IOCTL_STRUCT_CONV_TO(SIOCSIFBRDADDR, ifreq);
   1491 	case OSIOCGIFNETMASK32:
   1492 		IOCTL_STRUCT_CONV_TO(OSIOCGIFNETMASK, ifreq);
   1493 	case SIOCGIFNETMASK32:
   1494 		IOCTL_STRUCT_CONV_TO(SIOCGIFNETMASK, ifreq);
   1495 	case SIOCSIFNETMASK32:
   1496 		IOCTL_STRUCT_CONV_TO(SIOCSIFNETMASK, ifreq);
   1497 	case SIOCGIFMETRIC32:
   1498 		IOCTL_STRUCT_CONV_TO(SIOCGIFMETRIC, ifreq);
   1499 	case SIOCSIFMETRIC32:
   1500 		IOCTL_STRUCT_CONV_TO(SIOCSIFMETRIC, ifreq);
   1501 	case SIOCDIFADDR32:
   1502 		IOCTL_STRUCT_CONV_TO(SIOCDIFADDR, ifreq);
   1503 	case SIOCADDMULTI32:
   1504 		IOCTL_STRUCT_CONV_TO(SIOCADDMULTI, ifreq);
   1505 	case SIOCDELMULTI32:
   1506 		IOCTL_STRUCT_CONV_TO(SIOCDELMULTI, ifreq);
   1507 	case SIOCSIFMEDIA32:
   1508 		IOCTL_STRUCT_CONV_TO(SIOCSIFMEDIA, ifreq);
   1509 	case SIOCSIFMTU32:
   1510 		IOCTL_STRUCT_CONV_TO(SIOCSIFMTU, ifreq);
   1511 	case SIOCGIFMTU32:
   1512 		IOCTL_STRUCT_CONV_TO(SIOCGIFMTU, ifreq);
   1513 	case BIOCGETIF32:
   1514 		IOCTL_STRUCT_CONV_TO(BIOCGETIF, ifreq);
   1515 	case BIOCSETIF32:
   1516 		IOCTL_STRUCT_CONV_TO(BIOCSETIF, ifreq);
   1517 	case SIOCPHASE132:
   1518 		IOCTL_STRUCT_CONV_TO(SIOCPHASE1, ifreq);
   1519 	case SIOCPHASE232:
   1520 		IOCTL_STRUCT_CONV_TO(SIOCPHASE2, ifreq);
   1521 #endif
   1522 
   1523 	case OOSIOCGIFCONF32:
   1524 		IOCTL_STRUCT_CONV_TO(OOSIOCGIFCONF, ifconf);
   1525 	case OSIOCGIFCONF32:
   1526 		IOCTL_STRUCT_CONV_TO(OSIOCGIFCONF, ifconf);
   1527 	case SIOCGIFCONF32:
   1528 		IOCTL_STRUCT_CONV_TO(SIOCGIFCONF, ifconf);
   1529 
   1530 	case SIOCGIFFLAGS32:
   1531 		IOCTL_STRUCT_CONV_TO(SIOCGIFFLAGS, ifreq);
   1532 	case SIOCSIFFLAGS32:
   1533 		IOCTL_STRUCT_CONV_TO(SIOCSIFFLAGS, ifreq);
   1534 
   1535 	case SIOCGIFADDRPREF32:
   1536 		IOCTL_STRUCT_CONV_TO(SIOCGIFADDRPREF, if_addrprefreq);
   1537 	case SIOCSIFADDRPREF32:
   1538 		IOCTL_STRUCT_CONV_TO(SIOCSIFADDRPREF, if_addrprefreq);
   1539 
   1540 
   1541 	case OSIOCGIFFLAGS32:
   1542 		IOCTL_STRUCT_CONV_TO(OSIOCGIFFLAGS, oifreq);
   1543 	case OSIOCSIFFLAGS32:
   1544 		IOCTL_STRUCT_CONV_TO(OSIOCSIFFLAGS, oifreq);
   1545 
   1546 	case SIOCGIFMEDIA32_80:
   1547 		IOCTL_STRUCT_CONV_TO(SIOCGIFMEDIA_80, ifmediareq);
   1548 	case SIOCGIFMEDIA32:
   1549 		IOCTL_STRUCT_CONV_TO(SIOCGIFMEDIA, ifmediareq);
   1550 
   1551 	case SIOCGNBRINFO32:
   1552 		IOCTL_STRUCT_CONV_TO(SIOCGNBRINFO, in_nbrinfo);
   1553 	case SIOCGNBRINFO_IN632:
   1554 		IOCTL_STRUCT_CONV_TO(SIOCGNBRINFO_IN6, in6_nbrinfo);
   1555 
   1556 	case SIOCGIFGENERIC32:
   1557 		IOCTL_STRUCT_CONV_TO(SIOCGIFGENERIC, ifreq);
   1558 	case SIOCSIFGENERIC32:
   1559 		IOCTL_STRUCT_CONV_TO(SIOCSIFGENERIC, ifreq);
   1560 
   1561 	case PPPOESETPARMS32:
   1562 		IOCTL_STRUCT_CONV_TO(PPPOESETPARMS, pppoediscparms);
   1563 	case PPPOEGETPARMS32:
   1564 		IOCTL_STRUCT_CONV_TO(PPPOEGETPARMS, pppoediscparms);
   1565 	case SPPPGETAUTHCFG32:
   1566 		IOCTL_STRUCT_CONV_TO(SPPPGETAUTHCFG, spppauthcfg);
   1567 	case SPPPSETAUTHCFG32:
   1568 		IOCTL_STRUCT_CONV_TO(SPPPSETAUTHCFG, spppauthcfg);
   1569 
   1570 	case SIOCSDRVSPEC32:
   1571 		IOCTL_STRUCT_CONV_TO(SIOCSDRVSPEC, ifdrv);
   1572 	case SIOCGDRVSPEC32:
   1573 		IOCTL_STRUCT_CONV_TO(SIOCGDRVSPEC, ifdrv);
   1574 
   1575 	case SIOCGETVIFCNT32:
   1576 		IOCTL_STRUCT_CONV_TO(SIOCGETVIFCNT, sioc_vif_req);
   1577 
   1578 	case SIOCGETSGCNT32:
   1579 		IOCTL_STRUCT_CONV_TO(SIOCGETSGCNT, sioc_sg_req);
   1580 
   1581 	case FSSIOCSET32:	/* XXX FSSIOCSET50 not yet handled */
   1582 		IOCTL_STRUCT_CONV_TO(FSSIOCSET, fss_set);
   1583 	case FSSIOCGET32:	/* XXX FSSIOCGET50 not yet handled */
   1584 		IOCTL_STRUCT_CONV_TO(FSSIOCGET, fss_get);
   1585 
   1586 	case VNDIOCSET32:
   1587 		IOCTL_STRUCT_CONV_TO(VNDIOCSET, vnd_ioctl);
   1588 	case VNDIOCCLR32:
   1589 		IOCTL_STRUCT_CONV_TO(VNDIOCCLR, vnd_ioctl);
   1590 	case VNDIOCGET32:
   1591 		IOCTL_STRUCT_CONV_TO(VNDIOCGET, vnd_user);
   1592 	case VNDIOCSET5032:
   1593 		IOCTL_STRUCT_CONV_TO(VNDIOCSET50, vnd_ioctl50);
   1594 	case VNDIOCCLR5032:
   1595 		IOCTL_STRUCT_CONV_TO(VNDIOCCLR50, vnd_ioctl50);
   1596 
   1597 	case ENVSYS_GETDICTIONARY32:
   1598 		IOCTL_STRUCT_CONV_TO(ENVSYS_GETDICTIONARY, plistref);
   1599 	case ENVSYS_SETDICTIONARY32:
   1600 		IOCTL_STRUCT_CONV_TO(ENVSYS_SETDICTIONARY, plistref);
   1601 	case ENVSYS_REMOVEPROPS32:
   1602 		IOCTL_STRUCT_CONV_TO(ENVSYS_REMOVEPROPS, plistref);
   1603 
   1604 	case WDOGIOC_GWDOGS32:
   1605 		IOCTL_STRUCT_CONV_TO(WDOGIOC_GWDOGS, wdog_conf);
   1606 
   1607 	case BIOCSETF32:
   1608 		IOCTL_STRUCT_CONV_TO(BIOCSETF, bpf_program);
   1609 	case BIOCSETWF32:
   1610 		IOCTL_STRUCT_CONV_TO(BIOCSETWF, bpf_program);
   1611 	case BIOCSTCPF32:
   1612 		IOCTL_STRUCT_CONV_TO(BIOCSTCPF, bpf_program);
   1613 	case BIOCSUDPF32:
   1614 		IOCTL_STRUCT_CONV_TO(BIOCSUDPF, bpf_program);
   1615 	case BIOCGDLTLIST32:
   1616 		IOCTL_STRUCT_CONV_TO(BIOCGDLTLIST, bpf_dltlist);
   1617 	case BIOCSRTIMEOUT32:
   1618 #define netbsd32_to_timeval(s32p, p, cmd) netbsd32_to_timeval(s32p, p)
   1619 #define netbsd32_from_timeval(p, s32p, cmd) netbsd32_from_timeval(p, s32p)
   1620 		IOCTL_STRUCT_CONV_TO(BIOCSRTIMEOUT, timeval);
   1621 #undef netbsd32_to_timeval
   1622 #undef netbsd32_from_timeval
   1623 
   1624 	case WSDISPLAYIO_ADDSCREEN32:
   1625 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_ADDSCREEN,
   1626 		    wsdisplay_addscreendata);
   1627 
   1628 	case WSDISPLAYIO_GCURSOR32:
   1629 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_GCURSOR, wsdisplay_cursor);
   1630 	case WSDISPLAYIO_SCURSOR32:
   1631 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_SCURSOR, wsdisplay_cursor);
   1632 
   1633 	case WSDISPLAYIO_GETCMAP32:
   1634 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_GETCMAP, wsdisplay_cmap);
   1635 	case WSDISPLAYIO_PUTCMAP32:
   1636 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_PUTCMAP, wsdisplay_cmap);
   1637 
   1638 	case WSDISPLAYIO_LDFONT32:
   1639 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_LDFONT, wsdisplay_font);
   1640 	case WSDISPLAYIO_SFONT32:
   1641 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_SFONT, wsdisplay_usefontdata);
   1642 
   1643 	case SIOCS8021132:
   1644 		IOCTL_STRUCT_CONV_TO(SIOCS80211, ieee80211req);
   1645 	case SIOCG8021132:
   1646 		IOCTL_STRUCT_CONV_TO(SIOCG80211, ieee80211req);
   1647 	case SIOCS80211NWKEY32:
   1648 		IOCTL_STRUCT_CONV_TO(SIOCS80211NWKEY, ieee80211_nwkey);
   1649 	case SIOCG80211NWKEY32:
   1650 		IOCTL_STRUCT_CONV_TO(SIOCG80211NWKEY, ieee80211_nwkey);
   1651 
   1652 	case POWER_EVENT_RECVDICT32:
   1653 		IOCTL_STRUCT_CONV_TO(POWER_EVENT_RECVDICT, plistref);
   1654 
   1655 	case CLOCKCTL_SETTIMEOFDAY32:
   1656 		IOCTL_STRUCT_CONV_TO(CLOCKCTL_SETTIMEOFDAY,
   1657 		    clockctl_settimeofday);
   1658 	case CLOCKCTL_ADJTIME32:
   1659 		IOCTL_STRUCT_CONV_TO(CLOCKCTL_ADJTIME, clockctl_adjtime);
   1660 	case CLOCKCTL_CLOCK_SETTIME32:
   1661 		IOCTL_STRUCT_CONV_TO(CLOCKCTL_CLOCK_SETTIME,
   1662 		    clockctl_clock_settime);
   1663 	case CLOCKCTL_NTP_ADJTIME32:
   1664 #ifdef NTP
   1665 		{
   1666 			size = IOCPARM_LEN(CLOCKCTL_NTP_ADJTIME);
   1667 			if (size > sizeof(stkbuf))
   1668 				data = memp = kmem_alloc(size, KM_SLEEP);
   1669 			else
   1670 				data = (void *)stkbuf;
   1671 
   1672 			netbsd32_to_clockctl_ntp_adjtime(
   1673 				(const struct netbsd32_clockctl_ntp_adjtime *)data32,
   1674 				(struct clockctl_ntp_adjtime *)data,
   1675 				CLOCKCTL_NTP_ADJTIME);
   1676 			error = netbsd32_do_clockctl_ntp_adjtime(fp,
   1677 				(struct clockctl_ntp_adjtime *)data);
   1678 			netbsd32_from_clockctl_ntp_adjtime(
   1679 				(const struct clockctl_ntp_adjtime *)data,
   1680 				(struct netbsd32_clockctl_ntp_adjtime *)data32,
   1681 				CLOCKCTL_NTP_ADJTIME);
   1682 
   1683 			break;
   1684 		}
   1685 #else
   1686 		error = ENOTTY;
   1687 		break;
   1688 #endif /* NTP */
   1689 
   1690 	case KIOCGSYMBOL32:
   1691 		IOCTL_STRUCT_CONV_TO(KIOCGSYMBOL, ksyms_gsymbol);
   1692 	case KIOCGVALUE32:
   1693 		IOCTL_STRUCT_CONV_TO(KIOCGVALUE, ksyms_gvalue);
   1694 
   1695         case IOC_NPF_LOAD32:
   1696                 IOCTL_CONV_TO(IOC_NPF_LOAD, nvlist_ref_t);
   1697         case IOC_NPF_TABLE32:
   1698                 IOCTL_STRUCT_CONV_TO(IOC_NPF_TABLE, npf_ioctl_table);
   1699         case IOC_NPF_STATS32:
   1700                 IOCTL_CONV_TO(IOC_NPF_STATS, voidp);
   1701         case IOC_NPF_SAVE32:
   1702                 IOCTL_CONV_TO(IOC_NPF_SAVE, nvlist_ref_t);
   1703         case IOC_NPF_RULE32:
   1704                 IOCTL_CONV_TO(IOC_NPF_RULE, nvlist_ref_t);
   1705         case IOC_NPF_CONN_LOOKUP32:
   1706                 IOCTL_CONV_TO(IOC_NPF_CONN_LOOKUP, nvlist_ref_t);
   1707 
   1708 	case DRVRESCANBUS32:
   1709 		IOCTL_STRUCT_CONV_TO(DRVRESCANBUS, devrescanargs);
   1710 	case DRVLISTDEV32:
   1711 		IOCTL_STRUCT_CONV_TO(DRVLISTDEV, devlistargs);
   1712 	case DRVCTLCOMMAND32:
   1713 		IOCTL_STRUCT_CONV_TO(DRVCTLCOMMAND, plistref);
   1714 	case DRVGETEVENT32:
   1715 		IOCTL_STRUCT_CONV_TO(DRVGETEVENT, plistref);
   1716 
   1717 	case DIOCGSTRATEGY32:
   1718 		IOCTL_STRUCT_CONV_TO(DIOCGSTRATEGY, disk_strategy);
   1719 	case DIOCSSTRATEGY32:
   1720 		IOCTL_STRUCT_CONV_TO(DIOCSSTRATEGY, disk_strategy);
   1721 	case DIOCGDISKINFO32:
   1722 		IOCTL_STRUCT_CONV_TO(DIOCGDISKINFO, plistref);
   1723 	case DIOCLWEDGES32:
   1724 		IOCTL_STRUCT_CONV_TO(DIOCLWEDGES, dkwedge_list);
   1725 
   1726 	case IOC_LOCKSTAT_ENABLE32:
   1727 		IOCTL_STRUCT_CONV_TO(IOC_LOCKSTAT_ENABLE, lsenable);
   1728 	case IOC_LOCKSTAT_DISABLE32:
   1729 		IOCTL_STRUCT_CONV_TO(IOC_LOCKSTAT_DISABLE, lsdisable);
   1730 
   1731 	default:
   1732 #ifdef NETBSD32_DRMKMS
   1733 		if (IOCGROUP(com) == 'd') {
   1734 			error = netbsd32_drm_ioctl(fp, com, data32, l);
   1735 			break;
   1736 		}
   1737 #endif
   1738 #ifdef NETBSD32_MD_IOCTL
   1739 		error = netbsd32_md_ioctl(fp, com, data32, l);
   1740 #else
   1741 		error = (*fp->f_ops->fo_ioctl)(fp, com, data32);
   1742 #endif
   1743 		break;
   1744 	}
   1745 
   1746 	if (error == EPASSTHROUGH)
   1747 		error = ENOTTY;
   1748 
   1749 	/*
   1750 	 * Copy any data to user, size was
   1751 	 * already set and checked above.
   1752 	 */
   1753 	if (error == 0 && (com&IOC_OUT) && size32) {
   1754 		error = copyout(data32, SCARG_P32(uap, data), size32);
   1755 		ktrgenio(fd, UIO_READ, SCARG_P32(uap, data),
   1756 		    size32, error);
   1757 	}
   1758 
   1759  out:
   1760 	/* If we allocated data, free it here. */
   1761 	if (memp32)
   1762 		kmem_free(memp32, alloc_size32);
   1763 	if (memp)
   1764 		kmem_free(memp, size);
   1765 	fd_putfile(fd);
   1766 	return error;
   1767 }
   1768