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