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