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