netbsd32_netbsd.c revision 1.28.2.5 1 /* $NetBSD: netbsd32_netbsd.c,v 1.28.2.5 2001/06/16 20:18:45 he Exp $ */
2
3 /*
4 * Copyright (c) 1998 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 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31 #include "opt_ddb.h"
32 #include "opt_ktrace.h"
33 #include "opt_ntp.h"
34 #include "opt_compat_netbsd.h"
35 #include "opt_compat_freebsd.h"
36 #include "opt_compat_linux.h"
37 #include "opt_compat_sunos.h"
38 #include "opt_compat_43.h"
39 #include "opt_sysv.h"
40 #if defined(COMPAT_43) || defined(COMPAT_SUNOS) || defined(COMPAT_LINUX) || \
41 defined(COMPAT_FREEBSD)
42 #define COMPAT_OLDSOCK /* used by <sys/socket.h> */
43 #endif
44
45 #include "fs_lfs.h"
46 #include "fs_nfs.h"
47
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/filedesc.h>
51 #include <sys/kernel.h>
52 #include <sys/ipc.h>
53 #include <sys/msg.h>
54 #define msg __msg /* Don't ask me! */
55 #include <sys/sem.h>
56 #include <sys/shm.h>
57 #include <sys/malloc.h>
58 #include <sys/mount.h>
59 #include <sys/socket.h>
60 #include <sys/sockio.h>
61 #include <sys/socketvar.h>
62 #include <sys/mbuf.h>
63 #include <sys/stat.h>
64 #include <sys/time.h>
65 #include <sys/timex.h>
66 #include <sys/signalvar.h>
67 #include <sys/wait.h>
68 #include <sys/ptrace.h>
69 #include <sys/ktrace.h>
70 #include <sys/trace.h>
71 #include <sys/resourcevar.h>
72 #include <sys/pool.h>
73 #include <sys/vnode.h>
74 #include <sys/file.h>
75 #include <sys/filedesc.h>
76 #include <sys/namei.h>
77
78 #include <vm/vm.h>
79 #include <vm/vm_kern.h>
80 #include <sys/syscallargs.h>
81 #include <sys/proc.h>
82 #include <sys/acct.h>
83 #include <sys/exec.h>
84 #define __SYSCTL_PRIVATE
85 #include <sys/sysctl.h>
86
87 #include <net/if.h>
88
89 #include <compat/netbsd32/netbsd32.h>
90 #include <compat/netbsd32/netbsd32_syscallargs.h>
91
92 #include <machine/frame.h>
93
94 #if defined(DDB)
95 #include <ddb/ddbvar.h>
96 #endif
97
98 static __inline void netbsd32_from_timeval __P((struct timeval *, struct netbsd32_timeval *));
99 static __inline void netbsd32_to_timeval __P((struct netbsd32_timeval *, struct timeval *));
100 static __inline void netbsd32_from_itimerval __P((struct itimerval *, struct netbsd32_itimerval *));
101 static __inline void netbsd32_to_itimerval __P((struct netbsd32_itimerval *, struct itimerval *));
102 static __inline void netbsd32_to_timespec __P((struct netbsd32_timespec *, struct timespec *));
103 static __inline void netbsd32_from_timespec __P((struct timespec *, struct netbsd32_timespec *));
104 static __inline void netbsd32_from_rusage __P((struct rusage *, struct netbsd32_rusage *));
105 static __inline void netbsd32_to_rusage __P((struct netbsd32_rusage *, struct rusage *));
106 static __inline int netbsd32_to_iovecin __P((struct netbsd32_iovec *, struct iovec *, int));
107 static __inline void netbsd32_to_msghdr __P((struct netbsd32_msghdr *, struct msghdr *));
108 static __inline void netbsd32_from_msghdr __P((struct netbsd32_msghdr *, struct msghdr *));
109 static __inline void netbsd32_from_statfs __P((struct statfs *, struct netbsd32_statfs *));
110 static __inline void netbsd32_from_timex __P((struct timex *, struct netbsd32_timex *));
111 static __inline void netbsd32_to_timex __P((struct netbsd32_timex *, struct timex *));
112 static __inline void netbsd32_from___stat13 __P((struct stat *, struct netbsd32_stat *));
113 static __inline void netbsd32_to_ipc_perm __P((struct netbsd32_ipc_perm *, struct ipc_perm *));
114 static __inline void netbsd32_from_ipc_perm __P((struct ipc_perm *, struct netbsd32_ipc_perm *));
115 static __inline void netbsd32_to_msg __P((struct netbsd32_msg *, struct msg *));
116 static __inline void netbsd32_from_msg __P((struct msg *, struct netbsd32_msg *));
117 static __inline void netbsd32_to_msqid_ds __P((struct netbsd32_msqid_ds *, struct msqid_ds *));
118 static __inline void netbsd32_from_msqid_ds __P((struct msqid_ds *, struct netbsd32_msqid_ds *));
119 static __inline void netbsd32_to_shmid_ds __P((struct netbsd32_shmid_ds *, struct shmid_ds *));
120 static __inline void netbsd32_from_shmid_ds __P((struct shmid_ds *, struct netbsd32_shmid_ds *));
121 static __inline void netbsd32_to_semid_ds __P((struct netbsd32_semid_ds *, struct semid_ds *));
122 static __inline void netbsd32_from_semid_ds __P((struct semid_ds *, struct netbsd32_semid_ds *));
123
124
125 static int recvit32 __P((struct proc *, int, struct netbsd32_msghdr *, struct iovec *, caddr_t,
126 register_t *));
127 static int dofilereadv32 __P((struct proc *, int, struct file *, struct netbsd32_iovec *,
128 int, off_t *, int, register_t *));
129 static int dofilewritev32 __P((struct proc *, int, struct file *, struct netbsd32_iovec *,
130 int, off_t *, int, register_t *));
131 static int change_utimes32 __P((struct vnode *, struct timeval *, struct proc *));
132
133 /* converters for structures that we need */
134 static __inline void
135 netbsd32_from_timeval(tv, tv32)
136 struct timeval *tv;
137 struct netbsd32_timeval *tv32;
138 {
139
140 tv32->tv_sec = (netbsd32_long)tv->tv_sec;
141 tv32->tv_usec = (netbsd32_long)tv->tv_usec;
142 }
143
144 static __inline void
145 netbsd32_to_timeval(tv32, tv)
146 struct netbsd32_timeval *tv32;
147 struct timeval *tv;
148 {
149
150 tv->tv_sec = (long)tv32->tv_sec;
151 tv->tv_usec = (long)tv32->tv_usec;
152 }
153
154 static __inline void
155 netbsd32_from_itimerval(itv, itv32)
156 struct itimerval *itv;
157 struct netbsd32_itimerval *itv32;
158 {
159
160 netbsd32_from_timeval(&itv->it_interval,
161 &itv32->it_interval);
162 netbsd32_from_timeval(&itv->it_value,
163 &itv32->it_value);
164 }
165
166 static __inline void
167 netbsd32_to_itimerval(itv32, itv)
168 struct netbsd32_itimerval *itv32;
169 struct itimerval *itv;
170 {
171
172 netbsd32_to_timeval(&itv32->it_interval, &itv->it_interval);
173 netbsd32_to_timeval(&itv32->it_value, &itv->it_value);
174 }
175
176 static __inline void
177 netbsd32_to_timespec(s32p, p)
178 struct netbsd32_timespec *s32p;
179 struct timespec *p;
180 {
181
182 p->tv_sec = (time_t)s32p->tv_sec;
183 p->tv_nsec = (long)s32p->tv_nsec;
184 }
185
186 static __inline void
187 netbsd32_from_timespec(p, s32p)
188 struct timespec *p;
189 struct netbsd32_timespec *s32p;
190 {
191
192 s32p->tv_sec = (netbsd32_time_t)p->tv_sec;
193 s32p->tv_nsec = (netbsd32_long)p->tv_nsec;
194 }
195
196 static __inline void
197 netbsd32_from_rusage(rup, ru32p)
198 struct rusage *rup;
199 struct netbsd32_rusage *ru32p;
200 {
201
202 netbsd32_from_timeval(&rup->ru_utime, &ru32p->ru_utime);
203 netbsd32_from_timeval(&rup->ru_stime, &ru32p->ru_stime);
204 #define C(var) ru32p->var = (netbsd32_long)rup->var
205 C(ru_maxrss);
206 C(ru_ixrss);
207 C(ru_idrss);
208 C(ru_isrss);
209 C(ru_minflt);
210 C(ru_majflt);
211 C(ru_nswap);
212 C(ru_inblock);
213 C(ru_oublock);
214 C(ru_msgsnd);
215 C(ru_msgrcv);
216 C(ru_nsignals);
217 C(ru_nvcsw);
218 C(ru_nivcsw);
219 #undef C
220 }
221
222 static __inline void
223 netbsd32_to_rusage(ru32p, rup)
224 struct netbsd32_rusage *ru32p;
225 struct rusage *rup;
226 {
227
228 netbsd32_to_timeval(&ru32p->ru_utime, &rup->ru_utime);
229 netbsd32_to_timeval(&ru32p->ru_stime, &rup->ru_stime);
230 #define C(var) rup->var = (long)ru32p->var
231 C(ru_maxrss);
232 C(ru_ixrss);
233 C(ru_idrss);
234 C(ru_isrss);
235 C(ru_minflt);
236 C(ru_majflt);
237 C(ru_nswap);
238 C(ru_inblock);
239 C(ru_oublock);
240 C(ru_msgsnd);
241 C(ru_msgrcv);
242 C(ru_nsignals);
243 C(ru_nvcsw);
244 C(ru_nivcsw);
245 #undef C
246 }
247
248 static __inline int
249 netbsd32_to_iovecin(iov32p, iovp, len)
250 struct netbsd32_iovec *iov32p;
251 struct iovec *iovp;
252 int len;
253 {
254 int i, error=0;
255 u_int32_t iov_base;
256 u_int32_t iov_len;
257 /*
258 * We could allocate an iov32p, do a copyin, and translate
259 * each field and then free it all up, or we could copyin
260 * each field separately. I'm doing the latter to reduce
261 * the number of MALLOC()s.
262 */
263 for (i = 0; i < len; i++, iovp++, iov32p++) {
264 if ((error = copyin((caddr_t)&iov32p->iov_base, &iov_base, sizeof(iov_base))))
265 return (error);
266 if ((error = copyin((caddr_t)&iov32p->iov_len, &iov_len, sizeof(iov_len))))
267 return (error);
268 iovp->iov_base = (void *)(u_long)iov_base;
269 iovp->iov_len = (size_t)iov_len;
270 }
271 }
272
273 /* msg_iov must be done separately */
274 static __inline void
275 netbsd32_to_msghdr(mhp32, mhp)
276 struct netbsd32_msghdr *mhp32;
277 struct msghdr *mhp;
278 {
279
280 mhp->msg_name = (caddr_t)(u_long)mhp32->msg_name;
281 mhp->msg_namelen = mhp32->msg_namelen;
282 mhp->msg_iovlen = (size_t)mhp32->msg_iovlen;
283 mhp->msg_control = (caddr_t)(u_long)mhp32->msg_control;
284 mhp->msg_controllen = mhp32->msg_controllen;
285 mhp->msg_flags = mhp32->msg_flags;
286 }
287
288 /* msg_iov must be done separately */
289 static __inline void
290 netbsd32_from_msghdr(mhp32, mhp)
291 struct netbsd32_msghdr *mhp32;
292 struct msghdr *mhp;
293 {
294
295 mhp32->msg_name = mhp32->msg_name;
296 mhp32->msg_namelen = mhp32->msg_namelen;
297 mhp32->msg_iovlen = mhp32->msg_iovlen;
298 mhp32->msg_control = mhp32->msg_control;
299 mhp32->msg_controllen = mhp->msg_controllen;
300 mhp32->msg_flags = mhp->msg_flags;
301 }
302
303 static __inline void
304 netbsd32_from_statfs(sbp, sb32p)
305 struct statfs *sbp;
306 struct netbsd32_statfs *sb32p;
307 {
308 sb32p->f_type = sbp->f_type;
309 sb32p->f_flags = sbp->f_flags;
310 sb32p->f_bsize = (netbsd32_long)sbp->f_bsize;
311 sb32p->f_iosize = (netbsd32_long)sbp->f_iosize;
312 sb32p->f_blocks = (netbsd32_long)sbp->f_blocks;
313 sb32p->f_bfree = (netbsd32_long)sbp->f_bfree;
314 sb32p->f_bavail = (netbsd32_long)sbp->f_bavail;
315 sb32p->f_files = (netbsd32_long)sbp->f_files;
316 sb32p->f_ffree = (netbsd32_long)sbp->f_ffree;
317 sb32p->f_fsid = sbp->f_fsid;
318 sb32p->f_owner = sbp->f_owner;
319 sb32p->f_spare[0] = 0;
320 sb32p->f_spare[1] = 0;
321 sb32p->f_spare[2] = 0;
322 sb32p->f_spare[3] = 0;
323 #if 1
324 /* May as well do the whole batch in one go */
325 memcpy(sb32p->f_fstypename, sbp->f_fstypename, MFSNAMELEN+MNAMELEN+MNAMELEN);
326 #else
327 /* If we want to be careful */
328 memcpy(sb32p->f_fstypename, sbp->f_fstypename, MFSNAMELEN);
329 memcpy(sb32p->f_mntonname, sbp->f_mntonname, MNAMELEN);
330 memcpy(sb32p->f_mntfromname, sbp->f_mntfromname, MNAMELEN);
331 #endif
332 }
333
334 static __inline void
335 netbsd32_from_timex(txp, tx32p)
336 struct timex *txp;
337 struct netbsd32_timex *tx32p;
338 {
339
340 tx32p->modes = txp->modes;
341 tx32p->offset = (netbsd32_long)txp->offset;
342 tx32p->freq = (netbsd32_long)txp->freq;
343 tx32p->maxerror = (netbsd32_long)txp->maxerror;
344 tx32p->esterror = (netbsd32_long)txp->esterror;
345 tx32p->status = txp->status;
346 tx32p->constant = (netbsd32_long)txp->constant;
347 tx32p->precision = (netbsd32_long)txp->precision;
348 tx32p->tolerance = (netbsd32_long)txp->tolerance;
349 tx32p->ppsfreq = (netbsd32_long)txp->ppsfreq;
350 tx32p->jitter = (netbsd32_long)txp->jitter;
351 tx32p->shift = txp->shift;
352 tx32p->stabil = (netbsd32_long)txp->stabil;
353 tx32p->jitcnt = (netbsd32_long)txp->jitcnt;
354 tx32p->calcnt = (netbsd32_long)txp->calcnt;
355 tx32p->errcnt = (netbsd32_long)txp->errcnt;
356 tx32p->stbcnt = (netbsd32_long)txp->stbcnt;
357 }
358
359 static __inline void
360 netbsd32_to_timex(tx32p, txp)
361 struct netbsd32_timex *tx32p;
362 struct timex *txp;
363 {
364
365 txp->modes = tx32p->modes;
366 txp->offset = (long)tx32p->offset;
367 txp->freq = (long)tx32p->freq;
368 txp->maxerror = (long)tx32p->maxerror;
369 txp->esterror = (long)tx32p->esterror;
370 txp->status = tx32p->status;
371 txp->constant = (long)tx32p->constant;
372 txp->precision = (long)tx32p->precision;
373 txp->tolerance = (long)tx32p->tolerance;
374 txp->ppsfreq = (long)tx32p->ppsfreq;
375 txp->jitter = (long)tx32p->jitter;
376 txp->shift = tx32p->shift;
377 txp->stabil = (long)tx32p->stabil;
378 txp->jitcnt = (long)tx32p->jitcnt;
379 txp->calcnt = (long)tx32p->calcnt;
380 txp->errcnt = (long)tx32p->errcnt;
381 txp->stbcnt = (long)tx32p->stbcnt;
382 }
383
384 static __inline void
385 netbsd32_from___stat13(sbp, sb32p)
386 struct stat *sbp;
387 struct netbsd32_stat *sb32p;
388 {
389 sb32p->st_dev = sbp->st_dev;
390 sb32p->st_ino = sbp->st_ino;
391 sb32p->st_mode = sbp->st_mode;
392 sb32p->st_nlink = sbp->st_nlink;
393 sb32p->st_uid = sbp->st_uid;
394 sb32p->st_gid = sbp->st_gid;
395 sb32p->st_rdev = sbp->st_rdev;
396 if (sbp->st_size < (quad_t)1 << 32)
397 sb32p->st_size = sbp->st_size;
398 else
399 sb32p->st_size = -2;
400 sb32p->st_atimespec.tv_sec = (netbsd32_time_t)sbp->st_atimespec.tv_sec;
401 sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec;
402 sb32p->st_mtimespec.tv_sec = (netbsd32_time_t)sbp->st_mtimespec.tv_sec;
403 sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec;
404 sb32p->st_ctimespec.tv_sec = (netbsd32_time_t)sbp->st_ctimespec.tv_sec;
405 sb32p->st_ctimespec.tv_nsec = (netbsd32_long)sbp->st_ctimespec.tv_nsec;
406 sb32p->st_blksize = sbp->st_blksize;
407 sb32p->st_blocks = sbp->st_blocks;
408 sb32p->st_flags = sbp->st_flags;
409 sb32p->st_gen = sbp->st_gen;
410 }
411
412 static __inline void
413 netbsd32_to_ipc_perm(ip32p, ipp)
414 struct netbsd32_ipc_perm *ip32p;
415 struct ipc_perm *ipp;
416 {
417
418 ipp->cuid = ip32p->cuid;
419 ipp->cgid = ip32p->cgid;
420 ipp->uid = ip32p->uid;
421 ipp->gid = ip32p->gid;
422 ipp->mode = ip32p->mode;
423 ipp->_seq = ip32p->_seq;
424 ipp->_key = (key_t)ip32p->_key;
425 }
426
427 static __inline void
428 netbsd32_from_ipc_perm(ipp, ip32p)
429 struct ipc_perm *ipp;
430 struct netbsd32_ipc_perm *ip32p;
431 {
432
433 ip32p->cuid = ipp->cuid;
434 ip32p->cgid = ipp->cgid;
435 ip32p->uid = ipp->uid;
436 ip32p->gid = ipp->gid;
437 ip32p->mode = ipp->mode;
438 ip32p->_seq = ipp->_seq;
439 ip32p->_key = (netbsd32_key_t)ipp->_key;
440 }
441
442 static __inline void
443 netbsd32_to_msg(m32p, mp)
444 struct netbsd32_msg *m32p;
445 struct msg *mp;
446 {
447
448 mp->msg_next = (struct msg *)(u_long)m32p->msg_next;
449 mp->msg_type = (long)m32p->msg_type;
450 mp->msg_ts = m32p->msg_ts;
451 mp->msg_spot = m32p->msg_spot;
452 }
453
454 static __inline void
455 netbsd32_from_msg(mp, m32p)
456 struct msg *mp;
457 struct netbsd32_msg *m32p;
458 {
459
460 m32p->msg_next = (netbsd32_msgp_t)(u_long)mp->msg_next;
461 m32p->msg_type = (netbsd32_long)mp->msg_type;
462 m32p->msg_ts = mp->msg_ts;
463 m32p->msg_spot = mp->msg_spot;
464 }
465
466 static __inline void
467 netbsd32_to_msqid_ds(ds32p, dsp)
468 struct netbsd32_msqid_ds *ds32p;
469 struct msqid_ds *dsp;
470 {
471
472 netbsd32_to_ipc_perm(&ds32p->msg_perm, &dsp->msg_perm);
473 netbsd32_to_msg((struct netbsd32_msg *)(u_long)ds32p->_msg_first, dsp->_msg_first);
474 netbsd32_to_msg((struct netbsd32_msg *)(u_long)ds32p->_msg_last, dsp->_msg_last);
475 dsp->_msg_cbytes = (u_long)ds32p->_msg_cbytes;
476 dsp->msg_qnum = (u_long)ds32p->msg_qnum;
477 dsp->msg_qbytes = (u_long)ds32p->msg_qbytes;
478 dsp->msg_lspid = ds32p->msg_lspid;
479 dsp->msg_lrpid = ds32p->msg_lrpid;
480 dsp->msg_rtime = (time_t)ds32p->msg_rtime;
481 dsp->msg_stime = (time_t)ds32p->msg_stime;
482 dsp->msg_ctime = (time_t)ds32p->msg_ctime;
483 }
484
485 static __inline void
486 netbsd32_from_msqid_ds(dsp, ds32p)
487 struct msqid_ds *dsp;
488 struct netbsd32_msqid_ds *ds32p;
489 {
490
491 netbsd32_from_ipc_perm(&dsp->msg_perm, &ds32p->msg_perm);
492 netbsd32_from_msg(dsp->_msg_first, (struct netbsd32_msg *)(u_long)ds32p->_msg_first);
493 netbsd32_from_msg(dsp->_msg_last, (struct netbsd32_msg *)(u_long)ds32p->_msg_last);
494 ds32p->_msg_cbytes = (netbsd32_u_long)dsp->_msg_cbytes;
495 ds32p->msg_qnum = (netbsd32_u_long)dsp->msg_qnum;
496 ds32p->msg_qbytes = (netbsd32_u_long)dsp->msg_qbytes;
497 ds32p->msg_lspid = dsp->msg_lspid;
498 ds32p->msg_lrpid = dsp->msg_lrpid;
499 ds32p->msg_rtime = dsp->msg_rtime;
500 ds32p->msg_stime = dsp->msg_stime;
501 ds32p->msg_ctime = dsp->msg_ctime;
502 }
503
504 static __inline void
505 netbsd32_to_shmid_ds(ds32p, dsp)
506 struct netbsd32_shmid_ds *ds32p;
507 struct shmid_ds *dsp;
508 {
509
510 netbsd32_to_ipc_perm(&ds32p->shm_perm, &dsp->shm_perm);
511 dsp->shm_segsz = ds32p->shm_segsz;
512 dsp->shm_lpid = ds32p->shm_lpid;
513 dsp->shm_cpid = ds32p->shm_cpid;
514 dsp->shm_nattch = ds32p->shm_nattch;
515 dsp->shm_atime = (long)ds32p->shm_atime;
516 dsp->shm_dtime = (long)ds32p->shm_dtime;
517 dsp->shm_ctime = (long)ds32p->shm_ctime;
518 dsp->_shm_internal = (void *)(u_long)ds32p->_shm_internal;
519 }
520
521 static __inline void
522 netbsd32_from_shmid_ds(dsp, ds32p)
523 struct shmid_ds *dsp;
524 struct netbsd32_shmid_ds *ds32p;
525 {
526
527 netbsd32_from_ipc_perm(&dsp->shm_perm, &ds32p->shm_perm);
528 ds32p->shm_segsz = dsp->shm_segsz;
529 ds32p->shm_lpid = dsp->shm_lpid;
530 ds32p->shm_cpid = dsp->shm_cpid;
531 ds32p->shm_nattch = dsp->shm_nattch;
532 ds32p->shm_atime = (netbsd32_long)dsp->shm_atime;
533 ds32p->shm_dtime = (netbsd32_long)dsp->shm_dtime;
534 ds32p->shm_ctime = (netbsd32_long)dsp->shm_ctime;
535 ds32p->_shm_internal = (netbsd32_voidp)(u_long)dsp->_shm_internal;
536 }
537
538 static __inline void
539 netbsd32_to_semid_ds(s32dsp, dsp)
540 struct netbsd32_semid_ds *s32dsp;
541 struct semid_ds *dsp;
542 {
543
544 netbsd32_from_ipc_perm(&dsp->sem_perm, &s32dsp->sem_perm);
545 dsp->_sem_base = (struct __sem *)(u_long)s32dsp->_sem_base;
546 dsp->sem_nsems = s32dsp->sem_nsems;
547 dsp->sem_otime = s32dsp->sem_otime;
548 dsp->sem_ctime = s32dsp->sem_ctime;
549 }
550
551 static __inline void
552 netbsd32_from_semid_ds(dsp, s32dsp)
553 struct semid_ds *dsp;
554 struct netbsd32_semid_ds *s32dsp;
555 {
556
557 netbsd32_to_ipc_perm(&s32dsp->sem_perm, &dsp->sem_perm);
558 s32dsp->_sem_base = (netbsd32_semp_t)(u_long)dsp->_sem_base;
559 s32dsp->sem_nsems = dsp->sem_nsems;
560 s32dsp->sem_otime = dsp->sem_otime;
561 s32dsp->sem_ctime = dsp->sem_ctime;
562 }
563
564 /*
565 * below are all the standard NetBSD system calls, in the 32bit
566 * environment, witht he necessary conversions to 64bit before
567 * calling the real syscall.
568 */
569
570
571 int
572 netbsd32_exit(p, v, retval)
573 struct proc *p;
574 void *v;
575 register_t *retval;
576 {
577 struct netbsd32_exit_args /* {
578 syscallarg(int) rval;
579 } */ *uap = v;
580 struct sys_exit_args ua;
581
582 NETBSD32TO64_UAP(rval);
583 sys_exit(p, &ua, retval);
584 }
585
586 int
587 netbsd32_read(p, v, retval)
588 struct proc *p;
589 void *v;
590 register_t *retval;
591 {
592 struct netbsd32_read_args /* {
593 syscallarg(int) fd;
594 syscallarg(netbsd32_voidp) buf;
595 syscallarg(netbsd32_size_t) nbyte;
596 } */ *uap = v;
597 struct sys_read_args ua;
598
599 NETBSD32TO64_UAP(fd);
600 NETBSD32TOP_UAP(buf, void *);
601 NETBSD32TOX_UAP(nbyte, size_t);
602 return sys_read(p, &ua, retval);
603 }
604
605 int
606 netbsd32_write(p, v, retval)
607 struct proc *p;
608 void *v;
609 register_t *retval;
610 {
611 struct netbsd32_write_args /* {
612 syscallarg(int) fd;
613 syscallarg(const netbsd32_voidp) buf;
614 syscallarg(netbsd32_size_t) nbyte;
615 } */ *uap = v;
616 struct sys_write_args ua;
617
618 NETBSD32TO64_UAP(fd);
619 NETBSD32TOP_UAP(buf, void *);
620 NETBSD32TOX_UAP(nbyte, size_t);
621 return sys_write(p, &ua, retval);
622 }
623
624 int
625 netbsd32_close(p, v, retval)
626 struct proc *p;
627 void *v;
628 register_t *retval;
629 {
630 struct netbsd32_close_args /* {
631 syscallarg(int) fd;
632 } */ *uap = v;
633 struct sys_close_args ua;
634
635 NETBSD32TO64_UAP(fd);
636 return sys_close(p, &ua, retval);
637 }
638
639 int
640 netbsd32_open(p, v, retval)
641 struct proc *p;
642 void *v;
643 register_t *retval;
644 {
645 struct netbsd32_open_args /* {
646 syscallarg(const netbsd32_charp) path;
647 syscallarg(int) flags;
648 syscallarg(mode_t) mode;
649 } */ *uap = v;
650 struct sys_open_args ua;
651 caddr_t sg;
652
653 NETBSD32TOP_UAP(path, const char);
654 NETBSD32TO64_UAP(flags);
655 NETBSD32TO64_UAP(mode);
656 sg = stackgap_init(p->p_emul);
657 NETBSD32_CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
658
659 return (sys_open(p, &ua, retval));
660 }
661
662 int
663 netbsd32_wait4(q, v, retval)
664 struct proc *q;
665 void *v;
666 register_t *retval;
667 {
668 struct netbsd32_wait4_args /* {
669 syscallarg(int) pid;
670 syscallarg(netbsd32_intp) status;
671 syscallarg(int) options;
672 syscallarg(netbsd32_rusagep_t) rusage;
673 } */ *uap = v;
674 struct netbsd32_rusage ru32;
675 int nfound;
676 struct proc *p, *t;
677 int status, error;
678
679 if (SCARG(uap, pid) == 0)
680 SCARG(uap, pid) = -q->p_pgid;
681 if (SCARG(uap, options) &~ (WUNTRACED|WNOHANG))
682 return (EINVAL);
683
684 loop:
685 nfound = 0;
686 for (p = q->p_children.lh_first; p != 0; p = p->p_sibling.le_next) {
687 if (SCARG(uap, pid) != WAIT_ANY &&
688 p->p_pid != SCARG(uap, pid) &&
689 p->p_pgid != -SCARG(uap, pid))
690 continue;
691 nfound++;
692 if (p->p_stat == SZOMB) {
693 retval[0] = p->p_pid;
694
695 if (SCARG(uap, status)) {
696 status = p->p_xstat; /* convert to int */
697 error = copyout((caddr_t)&status,
698 (caddr_t)(u_long)SCARG(uap, status),
699 sizeof(status));
700 if (error)
701 return (error);
702 }
703 if (SCARG(uap, rusage)) {
704 netbsd32_from_rusage(p->p_ru, &ru32);
705 if ((error = copyout((caddr_t)&ru32,
706 (caddr_t)(u_long)SCARG(uap, rusage),
707 sizeof(struct netbsd32_rusage))))
708 return (error);
709 }
710 /*
711 * If we got the child via ptrace(2) or procfs, and
712 * the parent is different (meaning the process was
713 * attached, rather than run as a child), then we need
714 * to give it back to the old parent, and send the
715 * parent a SIGCHLD. The rest of the cleanup will be
716 * done when the old parent waits on the child.
717 */
718 if ((p->p_flag & P_TRACED) &&
719 p->p_oppid != p->p_pptr->p_pid) {
720 t = pfind(p->p_oppid);
721 proc_reparent(p, t ? t : initproc);
722 p->p_oppid = 0;
723 p->p_flag &= ~(P_TRACED|P_WAITED|P_FSTRACE);
724 psignal(p->p_pptr, SIGCHLD);
725 wakeup((caddr_t)p->p_pptr);
726 return (0);
727 }
728 p->p_xstat = 0;
729 ruadd(&q->p_stats->p_cru, p->p_ru);
730 pool_put(&rusage_pool, p->p_ru);
731
732 /*
733 * Finally finished with old proc entry.
734 * Unlink it from its process group and free it.
735 */
736 leavepgrp(p);
737
738 LIST_REMOVE(p, p_list); /* off zombproc */
739
740 LIST_REMOVE(p, p_sibling);
741
742 /*
743 * Decrement the count of procs running with this uid.
744 */
745 (void)chgproccnt(p->p_cred->p_ruid, -1);
746
747 /*
748 * Free up credentials.
749 */
750 if (--p->p_cred->p_refcnt == 0) {
751 crfree(p->p_cred->pc_ucred);
752 pool_put(&pcred_pool, p->p_cred);
753 }
754
755 /*
756 * Release reference to text vnode
757 */
758 if (p->p_textvp)
759 vrele(p->p_textvp);
760
761 pool_put(&proc_pool, p);
762 nprocs--;
763 return (0);
764 }
765 if (p->p_stat == SSTOP && (p->p_flag & P_WAITED) == 0 &&
766 (p->p_flag & P_TRACED || SCARG(uap, options) & WUNTRACED)) {
767 p->p_flag |= P_WAITED;
768 retval[0] = p->p_pid;
769
770 if (SCARG(uap, status)) {
771 status = W_STOPCODE(p->p_xstat);
772 error = copyout((caddr_t)&status,
773 (caddr_t)(u_long)SCARG(uap, status),
774 sizeof(status));
775 } else
776 error = 0;
777 return (error);
778 }
779 }
780 if (nfound == 0)
781 return (ECHILD);
782 if (SCARG(uap, options) & WNOHANG) {
783 retval[0] = 0;
784 return (0);
785 }
786 if ((error = tsleep((caddr_t)q, PWAIT | PCATCH, "wait", 0)) != 0)
787 return (error);
788 goto loop;
789 }
790
791 int
792 netbsd32_link(p, v, retval)
793 struct proc *p;
794 void *v;
795 register_t *retval;
796 {
797 struct netbsd32_link_args /* {
798 syscallarg(const netbsd32_charp) path;
799 syscallarg(const netbsd32_charp) link;
800 } */ *uap = v;
801 struct sys_link_args ua;
802
803 NETBSD32TOP_UAP(path, const char);
804 NETBSD32TOP_UAP(link, const char);
805 return (sys_link(p, &ua, retval));
806 }
807
808 int
809 netbsd32_unlink(p, v, retval)
810 struct proc *p;
811 void *v;
812 register_t *retval;
813 {
814 struct netbsd32_unlink_args /* {
815 syscallarg(const netbsd32_charp) path;
816 } */ *uap = v;
817 struct sys_unlink_args ua;
818
819 NETBSD32TOP_UAP(path, const char);
820
821 return (sys_unlink(p, &ua, retval));
822 }
823
824 int
825 netbsd32_chdir(p, v, retval)
826 struct proc *p;
827 void *v;
828 register_t *retval;
829 {
830 struct netbsd32_chdir_args /* {
831 syscallarg(const netbsd32_charp) path;
832 } */ *uap = v;
833 struct sys_chdir_args ua;
834
835 NETBSD32TOP_UAP(path, const char);
836
837 return (sys_chdir(p, &ua, retval));
838 }
839
840 int
841 netbsd32_fchdir(p, v, retval)
842 struct proc *p;
843 void *v;
844 register_t *retval;
845 {
846 struct netbsd32_fchdir_args /* {
847 syscallarg(int) fd;
848 } */ *uap = v;
849 struct sys_fchdir_args ua;
850
851 NETBSD32TO64_UAP(fd);
852
853 return (sys_fchdir(p, &ua, retval));
854 }
855
856 int
857 netbsd32_mknod(p, v, retval)
858 struct proc *p;
859 void *v;
860 register_t *retval;
861 {
862 struct netbsd32_mknod_args /* {
863 syscallarg(const netbsd32_charp) path;
864 syscallarg(mode_t) mode;
865 syscallarg(dev_t) dev;
866 } */ *uap = v;
867 struct sys_mknod_args ua;
868
869 NETBSD32TOP_UAP(path, const char);
870 NETBSD32TO64_UAP(dev);
871 NETBSD32TO64_UAP(mode);
872
873 return (sys_mknod(p, &ua, retval));
874 }
875
876 int
877 netbsd32_chmod(p, v, retval)
878 struct proc *p;
879 void *v;
880 register_t *retval;
881 {
882 struct netbsd32_chmod_args /* {
883 syscallarg(const netbsd32_charp) path;
884 syscallarg(mode_t) mode;
885 } */ *uap = v;
886 struct sys_chmod_args ua;
887
888 NETBSD32TOP_UAP(path, const char);
889 NETBSD32TO64_UAP(mode);
890
891 return (sys_chmod(p, &ua, retval));
892 }
893
894 int
895 netbsd32_chown(p, v, retval)
896 struct proc *p;
897 void *v;
898 register_t *retval;
899 {
900 struct netbsd32_chown_args /* {
901 syscallarg(const netbsd32_charp) path;
902 syscallarg(uid_t) uid;
903 syscallarg(gid_t) gid;
904 } */ *uap = v;
905 struct sys_chown_args ua;
906
907 NETBSD32TOP_UAP(path, const char);
908 NETBSD32TO64_UAP(uid);
909 NETBSD32TO64_UAP(gid);
910
911 return (sys_chown(p, &ua, retval));
912 }
913
914 int
915 netbsd32_break(p, v, retval)
916 struct proc *p;
917 void *v;
918 register_t *retval;
919 {
920 struct netbsd32_break_args /* {
921 syscallarg(netbsd32_charp) nsize;
922 } */ *uap = v;
923 struct sys_obreak_args ua;
924
925 SCARG(&ua, nsize) = (char *)(u_long)SCARG(uap, nsize);
926 NETBSD32TOP_UAP(nsize, char);
927 return (sys_obreak(p, &ua, retval));
928 }
929
930 int
931 netbsd32_getfsstat(p, v, retval)
932 struct proc *p;
933 void *v;
934 register_t *retval;
935 {
936 struct netbsd32_getfsstat_args /* {
937 syscallarg(netbsd32_statfsp_t) buf;
938 syscallarg(netbsd32_long) bufsize;
939 syscallarg(int) flags;
940 } */ *uap = v;
941 struct mount *mp, *nmp;
942 struct statfs *sp;
943 struct netbsd32_statfs sb32;
944 caddr_t sfsp;
945 long count, maxcount, error;
946
947 maxcount = SCARG(uap, bufsize) / sizeof(struct netbsd32_statfs);
948 sfsp = (caddr_t)SCARG(uap, buf);
949 simple_lock(&mountlist_slock);
950 count = 0;
951 for (mp = mountlist.cqh_first; mp != (void *)&mountlist; mp = nmp) {
952 if (vfs_busy(mp, LK_NOWAIT, &mountlist_slock)) {
953 nmp = mp->mnt_list.cqe_next;
954 continue;
955 }
956 if (sfsp && count < maxcount) {
957 sp = &mp->mnt_stat;
958 /*
959 * If MNT_NOWAIT or MNT_LAZY is specified, do not
960 * refresh the fsstat cache. MNT_WAIT or MNT_LAXY
961 * overrides MNT_NOWAIT.
962 */
963 if (SCARG(uap, flags) != MNT_NOWAIT &&
964 SCARG(uap, flags) != MNT_LAZY &&
965 (SCARG(uap, flags) == MNT_WAIT ||
966 SCARG(uap, flags) == 0) &&
967 (error = VFS_STATFS(mp, sp, p)) != 0) {
968 simple_lock(&mountlist_slock);
969 nmp = mp->mnt_list.cqe_next;
970 vfs_unbusy(mp);
971 continue;
972 }
973 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
974 sp->f_oflags = sp->f_flags & 0xffff;
975 netbsd32_from_statfs(sp, &sb32);
976 error = copyout(&sb32, sfsp, sizeof(sb32));
977 if (error) {
978 vfs_unbusy(mp);
979 return (error);
980 }
981 sfsp += sizeof(sb32);
982 }
983 count++;
984 simple_lock(&mountlist_slock);
985 nmp = mp->mnt_list.cqe_next;
986 vfs_unbusy(mp);
987 }
988 simple_unlock(&mountlist_slock);
989 if (sfsp && count > maxcount)
990 *retval = maxcount;
991 else
992 *retval = count;
993 return (0);
994 }
995
996 int
997 netbsd32_mount(p, v, retval)
998 struct proc *p;
999 void *v;
1000 register_t *retval;
1001 {
1002 struct netbsd32_mount_args /* {
1003 syscallarg(const netbsd32_charp) type;
1004 syscallarg(const netbsd32_charp) path;
1005 syscallarg(int) flags;
1006 syscallarg(netbsd32_voidp) data;
1007 } */ *uap = v;
1008 struct sys_mount_args ua;
1009
1010 NETBSD32TOP_UAP(type, const char);
1011 NETBSD32TOP_UAP(path, const char);
1012 NETBSD32TO64_UAP(flags);
1013 NETBSD32TOP_UAP(data, void);
1014 return (sys_mount(p, &ua, retval));
1015 }
1016
1017 int
1018 netbsd32_unmount(p, v, retval)
1019 struct proc *p;
1020 void *v;
1021 register_t *retval;
1022 {
1023 struct netbsd32_unmount_args /* {
1024 syscallarg(const netbsd32_charp) path;
1025 syscallarg(int) flags;
1026 } */ *uap = v;
1027 struct sys_unmount_args ua;
1028
1029 NETBSD32TOP_UAP(path, const char);
1030 NETBSD32TO64_UAP(flags);
1031 return (sys_unmount(p, &ua, retval));
1032 }
1033
1034 int
1035 netbsd32_setuid(p, v, retval)
1036 struct proc *p;
1037 void *v;
1038 register_t *retval;
1039 {
1040 struct netbsd32_setuid_args /* {
1041 syscallarg(uid_t) uid;
1042 } */ *uap = v;
1043 struct sys_setuid_args ua;
1044
1045 NETBSD32TO64_UAP(uid);
1046 return (sys_setuid(p, &ua, retval));
1047 }
1048
1049 int
1050 netbsd32_ptrace(p, v, retval)
1051 struct proc *p;
1052 void *v;
1053 register_t *retval;
1054 {
1055 struct netbsd32_ptrace_args /* {
1056 syscallarg(int) req;
1057 syscallarg(pid_t) pid;
1058 syscallarg(netbsd32_caddr_t) addr;
1059 syscallarg(int) data;
1060 } */ *uap = v;
1061 struct sys_ptrace_args ua;
1062
1063 NETBSD32TO64_UAP(req);
1064 NETBSD32TO64_UAP(pid);
1065 NETBSD32TOX64_UAP(addr, caddr_t);
1066 NETBSD32TO64_UAP(data);
1067 return (sys_ptrace(p, &ua, retval));
1068 }
1069
1070 int
1071 netbsd32_recvmsg(p, v, retval)
1072 struct proc *p;
1073 void *v;
1074 register_t *retval;
1075 {
1076 struct netbsd32_recvmsg_args /* {
1077 syscallarg(int) s;
1078 syscallarg(netbsd32_msghdrp_t) msg;
1079 syscallarg(int) flags;
1080 } */ *uap = v;
1081 struct netbsd32_msghdr msg;
1082 struct iovec aiov[UIO_SMALLIOV], *uiov, *iov;
1083 int error;
1084
1085 error = copyin((caddr_t)(u_long)SCARG(uap, msg), (caddr_t)&msg,
1086 sizeof(msg));
1087 /* netbsd32_msghdr needs the iov pre-allocated */
1088 if (error)
1089 return (error);
1090 if ((u_int)msg.msg_iovlen > UIO_SMALLIOV) {
1091 if ((u_int)msg.msg_iovlen > IOV_MAX)
1092 return (EMSGSIZE);
1093 MALLOC(iov, struct iovec *,
1094 sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
1095 M_WAITOK);
1096 } else if ((u_int)msg.msg_iovlen > 0)
1097 iov = aiov;
1098 else
1099 return (EMSGSIZE);
1100 #ifdef COMPAT_OLDSOCK
1101 msg.msg_flags = SCARG(uap, flags) &~ MSG_COMPAT;
1102 #else
1103 msg.msg_flags = SCARG(uap, flags);
1104 #endif
1105 uiov = (struct iovec *)(u_long)msg.msg_iov;
1106 error = netbsd32_to_iovecin((struct netbsd32_iovec *)uiov,
1107 iov, msg.msg_iovlen);
1108 if (error)
1109 goto done;
1110 if ((error = recvit32(p, SCARG(uap, s), &msg, iov, (caddr_t)0, retval)) == 0) {
1111 error = copyout((caddr_t)&msg, (caddr_t)(u_long)SCARG(uap, msg),
1112 sizeof(msg));
1113 }
1114 done:
1115 if (iov != aiov)
1116 FREE(iov, M_IOV);
1117 return (error);
1118 }
1119
1120 int
1121 recvit32(p, s, mp, iov, namelenp, retsize)
1122 struct proc *p;
1123 int s;
1124 struct netbsd32_msghdr *mp;
1125 struct iovec *iov;
1126 caddr_t namelenp;
1127 register_t *retsize;
1128 {
1129 struct file *fp;
1130 struct uio auio;
1131 int i;
1132 int len, error;
1133 struct mbuf *from = 0, *control = 0;
1134 struct socket *so;
1135 #ifdef KTRACE
1136 struct iovec *ktriov = NULL;
1137 #endif
1138
1139 /* getsock() will use the descriptor for us */
1140 if ((error = getsock(p->p_fd, s, &fp)) != 0)
1141 return (error);
1142 auio.uio_iov = (struct iovec *)(u_long)mp->msg_iov;
1143 auio.uio_iovcnt = mp->msg_iovlen;
1144 auio.uio_segflg = UIO_USERSPACE;
1145 auio.uio_rw = UIO_READ;
1146 auio.uio_procp = p;
1147 auio.uio_offset = 0; /* XXX */
1148 auio.uio_resid = 0;
1149 for (i = 0; i < mp->msg_iovlen; i++, iov++) {
1150 #if 0
1151 /* cannot happen iov_len is unsigned */
1152 if (iov->iov_len < 0) {
1153 error = EINVAL;
1154 goto out1;
1155 }
1156 #endif
1157 /*
1158 * Reads return ssize_t because -1 is returned on error.
1159 * Therefore we must restrict the length to SSIZE_MAX to
1160 * avoid garbage return values.
1161 */
1162 auio.uio_resid += iov->iov_len;
1163 if (iov->iov_len > SSIZE_MAX || auio.uio_resid > SSIZE_MAX) {
1164 error = EINVAL;
1165 goto out1;
1166 }
1167 }
1168 #ifdef KTRACE
1169 if (KTRPOINT(p, KTR_GENIO)) {
1170 int iovlen = auio.uio_iovcnt * sizeof(struct iovec);
1171
1172 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
1173 memcpy((caddr_t)ktriov, (caddr_t)auio.uio_iov, iovlen);
1174 }
1175 #endif
1176 len = auio.uio_resid;
1177 so = (struct socket *)fp->f_data;
1178 error = (*so->so_receive)(so, &from, &auio, NULL,
1179 mp->msg_control ? &control : NULL, &mp->msg_flags);
1180 if (error) {
1181 if (auio.uio_resid != len && (error == ERESTART ||
1182 error == EINTR || error == EWOULDBLOCK))
1183 error = 0;
1184 }
1185 #ifdef KTRACE
1186 if (ktriov != NULL) {
1187 if (error == 0)
1188 ktrgenio(p, s, UIO_READ, ktriov,
1189 len - auio.uio_resid, error);
1190 FREE(ktriov, M_TEMP);
1191 }
1192 #endif
1193 if (error)
1194 goto out;
1195 *retsize = len - auio.uio_resid;
1196 if (mp->msg_name) {
1197 len = mp->msg_namelen;
1198 if (len <= 0 || from == 0)
1199 len = 0;
1200 else {
1201 #ifdef COMPAT_OLDSOCK
1202 if (mp->msg_flags & MSG_COMPAT)
1203 mtod(from, struct osockaddr *)->sa_family =
1204 mtod(from, struct sockaddr *)->sa_family;
1205 #endif
1206 if (len > from->m_len)
1207 len = from->m_len;
1208 /* else if len < from->m_len ??? */
1209 error = copyout(mtod(from, caddr_t),
1210 (caddr_t)(u_long)mp->msg_name, (unsigned)len);
1211 if (error)
1212 goto out;
1213 }
1214 mp->msg_namelen = len;
1215 if (namelenp &&
1216 (error = copyout((caddr_t)&len, namelenp, sizeof(int)))) {
1217 #ifdef COMPAT_OLDSOCK
1218 if (mp->msg_flags & MSG_COMPAT)
1219 error = 0; /* old recvfrom didn't check */
1220 else
1221 #endif
1222 goto out;
1223 }
1224 }
1225 if (mp->msg_control) {
1226 #ifdef COMPAT_OLDSOCK
1227 /*
1228 * We assume that old recvmsg calls won't receive access
1229 * rights and other control info, esp. as control info
1230 * is always optional and those options didn't exist in 4.3.
1231 * If we receive rights, trim the cmsghdr; anything else
1232 * is tossed.
1233 */
1234 if (control && mp->msg_flags & MSG_COMPAT) {
1235 if (mtod(control, struct cmsghdr *)->cmsg_level !=
1236 SOL_SOCKET ||
1237 mtod(control, struct cmsghdr *)->cmsg_type !=
1238 SCM_RIGHTS) {
1239 mp->msg_controllen = 0;
1240 goto out;
1241 }
1242 control->m_len -= sizeof(struct cmsghdr);
1243 control->m_data += sizeof(struct cmsghdr);
1244 }
1245 #endif
1246 len = mp->msg_controllen;
1247 if (len <= 0 || control == 0)
1248 len = 0;
1249 else {
1250 struct mbuf *m = control;
1251 caddr_t p = (caddr_t)(u_long)mp->msg_control;
1252
1253 do {
1254 i = m->m_len;
1255 if (len < i) {
1256 mp->msg_flags |= MSG_CTRUNC;
1257 i = len;
1258 }
1259 error = copyout(mtod(m, caddr_t), p,
1260 (unsigned)i);
1261 if (m->m_next)
1262 i = ALIGN(i);
1263 p += i;
1264 len -= i;
1265 if (error != 0 || len <= 0)
1266 break;
1267 } while ((m = m->m_next) != NULL);
1268 len = p - (caddr_t)(u_long)mp->msg_control;
1269 }
1270 mp->msg_controllen = len;
1271 }
1272 out:
1273 if (from)
1274 m_freem(from);
1275 if (control)
1276 m_freem(control);
1277 out1:
1278 FILE_UNUSE(fp, p);
1279 return (error);
1280 }
1281
1282
1283 int
1284 netbsd32_sendmsg(p, v, retval)
1285 struct proc *p;
1286 void *v;
1287 register_t *retval;
1288 {
1289 struct netbsd32_sendmsg_args /* {
1290 syscallarg(int) s;
1291 syscallarg(const netbsd32_msghdrp_t) msg;
1292 syscallarg(int) flags;
1293 } */ *uap = v;
1294 struct msghdr msg;
1295 struct netbsd32_msghdr msg32;
1296 struct iovec aiov[UIO_SMALLIOV], *iov;
1297 int error;
1298
1299 error = copyin((caddr_t)(u_long)SCARG(uap, msg),
1300 (caddr_t)&msg32, sizeof(msg32));
1301 if (error)
1302 return (error);
1303 netbsd32_to_msghdr(&msg32, &msg);
1304 if ((u_int)msg.msg_iovlen > UIO_SMALLIOV) {
1305 if ((u_int)msg.msg_iovlen > IOV_MAX)
1306 return (EMSGSIZE);
1307 MALLOC(iov, struct iovec *,
1308 sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
1309 M_WAITOK);
1310 } else if ((u_int)msg.msg_iovlen > 0)
1311 iov = aiov;
1312 else
1313 return (EMSGSIZE);
1314 error = netbsd32_to_iovecin((struct netbsd32_iovec *)msg.msg_iov,
1315 iov, msg.msg_iovlen);
1316 if (error)
1317 goto done;
1318 msg.msg_iov = iov;
1319 #ifdef COMPAT_OLDSOCK
1320 msg.msg_flags = 0;
1321 #endif
1322 /* Luckily we can use this directly */
1323 error = sendit(p, SCARG(uap, s), &msg, SCARG(uap, flags), retval);
1324 done:
1325 if (iov != aiov)
1326 FREE(iov, M_IOV);
1327 return (error);
1328 }
1329
1330 int
1331 netbsd32_recvfrom(p, v, retval)
1332 struct proc *p;
1333 void *v;
1334 register_t *retval;
1335 {
1336 struct netbsd32_recvfrom_args /* {
1337 syscallarg(int) s;
1338 syscallarg(netbsd32_voidp) buf;
1339 syscallarg(netbsd32_size_t) len;
1340 syscallarg(int) flags;
1341 syscallarg(netbsd32_sockaddrp_t) from;
1342 syscallarg(netbsd32_intp) fromlenaddr;
1343 } */ *uap = v;
1344 struct netbsd32_msghdr msg;
1345 struct iovec aiov;
1346 int error;
1347
1348 if (SCARG(uap, fromlenaddr)) {
1349 error = copyin((caddr_t)(u_long)SCARG(uap, fromlenaddr),
1350 (caddr_t)&msg.msg_namelen,
1351 sizeof(msg.msg_namelen));
1352 if (error)
1353 return (error);
1354 } else
1355 msg.msg_namelen = 0;
1356 msg.msg_name = SCARG(uap, from);
1357 msg.msg_iov = NULL; /* We can't store a real pointer here */
1358 msg.msg_iovlen = 1;
1359 aiov.iov_base = (caddr_t)(u_long)SCARG(uap, buf);
1360 aiov.iov_len = (u_long)SCARG(uap, len);
1361 msg.msg_control = 0;
1362 msg.msg_flags = SCARG(uap, flags);
1363 return (recvit32(p, SCARG(uap, s), &msg, &aiov,
1364 (caddr_t)(u_long)SCARG(uap, fromlenaddr), retval));
1365 }
1366
1367 int
1368 netbsd32_sendto(p, v, retval)
1369 struct proc *p;
1370 void *v;
1371 register_t *retval;
1372 {
1373 struct netbsd32_sendto_args /* {
1374 syscallarg(int) s;
1375 syscallarg(const netbsd32_voidp) buf;
1376 syscallarg(netbsd32_size_t) len;
1377 syscallarg(int) flags;
1378 syscallarg(const netbsd32_sockaddrp_t) to;
1379 syscallarg(int) tolen;
1380 } */ *uap = v;
1381 struct msghdr msg;
1382 struct iovec aiov;
1383
1384 msg.msg_name = (caddr_t)(u_long)SCARG(uap, to); /* XXX kills const */
1385 msg.msg_namelen = SCARG(uap, tolen);
1386 msg.msg_iov = &aiov;
1387 msg.msg_iovlen = 1;
1388 msg.msg_control = 0;
1389 #ifdef COMPAT_OLDSOCK
1390 msg.msg_flags = 0;
1391 #endif
1392 aiov.iov_base = (char *)(u_long)SCARG(uap, buf); /* XXX kills const */
1393 aiov.iov_len = SCARG(uap, len);
1394 return (sendit(p, SCARG(uap, s), &msg, SCARG(uap, flags), retval));
1395 }
1396
1397 int
1398 netbsd32_accept(p, v, retval)
1399 struct proc *p;
1400 void *v;
1401 register_t *retval;
1402 {
1403 struct netbsd32_accept_args /* {
1404 syscallarg(int) s;
1405 syscallarg(netbsd32_sockaddrp_t) name;
1406 syscallarg(netbsd32_intp) anamelen;
1407 } */ *uap = v;
1408 struct sys_accept_args ua;
1409
1410 NETBSD32TO64_UAP(s);
1411 NETBSD32TOP_UAP(name, struct sockaddr);
1412 NETBSD32TOP_UAP(anamelen, int);
1413 return (sys_accept(p, &ua, retval));
1414 }
1415
1416 int
1417 netbsd32_getpeername(p, v, retval)
1418 struct proc *p;
1419 void *v;
1420 register_t *retval;
1421 {
1422 struct netbsd32_getpeername_args /* {
1423 syscallarg(int) fdes;
1424 syscallarg(netbsd32_sockaddrp_t) asa;
1425 syscallarg(netbsd32_intp) alen;
1426 } */ *uap = v;
1427 struct sys_getpeername_args ua;
1428
1429 NETBSD32TO64_UAP(fdes);
1430 NETBSD32TOP_UAP(asa, struct sockaddr);
1431 NETBSD32TOP_UAP(alen, int);
1432 /* NB: do the protocol specific sockaddrs need to be converted? */
1433 return (sys_getpeername(p, &ua, retval));
1434 }
1435
1436 int
1437 netbsd32_getsockname(p, v, retval)
1438 struct proc *p;
1439 void *v;
1440 register_t *retval;
1441 {
1442 struct netbsd32_getsockname_args /* {
1443 syscallarg(int) fdes;
1444 syscallarg(netbsd32_sockaddrp_t) asa;
1445 syscallarg(netbsd32_intp) alen;
1446 } */ *uap = v;
1447 struct sys_getsockname_args ua;
1448
1449 NETBSD32TO64_UAP(fdes);
1450 NETBSD32TOP_UAP(asa, struct sockaddr);
1451 NETBSD32TOP_UAP(alen, int);
1452 return (sys_getsockname(p, &ua, retval));
1453 }
1454
1455 int
1456 netbsd32_access(p, v, retval)
1457 struct proc *p;
1458 void *v;
1459 register_t *retval;
1460 {
1461 struct netbsd32_access_args /* {
1462 syscallarg(const netbsd32_charp) path;
1463 syscallarg(int) flags;
1464 } */ *uap = v;
1465 struct sys_access_args ua;
1466 caddr_t sg;
1467
1468 NETBSD32TOP_UAP(path, const char);
1469 NETBSD32TO64_UAP(flags);
1470 sg = stackgap_init(p->p_emul);
1471 NETBSD32_CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
1472
1473 return (sys_access(p, &ua, retval));
1474 }
1475
1476 int
1477 netbsd32_chflags(p, v, retval)
1478 struct proc *p;
1479 void *v;
1480 register_t *retval;
1481 {
1482 struct netbsd32_chflags_args /* {
1483 syscallarg(const netbsd32_charp) path;
1484 syscallarg(netbsd32_u_long) flags;
1485 } */ *uap = v;
1486 struct sys_chflags_args ua;
1487
1488 NETBSD32TOP_UAP(path, const char);
1489 NETBSD32TO64_UAP(flags);
1490
1491 return (sys_chflags(p, &ua, retval));
1492 }
1493
1494 int
1495 netbsd32_fchflags(p, v, retval)
1496 struct proc *p;
1497 void *v;
1498 register_t *retval;
1499 {
1500 struct netbsd32_fchflags_args /* {
1501 syscallarg(int) fd;
1502 syscallarg(netbsd32_u_long) flags;
1503 } */ *uap = v;
1504 struct sys_fchflags_args ua;
1505
1506 NETBSD32TO64_UAP(fd);
1507 NETBSD32TO64_UAP(flags);
1508
1509 return (sys_fchflags(p, &ua, retval));
1510 }
1511
1512 int
1513 netbsd32_kill(p, v, retval)
1514 struct proc *p;
1515 void *v;
1516 register_t *retval;
1517 {
1518 struct netbsd32_kill_args /* {
1519 syscallarg(int) pid;
1520 syscallarg(int) signum;
1521 } */ *uap = v;
1522 struct sys_kill_args ua;
1523
1524 NETBSD32TO64_UAP(pid);
1525 NETBSD32TO64_UAP(signum);
1526
1527 return (sys_kill(p, &ua, retval));
1528 }
1529
1530 int
1531 netbsd32_dup(p, v, retval)
1532 struct proc *p;
1533 void *v;
1534 register_t *retval;
1535 {
1536 struct netbsd32_dup_args /* {
1537 syscallarg(int) fd;
1538 } */ *uap = v;
1539 struct sys_dup_args ua;
1540
1541 NETBSD32TO64_UAP(fd);
1542
1543 return (sys_dup(p, &ua, retval));
1544 }
1545
1546 int
1547 netbsd32_profil(p, v, retval)
1548 struct proc *p;
1549 void *v;
1550 register_t *retval;
1551 {
1552 struct netbsd32_profil_args /* {
1553 syscallarg(netbsd32_caddr_t) samples;
1554 syscallarg(netbsd32_size_t) size;
1555 syscallarg(netbsd32_u_long) offset;
1556 syscallarg(u_int) scale;
1557 } */ *uap = v;
1558 struct sys_profil_args ua;
1559
1560 NETBSD32TOX64_UAP(samples, caddr_t);
1561 NETBSD32TOX_UAP(size, size_t);
1562 NETBSD32TOX_UAP(offset, u_long);
1563 NETBSD32TO64_UAP(scale);
1564 return (sys_profil(p, &ua, retval));
1565 }
1566
1567 int
1568 netbsd32_ktrace(p, v, retval)
1569 struct proc *p;
1570 void *v;
1571 register_t *retval;
1572 {
1573 struct netbsd32_ktrace_args /* {
1574 syscallarg(const netbsd32_charp) fname;
1575 syscallarg(int) ops;
1576 syscallarg(int) facs;
1577 syscallarg(int) pid;
1578 } */ *uap = v;
1579 struct sys_ktrace_args ua;
1580
1581 NETBSD32TOP_UAP(fname, const char);
1582 NETBSD32TO64_UAP(ops);
1583 NETBSD32TO64_UAP(facs);
1584 NETBSD32TO64_UAP(pid);
1585 return (sys_ktrace(p, &ua, retval));
1586 }
1587
1588 int
1589 netbsd32_sigaction(p, v, retval)
1590 struct proc *p;
1591 void *v;
1592 register_t *retval;
1593 {
1594 struct netbsd32_sigaction_args /* {
1595 syscallarg(int) signum;
1596 syscallarg(const netbsd32_sigactionp_t) nsa;
1597 syscallarg(netbsd32_sigactionp_t) osa;
1598 } */ *uap = v;
1599 struct sigaction nsa, osa;
1600 struct netbsd32_sigaction *sa32p, sa32;
1601 int error;
1602
1603 if (SCARG(uap, nsa)) {
1604 sa32p = (struct netbsd32_sigaction *)(u_long)SCARG(uap, nsa);
1605 if (copyin(sa32p, &sa32, sizeof(sa32)))
1606 return EFAULT;
1607 nsa.sa_handler = (void *)(u_long)sa32.sa_handler;
1608 nsa.sa_mask = sa32.sa_mask;
1609 nsa.sa_flags = sa32.sa_flags;
1610 }
1611 error = sigaction1(p, SCARG(uap, signum),
1612 SCARG(uap, nsa) ? &nsa : 0,
1613 SCARG(uap, osa) ? &osa : 0);
1614
1615 if (error)
1616 return (error);
1617
1618 if (SCARG(uap, osa)) {
1619 sa32.sa_handler = (netbsd32_sigactionp_t)(u_long)osa.sa_handler;
1620 sa32.sa_mask = osa.sa_mask;
1621 sa32.sa_flags = osa.sa_flags;
1622 sa32p = (struct netbsd32_sigaction *)(u_long)SCARG(uap, osa);
1623 if (copyout(&sa32, sa32p, sizeof(sa32)))
1624 return EFAULT;
1625 }
1626
1627 return (0);
1628 }
1629
1630 int
1631 netbsd32___getlogin(p, v, retval)
1632 struct proc *p;
1633 void *v;
1634 register_t *retval;
1635 {
1636 struct netbsd32___getlogin_args /* {
1637 syscallarg(netbsd32_charp) namebuf;
1638 syscallarg(u_int) namelen;
1639 } */ *uap = v;
1640 struct sys___getlogin_args ua;
1641
1642 NETBSD32TOP_UAP(namebuf, char);
1643 NETBSD32TO64_UAP(namelen);
1644 return (sys___getlogin(p, &ua, retval));
1645 }
1646
1647 int
1648 netbsd32_setlogin(p, v, retval)
1649 struct proc *p;
1650 void *v;
1651 register_t *retval;
1652 {
1653 struct netbsd32_setlogin_args /* {
1654 syscallarg(const netbsd32_charp) namebuf;
1655 } */ *uap = v;
1656 struct sys_setlogin_args ua;
1657
1658 NETBSD32TOP_UAP(namebuf, char);
1659 return (sys_setlogin(p, &ua, retval));
1660 }
1661
1662 int
1663 netbsd32_acct(p, v, retval)
1664 struct proc *p;
1665 void *v;
1666 register_t *retval;
1667 {
1668 struct netbsd32_acct_args /* {
1669 syscallarg(const netbsd32_charp) path;
1670 } */ *uap = v;
1671 struct sys_acct_args ua;
1672
1673 NETBSD32TOP_UAP(path, const char);
1674 return (sys_acct(p, &ua, retval));
1675 }
1676
1677 int
1678 netbsd32_revoke(p, v, retval)
1679 struct proc *p;
1680 void *v;
1681 register_t *retval;
1682 {
1683 struct netbsd32_revoke_args /* {
1684 syscallarg(const netbsd32_charp) path;
1685 } */ *uap = v;
1686 struct sys_revoke_args ua;
1687 caddr_t sg;
1688
1689 NETBSD32TOP_UAP(path, const char);
1690 sg = stackgap_init(p->p_emul);
1691 NETBSD32_CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
1692
1693 return (sys_revoke(p, &ua, retval));
1694 }
1695
1696 int
1697 netbsd32_symlink(p, v, retval)
1698 struct proc *p;
1699 void *v;
1700 register_t *retval;
1701 {
1702 struct netbsd32_symlink_args /* {
1703 syscallarg(const netbsd32_charp) path;
1704 syscallarg(const netbsd32_charp) link;
1705 } */ *uap = v;
1706 struct sys_symlink_args ua;
1707
1708 NETBSD32TOP_UAP(path, const char);
1709 NETBSD32TOP_UAP(link, const char);
1710
1711 return (sys_symlink(p, &ua, retval));
1712 }
1713
1714 int
1715 netbsd32_readlink(p, v, retval)
1716 struct proc *p;
1717 void *v;
1718 register_t *retval;
1719 {
1720 struct netbsd32_readlink_args /* {
1721 syscallarg(const netbsd32_charp) path;
1722 syscallarg(netbsd32_charp) buf;
1723 syscallarg(netbsd32_size_t) count;
1724 } */ *uap = v;
1725 struct sys_readlink_args ua;
1726 caddr_t sg;
1727
1728 NETBSD32TOP_UAP(path, const char);
1729 NETBSD32TOP_UAP(buf, char);
1730 NETBSD32TOX_UAP(count, size_t);
1731 sg = stackgap_init(p->p_emul);
1732 NETBSD32_CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
1733
1734 return (sys_readlink(p, &ua, retval));
1735 }
1736
1737 /*
1738 * Need to completly reimplement this syscall due to argument copying.
1739 */
1740 int
1741 netbsd32_execve(p, v, retval)
1742 struct proc *p;
1743 void *v;
1744 register_t *retval;
1745 {
1746 struct netbsd32_execve_args /* {
1747 syscallarg(const netbsd32_charp) path;
1748 syscallarg(netbsd32_charpp) argp;
1749 syscallarg(netbsd32_charpp) envp;
1750 } */ *uap = v;
1751 struct sys_execve_args ua;
1752 caddr_t sg;
1753 /* Function args */
1754 int error, i;
1755 struct exec_package pack;
1756 struct nameidata nid;
1757 struct vattr attr;
1758 struct ucred *cred = p->p_ucred;
1759 char *argp;
1760 netbsd32_charp const *cpp;
1761 char *dp;
1762 netbsd32_charp sp;
1763 long argc, envc;
1764 size_t len;
1765 char *stack;
1766 struct ps_strings arginfo;
1767 struct vmspace *vm;
1768 char **tmpfap;
1769 int szsigcode;
1770 extern struct emul emul_netbsd;
1771
1772
1773 NETBSD32TOP_UAP(path, const char);
1774 NETBSD32TOP_UAP(argp, char *);
1775 NETBSD32TOP_UAP(envp, char *);
1776 sg = stackgap_init(p->p_emul);
1777 NETBSD32_CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
1778
1779 /*
1780 * figure out the maximum size of an exec header, if necessary.
1781 * XXX should be able to keep LKM code from modifying exec switch
1782 * when we're still using it, but...
1783 */
1784 if (exec_maxhdrsz == 0) {
1785 for (i = 0; i < nexecs; i++)
1786 if (execsw[i].es_check != NULL
1787 && execsw[i].es_hdrsz > exec_maxhdrsz)
1788 exec_maxhdrsz = execsw[i].es_hdrsz;
1789 }
1790
1791 /* init the namei data to point the file user's program name */
1792 /* XXX cgd 960926: why do this here? most will be clobbered. */
1793 NDINIT(&nid, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(&ua, path), p);
1794
1795 /*
1796 * initialize the fields of the exec package.
1797 */
1798 pack.ep_name = SCARG(&ua, path);
1799 MALLOC(pack.ep_hdr, void *, exec_maxhdrsz, M_EXEC, M_WAITOK);
1800 pack.ep_hdrlen = exec_maxhdrsz;
1801 pack.ep_hdrvalid = 0;
1802 pack.ep_ndp = &nid;
1803 pack.ep_emul_arg = NULL;
1804 pack.ep_vmcmds.evs_cnt = 0;
1805 pack.ep_vmcmds.evs_used = 0;
1806 pack.ep_vap = &attr;
1807 pack.ep_emul = &emul_netbsd;
1808 pack.ep_flags = 0;
1809
1810 /* see if we can run it. */
1811 if ((error = check_exec(p, &pack)) != 0)
1812 goto freehdr;
1813
1814 /* XXX -- THE FOLLOWING SECTION NEEDS MAJOR CLEANUP */
1815
1816 /* allocate an argument buffer */
1817 argp = (char *) uvm_km_valloc_wait(exec_map, NCARGS);
1818 #ifdef DIAGNOSTIC
1819 if (argp == (vaddr_t) 0)
1820 panic("execve: argp == NULL");
1821 #endif
1822 dp = argp;
1823 argc = 0;
1824
1825 /* copy the fake args list, if there's one, freeing it as we go */
1826 if (pack.ep_flags & EXEC_HASARGL) {
1827 tmpfap = pack.ep_fa;
1828 while (*tmpfap != NULL) {
1829 char *cp;
1830
1831 cp = *tmpfap;
1832 while (*cp)
1833 *dp++ = *cp++;
1834 dp++;
1835
1836 FREE(*tmpfap, M_EXEC);
1837 tmpfap++; argc++;
1838 }
1839 FREE(pack.ep_fa, M_EXEC);
1840 pack.ep_flags &= ~EXEC_HASARGL;
1841 }
1842
1843 /* Now get argv & environment */
1844 if (!(cpp = (netbsd32_charp *)SCARG(&ua, argp))) {
1845 error = EINVAL;
1846 goto bad;
1847 }
1848
1849 if (pack.ep_flags & EXEC_SKIPARG)
1850 cpp++;
1851
1852 while (1) {
1853 len = argp + ARG_MAX - dp;
1854 if ((error = copyin(cpp, &sp, sizeof(sp))) != 0)
1855 goto bad;
1856 if (!sp)
1857 break;
1858 if ((error = copyinstr((char *)(u_long)sp, dp,
1859 len, &len)) != 0) {
1860 if (error == ENAMETOOLONG)
1861 error = E2BIG;
1862 goto bad;
1863 }
1864 dp += len;
1865 cpp++;
1866 argc++;
1867 }
1868
1869 envc = 0;
1870 /* environment need not be there */
1871 if ((cpp = (netbsd32_charp *)SCARG(&ua, envp)) != NULL ) {
1872 while (1) {
1873 len = argp + ARG_MAX - dp;
1874 if ((error = copyin(cpp, &sp, sizeof(sp))) != 0)
1875 goto bad;
1876 if (!sp)
1877 break;
1878 if ((error = copyinstr((char *)(u_long)sp,
1879 dp, len, &len)) != 0) {
1880 if (error == ENAMETOOLONG)
1881 error = E2BIG;
1882 goto bad;
1883 }
1884 dp += len;
1885 cpp++;
1886 envc++;
1887 }
1888 }
1889
1890 dp = (char *) ALIGN(dp);
1891
1892 szsigcode = pack.ep_emul->e_esigcode - pack.ep_emul->e_sigcode;
1893
1894 /* Now check if args & environ fit into new stack */
1895 if (pack.ep_flags & EXEC_32)
1896 len = ((argc + envc + 2 + pack.ep_emul->e_arglen) * sizeof(int) +
1897 sizeof(int) + dp + STACKGAPLEN + szsigcode +
1898 sizeof(struct ps_strings)) - argp;
1899 else
1900 len = ((argc + envc + 2 + pack.ep_emul->e_arglen) * sizeof(char *) +
1901 sizeof(int) + dp + STACKGAPLEN + szsigcode +
1902 sizeof(struct ps_strings)) - argp;
1903
1904 len = ALIGN(len); /* make the stack "safely" aligned */
1905
1906 if (len > pack.ep_ssize) { /* in effect, compare to initial limit */
1907 error = ENOMEM;
1908 goto bad;
1909 }
1910
1911 /* adjust "active stack depth" for process VSZ */
1912 pack.ep_ssize = len; /* maybe should go elsewhere, but... */
1913
1914 /*
1915 * Do whatever is necessary to prepare the address space
1916 * for remapping. Note that this might replace the current
1917 * vmspace with another!
1918 */
1919 uvmspace_exec(p);
1920
1921 /* Now map address space */
1922 vm = p->p_vmspace;
1923 vm->vm_taddr = (char *) pack.ep_taddr;
1924 vm->vm_tsize = btoc(pack.ep_tsize);
1925 vm->vm_daddr = (char *) pack.ep_daddr;
1926 vm->vm_dsize = btoc(pack.ep_dsize);
1927 vm->vm_ssize = btoc(pack.ep_ssize);
1928 vm->vm_maxsaddr = (char *) pack.ep_maxsaddr;
1929 vm->vm_minsaddr = (char *) pack.ep_minsaddr;
1930
1931 /* create the new process's VM space by running the vmcmds */
1932 #ifdef DIAGNOSTIC
1933 if (pack.ep_vmcmds.evs_used == 0)
1934 panic("execve: no vmcmds");
1935 #endif
1936 for (i = 0; i < pack.ep_vmcmds.evs_used && !error; i++) {
1937 struct exec_vmcmd *vcp;
1938
1939 vcp = &pack.ep_vmcmds.evs_cmds[i];
1940 error = (*vcp->ev_proc)(p, vcp);
1941 }
1942
1943 /* free the vmspace-creation commands, and release their references */
1944 kill_vmcmds(&pack.ep_vmcmds);
1945
1946 /* if an error happened, deallocate and punt */
1947 if (error)
1948 goto exec_abort;
1949
1950 /* remember information about the process */
1951 arginfo.ps_nargvstr = argc;
1952 arginfo.ps_nenvstr = envc;
1953
1954 stack = (char *) (vm->vm_minsaddr - len);
1955 /* Now copy argc, args & environ to new stack */
1956 if (!(*pack.ep_emul->e_copyargs)(&pack, &arginfo, stack, argp))
1957 goto exec_abort;
1958
1959 /* fill process ps_strings info */
1960 p->p_psstr = (struct ps_strings *)(stack - sizeof(struct ps_strings));
1961 p->p_psargv = offsetof(struct ps_strings, ps_argvstr);
1962 p->p_psnargv = offsetof(struct ps_strings, ps_nargvstr);
1963 p->p_psenv = offsetof(struct ps_strings, ps_envstr);
1964 p->p_psnenv = offsetof(struct ps_strings, ps_nenvstr);
1965
1966 /* copy out the process's ps_strings structure */
1967 if (copyout(&arginfo, (char *)p->p_psstr, sizeof(arginfo)))
1968 goto exec_abort;
1969
1970 /* copy out the process's signal trapoline code */
1971 if (szsigcode) {
1972 if (copyout((char *)pack.ep_emul->e_sigcode,
1973 p->p_sigacts->ps_sigcode = (char *)p->p_psstr - szsigcode,
1974 szsigcode))
1975 goto exec_abort;
1976 #ifdef PMAP_NEED_PROCWR
1977 /* This is code. Let the pmap do what is needed. */
1978 pmap_procwr(p, (vaddr_t)p->p_sigacts->ps_sigcode, szsigcode);
1979 #endif
1980 }
1981
1982 stopprofclock(p); /* stop profiling */
1983 fdcloseexec(p); /* handle close on exec */
1984 execsigs(p); /* reset catched signals */
1985 p->p_ctxlink = NULL; /* reset ucontext link */
1986
1987 /* set command name & other accounting info */
1988 len = min(nid.ni_cnd.cn_namelen, MAXCOMLEN);
1989 memcpy(p->p_comm, nid.ni_cnd.cn_nameptr, len);
1990 p->p_comm[len] = 0;
1991 p->p_acflag &= ~AFORK;
1992
1993 /* record proc's vnode, for use by procfs and others */
1994 if (p->p_textvp)
1995 vrele(p->p_textvp);
1996 VREF(pack.ep_vp);
1997 p->p_textvp = pack.ep_vp;
1998
1999 p->p_flag |= P_EXEC;
2000 if (p->p_flag & P_PPWAIT) {
2001 p->p_flag &= ~P_PPWAIT;
2002 wakeup((caddr_t) p->p_pptr);
2003 }
2004
2005 /*
2006 * deal with set[ug]id.
2007 * MNT_NOSUID has already been used to disable s[ug]id.
2008 */
2009 if ((p->p_flag & P_TRACED) == 0 &&
2010
2011 (((attr.va_mode & S_ISUID) != 0 &&
2012 p->p_ucred->cr_uid != attr.va_uid) ||
2013
2014 ((attr.va_mode & S_ISGID) != 0 &&
2015 p->p_ucred->cr_gid != attr.va_gid))) {
2016 /*
2017 * Mark the process as SUGID before we do
2018 * anything that might block.
2019 */
2020 p_sugid(p);
2021
2022 p->p_ucred = crcopy(cred);
2023 #ifdef KTRACE
2024 /*
2025 * If process is being ktraced, turn off - unless
2026 * root set it.
2027 */
2028 if (p->p_tracep && !(p->p_traceflag & KTRFAC_ROOT))
2029 ktrderef(p);
2030 #endif
2031 if (attr.va_mode & S_ISUID)
2032 p->p_ucred->cr_uid = attr.va_uid;
2033 if (attr.va_mode & S_ISGID)
2034 p->p_ucred->cr_gid = attr.va_gid;
2035 } else
2036 p->p_flag &= ~P_SUGID;
2037 p->p_cred->p_svuid = p->p_ucred->cr_uid;
2038 p->p_cred->p_svgid = p->p_ucred->cr_gid;
2039
2040 uvm_km_free_wakeup(exec_map, (vaddr_t) argp, NCARGS);
2041
2042 FREE(nid.ni_cnd.cn_pnbuf, M_NAMEI);
2043 vn_lock(pack.ep_vp, LK_EXCLUSIVE | LK_RETRY);
2044 VOP_CLOSE(pack.ep_vp, FREAD, cred, p);
2045 vput(pack.ep_vp);
2046
2047 /* setup new registers and do misc. setup. */
2048 (*pack.ep_emul->e_setregs)(p, &pack, (u_long) stack);
2049
2050 if (p->p_flag & P_TRACED)
2051 psignal(p, SIGTRAP);
2052
2053 p->p_emul = pack.ep_emul;
2054 FREE(pack.ep_hdr, M_EXEC);
2055
2056 #ifdef KTRACE
2057 if (KTRPOINT(p, KTR_EMUL))
2058 ktremul(p);
2059 #endif
2060
2061 return (EJUSTRETURN);
2062
2063 bad:
2064 /* free the vmspace-creation commands, and release their references */
2065 kill_vmcmds(&pack.ep_vmcmds);
2066 /* kill any opened file descriptor, if necessary */
2067 if (pack.ep_flags & EXEC_HASFD) {
2068 pack.ep_flags &= ~EXEC_HASFD;
2069 (void) fdrelease(p, pack.ep_fd);
2070 }
2071 /* close and put the exec'd file */
2072 vn_lock(pack.ep_vp, LK_EXCLUSIVE | LK_RETRY);
2073 VOP_CLOSE(pack.ep_vp, FREAD, cred, p);
2074 vput(pack.ep_vp);
2075 FREE(nid.ni_cnd.cn_pnbuf, M_NAMEI);
2076 uvm_km_free_wakeup(exec_map, (vaddr_t) argp, NCARGS);
2077
2078 freehdr:
2079 FREE(pack.ep_hdr, M_EXEC);
2080 return error;
2081
2082 exec_abort:
2083 /*
2084 * the old process doesn't exist anymore. exit gracefully.
2085 * get rid of the (new) address space we have created, if any, get rid
2086 * of our namei data and vnode, and exit noting failure
2087 */
2088 uvm_deallocate(&vm->vm_map, VM_MIN_ADDRESS,
2089 VM_MAXUSER_ADDRESS - VM_MIN_ADDRESS);
2090 if (pack.ep_emul_arg)
2091 FREE(pack.ep_emul_arg, M_TEMP);
2092 FREE(nid.ni_cnd.cn_pnbuf, M_NAMEI);
2093 vn_lock(pack.ep_vp, LK_EXCLUSIVE | LK_RETRY);
2094 VOP_CLOSE(pack.ep_vp, FREAD, cred, p);
2095 vput(pack.ep_vp);
2096 uvm_km_free_wakeup(exec_map, (vaddr_t) argp, NCARGS);
2097 FREE(pack.ep_hdr, M_EXEC);
2098 exit1(p, W_EXITCODE(0, SIGABRT));
2099 exit1(p, -1);
2100
2101 /* NOTREACHED */
2102 return 0;
2103 }
2104
2105 int
2106 netbsd32_umask(p, v, retval)
2107 struct proc *p;
2108 void *v;
2109 register_t *retval;
2110 {
2111 struct netbsd32_umask_args /* {
2112 syscallarg(mode_t) newmask;
2113 } */ *uap = v;
2114 struct sys_umask_args ua;
2115
2116 NETBSD32TO64_UAP(newmask);
2117 return (sys_umask(p, &ua, retval));
2118 }
2119
2120 int
2121 netbsd32_chroot(p, v, retval)
2122 struct proc *p;
2123 void *v;
2124 register_t *retval;
2125 {
2126 struct netbsd32_chroot_args /* {
2127 syscallarg(const netbsd32_charp) path;
2128 } */ *uap = v;
2129 struct sys_chroot_args ua;
2130
2131 NETBSD32TOP_UAP(path, const char);
2132 return (sys_chroot(p, &ua, retval));
2133 }
2134
2135 int
2136 netbsd32_sbrk(p, v, retval)
2137 struct proc *p;
2138 void *v;
2139 register_t *retval;
2140 {
2141 struct netbsd32_sbrk_args /* {
2142 syscallarg(int) incr;
2143 } */ *uap = v;
2144 struct sys_sbrk_args ua;
2145
2146 NETBSD32TO64_UAP(incr);
2147 return (sys_sbrk(p, &ua, retval));
2148 }
2149
2150 int
2151 netbsd32_sstk(p, v, retval)
2152 struct proc *p;
2153 void *v;
2154 register_t *retval;
2155 {
2156 struct netbsd32_sstk_args /* {
2157 syscallarg(int) incr;
2158 } */ *uap = v;
2159 struct sys_sstk_args ua;
2160
2161 NETBSD32TO64_UAP(incr);
2162 return (sys_sstk(p, &ua, retval));
2163 }
2164
2165 int
2166 netbsd32_munmap(p, v, retval)
2167 struct proc *p;
2168 void *v;
2169 register_t *retval;
2170 {
2171 struct netbsd32_munmap_args /* {
2172 syscallarg(netbsd32_voidp) addr;
2173 syscallarg(netbsd32_size_t) len;
2174 } */ *uap = v;
2175 struct sys_munmap_args ua;
2176
2177 NETBSD32TOP_UAP(addr, void);
2178 NETBSD32TOX_UAP(len, size_t);
2179 return (sys_munmap(p, &ua, retval));
2180 }
2181
2182 int
2183 netbsd32_mprotect(p, v, retval)
2184 struct proc *p;
2185 void *v;
2186 register_t *retval;
2187 {
2188 struct netbsd32_mprotect_args /* {
2189 syscallarg(netbsd32_voidp) addr;
2190 syscallarg(netbsd32_size_t) len;
2191 syscallarg(int) prot;
2192 } */ *uap = v;
2193 struct sys_mprotect_args ua;
2194
2195 NETBSD32TOP_UAP(addr, void);
2196 NETBSD32TOX_UAP(len, size_t);
2197 NETBSD32TO64_UAP(prot);
2198 return (sys_mprotect(p, &ua, retval));
2199 }
2200
2201 int
2202 netbsd32_madvise(p, v, retval)
2203 struct proc *p;
2204 void *v;
2205 register_t *retval;
2206 {
2207 struct netbsd32_madvise_args /* {
2208 syscallarg(netbsd32_voidp) addr;
2209 syscallarg(netbsd32_size_t) len;
2210 syscallarg(int) behav;
2211 } */ *uap = v;
2212 struct sys_madvise_args ua;
2213
2214 NETBSD32TOP_UAP(addr, void);
2215 NETBSD32TOX_UAP(len, size_t);
2216 NETBSD32TO64_UAP(behav);
2217 return (sys_madvise(p, &ua, retval));
2218 }
2219
2220 int
2221 netbsd32_mincore(p, v, retval)
2222 struct proc *p;
2223 void *v;
2224 register_t *retval;
2225 {
2226 struct netbsd32_mincore_args /* {
2227 syscallarg(netbsd32_caddr_t) addr;
2228 syscallarg(netbsd32_size_t) len;
2229 syscallarg(netbsd32_charp) vec;
2230 } */ *uap = v;
2231 struct sys_mincore_args ua;
2232
2233 NETBSD32TOX64_UAP(addr, caddr_t);
2234 NETBSD32TOX_UAP(len, size_t);
2235 NETBSD32TOP_UAP(vec, char);
2236 return (sys_mincore(p, &ua, retval));
2237 }
2238
2239 int
2240 netbsd32_getgroups(p, v, retval)
2241 struct proc *p;
2242 void *v;
2243 register_t *retval;
2244 {
2245 struct netbsd32_getgroups_args /* {
2246 syscallarg(int) gidsetsize;
2247 syscallarg(netbsd32_gid_tp) gidset;
2248 } */ *uap = v;
2249 struct pcred *pc = p->p_cred;
2250 int ngrp;
2251 int error;
2252
2253 ngrp = SCARG(uap, gidsetsize);
2254 if (ngrp == 0) {
2255 *retval = pc->pc_ucred->cr_ngroups;
2256 return (0);
2257 }
2258 if (ngrp < pc->pc_ucred->cr_ngroups)
2259 return (EINVAL);
2260 ngrp = pc->pc_ucred->cr_ngroups;
2261 /* Should convert gid_t to netbsd32_gid_t, but they're the same */
2262 error = copyout((caddr_t)pc->pc_ucred->cr_groups,
2263 (caddr_t)(u_long)SCARG(uap, gidset),
2264 ngrp * sizeof(gid_t));
2265 if (error)
2266 return (error);
2267 *retval = ngrp;
2268 return (0);
2269 }
2270
2271 int
2272 netbsd32_setgroups(p, v, retval)
2273 struct proc *p;
2274 void *v;
2275 register_t *retval;
2276 {
2277 struct netbsd32_setgroups_args /* {
2278 syscallarg(int) gidsetsize;
2279 syscallarg(const netbsd32_gid_tp) gidset;
2280 } */ *uap = v;
2281 struct sys_setgroups_args ua;
2282
2283 NETBSD32TO64_UAP(gidsetsize);
2284 NETBSD32TOP_UAP(gidset, gid_t);
2285 return (sys_setgroups(p, &ua, retval));
2286 }
2287
2288 int
2289 netbsd32_setpgid(p, v, retval)
2290 struct proc *p;
2291 void *v;
2292 register_t *retval;
2293 {
2294 struct netbsd32_setpgid_args /* {
2295 syscallarg(int) pid;
2296 syscallarg(int) pgid;
2297 } */ *uap = v;
2298 struct sys_setpgid_args ua;
2299
2300 NETBSD32TO64_UAP(pid);
2301 NETBSD32TO64_UAP(pgid);
2302 return (sys_setpgid(p, &ua, retval));
2303 }
2304
2305 int
2306 netbsd32_setitimer(p, v, retval)
2307 struct proc *p;
2308 void *v;
2309 register_t *retval;
2310 {
2311 struct netbsd32_setitimer_args /* {
2312 syscallarg(int) which;
2313 syscallarg(const netbsd32_itimervalp_t) itv;
2314 syscallarg(netbsd32_itimervalp_t) oitv;
2315 } */ *uap = v;
2316 struct netbsd32_itimerval s32it, *itvp;
2317 int which = SCARG(uap, which);
2318 struct netbsd32_getitimer_args getargs;
2319 struct itimerval aitv;
2320 int s, error;
2321
2322 if ((u_int)which > ITIMER_PROF)
2323 return (EINVAL);
2324 itvp = (struct netbsd32_itimerval *)(u_long)SCARG(uap, itv);
2325 if (itvp && (error = copyin(itvp, &s32it, sizeof(s32it))))
2326 return (error);
2327 netbsd32_to_itimerval(&s32it, &aitv);
2328 if (SCARG(uap, oitv) != NULL) {
2329 SCARG(&getargs, which) = which;
2330 SCARG(&getargs, itv) = SCARG(uap, oitv);
2331 if ((error = netbsd32_getitimer(p, &getargs, retval)) != 0)
2332 return (error);
2333 }
2334 if (itvp == 0)
2335 return (0);
2336 if (itimerfix(&aitv.it_value) || itimerfix(&aitv.it_interval))
2337 return (EINVAL);
2338 s = splclock();
2339 if (which == ITIMER_REAL) {
2340 callout_stop(&p->p_realit_ch);
2341 if (timerisset(&aitv.it_value)) {
2342 /*
2343 * Don't need to check hzto() return value, here.
2344 * callout_reset() does it for us.
2345 */
2346 timeradd(&aitv.it_value, &time, &aitv.it_value);
2347 callout_reset(&p->p_realit_ch, hzto(&aitv.it_value),
2348 realitexpire, p);
2349 }
2350 p->p_realtimer = aitv;
2351 } else
2352 p->p_stats->p_timer[which] = aitv;
2353 splx(s);
2354 return (0);
2355 }
2356
2357 int
2358 netbsd32_getitimer(p, v, retval)
2359 struct proc *p;
2360 void *v;
2361 register_t *retval;
2362 {
2363 struct netbsd32_getitimer_args /* {
2364 syscallarg(int) which;
2365 syscallarg(netbsd32_itimervalp_t) itv;
2366 } */ *uap = v;
2367 int which = SCARG(uap, which);
2368 struct netbsd32_itimerval s32it;
2369 struct itimerval aitv;
2370 int s;
2371
2372 if ((u_int)which > ITIMER_PROF)
2373 return (EINVAL);
2374 s = splclock();
2375 if (which == ITIMER_REAL) {
2376 /*
2377 * Convert from absolute to relative time in .it_value
2378 * part of real time timer. If time for real time timer
2379 * has passed return 0, else return difference between
2380 * current time and time for the timer to go off.
2381 */
2382 aitv = p->p_realtimer;
2383 if (timerisset(&aitv.it_value)) {
2384 if (timercmp(&aitv.it_value, &time, <))
2385 timerclear(&aitv.it_value);
2386 else
2387 timersub(&aitv.it_value, &time, &aitv.it_value);
2388 }
2389 } else
2390 aitv = p->p_stats->p_timer[which];
2391 splx(s);
2392 netbsd32_from_itimerval(&aitv, &s32it);
2393 return (copyout(&s32it, (caddr_t)(u_long)SCARG(uap, itv), sizeof(s32it)));
2394 }
2395
2396 int
2397 netbsd32_fcntl(p, v, retval)
2398 struct proc *p;
2399 void *v;
2400 register_t *retval;
2401 {
2402 struct netbsd32_fcntl_args /* {
2403 syscallarg(int) fd;
2404 syscallarg(int) cmd;
2405 syscallarg(netbsd32_voidp) arg;
2406 } */ *uap = v;
2407 struct sys_fcntl_args ua;
2408
2409 NETBSD32TO64_UAP(fd);
2410 NETBSD32TO64_UAP(cmd);
2411 NETBSD32TOP_UAP(arg, void);
2412 /* XXXX we can do this 'cause flock doesn't change */
2413 return (sys_fcntl(p, &ua, retval));
2414 }
2415
2416 int
2417 netbsd32_dup2(p, v, retval)
2418 struct proc *p;
2419 void *v;
2420 register_t *retval;
2421 {
2422 struct netbsd32_dup2_args /* {
2423 syscallarg(int) from;
2424 syscallarg(int) to;
2425 } */ *uap = v;
2426 struct sys_dup2_args ua;
2427
2428 NETBSD32TO64_UAP(from);
2429 NETBSD32TO64_UAP(to);
2430 return (sys_dup2(p, &ua, retval));
2431 }
2432
2433 int
2434 netbsd32_select(p, v, retval)
2435 struct proc *p;
2436 void *v;
2437 register_t *retval;
2438 {
2439 struct netbsd32_select_args /* {
2440 syscallarg(int) nd;
2441 syscallarg(netbsd32_fd_setp_t) in;
2442 syscallarg(netbsd32_fd_setp_t) ou;
2443 syscallarg(netbsd32_fd_setp_t) ex;
2444 syscallarg(netbsd32_timevalp_t) tv;
2445 } */ *uap = v;
2446 /* This one must be done in-line 'cause of the timeval */
2447 struct netbsd32_timeval tv32;
2448 caddr_t bits;
2449 char smallbits[howmany(FD_SETSIZE, NFDBITS) * sizeof(fd_mask) * 6];
2450 struct timeval atv;
2451 int s, ncoll, error = 0, timo;
2452 size_t ni;
2453 extern int selwait, nselcoll;
2454 extern int selscan __P((struct proc *, fd_mask *, fd_mask *, int, register_t *));
2455
2456 if (SCARG(uap, nd) < 0)
2457 return (EINVAL);
2458 if (SCARG(uap, nd) > p->p_fd->fd_nfiles) {
2459 /* forgiving; slightly wrong */
2460 SCARG(uap, nd) = p->p_fd->fd_nfiles;
2461 }
2462 ni = howmany(SCARG(uap, nd), NFDBITS) * sizeof(fd_mask);
2463 if (ni * 6 > sizeof(smallbits))
2464 bits = malloc(ni * 6, M_TEMP, M_WAITOK);
2465 else
2466 bits = smallbits;
2467
2468 #define getbits(name, x) \
2469 if (SCARG(uap, name)) { \
2470 error = copyin((caddr_t)(u_long)SCARG(uap, name), bits + ni * x, ni); \
2471 if (error) \
2472 goto done; \
2473 } else \
2474 memset(bits + ni * x, 0, ni);
2475 getbits(in, 0);
2476 getbits(ou, 1);
2477 getbits(ex, 2);
2478 #undef getbits
2479
2480 if (SCARG(uap, tv)) {
2481 error = copyin((caddr_t)(u_long)SCARG(uap, tv), (caddr_t)&tv32,
2482 sizeof(tv32));
2483 if (error)
2484 goto done;
2485 netbsd32_to_timeval(&tv32, &atv);
2486 if (itimerfix(&atv)) {
2487 error = EINVAL;
2488 goto done;
2489 }
2490 s = splclock();
2491 timeradd(&atv, &time, &atv);
2492 splx(s);
2493 } else
2494 timo = 0;
2495 retry:
2496 ncoll = nselcoll;
2497 p->p_flag |= P_SELECT;
2498 error = selscan(p, (fd_mask *)(bits + ni * 0),
2499 (fd_mask *)(bits + ni * 3), SCARG(uap, nd), retval);
2500 if (error || *retval)
2501 goto done;
2502 if (SCARG(uap, tv)) {
2503 /*
2504 * We have to recalculate the timeout on every retry.
2505 */
2506 timo = hzto(&atv);
2507 if (timo <= 0)
2508 goto done;
2509 }
2510 s = splhigh();
2511 if ((p->p_flag & P_SELECT) == 0 || nselcoll != ncoll) {
2512 splx(s);
2513 goto retry;
2514 }
2515 p->p_flag &= ~P_SELECT;
2516 error = tsleep((caddr_t)&selwait, PSOCK | PCATCH, "select", timo);
2517 splx(s);
2518 if (error == 0)
2519 goto retry;
2520 done:
2521 p->p_flag &= ~P_SELECT;
2522 /* select is not restarted after signals... */
2523 if (error == ERESTART)
2524 error = EINTR;
2525 if (error == EWOULDBLOCK)
2526 error = 0;
2527 if (error == 0) {
2528 #define putbits(name, x) \
2529 if (SCARG(uap, name)) { \
2530 error = copyout(bits + ni * x, (caddr_t)(u_long)SCARG(uap, name), ni); \
2531 if (error) \
2532 goto out; \
2533 }
2534 putbits(in, 3);
2535 putbits(ou, 4);
2536 putbits(ex, 5);
2537 #undef putbits
2538 }
2539 out:
2540 if (ni * 6 > sizeof(smallbits))
2541 free(bits, M_TEMP);
2542 return (error);
2543 }
2544
2545 int
2546 netbsd32_fsync(p, v, retval)
2547 struct proc *p;
2548 void *v;
2549 register_t *retval;
2550 {
2551 struct netbsd32_fsync_args /* {
2552 syscallarg(int) fd;
2553 } */ *uap = v;
2554 struct sys_fsync_args ua;
2555
2556 NETBSD32TO64_UAP(fd);
2557 return (sys_fsync(p, &ua, retval));
2558 }
2559
2560 int
2561 netbsd32_setpriority(p, v, retval)
2562 struct proc *p;
2563 void *v;
2564 register_t *retval;
2565 {
2566 struct netbsd32_setpriority_args /* {
2567 syscallarg(int) which;
2568 syscallarg(int) who;
2569 syscallarg(int) prio;
2570 } */ *uap = v;
2571 struct sys_setpriority_args ua;
2572
2573 NETBSD32TO64_UAP(which);
2574 NETBSD32TO64_UAP(who);
2575 NETBSD32TO64_UAP(prio);
2576 return (sys_setpriority(p, &ua, retval));
2577 }
2578
2579 int
2580 netbsd32_socket(p, v, retval)
2581 struct proc *p;
2582 void *v;
2583 register_t *retval;
2584 {
2585 struct netbsd32_socket_args /* {
2586 syscallarg(int) domain;
2587 syscallarg(int) type;
2588 syscallarg(int) protocol;
2589 } */ *uap = v;
2590 struct sys_socket_args ua;
2591
2592 NETBSD32TO64_UAP(domain);
2593 NETBSD32TO64_UAP(type);
2594 NETBSD32TO64_UAP(protocol);
2595 return (sys_socket(p, &ua, retval));
2596 }
2597
2598 int
2599 netbsd32_connect(p, v, retval)
2600 struct proc *p;
2601 void *v;
2602 register_t *retval;
2603 {
2604 struct netbsd32_connect_args /* {
2605 syscallarg(int) s;
2606 syscallarg(const netbsd32_sockaddrp_t) name;
2607 syscallarg(int) namelen;
2608 } */ *uap = v;
2609 struct sys_connect_args ua;
2610
2611 NETBSD32TO64_UAP(s);
2612 NETBSD32TOP_UAP(name, struct sockaddr);
2613 NETBSD32TO64_UAP(namelen);
2614 return (sys_connect(p, &ua, retval));
2615 }
2616
2617 int
2618 netbsd32_getpriority(p, v, retval)
2619 struct proc *p;
2620 void *v;
2621 register_t *retval;
2622 {
2623 struct netbsd32_getpriority_args /* {
2624 syscallarg(int) which;
2625 syscallarg(int) who;
2626 } */ *uap = v;
2627 struct sys_getpriority_args ua;
2628
2629 NETBSD32TO64_UAP(which);
2630 NETBSD32TO64_UAP(who);
2631 return (sys_getpriority(p, &ua, retval));
2632 }
2633
2634 int
2635 netbsd32_bind(p, v, retval)
2636 struct proc *p;
2637 void *v;
2638 register_t *retval;
2639 {
2640 struct netbsd32_bind_args /* {
2641 syscallarg(int) s;
2642 syscallarg(const netbsd32_sockaddrp_t) name;
2643 syscallarg(int) namelen;
2644 } */ *uap = v;
2645 struct sys_bind_args ua;
2646
2647 NETBSD32TO64_UAP(s);
2648 NETBSD32TOP_UAP(name, struct sockaddr);
2649 NETBSD32TO64_UAP(namelen);
2650 return (sys_bind(p, &ua, retval));
2651 }
2652
2653 int
2654 netbsd32_setsockopt(p, v, retval)
2655 struct proc *p;
2656 void *v;
2657 register_t *retval;
2658 {
2659 struct netbsd32_setsockopt_args /* {
2660 syscallarg(int) s;
2661 syscallarg(int) level;
2662 syscallarg(int) name;
2663 syscallarg(const netbsd32_voidp) val;
2664 syscallarg(int) valsize;
2665 } */ *uap = v;
2666 struct sys_setsockopt_args ua;
2667
2668 NETBSD32TO64_UAP(s);
2669 NETBSD32TO64_UAP(level);
2670 NETBSD32TO64_UAP(name);
2671 NETBSD32TOP_UAP(val, void);
2672 NETBSD32TO64_UAP(valsize);
2673 /* may be more efficient to do this inline. */
2674 return (sys_setsockopt(p, &ua, retval));
2675 }
2676
2677 int
2678 netbsd32_listen(p, v, retval)
2679 struct proc *p;
2680 void *v;
2681 register_t *retval;
2682 {
2683 struct netbsd32_listen_args /* {
2684 syscallarg(int) s;
2685 syscallarg(int) backlog;
2686 } */ *uap = v;
2687 struct sys_listen_args ua;
2688
2689 NETBSD32TO64_UAP(s);
2690 NETBSD32TO64_UAP(backlog);
2691 return (sys_listen(p, &ua, retval));
2692 }
2693
2694 int
2695 netbsd32_gettimeofday(p, v, retval)
2696 struct proc *p;
2697 void *v;
2698 register_t *retval;
2699 {
2700 struct netbsd32_gettimeofday_args /* {
2701 syscallarg(netbsd32_timevalp_t) tp;
2702 syscallarg(netbsd32_timezonep_t) tzp;
2703 } */ *uap = v;
2704 struct timeval atv;
2705 struct netbsd32_timeval tv32;
2706 int error = 0;
2707 struct netbsd32_timezone tzfake;
2708
2709 if (SCARG(uap, tp)) {
2710 microtime(&atv);
2711 netbsd32_from_timeval(&atv, &tv32);
2712 error = copyout(&tv32, (caddr_t)(u_long)SCARG(uap, tp), sizeof(tv32));
2713 if (error)
2714 return (error);
2715 }
2716 if (SCARG(uap, tzp)) {
2717 /*
2718 * NetBSD has no kernel notion of time zone, so we just
2719 * fake up a timezone struct and return it if demanded.
2720 */
2721 tzfake.tz_minuteswest = 0;
2722 tzfake.tz_dsttime = 0;
2723 error = copyout(&tzfake, (caddr_t)(u_long)SCARG(uap, tzp), sizeof(tzfake));
2724 }
2725 return (error);
2726 }
2727
2728 #if 0
2729 static int settime32 __P((struct timeval *));
2730 /* This function is used by clock_settime and settimeofday */
2731 static int
2732 settime32(tv)
2733 struct timeval *tv;
2734 {
2735 struct timeval delta;
2736 int s;
2737
2738 /* WHAT DO WE DO ABOUT PENDING REAL-TIME TIMEOUTS??? */
2739 s = splclock();
2740 timersub(tv, &time, &delta);
2741 if ((delta.tv_sec < 0 || delta.tv_usec < 0) && securelevel > 1)
2742 return (EPERM);
2743 #ifdef notyet
2744 if ((delta.tv_sec < 86400) && securelevel > 0)
2745 return (EPERM);
2746 #endif
2747 time = *tv;
2748 (void) spllowersoftclock();
2749 timeradd(&boottime, &delta, &boottime);
2750 timeradd(&runtime, &delta, &runtime);
2751 # if defined(NFS) || defined(NFSSERVER)
2752 {
2753 extern void nqnfs_lease_updatetime __P((int));
2754
2755 nqnfs_lease_updatetime(delta.tv_sec);
2756 }
2757 # endif
2758 splx(s);
2759 resettodr();
2760 return (0);
2761 }
2762 #endif
2763
2764 int
2765 netbsd32_settimeofday(p, v, retval)
2766 struct proc *p;
2767 void *v;
2768 register_t *retval;
2769 {
2770 struct netbsd32_settimeofday_args /* {
2771 syscallarg(const netbsd32_timevalp_t) tv;
2772 syscallarg(const netbsd32_timezonep_t) tzp;
2773 } */ *uap = v;
2774 struct netbsd32_timeval atv32;
2775 struct timeval atv;
2776 struct netbsd32_timezone atz;
2777 int error;
2778
2779 if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
2780 return (error);
2781 /* Verify all parameters before changing time. */
2782 if (SCARG(uap, tv) && (error = copyin((caddr_t)(u_long)SCARG(uap, tv),
2783 &atv32, sizeof(atv32))))
2784 return (error);
2785 netbsd32_to_timeval(&atv32, &atv);
2786 /* XXX since we don't use tz, probably no point in doing copyin. */
2787 if (SCARG(uap, tzp) && (error = copyin((caddr_t)(u_long)SCARG(uap, tzp),
2788 &atz, sizeof(atz))))
2789 return (error);
2790 if (SCARG(uap, tv))
2791 if ((error = settime(&atv)))
2792 return (error);
2793 /*
2794 * NetBSD has no kernel notion of time zone, and only an
2795 * obsolete program would try to set it, so we log a warning.
2796 */
2797 if (SCARG(uap, tzp))
2798 printf("pid %d attempted to set the "
2799 "(obsolete) kernel time zone\n", p->p_pid);
2800 return (0);
2801 }
2802
2803 int
2804 netbsd32_fchown(p, v, retval)
2805 struct proc *p;
2806 void *v;
2807 register_t *retval;
2808 {
2809 struct netbsd32_fchown_args /* {
2810 syscallarg(int) fd;
2811 syscallarg(uid_t) uid;
2812 syscallarg(gid_t) gid;
2813 } */ *uap = v;
2814 struct sys_fchown_args ua;
2815
2816 NETBSD32TO64_UAP(fd);
2817 NETBSD32TO64_UAP(uid);
2818 NETBSD32TO64_UAP(gid);
2819 return (sys_fchown(p, &ua, retval));
2820 }
2821
2822 int
2823 netbsd32_fchmod(p, v, retval)
2824 struct proc *p;
2825 void *v;
2826 register_t *retval;
2827 {
2828 struct netbsd32_fchmod_args /* {
2829 syscallarg(int) fd;
2830 syscallarg(mode_t) mode;
2831 } */ *uap = v;
2832 struct sys_fchmod_args ua;
2833
2834 NETBSD32TO64_UAP(fd);
2835 NETBSD32TO64_UAP(mode);
2836 return (sys_fchmod(p, &ua, retval));
2837 }
2838
2839 int
2840 netbsd32_setreuid(p, v, retval)
2841 struct proc *p;
2842 void *v;
2843 register_t *retval;
2844 {
2845 struct netbsd32_setreuid_args /* {
2846 syscallarg(uid_t) ruid;
2847 syscallarg(uid_t) euid;
2848 } */ *uap = v;
2849 struct sys_setreuid_args ua;
2850
2851 NETBSD32TO64_UAP(ruid);
2852 NETBSD32TO64_UAP(euid);
2853 return (sys_setreuid(p, &ua, retval));
2854 }
2855
2856 int
2857 netbsd32_setregid(p, v, retval)
2858 struct proc *p;
2859 void *v;
2860 register_t *retval;
2861 {
2862 struct netbsd32_setregid_args /* {
2863 syscallarg(gid_t) rgid;
2864 syscallarg(gid_t) egid;
2865 } */ *uap = v;
2866 struct sys_setregid_args ua;
2867
2868 NETBSD32TO64_UAP(rgid);
2869 NETBSD32TO64_UAP(egid);
2870 return (sys_setregid(p, &ua, retval));
2871 }
2872
2873 int
2874 netbsd32_getrusage(p, v, retval)
2875 struct proc *p;
2876 void *v;
2877 register_t *retval;
2878 {
2879 struct netbsd32_getrusage_args /* {
2880 syscallarg(int) who;
2881 syscallarg(netbsd32_rusagep_t) rusage;
2882 } */ *uap = v;
2883 struct rusage *rup;
2884 struct netbsd32_rusage ru;
2885
2886 switch (SCARG(uap, who)) {
2887
2888 case RUSAGE_SELF:
2889 rup = &p->p_stats->p_ru;
2890 calcru(p, &rup->ru_utime, &rup->ru_stime, NULL);
2891 break;
2892
2893 case RUSAGE_CHILDREN:
2894 rup = &p->p_stats->p_cru;
2895 break;
2896
2897 default:
2898 return (EINVAL);
2899 }
2900 netbsd32_from_rusage(rup, &ru);
2901 return (copyout(&ru, (caddr_t)(u_long)SCARG(uap, rusage), sizeof(ru)));
2902 }
2903
2904 int
2905 netbsd32_getsockopt(p, v, retval)
2906 struct proc *p;
2907 void *v;
2908 register_t *retval;
2909 {
2910 struct netbsd32_getsockopt_args /* {
2911 syscallarg(int) s;
2912 syscallarg(int) level;
2913 syscallarg(int) name;
2914 syscallarg(netbsd32_voidp) val;
2915 syscallarg(netbsd32_intp) avalsize;
2916 } */ *uap = v;
2917 struct sys_getsockopt_args ua;
2918
2919 NETBSD32TO64_UAP(s);
2920 NETBSD32TO64_UAP(level);
2921 NETBSD32TO64_UAP(name);
2922 NETBSD32TOP_UAP(val, void);
2923 NETBSD32TOP_UAP(avalsize, int);
2924 return (sys_getsockopt(p, &ua, retval));
2925 }
2926
2927 int
2928 netbsd32_readv(p, v, retval)
2929 struct proc *p;
2930 void *v;
2931 register_t *retval;
2932 {
2933 struct netbsd32_readv_args /* {
2934 syscallarg(int) fd;
2935 syscallarg(const netbsd32_iovecp_t) iovp;
2936 syscallarg(int) iovcnt;
2937 } */ *uap = v;
2938 int fd = SCARG(uap, fd);
2939 struct file *fp;
2940 struct filedesc *fdp = p->p_fd;
2941
2942 if ((u_int)fd >= fdp->fd_nfiles ||
2943 (fp = fdp->fd_ofiles[fd]) == NULL ||
2944 (fp->f_flag & FREAD) == 0)
2945 return (EBADF);
2946
2947 return (dofilereadv32(p, fd, fp, (struct netbsd32_iovec *)(u_long)SCARG(uap, iovp),
2948 SCARG(uap, iovcnt), &fp->f_offset, FOF_UPDATE_OFFSET, retval));
2949 }
2950
2951 /* Damn thing copies in the iovec! */
2952 int
2953 dofilereadv32(p, fd, fp, iovp, iovcnt, offset, flags, retval)
2954 struct proc *p;
2955 int fd;
2956 struct file *fp;
2957 struct netbsd32_iovec *iovp;
2958 int iovcnt;
2959 off_t *offset;
2960 int flags;
2961 register_t *retval;
2962 {
2963 struct uio auio;
2964 struct iovec *iov;
2965 struct iovec *needfree;
2966 struct iovec aiov[UIO_SMALLIOV];
2967 long i, cnt, error = 0;
2968 u_int iovlen;
2969 #ifdef KTRACE
2970 struct iovec *ktriov = NULL;
2971 #endif
2972
2973 /* note: can't use iovlen until iovcnt is validated */
2974 iovlen = iovcnt * sizeof(struct iovec);
2975 if ((u_int)iovcnt > UIO_SMALLIOV) {
2976 if ((u_int)iovcnt > IOV_MAX)
2977 return (EINVAL);
2978 MALLOC(iov, struct iovec *, iovlen, M_IOV, M_WAITOK);
2979 needfree = iov;
2980 } else if ((u_int)iovcnt > 0) {
2981 iov = aiov;
2982 needfree = NULL;
2983 } else
2984 return (EINVAL);
2985
2986 auio.uio_iov = iov;
2987 auio.uio_iovcnt = iovcnt;
2988 auio.uio_rw = UIO_READ;
2989 auio.uio_segflg = UIO_USERSPACE;
2990 auio.uio_procp = p;
2991 error = netbsd32_to_iovecin(iovp, iov, iovcnt);
2992 if (error)
2993 goto done;
2994 auio.uio_resid = 0;
2995 for (i = 0; i < iovcnt; i++) {
2996 auio.uio_resid += iov->iov_len;
2997 /*
2998 * Reads return ssize_t because -1 is returned on error.
2999 * Therefore we must restrict the length to SSIZE_MAX to
3000 * avoid garbage return values.
3001 */
3002 if (iov->iov_len > SSIZE_MAX || auio.uio_resid > SSIZE_MAX) {
3003 error = EINVAL;
3004 goto done;
3005 }
3006 iov++;
3007 }
3008 #ifdef KTRACE
3009 /*
3010 * if tracing, save a copy of iovec
3011 */
3012 if (KTRPOINT(p, KTR_GENIO)) {
3013 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
3014 memcpy((caddr_t)ktriov, (caddr_t)auio.uio_iov, iovlen);
3015 }
3016 #endif
3017 cnt = auio.uio_resid;
3018 error = (*fp->f_ops->fo_read)(fp, offset, &auio, fp->f_cred, flags);
3019 if (error)
3020 if (auio.uio_resid != cnt && (error == ERESTART ||
3021 error == EINTR || error == EWOULDBLOCK))
3022 error = 0;
3023 cnt -= auio.uio_resid;
3024 #ifdef KTRACE
3025 if (KTRPOINT(p, KTR_GENIO))
3026 if (error == 0) {
3027 ktrgenio(p, fd, UIO_READ, ktriov, cnt,
3028 error);
3029 FREE(ktriov, M_TEMP);
3030 }
3031 #endif
3032 *retval = cnt;
3033 done:
3034 if (needfree)
3035 FREE(needfree, M_IOV);
3036 return (error);
3037 }
3038
3039
3040 int
3041 netbsd32_writev(p, v, retval)
3042 struct proc *p;
3043 void *v;
3044 register_t *retval;
3045 {
3046 struct netbsd32_writev_args /* {
3047 syscallarg(int) fd;
3048 syscallarg(const netbsd32_iovecp_t) iovp;
3049 syscallarg(int) iovcnt;
3050 } */ *uap = v;
3051 int fd = SCARG(uap, fd);
3052 struct file *fp;
3053 struct filedesc *fdp = p->p_fd;
3054
3055 if ((u_int)fd >= fdp->fd_nfiles ||
3056 (fp = fdp->fd_ofiles[fd]) == NULL ||
3057 (fp->f_flag & FWRITE) == 0)
3058 return (EBADF);
3059
3060 return (dofilewritev32(p, fd, fp, (struct netbsd32_iovec *)(u_long)SCARG(uap, iovp),
3061 SCARG(uap, iovcnt), &fp->f_offset, FOF_UPDATE_OFFSET, retval));
3062 }
3063
3064 int
3065 dofilewritev32(p, fd, fp, iovp, iovcnt, offset, flags, retval)
3066 struct proc *p;
3067 int fd;
3068 struct file *fp;
3069 struct netbsd32_iovec *iovp;
3070 int iovcnt;
3071 off_t *offset;
3072 int flags;
3073 register_t *retval;
3074 {
3075 struct uio auio;
3076 struct iovec *iov;
3077 struct iovec *needfree;
3078 struct iovec aiov[UIO_SMALLIOV];
3079 long i, cnt, error = 0;
3080 u_int iovlen;
3081 #ifdef KTRACE
3082 struct iovec *ktriov = NULL;
3083 #endif
3084
3085 /* note: can't use iovlen until iovcnt is validated */
3086 iovlen = iovcnt * sizeof(struct iovec);
3087 if ((u_int)iovcnt > UIO_SMALLIOV) {
3088 if ((u_int)iovcnt > IOV_MAX)
3089 return (EINVAL);
3090 MALLOC(iov, struct iovec *, iovlen, M_IOV, M_WAITOK);
3091 needfree = iov;
3092 } else if ((u_int)iovcnt > 0) {
3093 iov = aiov;
3094 needfree = NULL;
3095 } else
3096 return (EINVAL);
3097
3098 auio.uio_iov = iov;
3099 auio.uio_iovcnt = iovcnt;
3100 auio.uio_rw = UIO_WRITE;
3101 auio.uio_segflg = UIO_USERSPACE;
3102 auio.uio_procp = p;
3103 error = netbsd32_to_iovecin(iovp, iov, iovcnt);
3104 if (error)
3105 goto done;
3106 auio.uio_resid = 0;
3107 for (i = 0; i < iovcnt; i++) {
3108 auio.uio_resid += iov->iov_len;
3109 /*
3110 * Writes return ssize_t because -1 is returned on error.
3111 * Therefore we must restrict the length to SSIZE_MAX to
3112 * avoid garbage return values.
3113 */
3114 if (iov->iov_len > SSIZE_MAX || auio.uio_resid > SSIZE_MAX) {
3115 error = EINVAL;
3116 goto done;
3117 }
3118 iov++;
3119 }
3120 #ifdef KTRACE
3121 /*
3122 * if tracing, save a copy of iovec
3123 */
3124 if (KTRPOINT(p, KTR_GENIO)) {
3125 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
3126 memcpy((caddr_t)ktriov, (caddr_t)auio.uio_iov, iovlen);
3127 }
3128 #endif
3129 cnt = auio.uio_resid;
3130 error = (*fp->f_ops->fo_write)(fp, offset, &auio, fp->f_cred, flags);
3131 if (error) {
3132 if (auio.uio_resid != cnt && (error == ERESTART ||
3133 error == EINTR || error == EWOULDBLOCK))
3134 error = 0;
3135 if (error == EPIPE)
3136 psignal(p, SIGPIPE);
3137 }
3138 cnt -= auio.uio_resid;
3139 #ifdef KTRACE
3140 if (KTRPOINT(p, KTR_GENIO))
3141 if (error == 0) {
3142 ktrgenio(p, fd, UIO_WRITE, ktriov, cnt,
3143 error);
3144 FREE(ktriov, M_TEMP);
3145 }
3146 #endif
3147 *retval = cnt;
3148 done:
3149 if (needfree)
3150 FREE(needfree, M_IOV);
3151 return (error);
3152 }
3153
3154
3155 int
3156 netbsd32_rename(p, v, retval)
3157 struct proc *p;
3158 void *v;
3159 register_t *retval;
3160 {
3161 struct netbsd32_rename_args /* {
3162 syscallarg(const netbsd32_charp) from;
3163 syscallarg(const netbsd32_charp) to;
3164 } */ *uap = v;
3165 struct sys_rename_args ua;
3166
3167 NETBSD32TOP_UAP(from, const char);
3168 NETBSD32TOP_UAP(to, const char)
3169
3170 return (sys_rename(p, &ua, retval));
3171 }
3172
3173 int
3174 netbsd32_flock(p, v, retval)
3175 struct proc *p;
3176 void *v;
3177 register_t *retval;
3178 {
3179 struct netbsd32_flock_args /* {
3180 syscallarg(int) fd;
3181 syscallarg(int) how;
3182 } */ *uap = v;
3183 struct sys_flock_args ua;
3184
3185 NETBSD32TO64_UAP(fd);
3186 NETBSD32TO64_UAP(how)
3187
3188 return (sys_flock(p, &ua, retval));
3189 }
3190
3191 int
3192 netbsd32_mkfifo(p, v, retval)
3193 struct proc *p;
3194 void *v;
3195 register_t *retval;
3196 {
3197 struct netbsd32_mkfifo_args /* {
3198 syscallarg(const netbsd32_charp) path;
3199 syscallarg(mode_t) mode;
3200 } */ *uap = v;
3201 struct sys_mkfifo_args ua;
3202
3203 NETBSD32TOP_UAP(path, const char)
3204 NETBSD32TO64_UAP(mode);
3205 return (sys_mkfifo(p, &ua, retval));
3206 }
3207
3208 int
3209 netbsd32_shutdown(p, v, retval)
3210 struct proc *p;
3211 void *v;
3212 register_t *retval;
3213 {
3214 struct netbsd32_shutdown_args /* {
3215 syscallarg(int) s;
3216 syscallarg(int) how;
3217 } */ *uap = v;
3218 struct sys_shutdown_args ua;
3219
3220 NETBSD32TO64_UAP(s)
3221 NETBSD32TO64_UAP(how);
3222 return (sys_shutdown(p, &ua, retval));
3223 }
3224
3225 int
3226 netbsd32_socketpair(p, v, retval)
3227 struct proc *p;
3228 void *v;
3229 register_t *retval;
3230 {
3231 struct netbsd32_socketpair_args /* {
3232 syscallarg(int) domain;
3233 syscallarg(int) type;
3234 syscallarg(int) protocol;
3235 syscallarg(netbsd32_intp) rsv;
3236 } */ *uap = v;
3237 struct sys_socketpair_args ua;
3238
3239 NETBSD32TO64_UAP(domain);
3240 NETBSD32TO64_UAP(type);
3241 NETBSD32TO64_UAP(protocol);
3242 NETBSD32TOP_UAP(rsv, int);
3243 /* Since we're just copying out two `int's we can do this */
3244 return (sys_socketpair(p, &ua, retval));
3245 }
3246
3247 int
3248 netbsd32_mkdir(p, v, retval)
3249 struct proc *p;
3250 void *v;
3251 register_t *retval;
3252 {
3253 struct netbsd32_mkdir_args /* {
3254 syscallarg(const netbsd32_charp) path;
3255 syscallarg(mode_t) mode;
3256 } */ *uap = v;
3257 struct sys_mkdir_args ua;
3258
3259 NETBSD32TOP_UAP(path, const char)
3260 NETBSD32TO64_UAP(mode);
3261 return (sys_mkdir(p, &ua, retval));
3262 }
3263
3264 int
3265 netbsd32_rmdir(p, v, retval)
3266 struct proc *p;
3267 void *v;
3268 register_t *retval;
3269 {
3270 struct netbsd32_rmdir_args /* {
3271 syscallarg(const netbsd32_charp) path;
3272 } */ *uap = v;
3273 struct sys_rmdir_args ua;
3274
3275 NETBSD32TOP_UAP(path, const char);
3276 return (sys_rmdir(p, &ua, retval));
3277 }
3278
3279 int
3280 netbsd32_utimes(p, v, retval)
3281 struct proc *p;
3282 void *v;
3283 register_t *retval;
3284 {
3285 struct netbsd32_utimes_args /* {
3286 syscallarg(const netbsd32_charp) path;
3287 syscallarg(const netbsd32_timevalp_t) tptr;
3288 } */ *uap = v;
3289 int error;
3290 struct nameidata nd;
3291
3292 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, (char *)(u_long)SCARG(uap, path), p);
3293 if ((error = namei(&nd)) != 0)
3294 return (error);
3295
3296 error = change_utimes32(nd.ni_vp, (struct timeval *)(u_long)SCARG(uap, tptr), p);
3297
3298 vrele(nd.ni_vp);
3299 return (error);
3300 }
3301
3302 /*
3303 * Common routine to set access and modification times given a vnode.
3304 */
3305 static int
3306 change_utimes32(vp, tptr, p)
3307 struct vnode *vp;
3308 struct timeval *tptr;
3309 struct proc *p;
3310 {
3311 struct netbsd32_timeval tv32[2];
3312 struct timeval tv[2];
3313 struct vattr vattr;
3314 int error;
3315
3316 VATTR_NULL(&vattr);
3317 if (tptr == NULL) {
3318 microtime(&tv[0]);
3319 tv[1] = tv[0];
3320 vattr.va_vaflags |= VA_UTIMES_NULL;
3321 } else {
3322 error = copyin(tptr, tv, sizeof(tv));
3323 if (error)
3324 return (error);
3325 }
3326 netbsd32_to_timeval(&tv32[0], &tv[0]);
3327 netbsd32_to_timeval(&tv32[1], &tv[1]);
3328 VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
3329 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
3330 vattr.va_atime.tv_sec = tv[0].tv_sec;
3331 vattr.va_atime.tv_nsec = tv[0].tv_usec * 1000;
3332 vattr.va_mtime.tv_sec = tv[1].tv_sec;
3333 vattr.va_mtime.tv_nsec = tv[1].tv_usec * 1000;
3334 error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
3335 VOP_UNLOCK(vp, 0);
3336 return (error);
3337 }
3338
3339 int
3340 netbsd32_adjtime(p, v, retval)
3341 struct proc *p;
3342 void *v;
3343 register_t *retval;
3344 {
3345 struct netbsd32_adjtime_args /* {
3346 syscallarg(const netbsd32_timevalp_t) delta;
3347 syscallarg(netbsd32_timevalp_t) olddelta;
3348 } */ *uap = v;
3349 struct netbsd32_timeval atv;
3350 int32_t ndelta, ntickdelta, odelta;
3351 int s, error;
3352 extern long bigadj, timedelta;
3353 extern int tickdelta;
3354
3355 if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
3356 return (error);
3357
3358 error = copyin((caddr_t)(u_long)SCARG(uap, delta), &atv, sizeof(struct timeval));
3359 if (error)
3360 return (error);
3361 /*
3362 * Compute the total correction and the rate at which to apply it.
3363 * Round the adjustment down to a whole multiple of the per-tick
3364 * delta, so that after some number of incremental changes in
3365 * hardclock(), tickdelta will become zero, lest the correction
3366 * overshoot and start taking us away from the desired final time.
3367 */
3368 ndelta = atv.tv_sec * 1000000 + atv.tv_usec;
3369 if (ndelta > bigadj)
3370 ntickdelta = 10 * tickadj;
3371 else
3372 ntickdelta = tickadj;
3373 if (ndelta % ntickdelta)
3374 ndelta = ndelta / ntickdelta * ntickdelta;
3375
3376 /*
3377 * To make hardclock()'s job easier, make the per-tick delta negative
3378 * if we want time to run slower; then hardclock can simply compute
3379 * tick + tickdelta, and subtract tickdelta from timedelta.
3380 */
3381 if (ndelta < 0)
3382 ntickdelta = -ntickdelta;
3383 s = splclock();
3384 odelta = timedelta;
3385 timedelta = ndelta;
3386 tickdelta = ntickdelta;
3387 splx(s);
3388
3389 if (SCARG(uap, olddelta)) {
3390 atv.tv_sec = odelta / 1000000;
3391 atv.tv_usec = odelta % 1000000;
3392 (void) copyout(&atv, (caddr_t)(u_long)SCARG(uap, olddelta),
3393 sizeof(struct timeval));
3394 }
3395 return (0);
3396 }
3397
3398 int
3399 netbsd32_quotactl(p, v, retval)
3400 struct proc *p;
3401 void *v;
3402 register_t *retval;
3403 {
3404 struct netbsd32_quotactl_args /* {
3405 syscallarg(const netbsd32_charp) path;
3406 syscallarg(int) cmd;
3407 syscallarg(int) uid;
3408 syscallarg(netbsd32_caddr_t) arg;
3409 } */ *uap = v;
3410 struct sys_quotactl_args ua;
3411
3412 NETBSD32TOP_UAP(path, const char);
3413 NETBSD32TO64_UAP(cmd);
3414 NETBSD32TO64_UAP(uid);
3415 NETBSD32TOX64_UAP(arg, caddr_t);
3416 return (sys_quotactl(p, &ua, retval));
3417 }
3418
3419 #if defined(NFS) || defined(NFSSERVER)
3420 int
3421 netbsd32_nfssvc(p, v, retval)
3422 struct proc *p;
3423 void *v;
3424 register_t *retval;
3425 {
3426 #if 0
3427 struct netbsd32_nfssvc_args /* {
3428 syscallarg(int) flag;
3429 syscallarg(netbsd32_voidp) argp;
3430 } */ *uap = v;
3431 struct sys_nfssvc_args ua;
3432
3433 NETBSD32TO64_UAP(flag);
3434 NETBSD32TOP_UAP(argp, void);
3435 return (sys_nfssvc(p, &ua, retval));
3436 #else
3437 /* Why would we want to support a 32-bit nfsd? */
3438 return (ENOSYS);
3439 #endif
3440 }
3441 #endif
3442
3443 int
3444 netbsd32_statfs(p, v, retval)
3445 struct proc *p;
3446 void *v;
3447 register_t *retval;
3448 {
3449 struct netbsd32_statfs_args /* {
3450 syscallarg(const netbsd32_charp) path;
3451 syscallarg(netbsd32_statfsp_t) buf;
3452 } */ *uap = v;
3453 struct mount *mp;
3454 struct statfs *sp;
3455 struct netbsd32_statfs s32;
3456 int error;
3457 struct nameidata nd;
3458
3459 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, (char *)(u_long)SCARG(uap, path), p);
3460 if ((error = namei(&nd)) != 0)
3461 return (error);
3462 mp = nd.ni_vp->v_mount;
3463 sp = &mp->mnt_stat;
3464 vrele(nd.ni_vp);
3465 if ((error = VFS_STATFS(mp, sp, p)) != 0)
3466 return (error);
3467 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
3468 netbsd32_from_statfs(sp, &s32);
3469 return (copyout(&s32, (caddr_t)(u_long)SCARG(uap, buf), sizeof(s32)));
3470 }
3471
3472 int
3473 netbsd32_fstatfs(p, v, retval)
3474 struct proc *p;
3475 void *v;
3476 register_t *retval;
3477 {
3478 struct netbsd32_fstatfs_args /* {
3479 syscallarg(int) fd;
3480 syscallarg(netbsd32_statfsp_t) buf;
3481 } */ *uap = v;
3482 struct file *fp;
3483 struct mount *mp;
3484 struct statfs *sp;
3485 struct netbsd32_statfs s32;
3486 int error;
3487
3488 /* getvnode() will use the descriptor for us */
3489 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
3490 return (error);
3491 mp = ((struct vnode *)fp->f_data)->v_mount;
3492 sp = &mp->mnt_stat;
3493 if ((error = VFS_STATFS(mp, sp, p)) != 0)
3494 goto out;
3495 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
3496 netbsd32_from_statfs(sp, &s32);
3497 error = copyout(&s32, (caddr_t)(u_long)SCARG(uap, buf), sizeof(s32));
3498 out:
3499 FILE_UNUSE(fp, p);
3500 return (error);
3501 }
3502
3503 #if defined(NFS) || defined(NFSSERVER)
3504 int
3505 netbsd32_getfh(p, v, retval)
3506 struct proc *p;
3507 void *v;
3508 register_t *retval;
3509 {
3510 struct netbsd32_getfh_args /* {
3511 syscallarg(const netbsd32_charp) fname;
3512 syscallarg(netbsd32_fhandlep_t) fhp;
3513 } */ *uap = v;
3514 struct sys_getfh_args ua;
3515
3516 NETBSD32TOP_UAP(fname, const char);
3517 NETBSD32TOP_UAP(fhp, struct fhandle);
3518 /* Lucky for us a fhandlep_t doesn't change sizes */
3519 return (sys_getfh(p, &ua, retval));
3520 }
3521 #endif
3522
3523 int
3524 netbsd32_sysarch(p, v, retval)
3525 struct proc *p;
3526 void *v;
3527 register_t *retval;
3528 {
3529 struct netbsd32_sysarch_args /* {
3530 syscallarg(int) op;
3531 syscallarg(netbsd32_voidp) parms;
3532 } */ *uap = v;
3533
3534 switch (SCARG(uap, op)) {
3535 default:
3536 printf("(sparc64) netbsd32_sysarch(%d)\n", SCARG(uap, op));
3537 return EINVAL;
3538 }
3539 }
3540
3541 int
3542 netbsd32_pread(p, v, retval)
3543 struct proc *p;
3544 void *v;
3545 register_t *retval;
3546 {
3547 struct netbsd32_pread_args /* {
3548 syscallarg(int) fd;
3549 syscallarg(netbsd32_voidp) buf;
3550 syscallarg(netbsd32_size_t) nbyte;
3551 syscallarg(int) pad;
3552 syscallarg(off_t) offset;
3553 } */ *uap = v;
3554 struct sys_pread_args ua;
3555 ssize_t rt;
3556 int error;
3557
3558 NETBSD32TO64_UAP(fd);
3559 NETBSD32TOP_UAP(buf, void);
3560 NETBSD32TOX_UAP(nbyte, size_t);
3561 NETBSD32TO64_UAP(pad);
3562 NETBSD32TO64_UAP(offset);
3563 error = sys_pread(p, &ua, (register_t *)&rt);
3564 *(netbsd32_ssize_t *)retval = rt;
3565 return (error);
3566 }
3567
3568 int
3569 netbsd32_pwrite(p, v, retval)
3570 struct proc *p;
3571 void *v;
3572 register_t *retval;
3573 {
3574 struct netbsd32_pwrite_args /* {
3575 syscallarg(int) fd;
3576 syscallarg(const netbsd32_voidp) buf;
3577 syscallarg(netbsd32_size_t) nbyte;
3578 syscallarg(int) pad;
3579 syscallarg(off_t) offset;
3580 } */ *uap = v;
3581 struct sys_pwrite_args ua;
3582 ssize_t rt;
3583 int error;
3584
3585 NETBSD32TO64_UAP(fd);
3586 NETBSD32TOP_UAP(buf, void);
3587 NETBSD32TOX_UAP(nbyte, size_t);
3588 NETBSD32TO64_UAP(pad);
3589 NETBSD32TO64_UAP(offset);
3590 error = sys_pwrite(p, &ua, (register_t *)&rt);
3591 *(netbsd32_ssize_t *)retval = rt;
3592 return (error);
3593 }
3594
3595 #ifdef NTP
3596 int
3597 netbsd32_ntp_gettime(p, v, retval)
3598 struct proc *p;
3599 void *v;
3600 register_t *retval;
3601 {
3602 struct netbsd32_ntp_gettime_args /* {
3603 syscallarg(netbsd32_ntptimevalp_t) ntvp;
3604 } */ *uap = v;
3605 struct netbsd32_ntptimeval ntv32;
3606 struct timeval atv;
3607 struct ntptimeval ntv;
3608 int error = 0;
3609 int s;
3610
3611 /* The following are NTP variables */
3612 extern long time_maxerror;
3613 extern long time_esterror;
3614 extern int time_status;
3615 extern int time_state; /* clock state */
3616 extern int time_status; /* clock status bits */
3617
3618 if (SCARG(uap, ntvp)) {
3619 s = splclock();
3620 #ifdef EXT_CLOCK
3621 /*
3622 * The microtime() external clock routine returns a
3623 * status code. If less than zero, we declare an error
3624 * in the clock status word and return the kernel
3625 * (software) time variable. While there are other
3626 * places that call microtime(), this is the only place
3627 * that matters from an application point of view.
3628 */
3629 if (microtime(&atv) < 0) {
3630 time_status |= STA_CLOCKERR;
3631 ntv.time = time;
3632 } else
3633 time_status &= ~STA_CLOCKERR;
3634 #else /* EXT_CLOCK */
3635 microtime(&atv);
3636 #endif /* EXT_CLOCK */
3637 ntv.time = atv;
3638 ntv.maxerror = time_maxerror;
3639 ntv.esterror = time_esterror;
3640 (void) splx(s);
3641
3642 netbsd32_from_timeval(&ntv.time, &ntv32.time);
3643 ntv32.maxerror = (netbsd32_long)ntv.maxerror;
3644 ntv32.esterror = (netbsd32_long)ntv.esterror;
3645 error = copyout((caddr_t)&ntv32, (caddr_t)(u_long)SCARG(uap, ntvp),
3646 sizeof(ntv32));
3647 }
3648 if (!error) {
3649
3650 /*
3651 * Status word error decode. If any of these conditions
3652 * occur, an error is returned, instead of the status
3653 * word. Most applications will care only about the fact
3654 * the system clock may not be trusted, not about the
3655 * details.
3656 *
3657 * Hardware or software error
3658 */
3659 if ((time_status & (STA_UNSYNC | STA_CLOCKERR)) ||
3660
3661 /*
3662 * PPS signal lost when either time or frequency
3663 * synchronization requested
3664 */
3665 (time_status & (STA_PPSFREQ | STA_PPSTIME) &&
3666 !(time_status & STA_PPSSIGNAL)) ||
3667
3668 /*
3669 * PPS jitter exceeded when time synchronization
3670 * requested
3671 */
3672 (time_status & STA_PPSTIME &&
3673 time_status & STA_PPSJITTER) ||
3674
3675 /*
3676 * PPS wander exceeded or calibration error when
3677 * frequency synchronization requested
3678 */
3679 (time_status & STA_PPSFREQ &&
3680 time_status & (STA_PPSWANDER | STA_PPSERROR)))
3681 *retval = TIME_ERROR;
3682 else
3683 *retval = (register_t)time_state;
3684 }
3685 return(error);
3686 }
3687
3688 int
3689 netbsd32_ntp_adjtime(p, v, retval)
3690 struct proc *p;
3691 void *v;
3692 register_t *retval;
3693 {
3694 struct netbsd32_ntp_adjtime_args /* {
3695 syscallarg(netbsd32_timexp_t) tp;
3696 } */ *uap = v;
3697 struct netbsd32_timex ntv32;
3698 struct timex ntv;
3699 int error = 0;
3700 int modes;
3701 int s;
3702 extern long time_freq; /* frequency offset (scaled ppm) */
3703 extern long time_maxerror;
3704 extern long time_esterror;
3705 extern int time_state; /* clock state */
3706 extern int time_status; /* clock status bits */
3707 extern long time_constant; /* pll time constant */
3708 extern long time_offset; /* time offset (us) */
3709 extern long time_tolerance; /* frequency tolerance (scaled ppm) */
3710 extern long time_precision; /* clock precision (us) */
3711
3712 if ((error = copyin((caddr_t)(u_long)SCARG(uap, tp), (caddr_t)&ntv32,
3713 sizeof(ntv32))))
3714 return (error);
3715 netbsd32_to_timex(&ntv32, &ntv);
3716
3717 /*
3718 * Update selected clock variables - only the superuser can
3719 * change anything. Note that there is no error checking here on
3720 * the assumption the superuser should know what it is doing.
3721 */
3722 modes = ntv.modes;
3723 if (modes != 0 && (error = suser(p->p_ucred, &p->p_acflag)))
3724 return (error);
3725
3726 s = splclock();
3727 if (modes & MOD_FREQUENCY)
3728 #ifdef PPS_SYNC
3729 time_freq = ntv.freq - pps_freq;
3730 #else /* PPS_SYNC */
3731 time_freq = ntv.freq;
3732 #endif /* PPS_SYNC */
3733 if (modes & MOD_MAXERROR)
3734 time_maxerror = ntv.maxerror;
3735 if (modes & MOD_ESTERROR)
3736 time_esterror = ntv.esterror;
3737 if (modes & MOD_STATUS) {
3738 time_status &= STA_RONLY;
3739 time_status |= ntv.status & ~STA_RONLY;
3740 }
3741 if (modes & MOD_TIMECONST)
3742 time_constant = ntv.constant;
3743 if (modes & MOD_OFFSET)
3744 hardupdate(ntv.offset);
3745
3746 /*
3747 * Retrieve all clock variables
3748 */
3749 if (time_offset < 0)
3750 ntv.offset = -(-time_offset >> SHIFT_UPDATE);
3751 else
3752 ntv.offset = time_offset >> SHIFT_UPDATE;
3753 #ifdef PPS_SYNC
3754 ntv.freq = time_freq + pps_freq;
3755 #else /* PPS_SYNC */
3756 ntv.freq = time_freq;
3757 #endif /* PPS_SYNC */
3758 ntv.maxerror = time_maxerror;
3759 ntv.esterror = time_esterror;
3760 ntv.status = time_status;
3761 ntv.constant = time_constant;
3762 ntv.precision = time_precision;
3763 ntv.tolerance = time_tolerance;
3764 #ifdef PPS_SYNC
3765 ntv.shift = pps_shift;
3766 ntv.ppsfreq = pps_freq;
3767 ntv.jitter = pps_jitter >> PPS_AVG;
3768 ntv.stabil = pps_stabil;
3769 ntv.calcnt = pps_calcnt;
3770 ntv.errcnt = pps_errcnt;
3771 ntv.jitcnt = pps_jitcnt;
3772 ntv.stbcnt = pps_stbcnt;
3773 #endif /* PPS_SYNC */
3774 (void)splx(s);
3775
3776 netbsd32_from_timeval(&ntv, &ntv32);
3777 error = copyout((caddr_t)&ntv32, (caddr_t)SCARG(uap, tp), sizeof(ntv32));
3778 if (!error) {
3779
3780 /*
3781 * Status word error decode. See comments in
3782 * ntp_gettime() routine.
3783 */
3784 if ((time_status & (STA_UNSYNC | STA_CLOCKERR)) ||
3785 (time_status & (STA_PPSFREQ | STA_PPSTIME) &&
3786 !(time_status & STA_PPSSIGNAL)) ||
3787 (time_status & STA_PPSTIME &&
3788 time_status & STA_PPSJITTER) ||
3789 (time_status & STA_PPSFREQ &&
3790 time_status & (STA_PPSWANDER | STA_PPSERROR)))
3791 *retval = TIME_ERROR;
3792 else
3793 *retval = (register_t)time_state;
3794 }
3795 return error;
3796 }
3797 #else
3798 int
3799 netbsd32_ntp_gettime(p, v, retval)
3800 struct proc *p;
3801 void *v;
3802 register_t *retval;
3803 {
3804 return(ENOSYS);
3805 }
3806
3807 int
3808 netbsd32_ntp_adjtime(p, v, retval)
3809 struct proc *p;
3810 void *v;
3811 register_t *retval;
3812 {
3813 return (ENOSYS);
3814 }
3815 #endif
3816
3817 int
3818 netbsd32_setgid(p, v, retval)
3819 struct proc *p;
3820 void *v;
3821 register_t *retval;
3822 {
3823 struct netbsd32_setgid_args /* {
3824 syscallarg(gid_t) gid;
3825 } */ *uap = v;
3826 struct sys_setgid_args ua;
3827
3828 NETBSD32TO64_UAP(gid);
3829 return (sys_setgid(p, v, retval));
3830 }
3831
3832 int
3833 netbsd32_setegid(p, v, retval)
3834 struct proc *p;
3835 void *v;
3836 register_t *retval;
3837 {
3838 struct netbsd32_setegid_args /* {
3839 syscallarg(gid_t) egid;
3840 } */ *uap = v;
3841 struct sys_setegid_args ua;
3842
3843 NETBSD32TO64_UAP(egid);
3844 return (sys_setegid(p, v, retval));
3845 }
3846
3847 int
3848 netbsd32_seteuid(p, v, retval)
3849 struct proc *p;
3850 void *v;
3851 register_t *retval;
3852 {
3853 struct netbsd32_seteuid_args /* {
3854 syscallarg(gid_t) euid;
3855 } */ *uap = v;
3856 struct sys_seteuid_args ua;
3857
3858 NETBSD32TO64_UAP(euid);
3859 return (sys_seteuid(p, v, retval));
3860 }
3861
3862 #ifdef LFS
3863 int
3864 netbsd32_sys_lfs_bmapv(p, v, retval)
3865 struct proc *p;
3866 void *v;
3867 register_t *retval;
3868 {
3869 #if 0
3870 struct netbsd32_lfs_bmapv_args /* {
3871 syscallarg(netbsd32_fsid_tp_t) fsidp;
3872 syscallarg(netbsd32_block_infop_t) blkiov;
3873 syscallarg(int) blkcnt;
3874 } */ *uap = v;
3875 struct sys_lfs_bmapv_args ua;
3876
3877 NETBSD32TOP_UAP(fdidp, struct fsid);
3878 NETBSD32TO64_UAP(blkcnt);
3879 /* XXX finish me */
3880 #else
3881
3882 return (ENOSYS); /* XXX */
3883 #endif
3884 }
3885
3886 int
3887 netbsd32_sys_lfs_markv(p, v, retval)
3888 struct proc *p;
3889 void *v;
3890 register_t *retval;
3891 {
3892 #if 0
3893 struct netbsd32_lfs_markv_args /* {
3894 syscallarg(netbsd32_fsid_tp_t) fsidp;
3895 syscallarg(netbsd32_block_infop_t) blkiov;
3896 syscallarg(int) blkcnt;
3897 } */ *uap = v;
3898 #endif
3899
3900 return (ENOSYS); /* XXX */
3901 }
3902
3903 int
3904 netbsd32_sys_lfs_segclean(p, v, retval)
3905 struct proc *p;
3906 void *v;
3907 register_t *retval;
3908 {
3909 #if 0
3910 struct netbsd32_lfs_segclean_args /* {
3911 syscallarg(netbsd32_fsid_tp_t) fsidp;
3912 syscallarg(netbsd32_u_long) segment;
3913 } */ *uap = v;
3914 #endif
3915
3916 return (ENOSYS); /* XXX */
3917 }
3918
3919 int
3920 netbsd32_sys_lfs_segwait(p, v, retval)
3921 struct proc *p;
3922 void *v;
3923 register_t *retval;
3924 {
3925 #if 0
3926 struct netbsd32_lfs_segwait_args /* {
3927 syscallarg(netbsd32_fsid_tp_t) fsidp;
3928 syscallarg(netbsd32_timevalp_t) tv;
3929 } */ *uap = v;
3930 #endif
3931
3932 return (ENOSYS); /* XXX */
3933 }
3934 #endif
3935
3936 int
3937 netbsd32_pathconf(p, v, retval)
3938 struct proc *p;
3939 void *v;
3940 register_t *retval;
3941 {
3942 struct netbsd32_pathconf_args /* {
3943 syscallarg(int) fd;
3944 syscallarg(int) name;
3945 } */ *uap = v;
3946 struct sys_pathconf_args ua;
3947 long rt;
3948 int error;
3949
3950 NETBSD32TOP_UAP(path, const char);
3951 NETBSD32TO64_UAP(name);
3952 error = sys_pathconf(p, &ua, (register_t *)&rt);
3953 *(netbsd32_long *)retval = (netbsd32_long)rt;
3954 return (error);
3955 }
3956
3957 int
3958 netbsd32_fpathconf(p, v, retval)
3959 struct proc *p;
3960 void *v;
3961 register_t *retval;
3962 {
3963 struct netbsd32_fpathconf_args /* {
3964 syscallarg(int) fd;
3965 syscallarg(int) name;
3966 } */ *uap = v;
3967 struct sys_fpathconf_args ua;
3968 long rt;
3969 int error;
3970
3971 NETBSD32TO64_UAP(fd);
3972 NETBSD32TO64_UAP(name);
3973 error = sys_fpathconf(p, &ua, (register_t *)&rt);
3974 *(netbsd32_long *)retval = (netbsd32_long)rt;
3975 return (error);
3976 }
3977
3978 int
3979 netbsd32_getrlimit(p, v, retval)
3980 struct proc *p;
3981 void *v;
3982 register_t *retval;
3983 {
3984 struct netbsd32_getrlimit_args /* {
3985 syscallarg(int) which;
3986 syscallarg(netbsd32_rlimitp_t) rlp;
3987 } */ *uap = v;
3988 int which = SCARG(uap, which);
3989
3990 if ((u_int)which >= RLIM_NLIMITS)
3991 return (EINVAL);
3992 return (copyout(&p->p_rlimit[which], (caddr_t)(u_long)SCARG(uap, rlp),
3993 sizeof(struct rlimit)));
3994 }
3995
3996 int
3997 netbsd32_setrlimit(p, v, retval)
3998 struct proc *p;
3999 void *v;
4000 register_t *retval;
4001 {
4002 struct netbsd32_setrlimit_args /* {
4003 syscallarg(int) which;
4004 syscallarg(const netbsd32_rlimitp_t) rlp;
4005 } */ *uap = v;
4006 int which = SCARG(uap, which);
4007 struct rlimit alim;
4008 int error;
4009
4010 error = copyin((caddr_t)(u_long)SCARG(uap, rlp), &alim, sizeof(struct rlimit));
4011 if (error)
4012 return (error);
4013 return (dosetrlimit(p, p->p_cred, which, &alim));
4014 }
4015
4016 int
4017 netbsd32_mmap(p, v, retval)
4018 struct proc *p;
4019 void *v;
4020 register_t *retval;
4021 {
4022 struct netbsd32_mmap_args /* {
4023 syscallarg(netbsd32_voidp) addr;
4024 syscallarg(netbsd32_size_t) len;
4025 syscallarg(int) prot;
4026 syscallarg(int) flags;
4027 syscallarg(int) fd;
4028 syscallarg(netbsd32_long) pad;
4029 syscallarg(off_t) pos;
4030 } */ *uap = v;
4031 struct sys_mmap_args ua;
4032 void *rt;
4033 int error;
4034
4035 NETBSD32TOP_UAP(addr, void);
4036 NETBSD32TOX_UAP(len, size_t);
4037 NETBSD32TO64_UAP(prot);
4038 NETBSD32TO64_UAP(flags);
4039 NETBSD32TO64_UAP(fd);
4040 NETBSD32TOX_UAP(pad, long);
4041 NETBSD32TOX_UAP(pos, off_t);
4042 error = sys_mmap(p, &ua, (register_t *)&rt);
4043 if ((long)rt > (long)UINT_MAX)
4044 printf("netbsd32_mmap: retval out of range: 0x%qx",
4045 rt);
4046 *retval = (netbsd32_voidp)(u_long)rt;
4047 return (error);
4048 }
4049
4050 int
4051 netbsd32_lseek(p, v, retval)
4052 struct proc *p;
4053 void *v;
4054 register_t *retval;
4055 {
4056 struct netbsd32_lseek_args /* {
4057 syscallarg(int) fd;
4058 syscallarg(int) pad;
4059 syscallarg(off_t) offset;
4060 syscallarg(int) whence;
4061 } */ *uap = v;
4062 struct sys_lseek_args ua;
4063
4064 NETBSD32TO64_UAP(fd);
4065 NETBSD32TO64_UAP(pad);
4066 NETBSD32TO64_UAP(offset);
4067 NETBSD32TO64_UAP(whence);
4068 return (sys_lseek(p, &ua, retval));
4069 }
4070
4071 int
4072 netbsd32_truncate(p, v, retval)
4073 struct proc *p;
4074 void *v;
4075 register_t *retval;
4076 {
4077 struct netbsd32_truncate_args /* {
4078 syscallarg(const netbsd32_charp) path;
4079 syscallarg(int) pad;
4080 syscallarg(off_t) length;
4081 } */ *uap = v;
4082 struct sys_truncate_args ua;
4083
4084 NETBSD32TOP_UAP(path, const char);
4085 NETBSD32TO64_UAP(pad);
4086 NETBSD32TO64_UAP(length);
4087 return (sys_truncate(p, &ua, retval));
4088 }
4089
4090 int
4091 netbsd32_ftruncate(p, v, retval)
4092 struct proc *p;
4093 void *v;
4094 register_t *retval;
4095 {
4096 struct netbsd32_ftruncate_args /* {
4097 syscallarg(int) fd;
4098 syscallarg(int) pad;
4099 syscallarg(off_t) length;
4100 } */ *uap = v;
4101 struct sys_ftruncate_args ua;
4102
4103 NETBSD32TO64_UAP(fd);
4104 NETBSD32TO64_UAP(pad);
4105 NETBSD32TO64_UAP(length);
4106 return (sys_ftruncate(p, &ua, retval));
4107 }
4108
4109 int
4110 netbsd32___sysctl(p, v, retval)
4111 struct proc *p;
4112 void *v;
4113 register_t *retval;
4114 {
4115 struct netbsd32___sysctl_args /* {
4116 syscallarg(netbsd32_intp) name;
4117 syscallarg(u_int) namelen;
4118 syscallarg(netbsd32_voidp) old;
4119 syscallarg(netbsd32_size_tp) oldlenp;
4120 syscallarg(netbsd32_voidp) new;
4121 syscallarg(netbsd32_size_t) newlen;
4122 } */ *uap = v;
4123 int error;
4124 netbsd32_size_t savelen = 0;
4125 size_t oldlen = 0;
4126 sysctlfn *fn;
4127 int name[CTL_MAXNAME];
4128
4129 /*
4130 * Some of these sysctl functions do their own copyin/copyout.
4131 * We need to disable or emulate the ones that need their
4132 * arguments converted.
4133 */
4134
4135 if (SCARG(uap, new) != NULL &&
4136 (error = suser(p->p_ucred, &p->p_acflag)))
4137 return (error);
4138 /*
4139 * all top-level sysctl names are non-terminal
4140 */
4141 if (SCARG(uap, namelen) > CTL_MAXNAME || SCARG(uap, namelen) < 2)
4142 return (EINVAL);
4143 error = copyin((caddr_t)(u_long)SCARG(uap, name), &name,
4144 SCARG(uap, namelen) * sizeof(int));
4145 if (error)
4146 return (error);
4147
4148 switch (name[0]) {
4149 case CTL_KERN:
4150 fn = kern_sysctl;
4151 break;
4152 case CTL_HW:
4153 fn = hw_sysctl;
4154 break;
4155 case CTL_VM:
4156 fn = uvm_sysctl;
4157 break;
4158 case CTL_NET:
4159 fn = net_sysctl;
4160 break;
4161 case CTL_VFS:
4162 fn = vfs_sysctl;
4163 break;
4164 case CTL_MACHDEP:
4165 fn = cpu_sysctl;
4166 break;
4167 #ifdef DEBUG
4168 case CTL_DEBUG:
4169 fn = debug_sysctl;
4170 break;
4171 #endif
4172 #ifdef DDB
4173 case CTL_DDB:
4174 fn = ddb_sysctl;
4175 break;
4176 #endif
4177 case CTL_PROC:
4178 fn = proc_sysctl;
4179 break;
4180 default:
4181 return (EOPNOTSUPP);
4182 }
4183
4184 /*
4185 * XXX Hey, we wire `old', but what about `new'?
4186 */
4187
4188 if (SCARG(uap, oldlenp) &&
4189 (error = copyin((caddr_t)(u_long)SCARG(uap, oldlenp), &savelen,
4190 sizeof(savelen))))
4191 return (error);
4192 if (SCARG(uap, old) != NULL) {
4193 error = lockmgr(&sysctl_memlock, LK_EXCLUSIVE, NULL);
4194 if (error)
4195 return (error);
4196 if (uvm_vslock(p, (void *)(u_long)SCARG(uap, old), savelen,
4197 VM_PROT_READ|VM_PROT_WRITE) != KERN_SUCCESS) {
4198 (void) lockmgr(&sysctl_memlock, LK_RELEASE, NULL);
4199 return (EFAULT);
4200 }
4201 oldlen = savelen;
4202 }
4203 error = (*fn)(name + 1, SCARG(uap, namelen) - 1,
4204 (void *)(u_long)SCARG(uap, old), &oldlen,
4205 (void *)(u_long)SCARG(uap, new), SCARG(uap, newlen), p);
4206 if (SCARG(uap, old) != NULL) {
4207 uvm_vsunlock(p, (void *)(u_long)SCARG(uap, old), savelen);
4208 (void) lockmgr(&sysctl_memlock, LK_RELEASE, NULL);
4209 }
4210 savelen = oldlen;
4211 if (error)
4212 return (error);
4213 if (SCARG(uap, oldlenp))
4214 error = copyout(&savelen,
4215 (caddr_t)(u_long)SCARG(uap, oldlenp), sizeof(savelen));
4216 return (error);
4217 }
4218
4219 int
4220 netbsd32_mlock(p, v, retval)
4221 struct proc *p;
4222 void *v;
4223 register_t *retval;
4224 {
4225 struct netbsd32_mlock_args /* {
4226 syscallarg(const netbsd32_voidp) addr;
4227 syscallarg(netbsd32_size_t) len;
4228 } */ *uap = v;
4229 struct sys_mlock_args ua;
4230
4231 NETBSD32TOP_UAP(addr, const void);
4232 NETBSD32TO64_UAP(len);
4233 return (sys_mlock(p, &ua, retval));
4234 }
4235
4236 int
4237 netbsd32_munlock(p, v, retval)
4238 struct proc *p;
4239 void *v;
4240 register_t *retval;
4241 {
4242 struct netbsd32_munlock_args /* {
4243 syscallarg(const netbsd32_voidp) addr;
4244 syscallarg(netbsd32_size_t) len;
4245 } */ *uap = v;
4246 struct sys_munlock_args ua;
4247
4248 NETBSD32TOP_UAP(addr, const void);
4249 NETBSD32TO64_UAP(len);
4250 return (sys_munlock(p, &ua, retval));
4251 }
4252
4253 int
4254 netbsd32_undelete(p, v, retval)
4255 struct proc *p;
4256 void *v;
4257 register_t *retval;
4258 {
4259 struct netbsd32_undelete_args /* {
4260 syscallarg(const netbsd32_charp) path;
4261 } */ *uap = v;
4262 struct sys_undelete_args ua;
4263
4264 NETBSD32TOP_UAP(path, const char);
4265 return (sys_undelete(p, &ua, retval));
4266 }
4267
4268 int
4269 netbsd32_futimes(p, v, retval)
4270 struct proc *p;
4271 void *v;
4272 register_t *retval;
4273 {
4274 struct netbsd32_futimes_args /* {
4275 syscallarg(int) fd;
4276 syscallarg(const netbsd32_timevalp_t) tptr;
4277 } */ *uap = v;
4278 int error;
4279 struct file *fp;
4280
4281 /* getvnode() will use the descriptor for us */
4282 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
4283 return (error);
4284
4285 error = change_utimes32((struct vnode *)fp->f_data,
4286 (struct timeval *)(u_long)SCARG(uap, tptr), p);
4287 FILE_UNUSE(fp, p);
4288 return (error);
4289 }
4290
4291 int
4292 netbsd32_getpgid(p, v, retval)
4293 struct proc *p;
4294 void *v;
4295 register_t *retval;
4296 {
4297 struct netbsd32_getpgid_args /* {
4298 syscallarg(pid_t) pid;
4299 } */ *uap = v;
4300 struct sys_getpgid_args ua;
4301
4302 NETBSD32TO64_UAP(pid);
4303 return (sys_getpgid(p, &ua, retval));
4304 }
4305
4306 int
4307 netbsd32_reboot(p, v, retval)
4308 struct proc *p;
4309 void *v;
4310 register_t *retval;
4311 {
4312 struct netbsd32_reboot_args /* {
4313 syscallarg(int) opt;
4314 syscallarg(netbsd32_charp) bootstr;
4315 } */ *uap = v;
4316 struct sys_reboot_args ua;
4317
4318 NETBSD32TO64_UAP(opt);
4319 NETBSD32TOP_UAP(bootstr, char);
4320 return (sys_reboot(p, &ua, retval));
4321 }
4322
4323 int
4324 netbsd32_poll(p, v, retval)
4325 struct proc *p;
4326 void *v;
4327 register_t *retval;
4328 {
4329 struct netbsd32_poll_args /* {
4330 syscallarg(netbsd32_pollfdp_t) fds;
4331 syscallarg(u_int) nfds;
4332 syscallarg(int) timeout;
4333 } */ *uap = v;
4334 struct sys_poll_args ua;
4335
4336 NETBSD32TOP_UAP(fds, struct pollfd);
4337 NETBSD32TO64_UAP(nfds);
4338 NETBSD32TO64_UAP(timeout);
4339 return (sys_poll(p, &ua, retval));
4340 }
4341
4342 #if defined(SYSVSEM)
4343 /*
4344 * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
4345 *
4346 * This is BSD. We won't support System V IPC.
4347 * Too much work.
4348 *
4349 * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
4350 */
4351 int
4352 netbsd32___semctl14(p, v, retval)
4353 struct proc *p;
4354 void *v;
4355 register_t *retval;
4356 {
4357 #if 0
4358 struct netbsd32___semctl_args /* {
4359 syscallarg(int) semid;
4360 syscallarg(int) semnum;
4361 syscallarg(int) cmd;
4362 syscallarg(netbsd32_semunu_t *) arg;
4363 } */ *uap = v;
4364 union netbsd32_semun sem32;
4365 int semid = SCARG(uap, semid);
4366 int semnum = SCARG(uap, semnum);
4367 int cmd = SCARG(uap, cmd);
4368 union netbsd32_semun *arg = (void*)(u_long)SCARG(uap, arg);
4369 union netbsd32_semun real_arg;
4370 struct ucred *cred = p->p_ucred;
4371 int i, rval, eval;
4372 struct netbsd32_semid_ds sbuf;
4373 struct semid_ds *semaptr;
4374
4375 semlock(p);
4376
4377 semid = IPCID_TO_IX(semid);
4378 if (semid < 0 || semid >= seminfo.semmsl)
4379 return(EINVAL);
4380
4381 semaptr = &sema[semid];
4382 if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0 ||
4383 semaptr->sem_perm.seq != IPCID_TO_SEQ(SCARG(uap, semid)))
4384 return(EINVAL);
4385
4386 eval = 0;
4387 rval = 0;
4388
4389 switch (cmd) {
4390 case IPC_RMID:
4391 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_M)) != 0)
4392 return(eval);
4393 semaptr->sem_perm.cuid = cred->cr_uid;
4394 semaptr->sem_perm.uid = cred->cr_uid;
4395 semtot -= semaptr->sem_nsems;
4396 for (i = semaptr->_sem_base - sem; i < semtot; i++)
4397 sem[i] = sem[i + semaptr->sem_nsems];
4398 for (i = 0; i < seminfo.semmni; i++) {
4399 if ((sema[i].sem_perm.mode & SEM_ALLOC) &&
4400 sema[i]._sem_base > semaptr->_sem_base)
4401 sema[i]._sem_base -= semaptr->sem_nsems;
4402 }
4403 semaptr->sem_perm.mode = 0;
4404 semundo_clear(semid, -1);
4405 wakeup((caddr_t)semaptr);
4406 break;
4407
4408 case IPC_SET:
4409 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_M)))
4410 return(eval);
4411 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
4412 return(eval);
4413 if ((eval = copyin((caddr_t)(u_long)real_arg.buf, (caddr_t)&sbuf,
4414 sizeof(sbuf))) != 0)
4415 return(eval);
4416 semaptr->sem_perm.uid = sbuf.sem_perm.uid;
4417 semaptr->sem_perm.gid = sbuf.sem_perm.gid;
4418 semaptr->sem_perm.mode = (semaptr->sem_perm.mode & ~0777) |
4419 (sbuf.sem_perm.mode & 0777);
4420 semaptr->sem_ctime = time.tv_sec;
4421 break;
4422
4423 case IPC_STAT:
4424 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
4425 return(eval);
4426 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
4427 return(eval);
4428 eval = copyout((caddr_t)semaptr, (caddr_t)(u_long)real_arg.buf,
4429 sizeof(struct semid_ds));
4430 break;
4431
4432 case GETNCNT:
4433 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
4434 return(eval);
4435 if (semnum < 0 || semnum >= semaptr->sem_nsems)
4436 return(EINVAL);
4437 rval = semaptr->_sem_base[semnum].semncnt;
4438 break;
4439
4440 case GETPID:
4441 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
4442 return(eval);
4443 if (semnum < 0 || semnum >= semaptr->sem_nsems)
4444 return(EINVAL);
4445 rval = semaptr->_sem_base[semnum].sempid;
4446 break;
4447
4448 case GETVAL:
4449 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
4450 return(eval);
4451 if (semnum < 0 || semnum >= semaptr->sem_nsems)
4452 return(EINVAL);
4453 rval = semaptr->_sem_base[semnum].semval;
4454 break;
4455
4456 case GETALL:
4457 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
4458 return(eval);
4459 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
4460 return(eval);
4461 for (i = 0; i < semaptr->sem_nsems; i++) {
4462 eval = copyout((caddr_t)&semaptr->_sem_base[i].semval,
4463 &real_arg.array[i], sizeof(real_arg.array[0]));
4464 if (eval != 0)
4465 break;
4466 }
4467 break;
4468
4469 case GETZCNT:
4470 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
4471 return(eval);
4472 if (semnum < 0 || semnum >= semaptr->sem_nsems)
4473 return(EINVAL);
4474 rval = semaptr->_sem_base[semnum].semzcnt;
4475 break;
4476
4477 case SETVAL:
4478 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_W)))
4479 return(eval);
4480 if (semnum < 0 || semnum >= semaptr->sem_nsems)
4481 return(EINVAL);
4482 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
4483 return(eval);
4484 semaptr->_sem_base[semnum].semval = real_arg.val;
4485 semundo_clear(semid, semnum);
4486 wakeup((caddr_t)semaptr);
4487 break;
4488
4489 case SETALL:
4490 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_W)))
4491 return(eval);
4492 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
4493 return(eval);
4494 for (i = 0; i < semaptr->sem_nsems; i++) {
4495 eval = copyin(&real_arg.array[i],
4496 (caddr_t)&semaptr->_sem_base[i].semval,
4497 sizeof(real_arg.array[0]));
4498 if (eval != 0)
4499 break;
4500 }
4501 semundo_clear(semid, -1);
4502 wakeup((caddr_t)semaptr);
4503 break;
4504
4505 default:
4506 return(EINVAL);
4507 }
4508
4509 if (eval == 0)
4510 *retval = rval;
4511 return(eval);
4512 #else
4513 return (ENOSYS);
4514 #endif
4515 }
4516
4517 int
4518 netbsd32_semget(p, v, retval)
4519 struct proc *p;
4520 void *v;
4521 register_t *retval;
4522 {
4523 struct netbsd32_semget_args /* {
4524 syscallarg(netbsd32_key_t) key;
4525 syscallarg(int) nsems;
4526 syscallarg(int) semflg;
4527 } */ *uap = v;
4528 struct sys_semget_args ua;
4529
4530 NETBSD32TOX_UAP(key, key_t);
4531 NETBSD32TO64_UAP(nsems);
4532 NETBSD32TO64_UAP(semflg);
4533 return (sys_semget(p, &ua, retval));
4534 }
4535
4536 int
4537 netbsd32_semop(p, v, retval)
4538 struct proc *p;
4539 void *v;
4540 register_t *retval;
4541 {
4542 struct netbsd32_semop_args /* {
4543 syscallarg(int) semid;
4544 syscallarg(netbsd32_sembufp_t) sops;
4545 syscallarg(netbsd32_size_t) nsops;
4546 } */ *uap = v;
4547 struct sys_semop_args ua;
4548
4549 NETBSD32TO64_UAP(semid);
4550 NETBSD32TOP_UAP(sops, struct sembuf);
4551 NETBSD32TOX_UAP(nsops, size_t);
4552 return (sys_semop(p, &ua, retval));
4553 }
4554
4555 int
4556 netbsd32_semconfig(p, v, retval)
4557 struct proc *p;
4558 void *v;
4559 register_t *retval;
4560 {
4561 struct netbsd32_semconfig_args /* {
4562 syscallarg(int) flag;
4563 } */ *uap = v;
4564 struct sys_semconfig_args ua;
4565
4566 NETBSD32TO64_UAP(flag);
4567 return (sys_semconfig(p, &ua, retval));
4568 }
4569 #endif /* SYSVSEM */
4570
4571 #if defined(SYSVMSG)
4572
4573 int
4574 netbsd32___msgctl13(p, v, retval)
4575 struct proc *p;
4576 void *v;
4577 register_t *retval;
4578 {
4579 #if 0
4580 struct netbsd32_msgctl_args /* {
4581 syscallarg(int) msqid;
4582 syscallarg(int) cmd;
4583 syscallarg(netbsd32_msqid_dsp_t) buf;
4584 } */ *uap = v;
4585 struct sys_msgctl_args ua;
4586 struct msqid_ds ds;
4587 struct netbsd32_msqid_ds *ds32p;
4588 int error;
4589
4590 NETBSD32TO64_UAP(msqid);
4591 NETBSD32TO64_UAP(cmd);
4592 ds32p = (struct netbsd32_msqid_ds *)(u_long)SCARG(uap, buf);
4593 if (ds32p) {
4594 SCARG(&ua, buf) = NULL;
4595 netbsd32_to_msqid_ds(ds32p, &ds);
4596 } else
4597 SCARG(&ua, buf) = NULL;
4598 error = sys_msgctl(p, &ua, retval);
4599 if (error)
4600 return (error);
4601
4602 if (ds32p)
4603 netbsd32_from_msqid_ds(&ds, ds32p);
4604 return (0);
4605 #else
4606 return (ENOSYS);
4607 #endif
4608 }
4609
4610 int
4611 netbsd32_msgget(p, v, retval)
4612 struct proc *p;
4613 void *v;
4614 register_t *retval;
4615 {
4616 #if 0
4617 struct netbsd32_msgget_args /* {
4618 syscallarg(netbsd32_key_t) key;
4619 syscallarg(int) msgflg;
4620 } */ *uap = v;
4621 struct sys_msgget_args ua;
4622
4623 NETBSD32TOX_UAP(key, key_t);
4624 NETBSD32TO64_UAP(msgflg);
4625 return (sys_msgget(p, &ua, retval));
4626 #else
4627 return (ENOSYS);
4628 #endif
4629 }
4630
4631 int
4632 netbsd32_msgsnd(p, v, retval)
4633 struct proc *p;
4634 void *v;
4635 register_t *retval;
4636 {
4637 #if 0
4638 struct netbsd32_msgsnd_args /* {
4639 syscallarg(int) msqid;
4640 syscallarg(const netbsd32_voidp) msgp;
4641 syscallarg(netbsd32_size_t) msgsz;
4642 syscallarg(int) msgflg;
4643 } */ *uap = v;
4644 struct sys_msgsnd_args ua;
4645
4646 NETBSD32TO64_UAP(msqid);
4647 NETBSD32TOP_UAP(msgp, void);
4648 NETBSD32TOX_UAP(msgsz, size_t);
4649 NETBSD32TO64_UAP(msgflg);
4650 return (sys_msgsnd(p, &ua, retval));
4651 #else
4652 return (ENOSYS);
4653 #endif
4654 }
4655
4656 int
4657 netbsd32_msgrcv(p, v, retval)
4658 struct proc *p;
4659 void *v;
4660 register_t *retval;
4661 {
4662 #if 0
4663 struct netbsd32_msgrcv_args /* {
4664 syscallarg(int) msqid;
4665 syscallarg(netbsd32_voidp) msgp;
4666 syscallarg(netbsd32_size_t) msgsz;
4667 syscallarg(netbsd32_long) msgtyp;
4668 syscallarg(int) msgflg;
4669 } */ *uap = v;
4670 struct sys_msgrcv_args ua;
4671 ssize_t rt;
4672 int error;
4673
4674 NETBSD32TO64_UAP(msqid);
4675 NETBSD32TOP_UAP(msgp, void);
4676 NETBSD32TOX_UAP(msgsz, size_t);
4677 NETBSD32TOX_UAP(msgtyp, long);
4678 NETBSD32TO64_UAP(msgflg);
4679 error = sys_msgrcv(p, &ua, (register_t *)&rt);
4680 *(netbsd32_ssize_t *)retval = rt;
4681 return (error);
4682 #else
4683 return (ENOSYS);
4684 #endif
4685 }
4686 #endif /* SYSVMSG */
4687
4688 #if defined(SYSVSHM)
4689
4690 int
4691 netbsd32_shmat(p, v, retval)
4692 struct proc *p;
4693 void *v;
4694 register_t *retval;
4695 {
4696 #if 0
4697 struct netbsd32_shmat_args /* {
4698 syscallarg(int) shmid;
4699 syscallarg(const netbsd32_voidp) shmaddr;
4700 syscallarg(int) shmflg;
4701 } */ *uap = v;
4702 struct sys_shmat_args ua;
4703 void *rt;
4704 int error;
4705
4706 NETBSD32TO64_UAP(shmid);
4707 NETBSD32TOP_UAP(shmaddr, void);
4708 NETBSD32TO64_UAP(shmflg);
4709 error = sys_shmat(p, &ua, (register_t *)&rt);
4710 *retval = (netbsd32_voidp)(u_long)rt;
4711 return (error);
4712 #else
4713 return (ENOSYS);
4714 #endif
4715 }
4716
4717 int
4718 netbsd32___shmctl13(p, v, retval)
4719 struct proc *p;
4720 void *v;
4721 register_t *retval;
4722 {
4723 #if 0
4724 struct netbsd32_shmctl_args /* {
4725 syscallarg(int) shmid;
4726 syscallarg(int) cmd;
4727 syscallarg(netbsd32_shmid_dsp_t) buf;
4728 } */ *uap = v;
4729 struct sys_shmctl_args ua;
4730 struct shmid_ds ds;
4731 struct netbsd32_shmid_ds *ds32p;
4732 int error;
4733
4734 NETBSD32TO64_UAP(shmid);
4735 NETBSD32TO64_UAP(cmd);
4736 ds32p = (struct netbsd32_shmid_ds *)(u_long)SCARG(uap, buf);
4737 if (ds32p) {
4738 SCARG(&ua, buf) = NULL;
4739 netbsd32_to_shmid_ds(ds32p, &ds);
4740 } else
4741 SCARG(&ua, buf) = NULL;
4742 error = sys_shmctl(p, &ua, retval);
4743 if (error)
4744 return (error);
4745
4746 if (ds32p)
4747 netbsd32_from_shmid_ds(&ds, ds32p);
4748 return (0);
4749 #else
4750 return (ENOSYS);
4751 #endif
4752 }
4753
4754 int
4755 netbsd32_shmdt(p, v, retval)
4756 struct proc *p;
4757 void *v;
4758 register_t *retval;
4759 {
4760 #if 0
4761 struct netbsd32_shmdt_args /* {
4762 syscallarg(const netbsd32_voidp) shmaddr;
4763 } */ *uap = v;
4764 struct sys_shmdt_args ua;
4765
4766 NETBSD32TOP_UAP(shmaddr, const char);
4767 return (sys_shmdt(p, &ua, retval));
4768 #else
4769 return (ENOSYS);
4770 #endif
4771 }
4772
4773 int
4774 netbsd32_shmget(p, v, retval)
4775 struct proc *p;
4776 void *v;
4777 register_t *retval;
4778 {
4779 #if 0
4780 struct netbsd32_shmget_args /* {
4781 syscallarg(netbsd32_key_t) key;
4782 syscallarg(netbsd32_size_t) size;
4783 syscallarg(int) shmflg;
4784 } */ *uap = v;
4785 struct sys_shmget_args ua;
4786
4787 NETBSD32TOX_UAP(key, key_t)
4788 NETBSD32TOX_UAP(size, size_t)
4789 NETBSD32TO64_UAP(shmflg);
4790 return (sys_shmget(p, &ua, retval));
4791 #else
4792 return (ENOSYS);
4793 #endif
4794 }
4795 #endif /* SYSVSHM */
4796
4797 int
4798 netbsd32_clock_gettime(p, v, retval)
4799 struct proc *p;
4800 void *v;
4801 register_t *retval;
4802 {
4803 struct netbsd32_clock_gettime_args /* {
4804 syscallarg(netbsd32_clockid_t) clock_id;
4805 syscallarg(netbsd32_timespecp_t) tp;
4806 } */ *uap = v;
4807 clockid_t clock_id;
4808 struct timeval atv;
4809 struct timespec ats;
4810 struct netbsd32_timespec ts32;
4811
4812 clock_id = SCARG(uap, clock_id);
4813 if (clock_id != CLOCK_REALTIME)
4814 return (EINVAL);
4815
4816 microtime(&atv);
4817 TIMEVAL_TO_TIMESPEC(&atv,&ats);
4818 netbsd32_from_timespec(&ats, &ts32);
4819
4820 return copyout(&ts32, (caddr_t)(u_long)SCARG(uap, tp), sizeof(ts32));
4821 }
4822
4823 int
4824 netbsd32_clock_settime(p, v, retval)
4825 struct proc *p;
4826 void *v;
4827 register_t *retval;
4828 {
4829 struct netbsd32_clock_settime_args /* {
4830 syscallarg(netbsd32_clockid_t) clock_id;
4831 syscallarg(const netbsd32_timespecp_t) tp;
4832 } */ *uap = v;
4833 struct netbsd32_timespec ts32;
4834 clockid_t clock_id;
4835 struct timeval atv;
4836 struct timespec ats;
4837 int error;
4838
4839 if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
4840 return (error);
4841
4842 clock_id = SCARG(uap, clock_id);
4843 if (clock_id != CLOCK_REALTIME)
4844 return (EINVAL);
4845
4846 if ((error = copyin((caddr_t)(u_long)SCARG(uap, tp), &ts32, sizeof(ts32))) != 0)
4847 return (error);
4848
4849 netbsd32_to_timespec(&ts32, &ats);
4850 TIMESPEC_TO_TIMEVAL(&atv,&ats);
4851 if ((error = settime(&atv)))
4852 return (error);
4853
4854 return 0;
4855 }
4856
4857 int
4858 netbsd32_clock_getres(p, v, retval)
4859 struct proc *p;
4860 void *v;
4861 register_t *retval;
4862 {
4863 struct netbsd32_clock_getres_args /* {
4864 syscallarg(netbsd32_clockid_t) clock_id;
4865 syscallarg(netbsd32_timespecp_t) tp;
4866 } */ *uap = v;
4867 struct netbsd32_timespec ts32;
4868 clockid_t clock_id;
4869 struct timespec ts;
4870 int error = 0;
4871
4872 clock_id = SCARG(uap, clock_id);
4873 if (clock_id != CLOCK_REALTIME)
4874 return (EINVAL);
4875
4876 if (SCARG(uap, tp)) {
4877 ts.tv_sec = 0;
4878 ts.tv_nsec = 1000000000 / hz;
4879
4880 netbsd32_from_timespec(&ts, &ts32);
4881 error = copyout(&ts, (caddr_t)(u_long)SCARG(uap, tp), sizeof(ts));
4882 }
4883
4884 return error;
4885 }
4886
4887 int
4888 netbsd32_nanosleep(p, v, retval)
4889 struct proc *p;
4890 void *v;
4891 register_t *retval;
4892 {
4893 struct netbsd32_nanosleep_args /* {
4894 syscallarg(const netbsd32_timespecp_t) rqtp;
4895 syscallarg(netbsd32_timespecp_t) rmtp;
4896 } */ *uap = v;
4897 static int nanowait;
4898 struct netbsd32_timespec ts32;
4899 struct timespec rqt;
4900 struct timespec rmt;
4901 struct timeval atv, utv;
4902 int error, s, timo;
4903
4904 error = copyin((caddr_t)(u_long)SCARG(uap, rqtp), (caddr_t)&ts32,
4905 sizeof(ts32));
4906 if (error)
4907 return (error);
4908
4909 netbsd32_to_timespec(&ts32, &rqt);
4910 TIMESPEC_TO_TIMEVAL(&atv,&rqt)
4911 if (itimerfix(&atv))
4912 return (EINVAL);
4913
4914 s = splclock();
4915 timeradd(&atv,&time,&atv);
4916 timo = hzto(&atv);
4917 /*
4918 * Avoid inadvertantly sleeping forever
4919 */
4920 if (timo == 0)
4921 timo = 1;
4922 splx(s);
4923
4924 error = tsleep(&nanowait, PWAIT | PCATCH, "nanosleep", timo);
4925 if (error == ERESTART)
4926 error = EINTR;
4927 if (error == EWOULDBLOCK)
4928 error = 0;
4929
4930 if (SCARG(uap, rmtp)) {
4931 int error;
4932
4933 s = splclock();
4934 utv = time;
4935 splx(s);
4936
4937 timersub(&atv, &utv, &utv);
4938 if (utv.tv_sec < 0)
4939 timerclear(&utv);
4940
4941 TIMEVAL_TO_TIMESPEC(&utv,&rmt);
4942 netbsd32_from_timespec(&rmt, &ts32);
4943 error = copyout((caddr_t)&ts32, (caddr_t)(u_long)SCARG(uap,rmtp),
4944 sizeof(ts32));
4945 if (error)
4946 return (error);
4947 }
4948
4949 return error;
4950 }
4951
4952 int
4953 netbsd32_fdatasync(p, v, retval)
4954 struct proc *p;
4955 void *v;
4956 register_t *retval;
4957 {
4958 struct netbsd32_fdatasync_args /* {
4959 syscallarg(int) fd;
4960 } */ *uap = v;
4961 struct sys_fdatasync_args ua;
4962
4963 NETBSD32TO64_UAP(fd);
4964
4965 return (sys_fdatasync(p, &ua, retval));
4966 }
4967
4968 int
4969 netbsd32___posix_rename(p, v, retval)
4970 struct proc *p;
4971 void *v;
4972 register_t *retval;
4973 {
4974 struct netbsd32___posix_rename_args /* {
4975 syscallarg(const netbsd32_charp) from;
4976 syscallarg(const netbsd32_charp) to;
4977 } */ *uap = v;
4978 struct sys___posix_rename_args ua;
4979
4980 NETBSD32TOP_UAP(from, const char);
4981 NETBSD32TOP_UAP(to, const char);
4982
4983 return (sys___posix_rename(p, &ua, retval));
4984 }
4985
4986 int
4987 netbsd32_swapctl(p, v, retval)
4988 struct proc *p;
4989 void *v;
4990 register_t *retval;
4991 {
4992 struct netbsd32_swapctl_args /* {
4993 syscallarg(int) cmd;
4994 syscallarg(const netbsd32_voidp) arg;
4995 syscallarg(int) misc;
4996 } */ *uap = v;
4997 struct sys_swapctl_args ua;
4998
4999 NETBSD32TO64_UAP(cmd);
5000 NETBSD32TOP_UAP(arg, const void);
5001 NETBSD32TO64_UAP(misc);
5002 return (sys_swapctl(p, &ua, retval));
5003 }
5004
5005 int
5006 netbsd32_getdents(p, v, retval)
5007 struct proc *p;
5008 void *v;
5009 register_t *retval;
5010 {
5011 struct netbsd32_getdents_args /* {
5012 syscallarg(int) fd;
5013 syscallarg(netbsd32_charp) buf;
5014 syscallarg(netbsd32_size_t) count;
5015 } */ *uap = v;
5016 struct file *fp;
5017 int error, done;
5018
5019 /* getvnode() will use the descriptor for us */
5020 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
5021 return (error);
5022 if ((fp->f_flag & FREAD) == 0) {
5023 error = EBADF;
5024 goto out;
5025 }
5026 error = vn_readdir(fp, (caddr_t)(u_long)SCARG(uap, buf), UIO_USERSPACE,
5027 SCARG(uap, count), &done, p, 0, 0);
5028 *retval = done;
5029 out:
5030 FILE_UNUSE(fp, p);
5031 return (error);
5032 }
5033
5034
5035 int
5036 netbsd32_minherit(p, v, retval)
5037 struct proc *p;
5038 void *v;
5039 register_t *retval;
5040 {
5041 struct netbsd32_minherit_args /* {
5042 syscallarg(netbsd32_voidp) addr;
5043 syscallarg(netbsd32_size_t) len;
5044 syscallarg(int) inherit;
5045 } */ *uap = v;
5046 struct sys_minherit_args ua;
5047
5048 NETBSD32TOP_UAP(addr, void);
5049 NETBSD32TOX_UAP(len, size_t);
5050 NETBSD32TO64_UAP(inherit);
5051 return (sys_minherit(p, &ua, retval));
5052 }
5053
5054 int
5055 netbsd32_lchmod(p, v, retval)
5056 struct proc *p;
5057 void *v;
5058 register_t *retval;
5059 {
5060 struct netbsd32_lchmod_args /* {
5061 syscallarg(const netbsd32_charp) path;
5062 syscallarg(mode_t) mode;
5063 } */ *uap = v;
5064 struct sys_lchmod_args ua;
5065
5066 NETBSD32TOP_UAP(path, const char);
5067 NETBSD32TO64_UAP(mode);
5068 return (sys_lchmod(p, &ua, retval));
5069 }
5070
5071 int
5072 netbsd32_lchown(p, v, retval)
5073 struct proc *p;
5074 void *v;
5075 register_t *retval;
5076 {
5077 struct netbsd32_lchown_args /* {
5078 syscallarg(const netbsd32_charp) path;
5079 syscallarg(uid_t) uid;
5080 syscallarg(gid_t) gid;
5081 } */ *uap = v;
5082 struct sys_lchown_args ua;
5083
5084 NETBSD32TOP_UAP(path, const char);
5085 NETBSD32TO64_UAP(uid);
5086 NETBSD32TO64_UAP(gid);
5087 return (sys_lchown(p, &ua, retval));
5088 }
5089
5090 int
5091 netbsd32_lutimes(p, v, retval)
5092 struct proc *p;
5093 void *v;
5094 register_t *retval;
5095 {
5096 struct netbsd32_lutimes_args /* {
5097 syscallarg(const netbsd32_charp) path;
5098 syscallarg(const netbsd32_timevalp_t) tptr;
5099 } */ *uap = v;
5100 int error;
5101 struct nameidata nd;
5102
5103 NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, (caddr_t)(u_long)SCARG(uap, path), p);
5104 if ((error = namei(&nd)) != 0)
5105 return (error);
5106
5107 error = change_utimes32(nd.ni_vp, (struct timeval *)(u_long)SCARG(uap, tptr), p);
5108
5109 vrele(nd.ni_vp);
5110 return (error);
5111 }
5112
5113
5114 int
5115 netbsd32___msync13(p, v, retval)
5116 struct proc *p;
5117 void *v;
5118 register_t *retval;
5119 {
5120 struct netbsd32___msync13_args /* {
5121 syscallarg(netbsd32_voidp) addr;
5122 syscallarg(netbsd32_size_t) len;
5123 syscallarg(int) flags;
5124 } */ *uap = v;
5125 struct sys___msync13_args ua;
5126
5127 NETBSD32TOP_UAP(addr, void);
5128 NETBSD32TOX_UAP(len, size_t);
5129 NETBSD32TO64_UAP(flags);
5130 return (sys___msync13(p, &ua, retval));
5131 }
5132
5133 int
5134 netbsd32___stat13(p, v, retval)
5135 struct proc *p;
5136 void *v;
5137 register_t *retval;
5138 {
5139 struct netbsd32___stat13_args /* {
5140 syscallarg(const netbsd32_charp) path;
5141 syscallarg(netbsd32_statp_t) ub;
5142 } */ *uap = v;
5143 struct netbsd32_stat sb32;
5144 struct stat sb;
5145 int error;
5146 struct nameidata nd;
5147
5148 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
5149 (caddr_t)(u_long)SCARG(uap, path), p);
5150 if ((error = namei(&nd)) != 0)
5151 return (error);
5152 error = vn_stat(nd.ni_vp, &sb, p);
5153 vput(nd.ni_vp);
5154 if (error)
5155 return (error);
5156 netbsd32_from___stat13(&sb, &sb32);
5157 error = copyout(&sb32, (caddr_t)(u_long)SCARG(uap, ub), sizeof(sb32));
5158 return (error);
5159 }
5160
5161 int
5162 netbsd32___fstat13(p, v, retval)
5163 struct proc *p;
5164 void *v;
5165 register_t *retval;
5166 {
5167 struct netbsd32___fstat13_args /* {
5168 syscallarg(int) fd;
5169 syscallarg(netbsd32_statp_t) sb;
5170 } */ *uap = v;
5171 int fd = SCARG(uap, fd);
5172 struct filedesc *fdp = p->p_fd;
5173 struct file *fp;
5174 struct netbsd32_stat sb32;
5175 struct stat ub;
5176 int error = 0;
5177
5178 if ((u_int)fd >= fdp->fd_nfiles ||
5179 (fp = fdp->fd_ofiles[fd]) == NULL)
5180 return (EBADF);
5181 switch (fp->f_type) {
5182
5183 case DTYPE_VNODE:
5184 error = vn_stat((struct vnode *)fp->f_data, &ub, p);
5185 break;
5186
5187 case DTYPE_SOCKET:
5188 error = soo_stat((struct socket *)fp->f_data, &ub);
5189 break;
5190
5191 default:
5192 panic("fstat");
5193 /*NOTREACHED*/
5194 }
5195 if (error == 0) {
5196 netbsd32_from___stat13(&ub, &sb32);
5197 error = copyout(&sb32, (caddr_t)(u_long)SCARG(uap, sb), sizeof(sb32));
5198 }
5199 return (error);
5200 }
5201
5202 int
5203 netbsd32___lstat13(p, v, retval)
5204 struct proc *p;
5205 void *v;
5206 register_t *retval;
5207 {
5208 struct netbsd32___lstat13_args /* {
5209 syscallarg(const netbsd32_charp) path;
5210 syscallarg(netbsd32_statp_t) ub;
5211 } */ *uap = v;
5212 struct netbsd32_stat sb32;
5213 struct stat sb;
5214 int error;
5215 struct nameidata nd;
5216
5217 NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF, UIO_USERSPACE,
5218 (caddr_t)(u_long)SCARG(uap, path), p);
5219 if ((error = namei(&nd)) != 0)
5220 return (error);
5221 error = vn_stat(nd.ni_vp, &sb, p);
5222 vput(nd.ni_vp);
5223 if (error)
5224 return (error);
5225 netbsd32_from___stat13(&sb, &sb32);
5226 error = copyout(&sb32, (caddr_t)(u_long)SCARG(uap, ub), sizeof(sb32));
5227 return (error);
5228 }
5229
5230 int
5231 netbsd32___sigaltstack14(p, v, retval)
5232 struct proc *p;
5233 void *v;
5234 register_t *retval;
5235 {
5236 struct netbsd32___sigaltstack14_args /* {
5237 syscallarg(const netbsd32_sigaltstackp_t) nss;
5238 syscallarg(netbsd32_sigaltstackp_t) oss;
5239 } */ *uap = v;
5240 struct netbsd32_sigaltstack s32;
5241 struct sigaltstack nss, oss;
5242 int error;
5243
5244 if (SCARG(uap, nss)) {
5245 error = copyin((caddr_t)(u_long)SCARG(uap, nss), &s32, sizeof(s32));
5246 if (error)
5247 return (error);
5248 nss.ss_sp = (void *)(u_long)s32.ss_sp;
5249 nss.ss_size = (size_t)s32.ss_size;
5250 nss.ss_flags = s32.ss_flags;
5251 }
5252 error = sigaltstack1(p,
5253 SCARG(uap, nss) ? &nss : 0, SCARG(uap, oss) ? &oss : 0);
5254 if (error)
5255 return (error);
5256 if (SCARG(uap, oss)) {
5257 s32.ss_sp = (netbsd32_voidp)(u_long)oss.ss_sp;
5258 s32.ss_size = (netbsd32_size_t)oss.ss_size;
5259 s32.ss_flags = oss.ss_flags;
5260 error = copyout(&s32, (caddr_t)(u_long)SCARG(uap, oss), sizeof(s32));
5261 if (error)
5262 return (error);
5263 }
5264 return (0);
5265 }
5266
5267 int
5268 netbsd32___posix_chown(p, v, retval)
5269 struct proc *p;
5270 void *v;
5271 register_t *retval;
5272 {
5273 struct netbsd32___posix_chown_args /* {
5274 syscallarg(const netbsd32_charp) path;
5275 syscallarg(uid_t) uid;
5276 syscallarg(gid_t) gid;
5277 } */ *uap = v;
5278 struct sys___posix_chown_args ua;
5279
5280 NETBSD32TOP_UAP(path, const char);
5281 NETBSD32TO64_UAP(uid);
5282 NETBSD32TO64_UAP(gid);
5283 return (sys___posix_chown(p, &ua, retval));
5284 }
5285
5286 int
5287 netbsd32___posix_fchown(p, v, retval)
5288 struct proc *p;
5289 void *v;
5290 register_t *retval;
5291 {
5292 struct netbsd32___posix_fchown_args /* {
5293 syscallarg(int) fd;
5294 syscallarg(uid_t) uid;
5295 syscallarg(gid_t) gid;
5296 } */ *uap = v;
5297 struct sys___posix_fchown_args ua;
5298
5299 NETBSD32TO64_UAP(fd);
5300 NETBSD32TO64_UAP(uid);
5301 NETBSD32TO64_UAP(gid);
5302 return (sys___posix_fchown(p, &ua, retval));
5303 }
5304
5305 int
5306 netbsd32___posix_lchown(p, v, retval)
5307 struct proc *p;
5308 void *v;
5309 register_t *retval;
5310 {
5311 struct netbsd32___posix_lchown_args /* {
5312 syscallarg(const netbsd32_charp) path;
5313 syscallarg(uid_t) uid;
5314 syscallarg(gid_t) gid;
5315 } */ *uap = v;
5316 struct sys___posix_lchown_args ua;
5317
5318 NETBSD32TOP_UAP(path, const char);
5319 NETBSD32TO64_UAP(uid);
5320 NETBSD32TO64_UAP(gid);
5321 return (sys___posix_lchown(p, &ua, retval));
5322 }
5323
5324 int
5325 netbsd32_getsid(p, v, retval)
5326 struct proc *p;
5327 void *v;
5328 register_t *retval;
5329 {
5330 struct netbsd32_getsid_args /* {
5331 syscallarg(pid_t) pid;
5332 } */ *uap = v;
5333 struct sys_getsid_args ua;
5334
5335 NETBSD32TO64_UAP(pid);
5336 return (sys_getsid(p, &ua, retval));
5337 }
5338
5339 int
5340 netbsd32_fktrace(p, v, retval)
5341 struct proc *p;
5342 void *v;
5343 register_t *retval;
5344 {
5345 struct netbsd32_fktrace_args /* {
5346 syscallarg(const int) fd;
5347 syscallarg(int) ops;
5348 syscallarg(int) facs;
5349 syscallarg(int) pid;
5350 } */ *uap = v;
5351 struct sys_fktrace_args ua;
5352
5353 NETBSD32TOX_UAP(fd, const int);
5354 NETBSD32TO64_UAP(ops);
5355 NETBSD32TO64_UAP(facs);
5356 NETBSD32TO64_UAP(pid);
5357 return (sys_fktrace(p, &ua, retval));
5358 }
5359
5360 int
5361 netbsd32_preadv(p, v, retval)
5362 struct proc *p;
5363 void *v;
5364 register_t *retval;
5365 {
5366 struct netbsd32_preadv_args /* {
5367 syscallarg(int) fd;
5368 syscallarg(const netbsd32_iovecp_t) iovp;
5369 syscallarg(int) iovcnt;
5370 syscallarg(int) pad;
5371 syscallarg(off_t) offset;
5372 } */ *uap = v;
5373 struct filedesc *fdp = p->p_fd;
5374 struct file *fp;
5375 struct vnode *vp;
5376 off_t offset;
5377 int error, fd = SCARG(uap, fd);
5378
5379 if ((u_int)fd >= fdp->fd_nfiles ||
5380 (fp = fdp->fd_ofiles[fd]) == NULL ||
5381 (fp->f_flag & FREAD) == 0)
5382 return (EBADF);
5383
5384 vp = (struct vnode *)fp->f_data;
5385 if (fp->f_type != DTYPE_VNODE
5386 || vp->v_type == VFIFO)
5387 return (ESPIPE);
5388
5389 offset = SCARG(uap, offset);
5390
5391 /*
5392 * XXX This works because no file systems actually
5393 * XXX take any action on the seek operation.
5394 */
5395 if ((error = VOP_SEEK(vp, fp->f_offset, offset, fp->f_cred)) != 0)
5396 return (error);
5397
5398 return (dofilereadv32(p, fd, fp, (struct netbsd32_iovec *)(u_long)SCARG(uap, iovp), SCARG(uap, iovcnt),
5399 &offset, 0, retval));
5400 }
5401
5402 int
5403 netbsd32_pwritev(p, v, retval)
5404 struct proc *p;
5405 void *v;
5406 register_t *retval;
5407 {
5408 struct netbsd32_pwritev_args /* {
5409 syscallarg(int) fd;
5410 syscallarg(const netbsd32_iovecp_t) iovp;
5411 syscallarg(int) iovcnt;
5412 syscallarg(int) pad;
5413 syscallarg(off_t) offset;
5414 } */ *uap = v;
5415 struct filedesc *fdp = p->p_fd;
5416 struct file *fp;
5417 struct vnode *vp;
5418 off_t offset;
5419 int error, fd = SCARG(uap, fd);
5420
5421 if ((u_int)fd >= fdp->fd_nfiles ||
5422 (fp = fdp->fd_ofiles[fd]) == NULL ||
5423 (fp->f_flag & FWRITE) == 0)
5424 return (EBADF);
5425
5426 vp = (struct vnode *)fp->f_data;
5427 if (fp->f_type != DTYPE_VNODE
5428 || vp->v_type == VFIFO)
5429 return (ESPIPE);
5430
5431 offset = SCARG(uap, offset);
5432
5433 /*
5434 * XXX This works because no file systems actually
5435 * XXX take any action on the seek operation.
5436 */
5437 if ((error = VOP_SEEK(vp, fp->f_offset, offset, fp->f_cred)) != 0)
5438 return (error);
5439
5440 return (dofilewritev32(p, fd, fp, (struct netbsd32_iovec *)(u_long)SCARG(uap, iovp), SCARG(uap, iovcnt),
5441 &offset, 0, retval));
5442 }
5443
5444 /* ARGSUSED */
5445 int
5446 netbsd32___sigaction14(p, v, retval)
5447 struct proc *p;
5448 void *v;
5449 register_t *retval;
5450 {
5451 struct netbsd32___sigaction14_args /* {
5452 syscallarg(int) signum;
5453 syscallarg(const struct sigaction *) nsa;
5454 syscallarg(struct sigaction *) osa;
5455 } */ *uap = v;
5456 struct netbsd32_sigaction sa32;
5457 struct sigaction nsa, osa;
5458 int error;
5459
5460 if (SCARG(uap, nsa)) {
5461 error = copyin((caddr_t)(u_long)SCARG(uap, nsa),
5462 &sa32, sizeof(sa32));
5463 if (error)
5464 return (error);
5465 nsa.sa_handler = (void *)(u_long)sa32.sa_handler;
5466 nsa.sa_mask = sa32.sa_mask;
5467 nsa.sa_flags = sa32.sa_flags;
5468 }
5469 error = sigaction1(p, SCARG(uap, signum),
5470 SCARG(uap, nsa) ? &nsa : 0, SCARG(uap, osa) ? &osa : 0);
5471 if (error)
5472 return (error);
5473 if (SCARG(uap, osa)) {
5474 sa32.sa_handler = (netbsd32_voidp)(u_long)osa.sa_handler;
5475 sa32.sa_mask = osa.sa_mask;
5476 sa32.sa_flags = osa.sa_flags;
5477 error = copyout(&sa32, (caddr_t)(u_long)SCARG(uap, osa), sizeof(sa32));
5478 if (error)
5479 return (error);
5480 }
5481 return (0);
5482 }
5483
5484 int netbsd32___sigpending14(p, v, retval)
5485 struct proc *p;
5486 void *v;
5487 register_t *retval;
5488 {
5489 struct netbsd32___sigpending14_args /* {
5490 syscallarg(sigset_t *) set;
5491 } */ *uap = v;
5492 struct sys___sigpending14_args ua;
5493
5494 NETBSD32TOP_UAP(set, sigset_t);
5495 return (sys___sigpending14(p, &ua, retval));
5496 }
5497
5498 int netbsd32___sigprocmask14(p, v, retval)
5499 struct proc *p;
5500 void *v;
5501 register_t *retval;
5502 {
5503 struct netbsd32___sigprocmask14_args /* {
5504 syscallarg(int) how;
5505 syscallarg(const sigset_t *) set;
5506 syscallarg(sigset_t *) oset;
5507 } */ *uap = v;
5508 struct sys___sigprocmask14_args ua;
5509
5510 NETBSD32TO64_UAP(how);
5511 NETBSD32TOP_UAP(set, sigset_t);
5512 NETBSD32TOP_UAP(oset, sigset_t);
5513 return (sys___sigprocmask14(p, &ua, retval));
5514 }
5515
5516 int netbsd32___sigsuspend14(p, v, retval)
5517 struct proc *p;
5518 void *v;
5519 register_t *retval;
5520 {
5521 struct netbsd32___sigsuspend14_args /* {
5522 syscallarg(const sigset_t *) set;
5523 } */ *uap = v;
5524 struct sys___sigsuspend14_args ua;
5525
5526 NETBSD32TOP_UAP(set, sigset_t);
5527 return (sys___sigsuspend14(p, &ua, retval));
5528 };
5529
5530
5531 /*
5532 * Find pathname of process's current directory.
5533 *
5534 * Use vfs vnode-to-name reverse cache; if that fails, fall back
5535 * to reading directory contents.
5536 */
5537 int
5538 getcwd_common __P((struct vnode *, struct vnode *,
5539 char **, char *, int, int, struct proc *));
5540
5541 int netbsd32___getcwd(p, v, retval)
5542 struct proc *p;
5543 void *v;
5544 register_t *retval;
5545 {
5546 struct netbsd32___getcwd_args /* {
5547 syscallarg(char *) bufp;
5548 syscallarg(size_t) length;
5549 } */ *uap = v;
5550
5551 int error;
5552 char *path;
5553 char *bp, *bend;
5554 int len = (int)SCARG(uap, length);
5555 int lenused;
5556
5557 if (len > MAXPATHLEN*4)
5558 len = MAXPATHLEN*4;
5559 else if (len < 2)
5560 return ERANGE;
5561
5562 path = (char *)malloc(len, M_TEMP, M_WAITOK);
5563 if (!path)
5564 return ENOMEM;
5565
5566 bp = &path[len];
5567 bend = bp;
5568 *(--bp) = '\0';
5569
5570 /*
5571 * 5th argument here is "max number of vnodes to traverse".
5572 * Since each entry takes up at least 2 bytes in the output buffer,
5573 * limit it to N/2 vnodes for an N byte buffer.
5574 */
5575 #define GETCWD_CHECK_ACCESS 0x0001
5576 error = getcwd_common (p->p_cwdi->cwdi_cdir, NULL, &bp, path, len/2,
5577 GETCWD_CHECK_ACCESS, p);
5578
5579 if (error)
5580 goto out;
5581 lenused = bend - bp;
5582 *retval = lenused;
5583 /* put the result into user buffer */
5584 error = copyout(bp, (caddr_t)(u_long)SCARG(uap, bufp), lenused);
5585
5586 out:
5587 free(path, M_TEMP);
5588 return error;
5589 }
5590
5591 int netbsd32_fchroot(p, v, retval)
5592 struct proc *p;
5593 void *v;
5594 register_t *retval;
5595 {
5596 struct netbsd32_fchroot_args /* {
5597 syscallarg(int) fd;
5598 } */ *uap = v;
5599 struct sys_fchroot_args ua;
5600
5601 NETBSD32TO64_UAP(fd);
5602 return (sys_fchroot(p, &ua, retval));
5603 }
5604
5605 /*
5606 * Open a file given a file handle.
5607 *
5608 * Check permissions, allocate an open file structure,
5609 * and call the device open routine if any.
5610 */
5611 int
5612 netbsd32_fhopen(p, v, retval)
5613 struct proc *p;
5614 void *v;
5615 register_t *retval;
5616 {
5617 struct netbsd32_fhopen_args /* {
5618 syscallarg(const fhandle_t *) fhp;
5619 syscallarg(int) flags;
5620 } */ *uap = v;
5621 struct sys_fhopen_args ua;
5622
5623 NETBSD32TOP_UAP(fhp, fhandle_t);
5624 NETBSD32TO64_UAP(flags);
5625 return (sys_fhopen(p, &ua, retval));
5626 }
5627
5628 int netbsd32_fhstat(p, v, retval)
5629 struct proc *p;
5630 void *v;
5631 register_t *retval;
5632 {
5633 struct netbsd32_fhstat_args /* {
5634 syscallarg(const netbsd32_fhandlep_t) fhp;
5635 syscallarg(struct stat *) sb;
5636 } */ *uap = v;
5637 struct sys_fhstat_args ua;
5638
5639 NETBSD32TOP_UAP(fhp, const fhandle_t);
5640 NETBSD32TOP_UAP(sb, struct stat);
5641 return (sys_fhstat(p, &ua, retval));
5642 }
5643
5644 int netbsd32_fhstatfs(p, v, retval)
5645 struct proc *p;
5646 void *v;
5647 register_t *retval;
5648 {
5649 struct netbsd32_fhstatfs_args /* {
5650 syscallarg(const netbsd32_fhandlep_t) fhp;
5651 syscallarg(struct statfs *) buf;
5652 } */ *uap = v;
5653 struct sys_fhstatfs_args ua;
5654
5655 NETBSD32TOP_UAP(fhp, const fhandle_t);
5656 NETBSD32TOP_UAP(buf, struct statfs);
5657 return (sys_fhstatfs(p, &ua, retval));
5658 }
5659