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