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