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