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