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