netbsd32_netbsd.c revision 1.9 1 /* $NetBSD: netbsd32_netbsd.c,v 1.9 1999/03/25 15:34:37 mrg 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_ktrace.h"
32 #include "opt_ntp.h"
33 #include "opt_compat_freebsd.h"
34 #include "opt_compat_linux.h"
35 #include "opt_compat_sunos.h"
36 #include "opt_compat_43.h"
37 #if defined(COMPAT_43) || defined(COMPAT_SUNOS) || defined(COMPAT_LINUX) || \
38 defined(COMPAT_FREEBSD)
39 #define COMPAT_OLDSOCK /* used by <sys/socket.h> */
40 #endif
41
42 #include "fs_lfs.h"
43 #include "fs_nfs.h"
44
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/kernel.h>
48 #include <sys/ipc.h>
49 #include <sys/msg.h>
50 #include <sys/sem.h>
51 #include <sys/shm.h>
52 #include <sys/malloc.h>
53 #include <sys/mount.h>
54 #include <sys/socket.h>
55 #include <sys/sockio.h>
56 #include <sys/socketvar.h>
57 #include <sys/mbuf.h>
58 #include <sys/stat.h>
59 #include <sys/time.h>
60 #include <sys/timex.h>
61 #include <sys/signalvar.h>
62 #include <sys/wait.h>
63 #include <sys/ptrace.h>
64 #include <sys/ktrace.h>
65 #include <sys/trace.h>
66 #include <sys/resourcevar.h>
67 #include <sys/pool.h>
68 #include <sys/vnode.h>
69 #include <sys/file.h>
70 #include <sys/filedesc.h>
71 #include <sys/namei.h>
72
73 #include <vm/vm.h>
74 #include <sys/syscallargs.h>
75 #include <sys/proc.h>
76 #include <sys/sysctl.h>
77
78 #include <net/if.h>
79
80 #include <compat/sparc32/sparc32.h>
81 #include <compat/sparc32/sparc32_syscallargs.h>
82
83 #include <machine/frame.h>
84
85 static __inline void sparc32_from_timeval __P((struct timeval *, struct sparc32_timeval *));
86 static __inline void sparc32_to_timeval __P((struct sparc32_timeval *, struct timeval *));
87 static __inline void sparc32_from_itimerval __P((struct itimerval *, struct sparc32_itimerval *));
88 static __inline void sparc32_to_itimerval __P((struct sparc32_itimerval *, struct itimerval *));
89 static __inline void sparc32_to_timespec __P((struct sparc32_timespec *, struct timespec *));
90 static __inline void sparc32_from_timespec __P((struct timespec *, struct sparc32_timespec *));
91 static __inline void sparc32_from_rusage __P((struct rusage *, struct sparc32_rusage *));
92 static __inline void sparc32_to_rusage __P((struct sparc32_rusage *, struct rusage *));
93 static __inline int sparc32_to_iovecin __P((struct sparc32_iovec *, struct iovec *, int));
94 static __inline void sparc32_to_msghdr __P((struct sparc32_msghdr *, struct msghdr *));
95 static __inline void sparc32_from_msghdr __P((struct sparc32_msghdr *, struct msghdr *));
96 static __inline void sparc32_from_statfs __P((struct statfs *, struct sparc32_statfs *));
97 static __inline void sparc32_from_timex __P((struct timex *, struct sparc32_timex *));
98 static __inline void sparc32_to_timex __P((struct sparc32_timex *, struct timex *));
99 static __inline void sparc32_from___stat13 __P((struct stat *, struct sparc32_stat *));
100 static __inline void sparc32_to_ipc_perm __P((struct sparc32_ipc_perm *, struct ipc_perm *));
101 static __inline void sparc32_from_ipc_perm __P((struct ipc_perm *, struct sparc32_ipc_perm *));
102 static __inline void sparc32_to_msg __P((struct sparc32_msg *, struct msg *));
103 static __inline void sparc32_from_msg __P((struct msg *, struct sparc32_msg *));
104 static __inline void sparc32_to_msqid_ds __P((struct sparc32_msqid_ds *, struct msqid_ds *));
105 static __inline void sparc32_from_msqid_ds __P((struct msqid_ds *, struct sparc32_msqid_ds *));
106 static __inline void sparc32_to_shmid_ds __P((struct sparc32_shmid_ds *, struct shmid_ds *));
107 static __inline void sparc32_from_shmid_ds __P((struct shmid_ds *, struct sparc32_shmid_ds *));
108 static __inline void sparc32_to_semid_ds __P((struct sparc32_semid_ds *, struct semid_ds *));
109 static __inline void sparc32_from_semid_ds __P((struct semid_ds *, struct sparc32_semid_ds *));
110
111
112 static int recvit32 __P((struct proc *, int, struct sparc32_msghdr *, struct iovec *, caddr_t,
113 register_t *));
114 static int dofilereadv32 __P((struct proc *, int, struct file *, struct sparc32_iovec *,
115 int, off_t *, int, register_t *));
116 static int dofilewritev32 __P((struct proc *, int, struct file *, struct sparc32_iovec *,
117 int, off_t *, int, register_t *));
118 static int change_utimes32 __P((struct vnode *, struct timeval *, struct proc *));
119
120 /* converters for structures that we need */
121 static __inline void
122 sparc32_from_timeval(tv, tv32)
123 struct timeval *tv;
124 struct sparc32_timeval *tv32;
125 {
126
127 tv32->tv_sec = (sparc32_long)tv->tv_sec;
128 tv32->tv_usec = (sparc32_long)tv->tv_usec;
129 }
130
131 static __inline void
132 sparc32_to_timeval(tv32, tv)
133 struct sparc32_timeval *tv32;
134 struct timeval *tv;
135 {
136
137 tv->tv_sec = (long)tv32->tv_sec;
138 tv->tv_usec = (long)tv32->tv_usec;
139 }
140
141 static __inline void
142 sparc32_from_itimerval(itv, itv32)
143 struct itimerval *itv;
144 struct sparc32_itimerval *itv32;
145 {
146
147 sparc32_from_timeval(&itv->it_interval,
148 &itv32->it_interval);
149 sparc32_from_timeval(&itv->it_value,
150 &itv32->it_value);
151 }
152
153 static __inline void
154 sparc32_to_itimerval(itv32, itv)
155 struct sparc32_itimerval *itv32;
156 struct itimerval *itv;
157 {
158
159 sparc32_to_timeval(&itv32->it_interval, &itv->it_interval);
160 sparc32_to_timeval(&itv32->it_value, &itv->it_value);
161 }
162
163 static __inline void
164 sparc32_to_timespec(s32p, p)
165 struct sparc32_timespec *s32p;
166 struct timespec *p;
167 {
168
169 p->tv_sec = s32p->tv_sec;
170 p->tv_nsec = (long)s32p->tv_nsec;
171 }
172
173 static __inline void
174 sparc32_from_timespec(p, s32p)
175 struct timespec *p;
176 struct sparc32_timespec *s32p;
177 {
178
179 s32p->tv_sec = p->tv_sec;
180 s32p->tv_nsec = (sparc32_long)p->tv_nsec;
181 }
182
183 static __inline void
184 sparc32_from_rusage(rup, ru32p)
185 struct rusage *rup;
186 struct sparc32_rusage *ru32p;
187 {
188
189 sparc32_from_timeval(&rup->ru_utime, &ru32p->ru_utime);
190 sparc32_from_timeval(&rup->ru_stime, &ru32p->ru_stime);
191 #define C(var) ru32p->var = (sparc32_long)rup->var
192 C(ru_maxrss);
193 C(ru_ixrss);
194 C(ru_idrss);
195 C(ru_isrss);
196 C(ru_minflt);
197 C(ru_majflt);
198 C(ru_nswap);
199 C(ru_inblock);
200 C(ru_oublock);
201 C(ru_msgsnd);
202 C(ru_msgrcv);
203 C(ru_nsignals);
204 C(ru_nvcsw);
205 C(ru_nivcsw);
206 #undef C
207 }
208
209 static __inline void
210 sparc32_to_rusage(ru32p, rup)
211 struct sparc32_rusage *ru32p;
212 struct rusage *rup;
213 {
214
215 sparc32_to_timeval(&ru32p->ru_utime, &rup->ru_utime);
216 sparc32_to_timeval(&ru32p->ru_stime, &rup->ru_stime);
217 #define C(var) rup->var = (long)ru32p->var
218 C(ru_maxrss);
219 C(ru_ixrss);
220 C(ru_idrss);
221 C(ru_isrss);
222 C(ru_minflt);
223 C(ru_majflt);
224 C(ru_nswap);
225 C(ru_inblock);
226 C(ru_oublock);
227 C(ru_msgsnd);
228 C(ru_msgrcv);
229 C(ru_nsignals);
230 C(ru_nvcsw);
231 C(ru_nivcsw);
232 #undef C
233 }
234
235 static __inline int
236 sparc32_to_iovecin(iov32p, iovp, len)
237 struct sparc32_iovec *iov32p;
238 struct iovec *iovp;
239 int len;
240 {
241 int i, error=0;
242 u_int32_t iov_base;
243 u_int32_t iov_len;
244 /*
245 * We could allocate an iov32p, do a copyin, and translate
246 * each field and then free it all up, or we could copyin
247 * each field separately. I'm doing the latter to reduce
248 * the number of MALLOC()s.
249 */
250 printf("converting iovec at %p len %lx to %p\n", iov32p, len, iovp);
251 for (i = 0; i < len; i++, iovp++, iov32p++) {
252 if ((error = copyin((caddr_t)&iov32p->iov_base, &iov_base, sizeof(iov_base))))
253 return (error);
254 if ((error = copyin((caddr_t)&iov32p->iov_len, &iov_len, sizeof(iov_len))))
255 return (error);
256 iovp->iov_base = (void *)(u_long)iov_base;
257 iovp->iov_len = (size_t)iov_len;
258 printf("iovec slot %d base %p len %lx\n", i, iovp->iov_base, iovp->iov_len);
259 }
260 }
261
262 /* msg_iov must be done separately */
263 static __inline void
264 sparc32_to_msghdr(mhp32, mhp)
265 struct sparc32_msghdr *mhp32;
266 struct msghdr *mhp;
267 {
268
269 mhp->msg_name = (caddr_t)(u_long)mhp32->msg_name;
270 mhp->msg_namelen = mhp32->msg_namelen;
271 mhp->msg_iovlen = (size_t)mhp32->msg_iovlen;
272 mhp->msg_control = (caddr_t)(u_long)mhp32->msg_control;
273 mhp->msg_controllen = mhp32->msg_controllen;
274 mhp->msg_flags = mhp32->msg_flags;
275 }
276
277 /* msg_iov must be done separately */
278 static __inline void
279 sparc32_from_msghdr(mhp32, mhp)
280 struct sparc32_msghdr *mhp32;
281 struct msghdr *mhp;
282 {
283
284 mhp32->msg_name = mhp32->msg_name;
285 mhp32->msg_namelen = mhp32->msg_namelen;
286 mhp32->msg_iovlen = mhp32->msg_iovlen;
287 mhp32->msg_control = mhp32->msg_control;
288 mhp32->msg_controllen = mhp->msg_controllen;
289 mhp32->msg_flags = mhp->msg_flags;
290 }
291
292 static __inline void
293 sparc32_from_statfs(sbp, sb32p)
294 struct statfs *sbp;
295 struct sparc32_statfs *sb32p;
296 {
297
298 sb32p->f_type = sbp->f_type;
299 sb32p->f_flags = sbp->f_flags;
300 sb32p->f_bsize = (sparc32_long)sbp->f_bsize;
301 sb32p->f_iosize = (sparc32_long)sbp->f_iosize;
302 sb32p->f_blocks = (sparc32_long)sbp->f_blocks;
303 sb32p->f_bfree = (sparc32_long)sbp->f_bfree;
304 sb32p->f_bavail = (sparc32_long)sbp->f_bavail;
305 sb32p->f_files = (sparc32_long)sbp->f_files;
306 sb32p->f_ffree = (sparc32_long)sbp->f_ffree;
307 sb32p->f_fsid = sbp->f_fsid;
308 sb32p->f_owner = sbp->f_owner;
309 sb32p->f_spare[0] = 0;
310 sb32p->f_spare[1] = 0;
311 sb32p->f_spare[2] = 0;
312 sb32p->f_spare[3] = 0;
313 #if 1
314 /* May as well do the whole batch in one go */
315 memcpy(sb32p->f_fstypename, sbp->f_fstypename, MFSNAMELEN+MNAMELEN+MNAMELEN);
316 #else
317 /* If we want to be careful */
318 memcpy(sb32p->f_fstypename, sbp->f_fstypename, MFSNAMELEN);
319 memcpy(sb32p->f_mntonname, sbp->f_mntonname, MNAMELEN);
320 memcpy(sb32p->f_mntfromname, sbp->f_mntfromname, MNAMELEN);
321 #endif
322 }
323
324 static __inline void
325 sparc32_from_timex(txp, tx32p)
326 struct timex *txp;
327 struct sparc32_timex *tx32p;
328 {
329
330 tx32p->modes = txp->modes;
331 tx32p->offset = (sparc32_long)txp->offset;
332 tx32p->freq = (sparc32_long)txp->freq;
333 tx32p->maxerror = (sparc32_long)txp->maxerror;
334 tx32p->esterror = (sparc32_long)txp->esterror;
335 tx32p->status = txp->status;
336 tx32p->constant = (sparc32_long)txp->constant;
337 tx32p->precision = (sparc32_long)txp->precision;
338 tx32p->tolerance = (sparc32_long)txp->tolerance;
339 tx32p->ppsfreq = (sparc32_long)txp->ppsfreq;
340 tx32p->jitter = (sparc32_long)txp->jitter;
341 tx32p->shift = txp->shift;
342 tx32p->stabil = (sparc32_long)txp->stabil;
343 tx32p->jitcnt = (sparc32_long)txp->jitcnt;
344 tx32p->calcnt = (sparc32_long)txp->calcnt;
345 tx32p->errcnt = (sparc32_long)txp->errcnt;
346 tx32p->stbcnt = (sparc32_long)txp->stbcnt;
347 }
348
349 static __inline void
350 sparc32_to_timex(tx32p, txp)
351 struct sparc32_timex *tx32p;
352 struct timex *txp;
353 {
354
355 txp->modes = tx32p->modes;
356 txp->offset = (long)tx32p->offset;
357 txp->freq = (long)tx32p->freq;
358 txp->maxerror = (long)tx32p->maxerror;
359 txp->esterror = (long)tx32p->esterror;
360 txp->status = tx32p->status;
361 txp->constant = (long)tx32p->constant;
362 txp->precision = (long)tx32p->precision;
363 txp->tolerance = (long)tx32p->tolerance;
364 txp->ppsfreq = (long)tx32p->ppsfreq;
365 txp->jitter = (long)tx32p->jitter;
366 txp->shift = tx32p->shift;
367 txp->stabil = (long)tx32p->stabil;
368 txp->jitcnt = (long)tx32p->jitcnt;
369 txp->calcnt = (long)tx32p->calcnt;
370 txp->errcnt = (long)tx32p->errcnt;
371 txp->stbcnt = (long)tx32p->stbcnt;
372 }
373
374 static __inline void
375 sparc32_from___stat13(sbp, sb32p)
376 struct stat *sbp;
377 struct sparc32_stat *sb32p;
378 {
379 sb32p->st_dev = sbp->st_dev;
380 sb32p->st_ino = sbp->st_ino;
381 sb32p->st_mode = sbp->st_mode;
382 sb32p->st_nlink = sbp->st_nlink;
383 sb32p->st_uid = sbp->st_uid;
384 sb32p->st_gid = sbp->st_gid;
385 sb32p->st_rdev = sbp->st_rdev;
386 if (sbp->st_size < (quad_t)1 << 32)
387 sb32p->st_size = sbp->st_size;
388 else
389 sb32p->st_size = -2;
390 sb32p->st_atimespec.tv_sec = sbp->st_atimespec.tv_sec;
391 sb32p->st_atimespec.tv_nsec = (sparc32_long)sbp->st_atimespec.tv_nsec;
392 sb32p->st_mtimespec.tv_sec = sbp->st_mtimespec.tv_sec;
393 sb32p->st_mtimespec.tv_nsec = (sparc32_long)sbp->st_mtimespec.tv_nsec;
394 sb32p->st_ctimespec.tv_sec = sbp->st_ctimespec.tv_sec;
395 sb32p->st_ctimespec.tv_nsec = (sparc32_long)sbp->st_ctimespec.tv_nsec;
396 sb32p->st_blksize = sbp->st_blksize;
397 sb32p->st_blocks = sbp->st_blocks;
398 sb32p->st_flags = sbp->st_flags;
399 sb32p->st_gen = sbp->st_gen;
400 }
401
402 static __inline void
403 sparc32_to_ipc_perm(ip32p, ipp)
404 struct sparc32_ipc_perm *ip32p;
405 struct ipc_perm *ipp;
406 {
407
408 ipp->cuid = ip32p->cuid;
409 ipp->cgid = ip32p->cgid;
410 ipp->uid = ip32p->uid;
411 ipp->gid = ip32p->gid;
412 ipp->mode = ip32p->mode;
413 ipp->seq = ip32p->seq;
414 ipp->key = (key_t)ip32p->key;
415 }
416
417 static __inline void
418 sparc32_from_ipc_perm(ipp, ip32p)
419 struct ipc_perm *ipp;
420 struct sparc32_ipc_perm *ip32p;
421 {
422
423 ip32p->cuid = ipp->cuid;
424 ip32p->cgid = ipp->cgid;
425 ip32p->uid = ipp->uid;
426 ip32p->gid = ipp->gid;
427 ip32p->mode = ipp->mode;
428 ip32p->seq = ipp->seq;
429 ip32p->key = (sparc32_key_t)ipp->key;
430 }
431
432 static __inline void
433 sparc32_to_msg(m32p, mp)
434 struct sparc32_msg *m32p;
435 struct msg *mp;
436 {
437
438 mp->msg_next = (struct msg *)(u_long)m32p->msg_next;
439 mp->msg_type = (long)m32p->msg_type;
440 mp->msg_ts = m32p->msg_ts;
441 mp->msg_spot = m32p->msg_spot;
442 }
443
444 static __inline void
445 sparc32_from_msg(mp, m32p)
446 struct msg *mp;
447 struct sparc32_msg *m32p;
448 {
449
450 m32p->msg_next = (sparc32_msgp_t)(u_long)mp->msg_next;
451 m32p->msg_type = (sparc32_long)mp->msg_type;
452 m32p->msg_ts = mp->msg_ts;
453 m32p->msg_spot = mp->msg_spot;
454 }
455
456 static __inline void
457 sparc32_to_msqid_ds(ds32p, dsp)
458 struct sparc32_msqid_ds *ds32p;
459 struct msqid_ds *dsp;
460 {
461
462 sparc32_to_ipc_perm(&ds32p->msg_perm, &dsp->msg_perm);
463 sparc32_to_msg((struct sparc32_msg *)(u_long)ds32p->msg_first, dsp->msg_first);
464 sparc32_to_msg((struct sparc32_msg *)(u_long)ds32p->msg_last, dsp->msg_last);
465 dsp->msg_cbytes = (u_long)ds32p->msg_cbytes;
466 dsp->msg_qnum = (u_long)ds32p->msg_qnum;
467 dsp->msg_qbytes = (u_long)ds32p->msg_qbytes;
468 dsp->msg_lspid = ds32p->msg_lspid;
469 dsp->msg_lrpid = ds32p->msg_lrpid;
470 dsp->msg_rtime = (time_t)ds32p->msg_rtime;
471 dsp->msg_stime = (time_t)ds32p->msg_stime;
472 dsp->msg_ctime = (time_t)ds32p->msg_ctime;
473 }
474
475 static __inline void
476 sparc32_from_msqid_ds(dsp, ds32p)
477 struct msqid_ds *dsp;
478 struct sparc32_msqid_ds *ds32p;
479 {
480
481 sparc32_from_ipc_perm(&dsp->msg_perm, &ds32p->msg_perm);
482 sparc32_from_msg(dsp->msg_first, (struct sparc32_msg *)(u_long)ds32p->msg_first);
483 sparc32_from_msg(dsp->msg_last, (struct sparc32_msg *)(u_long)ds32p->msg_last);
484 ds32p->msg_cbytes = (sparc32_u_long)dsp->msg_cbytes;
485 ds32p->msg_qnum = (sparc32_u_long)dsp->msg_qnum;
486 ds32p->msg_qbytes = (sparc32_u_long)dsp->msg_qbytes;
487 ds32p->msg_lspid = dsp->msg_lspid;
488 ds32p->msg_lrpid = dsp->msg_lrpid;
489 ds32p->msg_rtime = dsp->msg_rtime;
490 ds32p->msg_stime = dsp->msg_stime;
491 ds32p->msg_ctime = dsp->msg_ctime;
492 }
493
494 static __inline void
495 sparc32_to_shmid_ds(ds32p, dsp)
496 struct sparc32_shmid_ds *ds32p;
497 struct shmid_ds *dsp;
498 {
499
500 sparc32_to_ipc_perm(&ds32p->shm_perm, &dsp->shm_perm);
501 dsp->shm_segsz = ds32p->shm_segsz;
502 dsp->shm_lpid = ds32p->shm_lpid;
503 dsp->shm_cpid = ds32p->shm_cpid;
504 dsp->shm_nattch = ds32p->shm_nattch;
505 dsp->shm_atime = (long)ds32p->shm_atime;
506 dsp->shm_dtime = (long)ds32p->shm_dtime;
507 dsp->shm_ctime = (long)ds32p->shm_ctime;
508 dsp->shm_internal = (void *)(u_long)ds32p->shm_internal;
509 }
510
511 static __inline void
512 sparc32_from_shmid_ds(dsp, ds32p)
513 struct shmid_ds *dsp;
514 struct sparc32_shmid_ds *ds32p;
515 {
516
517 sparc32_from_ipc_perm(&dsp->shm_perm, &ds32p->shm_perm);
518 ds32p->shm_segsz = dsp->shm_segsz;
519 ds32p->shm_lpid = dsp->shm_lpid;
520 ds32p->shm_cpid = dsp->shm_cpid;
521 ds32p->shm_nattch = dsp->shm_nattch;
522 ds32p->shm_atime = (sparc32_long)dsp->shm_atime;
523 ds32p->shm_dtime = (sparc32_long)dsp->shm_dtime;
524 ds32p->shm_ctime = (sparc32_long)dsp->shm_ctime;
525 ds32p->shm_internal = (sparc32_voidp)(u_long)dsp->shm_internal;
526 }
527
528 static __inline void
529 sparc32_to_semid_ds(s32dsp, dsp)
530 struct sparc32_semid_ds *s32dsp;
531 struct semid_ds *dsp;
532 {
533
534 sparc32_from_ipc_perm(&dsp->sem_perm, &s32dsp->sem_perm);
535 dsp->sem_base = (struct sem *)(u_long)s32dsp->sem_base;
536 dsp->sem_nsems = s32dsp->sem_nsems;
537 dsp->sem_otime = s32dsp->sem_otime;
538 dsp->sem_ctime = s32dsp->sem_ctime;
539 }
540
541 static __inline void
542 sparc32_from_semid_ds(dsp, s32dsp)
543 struct semid_ds *dsp;
544 struct sparc32_semid_ds *s32dsp;
545 {
546
547 sparc32_to_ipc_perm(&s32dsp->sem_perm, &dsp->sem_perm);
548 s32dsp->sem_base = (sparc32_semp_t)(u_long)dsp->sem_base;
549 s32dsp->sem_nsems = dsp->sem_nsems;
550 s32dsp->sem_otime = dsp->sem_otime;
551 s32dsp->sem_ctime = dsp->sem_ctime;
552 }
553
554 /*
555 * below are all the standard NetBSD system calls, in the 32bit
556 * environment, witht he necessary conversions to 64bit before
557 * calling the real syscall.
558 */
559
560
561 int
562 compat_sparc32_exit(p, v, retval)
563 struct proc *p;
564 void *v;
565 register_t *retval;
566 {
567 struct compat_sparc32_exit_args /* {
568 syscallarg(int) rval;
569 } */ *uap = v;
570 struct sys_exit_args ua;
571
572 SPARC32TO64_UAP(rval);
573 sys_exit(p, &ua, retval);
574 }
575
576 int
577 compat_sparc32_read(p, v, retval)
578 struct proc *p;
579 void *v;
580 register_t *retval;
581 {
582 struct compat_sparc32_read_args /* {
583 syscallarg(int) fd;
584 syscallarg(sparc32_voidp) buf;
585 syscallarg(sparc32_size_t) nbyte;
586 } */ *uap = v;
587 struct sys_read_args ua;
588
589 SPARC32TO64_UAP(fd);
590 SPARC32TOP_UAP(buf, void *);
591 SPARC32TOX_UAP(nbyte, size_t);
592 return sys_read(p, &ua, retval);
593 }
594
595 int
596 compat_sparc32_write(p, v, retval)
597 struct proc *p;
598 void *v;
599 register_t *retval;
600 {
601 struct compat_sparc32_write_args /* {
602 syscallarg(int) fd;
603 syscallarg(const sparc32_voidp) buf;
604 syscallarg(sparc32_size_t) nbyte;
605 } */ *uap = v;
606 struct sys_write_args ua;
607
608 SPARC32TO64_UAP(fd);
609 SPARC32TOP_UAP(buf, void *);
610 SPARC32TOX_UAP(nbyte, size_t);
611 return sys_write(p, &ua, retval);
612 }
613
614 int
615 compat_sparc32_close(p, v, retval)
616 struct proc *p;
617 void *v;
618 register_t *retval;
619 {
620 struct compat_sparc32_close_args /* {
621 syscallarg(int) fd;
622 } */ *uap = v;
623 struct sys_close_args ua;
624
625 SPARC32TO64_UAP(fd);
626 return sys_write(p, &ua, retval);
627 }
628
629 int
630 compat_sparc32_open(p, v, retval)
631 struct proc *p;
632 void *v;
633 register_t *retval;
634 {
635 struct compat_sparc32_open_args /* {
636 syscallarg(const sparc32_charp) path;
637 syscallarg(int) flags;
638 syscallarg(mode_t) mode;
639 } */ *uap = v;
640 struct sys_open_args ua;
641 caddr_t sg;
642
643 SPARC32TOP_UAP(path, const char);
644 SPARC32TO64_UAP(flags);
645 SPARC32TO64_UAP(mode);
646 sg = stackgap_init(p->p_emul);
647 SPARC32_CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
648
649 return (sys_open(p, &ua, retval));
650 }
651
652 int
653 compat_sparc32_wait4(q, v, retval)
654 struct proc *q;
655 void *v;
656 register_t *retval;
657 {
658 struct compat_sparc32_wait4_args /* {
659 syscallarg(int) pid;
660 syscallarg(sparc32_intp) status;
661 syscallarg(int) options;
662 syscallarg(sparc32_rusagep_t) rusage;
663 } */ *uap = v;
664 struct sparc32_rusage ru32;
665 register int nfound;
666 register struct proc *p, *t;
667 int status, error;
668
669 if (SCARG(uap, pid) == 0)
670 SCARG(uap, pid) = -q->p_pgid;
671 if (SCARG(uap, options) &~ (WUNTRACED|WNOHANG))
672 return (EINVAL);
673
674 loop:
675 nfound = 0;
676 for (p = q->p_children.lh_first; p != 0; p = p->p_sibling.le_next) {
677 if (SCARG(uap, pid) != WAIT_ANY &&
678 p->p_pid != SCARG(uap, pid) &&
679 p->p_pgid != -SCARG(uap, pid))
680 continue;
681 nfound++;
682 if (p->p_stat == SZOMB) {
683 retval[0] = p->p_pid;
684
685 if (SCARG(uap, status)) {
686 status = p->p_xstat; /* convert to int */
687 error = copyout((caddr_t)&status,
688 (caddr_t)(u_long)SCARG(uap, status),
689 sizeof(status));
690 if (error)
691 return (error);
692 }
693 if (SCARG(uap, rusage)) {
694 sparc32_from_rusage(p->p_ru, &ru32);
695 if ((error = copyout((caddr_t)&ru32,
696 (caddr_t)(u_long)SCARG(uap, rusage),
697 sizeof(struct sparc32_rusage))))
698 return (error);
699 }
700 /*
701 * If we got the child via ptrace(2) or procfs, and
702 * the parent is different (meaning the process was
703 * attached, rather than run as a child), then we need
704 * to give it back to the old parent, and send the
705 * parent a SIGCHLD. The rest of the cleanup will be
706 * done when the old parent waits on the child.
707 */
708 if ((p->p_flag & P_TRACED) &&
709 p->p_oppid != p->p_pptr->p_pid) {
710 t = pfind(p->p_oppid);
711 proc_reparent(p, t ? t : initproc);
712 p->p_oppid = 0;
713 p->p_flag &= ~(P_TRACED|P_WAITED|P_FSTRACE);
714 psignal(p->p_pptr, SIGCHLD);
715 wakeup((caddr_t)p->p_pptr);
716 return (0);
717 }
718 p->p_xstat = 0;
719 ruadd(&q->p_stats->p_cru, p->p_ru);
720 pool_put(&rusage_pool, p->p_ru);
721
722 /*
723 * Finally finished with old proc entry.
724 * Unlink it from its process group and free it.
725 */
726 leavepgrp(p);
727
728 LIST_REMOVE(p, p_list); /* off zombproc */
729
730 LIST_REMOVE(p, p_sibling);
731
732 /*
733 * Decrement the count of procs running with this uid.
734 */
735 (void)chgproccnt(p->p_cred->p_ruid, -1);
736
737 /*
738 * Free up credentials.
739 */
740 if (--p->p_cred->p_refcnt == 0) {
741 crfree(p->p_cred->pc_ucred);
742 pool_put(&pcred_pool, p->p_cred);
743 }
744
745 /*
746 * Release reference to text vnode
747 */
748 if (p->p_textvp)
749 vrele(p->p_textvp);
750
751 /*
752 * Give machine-dependent layer a chance
753 * to free anything that cpu_exit couldn't
754 * release while still running in process context.
755 */
756 cpu_wait(p);
757 pool_put(&proc_pool, p);
758 nprocs--;
759 return (0);
760 }
761 if (p->p_stat == SSTOP && (p->p_flag & P_WAITED) == 0 &&
762 (p->p_flag & P_TRACED || SCARG(uap, options) & WUNTRACED)) {
763 p->p_flag |= P_WAITED;
764 retval[0] = p->p_pid;
765
766 if (SCARG(uap, status)) {
767 status = W_STOPCODE(p->p_xstat);
768 error = copyout((caddr_t)&status,
769 (caddr_t)(u_long)SCARG(uap, status),
770 sizeof(status));
771 } else
772 error = 0;
773 return (error);
774 }
775 }
776 if (nfound == 0)
777 return (ECHILD);
778 if (SCARG(uap, options) & WNOHANG) {
779 retval[0] = 0;
780 return (0);
781 }
782 if ((error = tsleep((caddr_t)q, PWAIT | PCATCH, "wait", 0)) != 0)
783 return (error);
784 goto loop;
785 }
786
787 int
788 compat_sparc32_link(p, v, retval)
789 struct proc *p;
790 void *v;
791 register_t *retval;
792 {
793 struct compat_sparc32_link_args /* {
794 syscallarg(const sparc32_charp) path;
795 syscallarg(const sparc32_charp) link;
796 } */ *uap = v;
797 struct sys_link_args ua;
798
799 SPARC32TOP_UAP(path, const char);
800 SPARC32TOP_UAP(link, const char);
801 return (sys_link(p, &ua, retval));
802 }
803
804 int
805 compat_sparc32_unlink(p, v, retval)
806 struct proc *p;
807 void *v;
808 register_t *retval;
809 {
810 struct compat_sparc32_unlink_args /* {
811 syscallarg(const sparc32_charp) path;
812 } */ *uap = v;
813 struct sys_unlink_args ua;
814
815 SPARC32TOP_UAP(path, const char);
816
817 return (sys_unlink(p, &ua, retval));
818 }
819
820 int
821 compat_sparc32_chdir(p, v, retval)
822 struct proc *p;
823 void *v;
824 register_t *retval;
825 {
826 struct compat_sparc32_chdir_args /* {
827 syscallarg(const sparc32_charp) path;
828 } */ *uap = v;
829 struct sys_chdir_args ua;
830
831 SPARC32TOP_UAP(path, const char);
832
833 return (sys_chdir(p, &ua, retval));
834 }
835
836 int
837 compat_sparc32_fchdir(p, v, retval)
838 struct proc *p;
839 void *v;
840 register_t *retval;
841 {
842 struct compat_sparc32_fchdir_args /* {
843 syscallarg(int) fd;
844 } */ *uap = v;
845 struct sys_fchdir_args ua;
846
847 SPARC32TO64_UAP(fd);
848
849 return (sys_fchdir(p, &ua, retval));
850 }
851
852 int
853 compat_sparc32_mknod(p, v, retval)
854 struct proc *p;
855 void *v;
856 register_t *retval;
857 {
858 struct compat_sparc32_mknod_args /* {
859 syscallarg(const sparc32_charp) path;
860 syscallarg(mode_t) mode;
861 syscallarg(dev_t) dev;
862 } */ *uap = v;
863 struct sys_mknod_args ua;
864
865 SPARC32TOP_UAP(path, const char);
866 SPARC32TO64_UAP(dev);
867 SPARC32TO64_UAP(mode);
868
869 return (sys_mknod(p, &ua, retval));
870 }
871
872 int
873 compat_sparc32_chmod(p, v, retval)
874 struct proc *p;
875 void *v;
876 register_t *retval;
877 {
878 struct compat_sparc32_chmod_args /* {
879 syscallarg(const sparc32_charp) path;
880 syscallarg(mode_t) mode;
881 } */ *uap = v;
882 struct sys_chmod_args ua;
883
884 SPARC32TOP_UAP(path, const char);
885 SPARC32TO64_UAP(mode);
886
887 return (sys_chmod(p, &ua, retval));
888 }
889
890 int
891 compat_sparc32_chown(p, v, retval)
892 struct proc *p;
893 void *v;
894 register_t *retval;
895 {
896 struct compat_sparc32_chown_args /* {
897 syscallarg(const sparc32_charp) path;
898 syscallarg(uid_t) uid;
899 syscallarg(gid_t) gid;
900 } */ *uap = v;
901 struct sys_chown_args ua;
902
903 SPARC32TOP_UAP(path, const char);
904 SPARC32TO64_UAP(uid);
905 SPARC32TO64_UAP(gid);
906
907 return (sys_chown(p, &ua, retval));
908 }
909
910 int
911 compat_sparc32_break(p, v, retval)
912 struct proc *p;
913 void *v;
914 register_t *retval;
915 {
916 struct compat_sparc32_break_args /* {
917 syscallarg(sparc32_charp) nsize;
918 } */ *uap = v;
919 struct sys_obreak_args ua;
920
921 SCARG(&ua, nsize) = (char *)(u_long)SCARG(uap, nsize);
922 SPARC32TOP_UAP(nsize, char);
923 return (sys_obreak(p, &ua, retval));
924 }
925
926 int
927 compat_sparc32_getfsstat(p, v, retval)
928 struct proc *p;
929 void *v;
930 register_t *retval;
931 {
932 struct compat_sparc32_getfsstat_args /* {
933 syscallarg(sparc32_statfsp_t) buf;
934 syscallarg(sparc32_long) bufsize;
935 syscallarg(int) flags;
936 } */ *uap = v;
937 struct sys_getfsstat_args ua;
938 struct statfs sb;
939 struct sparc32_statfs *sb32p;
940 int error;
941
942 sb32p = (struct sparc32_statfs *)(u_long)SCARG(uap, buf);
943 if (sb32p)
944 SCARG(&ua, buf) = &sb;
945 else
946 SCARG(&ua, buf) = NULL;
947 SPARC32TOX_UAP(bufsize, long);
948 SPARC32TO64_UAP(flags);
949 error = sys_getfsstat(p, &ua, retval);
950 if (error)
951 return (error);
952
953 if (sb32p) {
954 struct sparc32_statfs sb32;
955 sparc32_from_statfs(&sb, &sb32);
956 if (copyout(&sb32, sb32p, sizeof(sb32)))
957 return EFAULT;
958 }
959 return (0);
960 }
961
962 int
963 compat_sparc32_mount(p, v, retval)
964 struct proc *p;
965 void *v;
966 register_t *retval;
967 {
968 struct compat_sparc32_mount_args /* {
969 syscallarg(const sparc32_charp) type;
970 syscallarg(const sparc32_charp) path;
971 syscallarg(int) flags;
972 syscallarg(sparc32_voidp) data;
973 } */ *uap = v;
974 struct sys_mount_args ua;
975
976 SPARC32TOP_UAP(type, const char);
977 SPARC32TOP_UAP(path, const char);
978 SPARC32TO64_UAP(flags);
979 SPARC32TOP_UAP(data, void);
980 return (sys_mount(p, &ua, retval));
981 }
982
983 int
984 compat_sparc32_unmount(p, v, retval)
985 struct proc *p;
986 void *v;
987 register_t *retval;
988 {
989 struct compat_sparc32_unmount_args /* {
990 syscallarg(const sparc32_charp) path;
991 syscallarg(int) flags;
992 } */ *uap = v;
993 struct sys_unmount_args ua;
994
995 SPARC32TOP_UAP(path, const char);
996 SPARC32TO64_UAP(flags);
997 return (sys_unmount(p, &ua, retval));
998 }
999
1000 int
1001 compat_sparc32_setuid(p, v, retval)
1002 struct proc *p;
1003 void *v;
1004 register_t *retval;
1005 {
1006 struct compat_sparc32_setuid_args /* {
1007 syscallarg(uid_t) uid;
1008 } */ *uap = v;
1009 struct sys_setuid_args ua;
1010
1011 SPARC32TO64_UAP(uid);
1012 return (sys_setuid(p, &ua, retval));
1013 }
1014
1015 int
1016 compat_sparc32_ptrace(p, v, retval)
1017 struct proc *p;
1018 void *v;
1019 register_t *retval;
1020 {
1021 struct compat_sparc32_ptrace_args /* {
1022 syscallarg(int) req;
1023 syscallarg(pid_t) pid;
1024 syscallarg(sparc32_caddr_t) addr;
1025 syscallarg(int) data;
1026 } */ *uap = v;
1027 struct sys_ptrace_args ua;
1028
1029 SPARC32TO64_UAP(req);
1030 SPARC32TO64_UAP(pid);
1031 SPARC32TOX64_UAP(addr, caddr_t);
1032 SPARC32TO64_UAP(data);
1033 return (sys_ptrace(p, &ua, retval));
1034 }
1035
1036 int
1037 compat_sparc32_recvmsg(p, v, retval)
1038 struct proc *p;
1039 void *v;
1040 register_t *retval;
1041 {
1042 struct compat_sparc32_recvmsg_args /* {
1043 syscallarg(int) s;
1044 syscallarg(sparc32_msghdrp_t) msg;
1045 syscallarg(int) flags;
1046 } */ *uap = v;
1047 struct sparc32_msghdr msg;
1048 struct iovec aiov[UIO_SMALLIOV], *uiov, *iov;
1049 register int error;
1050
1051 error = copyin((caddr_t)(u_long)SCARG(uap, msg), (caddr_t)&msg,
1052 sizeof(msg));
1053 /* sparc32_msghdr needs the iov pre-allocated */
1054 if (error)
1055 return (error);
1056 if ((u_int)msg.msg_iovlen > UIO_SMALLIOV) {
1057 if ((u_int)msg.msg_iovlen > IOV_MAX)
1058 return (EMSGSIZE);
1059 MALLOC(iov, struct iovec *,
1060 sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
1061 M_WAITOK);
1062 } else if ((u_int)msg.msg_iovlen > 0)
1063 iov = aiov;
1064 else
1065 return (EMSGSIZE);
1066 #ifdef COMPAT_OLDSOCK
1067 msg.msg_flags = SCARG(uap, flags) &~ MSG_COMPAT;
1068 #else
1069 msg.msg_flags = SCARG(uap, flags);
1070 #endif
1071 uiov = (struct iovec *)(u_long)msg.msg_iov;
1072 error = sparc32_to_iovecin((struct sparc32_iovec *)uiov,
1073 iov, msg.msg_iovlen);
1074 if (error)
1075 goto done;
1076 if ((error = recvit32(p, SCARG(uap, s), &msg, iov, (caddr_t)0, retval)) == 0) {
1077 error = copyout((caddr_t)&msg, (caddr_t)(u_long)SCARG(uap, msg),
1078 sizeof(msg));
1079 }
1080 done:
1081 if (iov != aiov)
1082 FREE(iov, M_IOV);
1083 return (error);
1084 }
1085
1086 int
1087 recvit32(p, s, mp, iov, namelenp, retsize)
1088 struct proc *p;
1089 int s;
1090 struct sparc32_msghdr *mp;
1091 struct iovec *iov;
1092 caddr_t namelenp;
1093 register_t *retsize;
1094 {
1095 struct file *fp;
1096 struct uio auio;
1097 register int i;
1098 int len, error;
1099 struct mbuf *from = 0, *control = 0;
1100 struct socket *so;
1101 #ifdef KTRACE
1102 struct iovec *ktriov = NULL;
1103 #endif
1104
1105 if ((error = getsock(p->p_fd, s, &fp)) != 0)
1106 return (error);
1107 auio.uio_iov = (struct iovec *)(u_long)mp->msg_iov;
1108 auio.uio_iovcnt = mp->msg_iovlen;
1109 auio.uio_segflg = UIO_USERSPACE;
1110 auio.uio_rw = UIO_READ;
1111 auio.uio_procp = p;
1112 auio.uio_offset = 0; /* XXX */
1113 auio.uio_resid = 0;
1114 for (i = 0; i < mp->msg_iovlen; i++, iov++) {
1115 #if 0
1116 /* cannot happen iov_len is unsigned */
1117 if (iov->iov_len < 0)
1118 return (EINVAL);
1119 #endif
1120 /*
1121 * Reads return ssize_t because -1 is returned on error.
1122 * Therefore we must restrict the length to SSIZE_MAX to
1123 * avoid garbage return values.
1124 */
1125 auio.uio_resid += iov->iov_len;
1126 if (iov->iov_len > SSIZE_MAX || auio.uio_resid > SSIZE_MAX)
1127 return (EINVAL);
1128 }
1129 #ifdef KTRACE
1130 if (KTRPOINT(p, KTR_GENIO)) {
1131 int iovlen = auio.uio_iovcnt * sizeof(struct iovec);
1132
1133 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
1134 memcpy((caddr_t)ktriov, (caddr_t)auio.uio_iov, iovlen);
1135 }
1136 #endif
1137 len = auio.uio_resid;
1138 so = (struct socket *)fp->f_data;
1139 error = (*so->so_receive)(so, &from, &auio, NULL,
1140 mp->msg_control ? &control : NULL, &mp->msg_flags);
1141 if (error) {
1142 if (auio.uio_resid != len && (error == ERESTART ||
1143 error == EINTR || error == EWOULDBLOCK))
1144 error = 0;
1145 }
1146 #ifdef KTRACE
1147 if (ktriov != NULL) {
1148 if (error == 0)
1149 ktrgenio(p->p_tracep, s, UIO_READ,
1150 ktriov, len - auio.uio_resid, error);
1151 FREE(ktriov, M_TEMP);
1152 }
1153 #endif
1154 if (error)
1155 goto out;
1156 *retsize = len - auio.uio_resid;
1157 if (mp->msg_name) {
1158 len = mp->msg_namelen;
1159 if (len <= 0 || from == 0)
1160 len = 0;
1161 else {
1162 #ifdef COMPAT_OLDSOCK
1163 if (mp->msg_flags & MSG_COMPAT)
1164 mtod(from, struct osockaddr *)->sa_family =
1165 mtod(from, struct sockaddr *)->sa_family;
1166 #endif
1167 if (len > from->m_len)
1168 len = from->m_len;
1169 /* else if len < from->m_len ??? */
1170 error = copyout(mtod(from, caddr_t),
1171 (caddr_t)(u_long)mp->msg_name, (unsigned)len);
1172 if (error)
1173 goto out;
1174 }
1175 mp->msg_namelen = len;
1176 if (namelenp &&
1177 (error = copyout((caddr_t)&len, namelenp, sizeof(int)))) {
1178 #ifdef COMPAT_OLDSOCK
1179 if (mp->msg_flags & MSG_COMPAT)
1180 error = 0; /* old recvfrom didn't check */
1181 else
1182 #endif
1183 goto out;
1184 }
1185 }
1186 if (mp->msg_control) {
1187 #ifdef COMPAT_OLDSOCK
1188 /*
1189 * We assume that old recvmsg calls won't receive access
1190 * rights and other control info, esp. as control info
1191 * is always optional and those options didn't exist in 4.3.
1192 * If we receive rights, trim the cmsghdr; anything else
1193 * is tossed.
1194 */
1195 if (control && mp->msg_flags & MSG_COMPAT) {
1196 if (mtod(control, struct cmsghdr *)->cmsg_level !=
1197 SOL_SOCKET ||
1198 mtod(control, struct cmsghdr *)->cmsg_type !=
1199 SCM_RIGHTS) {
1200 mp->msg_controllen = 0;
1201 goto out;
1202 }
1203 control->m_len -= sizeof(struct cmsghdr);
1204 control->m_data += sizeof(struct cmsghdr);
1205 }
1206 #endif
1207 len = mp->msg_controllen;
1208 if (len <= 0 || control == 0)
1209 len = 0;
1210 else {
1211 struct mbuf *m = control;
1212 caddr_t p = (caddr_t)(u_long)mp->msg_control;
1213
1214 do {
1215 i = m->m_len;
1216 if (len < i) {
1217 mp->msg_flags |= MSG_CTRUNC;
1218 i = len;
1219 }
1220 error = copyout(mtod(m, caddr_t), p,
1221 (unsigned)i);
1222 if (m->m_next)
1223 i = ALIGN(i);
1224 p += i;
1225 len -= i;
1226 if (error != 0 || len <= 0)
1227 break;
1228 } while ((m = m->m_next) != NULL);
1229 len = p - (caddr_t)(u_long)mp->msg_control;
1230 }
1231 mp->msg_controllen = len;
1232 }
1233 out:
1234 if (from)
1235 m_freem(from);
1236 if (control)
1237 m_freem(control);
1238 return (error);
1239 }
1240
1241
1242 int
1243 compat_sparc32_sendmsg(p, v, retval)
1244 struct proc *p;
1245 void *v;
1246 register_t *retval;
1247 {
1248 struct compat_sparc32_sendmsg_args /* {
1249 syscallarg(int) s;
1250 syscallarg(const sparc32_msghdrp_t) msg;
1251 syscallarg(int) flags;
1252 } */ *uap = v;
1253 struct msghdr msg;
1254 struct sparc32_msghdr msg32;
1255 struct iovec aiov[UIO_SMALLIOV], *iov;
1256 int error;
1257
1258 error = copyin((caddr_t)(u_long)SCARG(uap, msg),
1259 (caddr_t)&msg32, sizeof(msg32));
1260 if (error)
1261 return (error);
1262 sparc32_to_msghdr(&msg32, &msg);
1263 if ((u_int)msg.msg_iovlen > UIO_SMALLIOV) {
1264 if ((u_int)msg.msg_iovlen > IOV_MAX)
1265 return (EMSGSIZE);
1266 MALLOC(iov, struct iovec *,
1267 sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
1268 M_WAITOK);
1269 } else if ((u_int)msg.msg_iovlen > 0)
1270 iov = aiov;
1271 else
1272 return (EMSGSIZE);
1273 error = sparc32_to_iovecin((struct sparc32_iovec *)msg.msg_iov,
1274 iov, msg.msg_iovlen);
1275 if (error)
1276 goto done;
1277 msg.msg_iov = iov;
1278 #ifdef COMPAT_OLDSOCK
1279 msg.msg_flags = 0;
1280 #endif
1281 /* Luckily we can use this directly */
1282 error = sendit(p, SCARG(uap, s), &msg, SCARG(uap, flags), retval);
1283 done:
1284 if (iov != aiov)
1285 FREE(iov, M_IOV);
1286 return (error);
1287 }
1288
1289 int
1290 compat_sparc32_recvfrom(p, v, retval)
1291 struct proc *p;
1292 void *v;
1293 register_t *retval;
1294 {
1295 struct compat_sparc32_recvfrom_args /* {
1296 syscallarg(int) s;
1297 syscallarg(sparc32_voidp) buf;
1298 syscallarg(sparc32_size_t) len;
1299 syscallarg(int) flags;
1300 syscallarg(sparc32_sockaddrp_t) from;
1301 syscallarg(sparc32_intp) fromlenaddr;
1302 } */ *uap = v;
1303 struct sparc32_msghdr msg;
1304 struct iovec aiov;
1305 int error;
1306
1307 if (SCARG(uap, fromlenaddr)) {
1308 error = copyin((caddr_t)(u_long)SCARG(uap, fromlenaddr),
1309 (caddr_t)&msg.msg_namelen,
1310 sizeof(msg.msg_namelen));
1311 if (error)
1312 return (error);
1313 } else
1314 msg.msg_namelen = 0;
1315 msg.msg_name = SCARG(uap, from);
1316 msg.msg_iov = NULL; /* We can't store a real pointer here */
1317 msg.msg_iovlen = 1;
1318 aiov.iov_base = (caddr_t)(u_long)SCARG(uap, buf);
1319 aiov.iov_len = (u_long)SCARG(uap, len);
1320 msg.msg_control = 0;
1321 msg.msg_flags = SCARG(uap, flags);
1322 return (recvit32(p, SCARG(uap, s), &msg, &aiov,
1323 (caddr_t)(u_long)SCARG(uap, fromlenaddr), retval));
1324 }
1325
1326 int
1327 compat_sparc32_sendto(p, v, retval)
1328 struct proc *p;
1329 void *v;
1330 register_t *retval;
1331 {
1332 struct compat_sparc32_sendto_args /* {
1333 syscallarg(int) s;
1334 syscallarg(const sparc32_voidp) buf;
1335 syscallarg(sparc32_size_t) len;
1336 syscallarg(int) flags;
1337 syscallarg(const sparc32_sockaddrp_t) to;
1338 syscallarg(int) tolen;
1339 } */ *uap = v;
1340 struct msghdr msg;
1341 struct iovec aiov;
1342
1343 msg.msg_name = (caddr_t)(u_long)SCARG(uap, to); /* XXX kills const */
1344 msg.msg_namelen = SCARG(uap, tolen);
1345 msg.msg_iov = &aiov;
1346 msg.msg_iovlen = 1;
1347 msg.msg_control = 0;
1348 #ifdef COMPAT_OLDSOCK
1349 msg.msg_flags = 0;
1350 #endif
1351 aiov.iov_base = (char *)(u_long)SCARG(uap, buf); /* XXX kills const */
1352 aiov.iov_len = SCARG(uap, len);
1353 return (sendit(p, SCARG(uap, s), &msg, SCARG(uap, flags), retval));
1354 }
1355
1356 int
1357 compat_sparc32_accept(p, v, retval)
1358 struct proc *p;
1359 void *v;
1360 register_t *retval;
1361 {
1362 struct compat_sparc32_accept_args /* {
1363 syscallarg(int) s;
1364 syscallarg(sparc32_sockaddrp_t) name;
1365 syscallarg(sparc32_intp) anamelen;
1366 } */ *uap = v;
1367 struct sys_accept_args ua;
1368
1369 SPARC32TO64_UAP(s);
1370 SPARC32TOP_UAP(name, struct sockaddr);
1371 SPARC32TOP_UAP(anamelen, int);
1372 return (sys_accept(p, &ua, retval));
1373 }
1374
1375 int
1376 compat_sparc32_getpeername(p, v, retval)
1377 struct proc *p;
1378 void *v;
1379 register_t *retval;
1380 {
1381 struct compat_sparc32_getpeername_args /* {
1382 syscallarg(int) fdes;
1383 syscallarg(sparc32_sockaddrp_t) asa;
1384 syscallarg(sparc32_intp) alen;
1385 } */ *uap = v;
1386 struct sys_getpeername_args ua;
1387
1388 SPARC32TO64_UAP(fdes);
1389 SPARC32TOP_UAP(asa, struct sockaddr);
1390 SPARC32TOP_UAP(alen, int);
1391 /* NB: do the protocol specific sockaddrs need to be converted? */
1392 return (sys_getpeername(p, &ua, retval));
1393 }
1394
1395 int
1396 compat_sparc32_getsockname(p, v, retval)
1397 struct proc *p;
1398 void *v;
1399 register_t *retval;
1400 {
1401 struct compat_sparc32_getsockname_args /* {
1402 syscallarg(int) fdes;
1403 syscallarg(sparc32_sockaddrp_t) asa;
1404 syscallarg(sparc32_intp) alen;
1405 } */ *uap = v;
1406 struct sys_getsockname_args ua;
1407
1408 SPARC32TO64_UAP(fdes);
1409 SPARC32TOP_UAP(asa, struct sockaddr);
1410 SPARC32TOP_UAP(alen, int);
1411 return (sys_getsockname(p, &ua, retval));
1412 }
1413
1414 int
1415 compat_sparc32_access(p, v, retval)
1416 struct proc *p;
1417 void *v;
1418 register_t *retval;
1419 {
1420 struct compat_sparc32_access_args /* {
1421 syscallarg(const sparc32_charp) path;
1422 syscallarg(int) flags;
1423 } */ *uap = v;
1424 struct sys_access_args ua;
1425 caddr_t sg;
1426
1427 SPARC32TOP_UAP(path, const char);
1428 SPARC32TO64_UAP(flags);
1429 sg = stackgap_init(p->p_emul);
1430 SPARC32_CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
1431
1432 return (sys_access(p, &ua, retval));
1433 }
1434
1435 int
1436 compat_sparc32_chflags(p, v, retval)
1437 struct proc *p;
1438 void *v;
1439 register_t *retval;
1440 {
1441 struct compat_sparc32_chflags_args /* {
1442 syscallarg(const sparc32_charp) path;
1443 syscallarg(sparc32_u_long) flags;
1444 } */ *uap = v;
1445 struct sys_chflags_args ua;
1446
1447 SPARC32TOP_UAP(path, const char);
1448 SPARC32TO64_UAP(flags);
1449
1450 return (sys_chflags(p, &ua, retval));
1451 }
1452
1453 int
1454 compat_sparc32_fchflags(p, v, retval)
1455 struct proc *p;
1456 void *v;
1457 register_t *retval;
1458 {
1459 struct compat_sparc32_fchflags_args /* {
1460 syscallarg(int) fd;
1461 syscallarg(sparc32_u_long) flags;
1462 } */ *uap = v;
1463 struct sys_fchflags_args ua;
1464
1465 SPARC32TO64_UAP(fd);
1466 SPARC32TO64_UAP(flags);
1467
1468 return (sys_fchflags(p, &ua, retval));
1469 }
1470
1471 int
1472 compat_sparc32_kill(p, v, retval)
1473 struct proc *p;
1474 void *v;
1475 register_t *retval;
1476 {
1477 struct compat_sparc32_kill_args /* {
1478 syscallarg(int) pid;
1479 syscallarg(int) signum;
1480 } */ *uap = v;
1481 struct sys_kill_args ua;
1482
1483 SPARC32TO64_UAP(pid);
1484 SPARC32TO64_UAP(signum);
1485
1486 return (sys_kill(p, &ua, retval));
1487 }
1488
1489 int
1490 compat_sparc32_dup(p, v, retval)
1491 struct proc *p;
1492 void *v;
1493 register_t *retval;
1494 {
1495 struct compat_sparc32_dup_args /* {
1496 syscallarg(int) fd;
1497 } */ *uap = v;
1498 struct sys_dup_args ua;
1499
1500 SPARC32TO64_UAP(fd);
1501
1502 return (sys_dup(p, &ua, retval));
1503 }
1504
1505 int
1506 compat_sparc32_profil(p, v, retval)
1507 struct proc *p;
1508 void *v;
1509 register_t *retval;
1510 {
1511 struct compat_sparc32_profil_args /* {
1512 syscallarg(sparc32_caddr_t) samples;
1513 syscallarg(sparc32_size_t) size;
1514 syscallarg(sparc32_u_long) offset;
1515 syscallarg(u_int) scale;
1516 } */ *uap = v;
1517 struct sys_profil_args ua;
1518
1519 SPARC32TOX64_UAP(samples, caddr_t);
1520 SPARC32TOX_UAP(size, size_t);
1521 SPARC32TOX_UAP(offset, u_long);
1522 SPARC32TO64_UAP(scale);
1523 return (sys_profil(p, &ua, retval));
1524 }
1525
1526 int
1527 compat_sparc32_ktrace(p, v, retval)
1528 struct proc *p;
1529 void *v;
1530 register_t *retval;
1531 {
1532 struct compat_sparc32_ktrace_args /* {
1533 syscallarg(const sparc32_charp) fname;
1534 syscallarg(int) ops;
1535 syscallarg(int) facs;
1536 syscallarg(int) pid;
1537 } */ *uap = v;
1538 struct sys_ktrace_args ua;
1539
1540 SPARC32TOP_UAP(fname, const char);
1541 SPARC32TO64_UAP(ops);
1542 SPARC32TO64_UAP(facs);
1543 SPARC32TO64_UAP(pid);
1544 return (sys_ktrace(p, &ua, retval));
1545 }
1546
1547 int
1548 compat_sparc32_sigaction(p, v, retval)
1549 struct proc *p;
1550 void *v;
1551 register_t *retval;
1552 {
1553 struct compat_sparc32_sigaction_args /* {
1554 syscallarg(int) signum;
1555 syscallarg(const sparc32_sigactionp_t) nsa;
1556 syscallarg(sparc32_sigactionp_t) osa;
1557 } */ *uap = v;
1558 struct sigaction nsa, osa;
1559 struct sparc32_sigaction *sa32p, sa32;
1560 int error;
1561
1562 if (SCARG(uap, nsa)) {
1563 sa32p = (struct sparc32_sigaction *)(u_long)SCARG(uap, nsa);
1564 if (copyin(sa32p, &sa32, sizeof(sa32)))
1565 return EFAULT;
1566 nsa.sa_handler = (void *)(u_long)sa32.sa_handler;
1567 nsa.sa_mask = sa32.sa_mask;
1568 nsa.sa_flags = sa32.sa_flags;
1569 }
1570 error = sigaction1(p, SCARG(uap, signum),
1571 SCARG(uap, nsa) ? &nsa : 0,
1572 SCARG(uap, osa) ? &osa : 0);
1573
1574 if (error)
1575 return (error);
1576
1577 if (SCARG(uap, osa)) {
1578 sa32.sa_handler = (sparc32_sigactionp_t)(u_long)osa.sa_handler;
1579 sa32.sa_mask = osa.sa_mask;
1580 sa32.sa_flags = osa.sa_flags;
1581 sa32p = (struct sparc32_sigaction *)(u_long)SCARG(uap, osa);
1582 if (copyout(&sa32, sa32p, sizeof(sa32)))
1583 return EFAULT;
1584 }
1585
1586 return (0);
1587 }
1588
1589 int
1590 compat_sparc32___getlogin(p, v, retval)
1591 struct proc *p;
1592 void *v;
1593 register_t *retval;
1594 {
1595 struct compat_sparc32___getlogin_args /* {
1596 syscallarg(sparc32_charp) namebuf;
1597 syscallarg(u_int) namelen;
1598 } */ *uap = v;
1599 struct sys___getlogin_args ua;
1600
1601 SPARC32TOP_UAP(namebuf, char);
1602 SPARC32TO64_UAP(namelen);
1603 return (sys___getlogin(p, &ua, retval));
1604 }
1605
1606 int
1607 compat_sparc32_setlogin(p, v, retval)
1608 struct proc *p;
1609 void *v;
1610 register_t *retval;
1611 {
1612 struct compat_sparc32_setlogin_args /* {
1613 syscallarg(const sparc32_charp) namebuf;
1614 } */ *uap = v;
1615 struct sys_setlogin_args ua;
1616
1617 SPARC32TOP_UAP(namebuf, char);
1618 return (sys_setlogin(p, &ua, retval));
1619 }
1620
1621 int
1622 compat_sparc32_acct(p, v, retval)
1623 struct proc *p;
1624 void *v;
1625 register_t *retval;
1626 {
1627 struct compat_sparc32_acct_args /* {
1628 syscallarg(const sparc32_charp) path;
1629 } */ *uap = v;
1630 struct sys_acct_args ua;
1631
1632 SPARC32TOP_UAP(path, const char);
1633 return (sys_acct(p, &ua, retval));
1634 }
1635
1636 int
1637 compat_sparc32_revoke(p, v, retval)
1638 struct proc *p;
1639 void *v;
1640 register_t *retval;
1641 {
1642 struct compat_sparc32_revoke_args /* {
1643 syscallarg(const sparc32_charp) path;
1644 } */ *uap = v;
1645 struct sys_revoke_args ua;
1646 caddr_t sg;
1647
1648 SPARC32TOP_UAP(path, const char);
1649 sg = stackgap_init(p->p_emul);
1650 SPARC32_CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
1651
1652 return (sys_revoke(p, &ua, retval));
1653 }
1654
1655 int
1656 compat_sparc32_symlink(p, v, retval)
1657 struct proc *p;
1658 void *v;
1659 register_t *retval;
1660 {
1661 struct compat_sparc32_symlink_args /* {
1662 syscallarg(const sparc32_charp) path;
1663 syscallarg(const sparc32_charp) link;
1664 } */ *uap = v;
1665 struct sys_symlink_args ua;
1666
1667 SPARC32TOP_UAP(path, const char);
1668 SPARC32TOP_UAP(link, const char);
1669
1670 return (sys_symlink(p, &ua, retval));
1671 }
1672
1673 int
1674 compat_sparc32_readlink(p, v, retval)
1675 struct proc *p;
1676 void *v;
1677 register_t *retval;
1678 {
1679 struct compat_sparc32_readlink_args /* {
1680 syscallarg(const sparc32_charp) path;
1681 syscallarg(sparc32_charp) buf;
1682 syscallarg(sparc32_size_t) count;
1683 } */ *uap = v;
1684 struct sys_readlink_args ua;
1685 caddr_t sg;
1686
1687 SPARC32TOP_UAP(path, const char);
1688 SPARC32TOP_UAP(buf, char);
1689 SPARC32TOX_UAP(count, size_t);
1690 sg = stackgap_init(p->p_emul);
1691 SPARC32_CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
1692
1693 return (sys_readlink(p, &ua, retval));
1694 }
1695
1696 int
1697 compat_sparc32_execve(p, v, retval)
1698 struct proc *p;
1699 void *v;
1700 register_t *retval;
1701 {
1702 struct compat_sparc32_execve_args /* {
1703 syscallarg(const sparc32_charp) path;
1704 syscallarg(sparc32_charpp) argp;
1705 syscallarg(sparc32_charpp) envp;
1706 } */ *uap = v;
1707 struct sys_execve_args ua;
1708 caddr_t sg;
1709
1710 SPARC32TOP_UAP(path, const char);
1711 SPARC32TOP_UAP(argp, char *);
1712 SPARC32TOP_UAP(envp, char *);
1713 sg = stackgap_init(p->p_emul);
1714 SPARC32_CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
1715
1716 return (sys_execve(p, &ua, retval));
1717 }
1718
1719 int
1720 compat_sparc32_umask(p, v, retval)
1721 struct proc *p;
1722 void *v;
1723 register_t *retval;
1724 {
1725 struct compat_sparc32_umask_args /* {
1726 syscallarg(mode_t) newmask;
1727 } */ *uap = v;
1728 struct sys_umask_args ua;
1729
1730 SPARC32TO64_UAP(newmask);
1731 return (sys_umask(p, &ua, retval));
1732 }
1733
1734 int
1735 compat_sparc32_chroot(p, v, retval)
1736 struct proc *p;
1737 void *v;
1738 register_t *retval;
1739 {
1740 struct compat_sparc32_chroot_args /* {
1741 syscallarg(const sparc32_charp) path;
1742 } */ *uap = v;
1743 struct sys_chroot_args ua;
1744
1745 SPARC32TOP_UAP(path, const char);
1746 return (sys_chroot(p, &ua, retval));
1747 }
1748
1749 int
1750 compat_sparc32_sbrk(p, v, retval)
1751 struct proc *p;
1752 void *v;
1753 register_t *retval;
1754 {
1755 struct compat_sparc32_sbrk_args /* {
1756 syscallarg(int) incr;
1757 } */ *uap = v;
1758 struct sys_sbrk_args ua;
1759
1760 SPARC32TO64_UAP(incr);
1761 return (sys_sbrk(p, &ua, retval));
1762 }
1763
1764 int
1765 compat_sparc32_sstk(p, v, retval)
1766 struct proc *p;
1767 void *v;
1768 register_t *retval;
1769 {
1770 struct compat_sparc32_sstk_args /* {
1771 syscallarg(int) incr;
1772 } */ *uap = v;
1773 struct sys_sstk_args ua;
1774
1775 SPARC32TO64_UAP(incr);
1776 return (sys_sstk(p, &ua, retval));
1777 }
1778
1779 int
1780 compat_sparc32_munmap(p, v, retval)
1781 struct proc *p;
1782 void *v;
1783 register_t *retval;
1784 {
1785 struct compat_sparc32_munmap_args /* {
1786 syscallarg(sparc32_voidp) addr;
1787 syscallarg(sparc32_size_t) len;
1788 } */ *uap = v;
1789 struct sys_munmap_args ua;
1790
1791 SPARC32TOP_UAP(addr, void);
1792 SPARC32TOX_UAP(len, size_t);
1793 return (sys_munmap(p, &ua, retval));
1794 }
1795
1796 int
1797 compat_sparc32_mprotect(p, v, retval)
1798 struct proc *p;
1799 void *v;
1800 register_t *retval;
1801 {
1802 struct compat_sparc32_mprotect_args /* {
1803 syscallarg(sparc32_voidp) addr;
1804 syscallarg(sparc32_size_t) len;
1805 syscallarg(int) prot;
1806 } */ *uap = v;
1807 struct sys_mprotect_args ua;
1808
1809 SPARC32TOP_UAP(addr, void);
1810 SPARC32TOX_UAP(len, size_t);
1811 SPARC32TO64_UAP(prot);
1812 return (sys_mprotect(p, &ua, retval));
1813 }
1814
1815 int
1816 compat_sparc32_madvise(p, v, retval)
1817 struct proc *p;
1818 void *v;
1819 register_t *retval;
1820 {
1821 struct compat_sparc32_madvise_args /* {
1822 syscallarg(sparc32_voidp) addr;
1823 syscallarg(sparc32_size_t) len;
1824 syscallarg(int) behav;
1825 } */ *uap = v;
1826 struct sys_madvise_args ua;
1827
1828 SPARC32TOP_UAP(addr, void);
1829 SPARC32TOX_UAP(len, size_t);
1830 SPARC32TO64_UAP(behav);
1831 return (sys_madvise(p, &ua, retval));
1832 }
1833
1834 int
1835 compat_sparc32_mincore(p, v, retval)
1836 struct proc *p;
1837 void *v;
1838 register_t *retval;
1839 {
1840 struct compat_sparc32_mincore_args /* {
1841 syscallarg(sparc32_caddr_t) addr;
1842 syscallarg(sparc32_size_t) len;
1843 syscallarg(sparc32_charp) vec;
1844 } */ *uap = v;
1845 struct sys_mincore_args ua;
1846
1847 SPARC32TOX64_UAP(addr, caddr_t);
1848 SPARC32TOX_UAP(len, size_t);
1849 SPARC32TOP_UAP(vec, char);
1850 return (sys_mincore(p, &ua, retval));
1851 }
1852
1853 int
1854 compat_sparc32_getgroups(p, v, retval)
1855 struct proc *p;
1856 void *v;
1857 register_t *retval;
1858 {
1859 struct compat_sparc32_getgroups_args /* {
1860 syscallarg(int) gidsetsize;
1861 syscallarg(sparc32_gid_tp) gidset;
1862 } */ *uap = v;
1863 register struct pcred *pc = p->p_cred;
1864 register int ngrp;
1865 int error;
1866
1867 ngrp = SCARG(uap, gidsetsize);
1868 if (ngrp == 0) {
1869 *retval = pc->pc_ucred->cr_ngroups;
1870 return (0);
1871 }
1872 if (ngrp < pc->pc_ucred->cr_ngroups)
1873 return (EINVAL);
1874 ngrp = pc->pc_ucred->cr_ngroups;
1875 /* Should convert gid_t to sparc32_gid_t, but they're the same */
1876 error = copyout((caddr_t)pc->pc_ucred->cr_groups,
1877 (caddr_t)(u_long)SCARG(uap, gidset),
1878 ngrp * sizeof(gid_t));
1879 if (error)
1880 return (error);
1881 *retval = ngrp;
1882 return (0);
1883 }
1884
1885 int
1886 compat_sparc32_setgroups(p, v, retval)
1887 struct proc *p;
1888 void *v;
1889 register_t *retval;
1890 {
1891 struct compat_sparc32_setgroups_args /* {
1892 syscallarg(int) gidsetsize;
1893 syscallarg(const sparc32_gid_tp) gidset;
1894 } */ *uap = v;
1895 struct sys_setgroups_args ua;
1896
1897 SPARC32TO64_UAP(gidsetsize);
1898 SPARC32TOP_UAP(gidset, gid_t);
1899 return (sys_setgroups(p, &ua, retval));
1900 }
1901
1902 int
1903 compat_sparc32_setpgid(p, v, retval)
1904 struct proc *p;
1905 void *v;
1906 register_t *retval;
1907 {
1908 struct compat_sparc32_setpgid_args /* {
1909 syscallarg(int) pid;
1910 syscallarg(int) pgid;
1911 } */ *uap = v;
1912 struct sys_setpgid_args ua;
1913
1914 SPARC32TO64_UAP(pid);
1915 SPARC32TO64_UAP(pgid);
1916 return (sys_setpgid(p, &ua, retval));
1917 }
1918
1919 int
1920 compat_sparc32_setitimer(p, v, retval)
1921 struct proc *p;
1922 void *v;
1923 register_t *retval;
1924 {
1925 struct compat_sparc32_setitimer_args /* {
1926 syscallarg(int) which;
1927 syscallarg(const sparc32_itimervalp_t) itv;
1928 syscallarg(sparc32_itimervalp_t) oitv;
1929 } */ *uap = v;
1930 struct sparc32_itimerval s32it, *itvp;
1931 int which = SCARG(uap, which);
1932 struct compat_sparc32_getitimer_args getargs;
1933 struct itimerval aitv;
1934 int s, error;
1935
1936 if ((u_int)which > ITIMER_PROF)
1937 return (EINVAL);
1938 itvp = (struct sparc32_itimerval *)(u_long)SCARG(uap, itv);
1939 if (itvp && (error = copyin(itvp, &s32it, sizeof(s32it))))
1940 return (error);
1941 sparc32_to_itimerval(&s32it, &aitv);
1942 if (SCARG(uap, oitv) != NULL) {
1943 SCARG(&getargs, which) = which;
1944 SCARG(&getargs, itv) = SCARG(uap, oitv);
1945 if ((error = compat_sparc32_getitimer(p, &getargs, retval)) != 0)
1946 return (error);
1947 }
1948 if (itvp == 0)
1949 return (0);
1950 if (itimerfix(&aitv.it_value) || itimerfix(&aitv.it_interval))
1951 return (EINVAL);
1952 s = splclock();
1953 if (which == ITIMER_REAL) {
1954 untimeout(realitexpire, p);
1955 if (timerisset(&aitv.it_value)) {
1956 timeradd(&aitv.it_value, &time, &aitv.it_value);
1957 timeout(realitexpire, p, hzto(&aitv.it_value));
1958 }
1959 p->p_realtimer = aitv;
1960 } else
1961 p->p_stats->p_timer[which] = aitv;
1962 splx(s);
1963 return (0);
1964 }
1965
1966 int
1967 compat_sparc32_getitimer(p, v, retval)
1968 struct proc *p;
1969 void *v;
1970 register_t *retval;
1971 {
1972 struct compat_sparc32_getitimer_args /* {
1973 syscallarg(int) which;
1974 syscallarg(sparc32_itimervalp_t) itv;
1975 } */ *uap = v;
1976 int which = SCARG(uap, which);
1977 struct sparc32_itimerval s32it;
1978 struct itimerval aitv;
1979 int s;
1980
1981 if ((u_int)which > ITIMER_PROF)
1982 return (EINVAL);
1983 s = splclock();
1984 if (which == ITIMER_REAL) {
1985 /*
1986 * Convert from absolute to relative time in .it_value
1987 * part of real time timer. If time for real time timer
1988 * has passed return 0, else return difference between
1989 * current time and time for the timer to go off.
1990 */
1991 aitv = p->p_realtimer;
1992 if (timerisset(&aitv.it_value)) {
1993 if (timercmp(&aitv.it_value, &time, <))
1994 timerclear(&aitv.it_value);
1995 else
1996 timersub(&aitv.it_value, &time, &aitv.it_value);
1997 }
1998 } else
1999 aitv = p->p_stats->p_timer[which];
2000 splx(s);
2001 sparc32_from_itimerval(&aitv, &s32it);
2002 return (copyout(&s32it, (caddr_t)(u_long)SCARG(uap, itv), sizeof(s32it)));
2003 }
2004
2005 int
2006 compat_sparc32_fcntl(p, v, retval)
2007 struct proc *p;
2008 void *v;
2009 register_t *retval;
2010 {
2011 struct compat_sparc32_fcntl_args /* {
2012 syscallarg(int) fd;
2013 syscallarg(int) cmd;
2014 syscallarg(sparc32_voidp) arg;
2015 } */ *uap = v;
2016 struct sys_fcntl_args ua;
2017
2018 SPARC32TO64_UAP(fd);
2019 SPARC32TO64_UAP(cmd);
2020 SPARC32TOP_UAP(arg, void);
2021 /* XXXX we can do this 'cause flock doesn't change */
2022 return (sys_fcntl(p, &ua, retval));
2023 }
2024
2025 int
2026 compat_sparc32_dup2(p, v, retval)
2027 struct proc *p;
2028 void *v;
2029 register_t *retval;
2030 {
2031 struct compat_sparc32_dup2_args /* {
2032 syscallarg(int) from;
2033 syscallarg(int) to;
2034 } */ *uap = v;
2035 struct sys_dup2_args ua;
2036
2037 SPARC32TO64_UAP(from);
2038 SPARC32TO64_UAP(to);
2039 return (sys_dup2(p, &ua, retval));
2040 }
2041
2042 int
2043 compat_sparc32_select(p, v, retval)
2044 struct proc *p;
2045 void *v;
2046 register_t *retval;
2047 {
2048 struct compat_sparc32_select_args /* {
2049 syscallarg(int) nd;
2050 syscallarg(sparc32_fd_setp_t) in;
2051 syscallarg(sparc32_fd_setp_t) ou;
2052 syscallarg(sparc32_fd_setp_t) ex;
2053 syscallarg(sparc32_timevalp_t) tv;
2054 } */ *uap = v;
2055 /* This one must be done in-line 'cause of the timeval */
2056 struct sparc32_timeval tv32;
2057 caddr_t bits;
2058 char smallbits[howmany(FD_SETSIZE, NFDBITS) * sizeof(fd_mask) * 6];
2059 struct timeval atv;
2060 int s, ncoll, error = 0, timo;
2061 size_t ni;
2062 extern int selwait, nselcoll;
2063 extern int selscan __P((struct proc *, fd_mask *, fd_mask *, int, register_t *));
2064
2065 if (SCARG(uap, nd) < 0)
2066 return (EINVAL);
2067 if (SCARG(uap, nd) > p->p_fd->fd_nfiles) {
2068 /* forgiving; slightly wrong */
2069 SCARG(uap, nd) = p->p_fd->fd_nfiles;
2070 }
2071 ni = howmany(SCARG(uap, nd), NFDBITS) * sizeof(fd_mask);
2072 if (ni * 6 > sizeof(smallbits))
2073 bits = malloc(ni * 6, M_TEMP, M_WAITOK);
2074 else
2075 bits = smallbits;
2076
2077 #define getbits(name, x) \
2078 if (SCARG(uap, name)) { \
2079 error = copyin((caddr_t)(u_long)SCARG(uap, name), bits + ni * x, ni); \
2080 if (error) \
2081 goto done; \
2082 } else \
2083 memset(bits + ni * x, 0, ni);
2084 getbits(in, 0);
2085 getbits(ou, 1);
2086 getbits(ex, 2);
2087 #undef getbits
2088
2089 if (SCARG(uap, tv)) {
2090 error = copyin((caddr_t)(u_long)SCARG(uap, tv), (caddr_t)&tv32,
2091 sizeof(tv32));
2092 if (error)
2093 goto done;
2094 sparc32_to_timeval(&tv32, &atv);
2095 if (itimerfix(&atv)) {
2096 error = EINVAL;
2097 goto done;
2098 }
2099 s = splclock();
2100 timeradd(&atv, &time, &atv);
2101 timo = hzto(&atv);
2102 /*
2103 * Avoid inadvertently sleeping forever.
2104 */
2105 if (timo == 0)
2106 timo = 1;
2107 splx(s);
2108 } else
2109 timo = 0;
2110 retry:
2111 ncoll = nselcoll;
2112 p->p_flag |= P_SELECT;
2113 error = selscan(p, (fd_mask *)(bits + ni * 0),
2114 (fd_mask *)(bits + ni * 3), SCARG(uap, nd), retval);
2115 if (error || *retval)
2116 goto done;
2117 s = splhigh();
2118 if (timo && timercmp(&time, &atv, >=)) {
2119 splx(s);
2120 goto done;
2121 }
2122 if ((p->p_flag & P_SELECT) == 0 || nselcoll != ncoll) {
2123 splx(s);
2124 goto retry;
2125 }
2126 p->p_flag &= ~P_SELECT;
2127 error = tsleep((caddr_t)&selwait, PSOCK | PCATCH, "select", timo);
2128 splx(s);
2129 if (error == 0)
2130 goto retry;
2131 done:
2132 p->p_flag &= ~P_SELECT;
2133 /* select is not restarted after signals... */
2134 if (error == ERESTART)
2135 error = EINTR;
2136 if (error == EWOULDBLOCK)
2137 error = 0;
2138 if (error == 0) {
2139 #define putbits(name, x) \
2140 if (SCARG(uap, name)) { \
2141 error = copyout(bits + ni * x, (caddr_t)(u_long)SCARG(uap, name), ni); \
2142 if (error) \
2143 goto out; \
2144 }
2145 putbits(in, 3);
2146 putbits(ou, 4);
2147 putbits(ex, 5);
2148 #undef putbits
2149 }
2150 out:
2151 if (ni * 6 > sizeof(smallbits))
2152 free(bits, M_TEMP);
2153 return (error);
2154 }
2155
2156 int
2157 compat_sparc32_fsync(p, v, retval)
2158 struct proc *p;
2159 void *v;
2160 register_t *retval;
2161 {
2162 struct compat_sparc32_fsync_args /* {
2163 syscallarg(int) fd;
2164 } */ *uap = v;
2165 struct sys_fsync_args ua;
2166
2167 SPARC32TO64_UAP(fd);
2168 return (sys_fsync(p, &ua, retval));
2169 }
2170
2171 int
2172 compat_sparc32_setpriority(p, v, retval)
2173 struct proc *p;
2174 void *v;
2175 register_t *retval;
2176 {
2177 struct compat_sparc32_setpriority_args /* {
2178 syscallarg(int) which;
2179 syscallarg(int) who;
2180 syscallarg(int) prio;
2181 } */ *uap = v;
2182 struct sys_setpriority_args ua;
2183
2184 SPARC32TO64_UAP(which);
2185 SPARC32TO64_UAP(who);
2186 SPARC32TO64_UAP(prio);
2187 return (sys_setpriority(p, &ua, retval));
2188 }
2189
2190 int
2191 compat_sparc32_socket(p, v, retval)
2192 struct proc *p;
2193 void *v;
2194 register_t *retval;
2195 {
2196 struct compat_sparc32_socket_args /* {
2197 syscallarg(int) domain;
2198 syscallarg(int) type;
2199 syscallarg(int) protocol;
2200 } */ *uap = v;
2201 struct sys_socket_args ua;
2202
2203 SPARC32TO64_UAP(domain);
2204 SPARC32TO64_UAP(type);
2205 SPARC32TO64_UAP(protocol);
2206 return (sys_socket(p, &ua, retval));
2207 }
2208
2209 int
2210 compat_sparc32_connect(p, v, retval)
2211 struct proc *p;
2212 void *v;
2213 register_t *retval;
2214 {
2215 struct compat_sparc32_connect_args /* {
2216 syscallarg(int) s;
2217 syscallarg(const sparc32_sockaddrp_t) name;
2218 syscallarg(int) namelen;
2219 } */ *uap = v;
2220 struct sys_connect_args ua;
2221
2222 SPARC32TO64_UAP(s);
2223 SPARC32TOP_UAP(name, struct sockaddr);
2224 SPARC32TO64_UAP(namelen);
2225 return (sys_connect(p, &ua, retval));
2226 }
2227
2228 int
2229 compat_sparc32_getpriority(p, v, retval)
2230 struct proc *p;
2231 void *v;
2232 register_t *retval;
2233 {
2234 struct compat_sparc32_getpriority_args /* {
2235 syscallarg(int) which;
2236 syscallarg(int) who;
2237 } */ *uap = v;
2238 struct sys_getpriority_args ua;
2239
2240 SPARC32TO64_UAP(which);
2241 SPARC32TO64_UAP(who);
2242 return (sys_getpriority(p, &ua, retval));
2243 }
2244
2245 #undef DEBUG
2246 int
2247 compat_sparc32_sigreturn(p, v, retval)
2248 struct proc *p;
2249 void *v;
2250 register_t *retval;
2251 {
2252 struct compat_sparc32_sigreturn_args /* {
2253 syscallarg(struct sparc32_sigcontext *) sigcntxp;
2254 } */ *uap = v;
2255 struct sparc32_sigcontext *scp;
2256 struct sparc32_sigcontext sc;
2257 register struct trapframe *tf;
2258 struct rwindow32 *rwstack, *kstack;
2259 sigset_t mask;
2260
2261 /* First ensure consistent stack state (see sendsig). */
2262 write_user_windows();
2263 if (rwindow_save(p)) {
2264 #ifdef DEBUG
2265 printf("sigreturn: rwindow_save(%p) failed, sending SIGILL\n", p);
2266 Debugger();
2267 #endif
2268 sigexit(p, SIGILL);
2269 }
2270 #ifdef DEBUG
2271 if (sigdebug & SDB_FOLLOW) {
2272 printf("sigreturn: %s[%d], sigcntxp %p\n",
2273 p->p_comm, p->p_pid, SCARG(uap, sigcntxp));
2274 if (sigdebug & SDB_DDB) Debugger();
2275 }
2276 #endif
2277 scp = (struct sparc32_sigcontext *)(u_long)SCARG(uap, sigcntxp);
2278 if ((vaddr_t)scp & 3 || (copyin((caddr_t)scp, &sc, sizeof sc) != 0))
2279 #ifdef DEBUG
2280 {
2281 printf("sigreturn: copyin failed\n");
2282 Debugger();
2283 return (EINVAL);
2284 }
2285 #else
2286 return (EINVAL);
2287 #endif
2288 tf = p->p_md.md_tf;
2289 /*
2290 * Only the icc bits in the psr are used, so it need not be
2291 * verified. pc and npc must be multiples of 4. This is all
2292 * that is required; if it holds, just do it.
2293 */
2294 if (((sc.sc_pc | sc.sc_npc) & 3) != 0)
2295 #ifdef DEBUG
2296 {
2297 printf("sigreturn: pc %p or npc %p invalid\n", sc.sc_pc, sc.sc_npc);
2298 Debugger();
2299 return (EINVAL);
2300 }
2301 #else
2302 return (EINVAL);
2303 #endif
2304 /* take only psr ICC field */
2305 tf->tf_tstate = (int64_t)(tf->tf_tstate & ~TSTATE_CCR) | PSRCC_TO_TSTATE(sc.sc_psr);
2306 tf->tf_pc = (int64_t)sc.sc_pc;
2307 tf->tf_npc = (int64_t)sc.sc_npc;
2308 tf->tf_global[1] = (int64_t)sc.sc_g1;
2309 tf->tf_out[0] = (int64_t)sc.sc_o0;
2310 tf->tf_out[6] = (int64_t)sc.sc_sp;
2311 rwstack = (struct rwindow32 *)tf->tf_out[6];
2312 kstack = (struct rwindow32 *)(((caddr_t)tf)-CCFSZ);
2313 #ifdef DEBUG
2314 if (sigdebug & SDB_FOLLOW) {
2315 printf("sys_sigreturn: return trapframe pc=%p sp=%p tstate=%x\n",
2316 (int)tf->tf_pc, (int)tf->tf_out[6], (int)tf->tf_tstate);
2317 if (sigdebug & SDB_DDB) Debugger();
2318 }
2319 #endif
2320 if (scp->sc_onstack & SS_ONSTACK)
2321 p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK;
2322 else
2323 p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK;
2324
2325 /* Restore signal mask */
2326 native_sigset13_to_sigset(&scp->sc_mask, &mask);
2327 (void) sigprocmask1(p, SIG_SETMASK, &mask, 0);
2328 return (EJUSTRETURN);
2329 }
2330
2331
2332 int
2333 compat_sparc32_bind(p, v, retval)
2334 struct proc *p;
2335 void *v;
2336 register_t *retval;
2337 {
2338 struct compat_sparc32_bind_args /* {
2339 syscallarg(int) s;
2340 syscallarg(const sparc32_sockaddrp_t) name;
2341 syscallarg(int) namelen;
2342 } */ *uap = v;
2343 struct sys_bind_args ua;
2344
2345 SPARC32TO64_UAP(s);
2346 SPARC32TOP_UAP(name, struct sockaddr);
2347 SPARC32TO64_UAP(namelen);
2348 return (sys_bind(p, &ua, retval));
2349 }
2350
2351 int
2352 compat_sparc32_setsockopt(p, v, retval)
2353 struct proc *p;
2354 void *v;
2355 register_t *retval;
2356 {
2357 struct compat_sparc32_setsockopt_args /* {
2358 syscallarg(int) s;
2359 syscallarg(int) level;
2360 syscallarg(int) name;
2361 syscallarg(const sparc32_voidp) val;
2362 syscallarg(int) valsize;
2363 } */ *uap = v;
2364 struct sys_setsockopt_args ua;
2365
2366 SPARC32TO64_UAP(s);
2367 SPARC32TO64_UAP(level);
2368 SPARC32TO64_UAP(name);
2369 SPARC32TOP_UAP(val, void);
2370 SPARC32TO64_UAP(valsize);
2371 /* may be more efficient to do this inline. */
2372 return (sys_setsockopt(p, &ua, retval));
2373 }
2374
2375 int
2376 compat_sparc32_listen(p, v, retval)
2377 struct proc *p;
2378 void *v;
2379 register_t *retval;
2380 {
2381 struct compat_sparc32_listen_args /* {
2382 syscallarg(int) s;
2383 syscallarg(int) backlog;
2384 } */ *uap = v;
2385 struct sys_listen_args ua;
2386
2387 SPARC32TO64_UAP(s);
2388 SPARC32TO64_UAP(backlog);
2389 return (sys_listen(p, &ua, retval));
2390 }
2391
2392 int
2393 compat_sparc32_vtrace(p, v, retval)
2394 struct proc *p;
2395 void *v;
2396 register_t *retval;
2397 {
2398 #ifdef TRACE
2399 struct compat_sparc32_vtrace_args /* {
2400 syscallarg(int) request;
2401 syscallarg(int) value;
2402 } */ *uap = v;
2403 struct sys_vtrace_args ua;
2404
2405 SPARC32TO64_UAP(request);
2406 SPARC32TO64_UAP(value);
2407 return (vtrace(p, &ua, retval));
2408 #else
2409 return (ENOSYS);
2410 #endif
2411 }
2412
2413 int
2414 compat_sparc32_gettimeofday(p, v, retval)
2415 struct proc *p;
2416 void *v;
2417 register_t *retval;
2418 {
2419 struct compat_sparc32_gettimeofday_args /* {
2420 syscallarg(sparc32_timevalp_t) tp;
2421 syscallarg(sparc32_timezonep_t) tzp;
2422 } */ *uap = v;
2423 struct timeval atv;
2424 struct sparc32_timeval tv32;
2425 int error = 0;
2426 struct sparc32_timezone tzfake;
2427
2428 if (SCARG(uap, tp)) {
2429 microtime(&atv);
2430 sparc32_from_timeval(&atv, &tv32);
2431 error = copyout(&tv32, (caddr_t)(u_long)SCARG(uap, tp), sizeof(tv32));
2432 if (error)
2433 return (error);
2434 }
2435 if (SCARG(uap, tzp)) {
2436 /*
2437 * NetBSD has no kernel notion of time zone, so we just
2438 * fake up a timezone struct and return it if demanded.
2439 */
2440 tzfake.tz_minuteswest = 0;
2441 tzfake.tz_dsttime = 0;
2442 error = copyout(&tzfake, (caddr_t)(u_long)SCARG(uap, tzp), sizeof(tzfake));
2443 }
2444 return (error);
2445 }
2446
2447 static int settime __P((struct timeval *));
2448 /* This function is used by clock_settime and settimeofday */
2449 static int
2450 settime(tv)
2451 struct timeval *tv;
2452 {
2453 struct timeval delta;
2454 int s;
2455
2456 /* WHAT DO WE DO ABOUT PENDING REAL-TIME TIMEOUTS??? */
2457 s = splclock();
2458 timersub(tv, &time, &delta);
2459 if ((delta.tv_sec < 0 || delta.tv_usec < 0) && securelevel > 1)
2460 return (EPERM);
2461 #ifdef notyet
2462 if ((delta.tv_sec < 86400) && securelevel > 0)
2463 return (EPERM);
2464 #endif
2465 time = *tv;
2466 (void) splsoftclock();
2467 timeradd(&boottime, &delta, &boottime);
2468 timeradd(&runtime, &delta, &runtime);
2469 # if defined(NFS) || defined(NFSSERVER)
2470 nqnfs_lease_updatetime(delta.tv_sec);
2471 # endif
2472 splx(s);
2473 resettodr();
2474 return (0);
2475 }
2476
2477
2478 int
2479 compat_sparc32_settimeofday(p, v, retval)
2480 struct proc *p;
2481 void *v;
2482 register_t *retval;
2483 {
2484 struct compat_sparc32_settimeofday_args /* {
2485 syscallarg(const sparc32_timevalp_t) tv;
2486 syscallarg(const sparc32_timezonep_t) tzp;
2487 } */ *uap = v;
2488 struct sparc32_timeval atv32;
2489 struct timeval atv;
2490 struct sparc32_timezone atz;
2491 int error;
2492
2493 if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
2494 return (error);
2495 /* Verify all parameters before changing time. */
2496 if (SCARG(uap, tv) && (error = copyin((caddr_t)(u_long)SCARG(uap, tv),
2497 &atv32, sizeof(atv32))))
2498 return (error);
2499 sparc32_to_timeval(&atv32, &atv);
2500 /* XXX since we don't use tz, probably no point in doing copyin. */
2501 if (SCARG(uap, tzp) && (error = copyin((caddr_t)(u_long)SCARG(uap, tzp),
2502 &atz, sizeof(atz))))
2503 return (error);
2504 if (SCARG(uap, tv))
2505 if ((error = settime(&atv)))
2506 return (error);
2507 /*
2508 * NetBSD has no kernel notion of time zone, and only an
2509 * obsolete program would try to set it, so we log a warning.
2510 */
2511 if (SCARG(uap, tzp))
2512 printf("pid %d attempted to set the "
2513 "(obsolete) kernel time zone\n", p->p_pid);
2514 return (0);
2515 }
2516
2517 int
2518 compat_sparc32_fchown(p, v, retval)
2519 struct proc *p;
2520 void *v;
2521 register_t *retval;
2522 {
2523 struct compat_sparc32_fchown_args /* {
2524 syscallarg(int) fd;
2525 syscallarg(uid_t) uid;
2526 syscallarg(gid_t) gid;
2527 } */ *uap = v;
2528 struct sys_fchown_args ua;
2529
2530 SPARC32TO64_UAP(fd);
2531 SPARC32TO64_UAP(uid);
2532 SPARC32TO64_UAP(gid);
2533 return (sys_fchown(p, &ua, retval));
2534 }
2535
2536 int
2537 compat_sparc32_fchmod(p, v, retval)
2538 struct proc *p;
2539 void *v;
2540 register_t *retval;
2541 {
2542 struct compat_sparc32_fchmod_args /* {
2543 syscallarg(int) fd;
2544 syscallarg(mode_t) mode;
2545 } */ *uap = v;
2546 struct sys_fchmod_args ua;
2547
2548 SPARC32TO64_UAP(fd);
2549 SPARC32TO64_UAP(mode);
2550 return (sys_fchmod(p, &ua, retval));
2551 }
2552
2553 int
2554 compat_sparc32_setreuid(p, v, retval)
2555 struct proc *p;
2556 void *v;
2557 register_t *retval;
2558 {
2559 struct compat_sparc32_setreuid_args /* {
2560 syscallarg(uid_t) ruid;
2561 syscallarg(uid_t) euid;
2562 } */ *uap = v;
2563 struct sys_setreuid_args ua;
2564
2565 SPARC32TO64_UAP(ruid);
2566 SPARC32TO64_UAP(euid);
2567 return (sys_setreuid(p, &ua, retval));
2568 }
2569
2570 int
2571 compat_sparc32_setregid(p, v, retval)
2572 struct proc *p;
2573 void *v;
2574 register_t *retval;
2575 {
2576 struct compat_sparc32_setregid_args /* {
2577 syscallarg(gid_t) rgid;
2578 syscallarg(gid_t) egid;
2579 } */ *uap = v;
2580 struct sys_setregid_args ua;
2581
2582 SPARC32TO64_UAP(rgid);
2583 SPARC32TO64_UAP(egid);
2584 return (sys_setregid(p, &ua, retval));
2585 }
2586
2587 int
2588 compat_sparc32_getrusage(p, v, retval)
2589 struct proc *p;
2590 void *v;
2591 register_t *retval;
2592 {
2593 struct compat_sparc32_getrusage_args /* {
2594 syscallarg(int) who;
2595 syscallarg(sparc32_rusagep_t) rusage;
2596 } */ *uap = v;
2597 struct rusage *rup;
2598 struct sparc32_rusage ru;
2599
2600 switch (SCARG(uap, who)) {
2601
2602 case RUSAGE_SELF:
2603 rup = &p->p_stats->p_ru;
2604 calcru(p, &rup->ru_utime, &rup->ru_stime, NULL);
2605 break;
2606
2607 case RUSAGE_CHILDREN:
2608 rup = &p->p_stats->p_cru;
2609 break;
2610
2611 default:
2612 return (EINVAL);
2613 }
2614 sparc32_from_rusage(rup, &ru);
2615 return (copyout(&ru, (caddr_t)(u_long)SCARG(uap, rusage), sizeof(ru)));
2616 }
2617
2618 int
2619 compat_sparc32_getsockopt(p, v, retval)
2620 struct proc *p;
2621 void *v;
2622 register_t *retval;
2623 {
2624 struct compat_sparc32_getsockopt_args /* {
2625 syscallarg(int) s;
2626 syscallarg(int) level;
2627 syscallarg(int) name;
2628 syscallarg(sparc32_voidp) val;
2629 syscallarg(sparc32_intp) avalsize;
2630 } */ *uap = v;
2631 struct sys_getsockopt_args ua;
2632
2633 SPARC32TO64_UAP(s);
2634 SPARC32TO64_UAP(level);
2635 SPARC32TO64_UAP(name);
2636 SPARC32TOP_UAP(val, void);
2637 SPARC32TOP_UAP(avalsize, int);
2638 return (sys_getsockopt(p, &ua, retval));
2639 }
2640
2641 int
2642 compat_sparc32_readv(p, v, retval)
2643 struct proc *p;
2644 void *v;
2645 register_t *retval;
2646 {
2647 struct compat_sparc32_readv_args /* {
2648 syscallarg(int) fd;
2649 syscallarg(const sparc32_iovecp_t) iovp;
2650 syscallarg(int) iovcnt;
2651 } */ *uap = v;
2652 int fd = SCARG(uap, fd);
2653 register struct file *fp;
2654 register struct filedesc *fdp = p->p_fd;
2655
2656 if ((u_int)fd >= fdp->fd_nfiles ||
2657 (fp = fdp->fd_ofiles[fd]) == NULL ||
2658 (fp->f_flag & FREAD) == 0)
2659 return (EBADF);
2660
2661 return (dofilereadv32(p, fd, fp, (struct sparc32_iovec *)(u_long)SCARG(uap, iovp),
2662 SCARG(uap, iovcnt), &fp->f_offset, FOF_UPDATE_OFFSET, retval));
2663 }
2664
2665 /* Damn thing copies in the iovec! */
2666 int
2667 dofilereadv32(p, fd, fp, iovp, iovcnt, offset, flags, retval)
2668 struct proc *p;
2669 int fd;
2670 struct file *fp;
2671 struct sparc32_iovec *iovp;
2672 int iovcnt;
2673 off_t *offset;
2674 int flags;
2675 register_t *retval;
2676 {
2677 struct uio auio;
2678 register struct iovec *iov;
2679 struct iovec *needfree;
2680 struct iovec aiov[UIO_SMALLIOV];
2681 long i, cnt, error = 0;
2682 u_int iovlen;
2683 #ifdef KTRACE
2684 struct iovec *ktriov = NULL;
2685 #endif
2686
2687 /* note: can't use iovlen until iovcnt is validated */
2688 iovlen = iovcnt * sizeof(struct iovec);
2689 if ((u_int)iovcnt > UIO_SMALLIOV) {
2690 if ((u_int)iovcnt > IOV_MAX)
2691 return (EINVAL);
2692 MALLOC(iov, struct iovec *, iovlen, M_IOV, M_WAITOK);
2693 needfree = iov;
2694 } else if ((u_int)iovcnt > 0) {
2695 iov = aiov;
2696 needfree = NULL;
2697 } else
2698 return (EINVAL);
2699
2700 auio.uio_iov = iov;
2701 auio.uio_iovcnt = iovcnt;
2702 auio.uio_rw = UIO_READ;
2703 auio.uio_segflg = UIO_USERSPACE;
2704 auio.uio_procp = p;
2705 error = sparc32_to_iovecin(iovp, iov, iovcnt);
2706 if (error)
2707 goto done;
2708 auio.uio_resid = 0;
2709 for (i = 0; i < iovcnt; i++) {
2710 auio.uio_resid += iov->iov_len;
2711 /*
2712 * Reads return ssize_t because -1 is returned on error.
2713 * Therefore we must restrict the length to SSIZE_MAX to
2714 * avoid garbage return values.
2715 */
2716 if (iov->iov_len > SSIZE_MAX || auio.uio_resid > SSIZE_MAX) {
2717 error = EINVAL;
2718 goto done;
2719 }
2720 iov++;
2721 }
2722 #ifdef KTRACE
2723 /*
2724 * if tracing, save a copy of iovec
2725 */
2726 if (KTRPOINT(p, KTR_GENIO)) {
2727 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
2728 memcpy((caddr_t)ktriov, (caddr_t)auio.uio_iov, iovlen);
2729 }
2730 #endif
2731 cnt = auio.uio_resid;
2732 error = (*fp->f_ops->fo_read)(fp, offset, &auio, fp->f_cred, flags);
2733 if (error)
2734 if (auio.uio_resid != cnt && (error == ERESTART ||
2735 error == EINTR || error == EWOULDBLOCK))
2736 error = 0;
2737 cnt -= auio.uio_resid;
2738 #ifdef KTRACE
2739 if (KTRPOINT(p, KTR_GENIO))
2740 if (error == 0) {
2741 ktrgenio(p->p_tracep, fd, UIO_READ, ktriov, cnt,
2742 error);
2743 FREE(ktriov, M_TEMP);
2744 }
2745 #endif
2746 *retval = cnt;
2747 done:
2748 if (needfree)
2749 FREE(needfree, M_IOV);
2750 return (error);
2751 }
2752
2753
2754 int
2755 compat_sparc32_writev(p, v, retval)
2756 struct proc *p;
2757 void *v;
2758 register_t *retval;
2759 {
2760 struct compat_sparc32_writev_args /* {
2761 syscallarg(int) fd;
2762 syscallarg(const sparc32_iovecp_t) iovp;
2763 syscallarg(int) iovcnt;
2764 } */ *uap = v;
2765 int fd = SCARG(uap, fd);
2766 register struct file *fp;
2767 register struct filedesc *fdp = p->p_fd;
2768
2769 if ((u_int)fd >= fdp->fd_nfiles ||
2770 (fp = fdp->fd_ofiles[fd]) == NULL ||
2771 (fp->f_flag & FWRITE) == 0)
2772 return (EBADF);
2773
2774 return (dofilewritev32(p, fd, fp, (struct sparc32_iovec *)(u_long)SCARG(uap, iovp),
2775 SCARG(uap, iovcnt), &fp->f_offset, FOF_UPDATE_OFFSET, retval));
2776 }
2777
2778 int
2779 dofilewritev32(p, fd, fp, iovp, iovcnt, offset, flags, retval)
2780 struct proc *p;
2781 int fd;
2782 struct file *fp;
2783 struct sparc32_iovec *iovp;
2784 int iovcnt;
2785 off_t *offset;
2786 int flags;
2787 register_t *retval;
2788 {
2789 struct uio auio;
2790 register struct iovec *iov;
2791 struct iovec *needfree;
2792 struct iovec aiov[UIO_SMALLIOV];
2793 long i, cnt, error = 0;
2794 u_int iovlen;
2795 #ifdef KTRACE
2796 struct iovec *ktriov = NULL;
2797 #endif
2798
2799 /* note: can't use iovlen until iovcnt is validated */
2800 iovlen = iovcnt * sizeof(struct iovec);
2801 if ((u_int)iovcnt > UIO_SMALLIOV) {
2802 if ((u_int)iovcnt > IOV_MAX)
2803 return (EINVAL);
2804 MALLOC(iov, struct iovec *, iovlen, M_IOV, M_WAITOK);
2805 needfree = iov;
2806 } else if ((u_int)iovcnt > 0) {
2807 iov = aiov;
2808 needfree = NULL;
2809 } else
2810 return (EINVAL);
2811
2812 auio.uio_iov = iov;
2813 auio.uio_iovcnt = iovcnt;
2814 auio.uio_rw = UIO_WRITE;
2815 auio.uio_segflg = UIO_USERSPACE;
2816 auio.uio_procp = p;
2817 error = sparc32_to_iovecin(iovp, iov, iovcnt);
2818 if (error)
2819 goto done;
2820 auio.uio_resid = 0;
2821 for (i = 0; i < iovcnt; i++) {
2822 auio.uio_resid += iov->iov_len;
2823 /*
2824 * Writes return ssize_t because -1 is returned on error.
2825 * Therefore we must restrict the length to SSIZE_MAX to
2826 * avoid garbage return values.
2827 */
2828 if (iov->iov_len > SSIZE_MAX || auio.uio_resid > SSIZE_MAX) {
2829 error = EINVAL;
2830 goto done;
2831 }
2832 iov++;
2833 }
2834 #ifdef KTRACE
2835 /*
2836 * if tracing, save a copy of iovec
2837 */
2838 if (KTRPOINT(p, KTR_GENIO)) {
2839 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
2840 memcpy((caddr_t)ktriov, (caddr_t)auio.uio_iov, iovlen);
2841 }
2842 #endif
2843 cnt = auio.uio_resid;
2844 error = (*fp->f_ops->fo_write)(fp, offset, &auio, fp->f_cred, flags);
2845 if (error) {
2846 if (auio.uio_resid != cnt && (error == ERESTART ||
2847 error == EINTR || error == EWOULDBLOCK))
2848 error = 0;
2849 if (error == EPIPE)
2850 psignal(p, SIGPIPE);
2851 }
2852 cnt -= auio.uio_resid;
2853 #ifdef KTRACE
2854 if (KTRPOINT(p, KTR_GENIO))
2855 if (error == 0) {
2856 ktrgenio(p->p_tracep, fd, UIO_WRITE, ktriov, cnt,
2857 error);
2858 FREE(ktriov, M_TEMP);
2859 }
2860 #endif
2861 *retval = cnt;
2862 done:
2863 if (needfree)
2864 FREE(needfree, M_IOV);
2865 return (error);
2866 }
2867
2868
2869 int
2870 compat_sparc32_rename(p, v, retval)
2871 struct proc *p;
2872 void *v;
2873 register_t *retval;
2874 {
2875 struct compat_sparc32_rename_args /* {
2876 syscallarg(const sparc32_charp) from;
2877 syscallarg(const sparc32_charp) to;
2878 } */ *uap = v;
2879 struct sys_rename_args ua;
2880
2881 SPARC32TOP_UAP(from, const char *);
2882 SPARC32TOP_UAP(to, const char *)
2883
2884 return (sys_rename(p, &ua, retval));
2885 }
2886
2887 int
2888 compat_sparc32_flock(p, v, retval)
2889 struct proc *p;
2890 void *v;
2891 register_t *retval;
2892 {
2893 struct compat_sparc32_flock_args /* {
2894 syscallarg(int) fd;
2895 syscallarg(int) how;
2896 } */ *uap = v;
2897 struct sys_flock_args ua;
2898
2899 SPARC32TO64_UAP(fd);
2900 SPARC32TO64_UAP(how)
2901
2902 return (sys_flock(p, &ua, retval));
2903 }
2904
2905 int
2906 compat_sparc32_mkfifo(p, v, retval)
2907 struct proc *p;
2908 void *v;
2909 register_t *retval;
2910 {
2911 struct compat_sparc32_mkfifo_args /* {
2912 syscallarg(const sparc32_charp) path;
2913 syscallarg(mode_t) mode;
2914 } */ *uap = v;
2915 struct sys_mkfifo_args ua;
2916
2917 SPARC32TOP_UAP(path, const char)
2918 SPARC32TO64_UAP(mode);
2919 return (sys_mkfifo(p, &ua, retval));
2920 }
2921
2922 int
2923 compat_sparc32_shutdown(p, v, retval)
2924 struct proc *p;
2925 void *v;
2926 register_t *retval;
2927 {
2928 struct compat_sparc32_shutdown_args /* {
2929 syscallarg(int) s;
2930 syscallarg(int) how;
2931 } */ *uap = v;
2932 struct sys_shutdown_args ua;
2933
2934 SPARC32TO64_UAP(s)
2935 SPARC32TO64_UAP(how);
2936 return (sys_shutdown(p, &ua, retval));
2937 }
2938
2939 int
2940 compat_sparc32_socketpair(p, v, retval)
2941 struct proc *p;
2942 void *v;
2943 register_t *retval;
2944 {
2945 struct compat_sparc32_socketpair_args /* {
2946 syscallarg(int) domain;
2947 syscallarg(int) type;
2948 syscallarg(int) protocol;
2949 syscallarg(sparc32_intp) rsv;
2950 } */ *uap = v;
2951 struct sys_socketpair_args ua;
2952
2953 SPARC32TO64_UAP(domain);
2954 SPARC32TO64_UAP(type);
2955 SPARC32TO64_UAP(protocol);
2956 SPARC32TOP_UAP(rsv, int);
2957 /* Since we're just copying out two `int's we can do this */
2958 return (sys_socketpair(p, &ua, retval));
2959 }
2960
2961 int
2962 compat_sparc32_mkdir(p, v, retval)
2963 struct proc *p;
2964 void *v;
2965 register_t *retval;
2966 {
2967 struct compat_sparc32_mkdir_args /* {
2968 syscallarg(const sparc32_charp) path;
2969 syscallarg(mode_t) mode;
2970 } */ *uap = v;
2971 struct sys_mkdir_args ua;
2972
2973 SPARC32TOP_UAP(path, const char)
2974 SPARC32TO64_UAP(mode);
2975 return (sys_mkdir(p, &ua, retval));
2976 }
2977
2978 int
2979 compat_sparc32_rmdir(p, v, retval)
2980 struct proc *p;
2981 void *v;
2982 register_t *retval;
2983 {
2984 struct compat_sparc32_rmdir_args /* {
2985 syscallarg(const sparc32_charp) path;
2986 } */ *uap = v;
2987 struct sys_rmdir_args ua;
2988
2989 SPARC32TOP_UAP(path, const char);
2990 return (sys_rmdir(p, &ua, retval));
2991 }
2992
2993 int
2994 compat_sparc32_utimes(p, v, retval)
2995 struct proc *p;
2996 void *v;
2997 register_t *retval;
2998 {
2999 struct compat_sparc32_utimes_args /* {
3000 syscallarg(const sparc32_charp) path;
3001 syscallarg(const sparc32_timevalp_t) tptr;
3002 } */ *uap = v;
3003 int error;
3004 struct nameidata nd;
3005
3006 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, (char *)(u_long)SCARG(uap, path), p);
3007 if ((error = namei(&nd)) != 0)
3008 return (error);
3009
3010 error = change_utimes32(nd.ni_vp, (struct timeval *)(u_long)SCARG(uap, tptr), p);
3011
3012 vrele(nd.ni_vp);
3013 return (error);
3014 }
3015
3016 /*
3017 * Common routine to set access and modification times given a vnode.
3018 */
3019 static int
3020 change_utimes32(vp, tptr, p)
3021 struct vnode *vp;
3022 struct timeval *tptr;
3023 struct proc *p;
3024 {
3025 struct sparc32_timeval tv32[2];
3026 struct timeval tv[2];
3027 struct vattr vattr;
3028 int error;
3029
3030 VATTR_NULL(&vattr);
3031 if (tptr == NULL) {
3032 microtime(&tv[0]);
3033 tv[1] = tv[0];
3034 vattr.va_vaflags |= VA_UTIMES_NULL;
3035 } else {
3036 error = copyin(tptr, tv, sizeof(tv));
3037 if (error)
3038 return (error);
3039 }
3040 sparc32_to_timeval(&tv32[0], &tv[0]);
3041 sparc32_to_timeval(&tv32[1], &tv[1]);
3042 VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
3043 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
3044 vattr.va_atime.tv_sec = tv[0].tv_sec;
3045 vattr.va_atime.tv_nsec = tv[0].tv_usec * 1000;
3046 vattr.va_mtime.tv_sec = tv[1].tv_sec;
3047 vattr.va_mtime.tv_nsec = tv[1].tv_usec * 1000;
3048 error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
3049 VOP_UNLOCK(vp, 0);
3050 return (error);
3051 }
3052
3053 int
3054 compat_sparc32_adjtime(p, v, retval)
3055 struct proc *p;
3056 void *v;
3057 register_t *retval;
3058 {
3059 struct compat_sparc32_adjtime_args /* {
3060 syscallarg(const sparc32_timevalp_t) delta;
3061 syscallarg(sparc32_timevalp_t) olddelta;
3062 } */ *uap = v;
3063 struct sparc32_timeval atv;
3064 int32_t ndelta, ntickdelta, odelta;
3065 int s, error;
3066 extern long bigadj, timedelta;
3067 extern int tickdelta;
3068
3069 if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
3070 return (error);
3071
3072 error = copyin((caddr_t)(u_long)SCARG(uap, delta), &atv, sizeof(struct timeval));
3073 if (error)
3074 return (error);
3075 /*
3076 * Compute the total correction and the rate at which to apply it.
3077 * Round the adjustment down to a whole multiple of the per-tick
3078 * delta, so that after some number of incremental changes in
3079 * hardclock(), tickdelta will become zero, lest the correction
3080 * overshoot and start taking us away from the desired final time.
3081 */
3082 ndelta = atv.tv_sec * 1000000 + atv.tv_usec;
3083 if (ndelta > bigadj)
3084 ntickdelta = 10 * tickadj;
3085 else
3086 ntickdelta = tickadj;
3087 if (ndelta % ntickdelta)
3088 ndelta = ndelta / ntickdelta * ntickdelta;
3089
3090 /*
3091 * To make hardclock()'s job easier, make the per-tick delta negative
3092 * if we want time to run slower; then hardclock can simply compute
3093 * tick + tickdelta, and subtract tickdelta from timedelta.
3094 */
3095 if (ndelta < 0)
3096 ntickdelta = -ntickdelta;
3097 s = splclock();
3098 odelta = timedelta;
3099 timedelta = ndelta;
3100 tickdelta = ntickdelta;
3101 splx(s);
3102
3103 if (SCARG(uap, olddelta)) {
3104 atv.tv_sec = odelta / 1000000;
3105 atv.tv_usec = odelta % 1000000;
3106 (void) copyout(&atv, (caddr_t)(u_long)SCARG(uap, olddelta),
3107 sizeof(struct timeval));
3108 }
3109 return (0);
3110 }
3111
3112 int
3113 compat_sparc32_quotactl(p, v, retval)
3114 struct proc *p;
3115 void *v;
3116 register_t *retval;
3117 {
3118 struct compat_sparc32_quotactl_args /* {
3119 syscallarg(const sparc32_charp) path;
3120 syscallarg(int) cmd;
3121 syscallarg(int) uid;
3122 syscallarg(sparc32_caddr_t) arg;
3123 } */ *uap = v;
3124 struct sys_quotactl_args ua;
3125
3126 SPARC32TOP_UAP(path, const char);
3127 SPARC32TO64_UAP(cmd);
3128 SPARC32TO64_UAP(uid);
3129 SPARC32TOX64_UAP(arg, caddr_t);
3130 return (sys_quotactl(p, &ua, retval));
3131 }
3132
3133 #if defined(NFS) || defined(NFSSERVER)
3134 int
3135 compat_sparc32_nfssvc(p, v, retval)
3136 struct proc *p;
3137 void *v;
3138 register_t *retval;
3139 {
3140 #if 0
3141 struct compat_sparc32_nfssvc_args /* {
3142 syscallarg(int) flag;
3143 syscallarg(sparc32_voidp) argp;
3144 } */ *uap = v;
3145 struct sys_nfssvc_args ua;
3146
3147 SPARC32TO64_UAP(flag);
3148 SPARC32TOP_UAP(argp, void);
3149 return (sys_nfssvc(p, &ua, retval));
3150 #else
3151 /* Why would we want to support a 32-bit nfsd? */
3152 return (ENOSYS);
3153 #endif
3154 }
3155 #endif
3156
3157 int
3158 compat_sparc32_statfs(p, v, retval)
3159 struct proc *p;
3160 void *v;
3161 register_t *retval;
3162 {
3163 struct compat_sparc32_statfs_args /* {
3164 syscallarg(const sparc32_charp) path;
3165 syscallarg(sparc32_statfsp_t) buf;
3166 } */ *uap = v;
3167 register struct mount *mp;
3168 register struct statfs *sp;
3169 struct sparc32_statfs s32;
3170 int error;
3171 struct nameidata nd;
3172
3173 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, (char *)(u_long)SCARG(uap, path), p);
3174 if ((error = namei(&nd)) != 0)
3175 return (error);
3176 mp = nd.ni_vp->v_mount;
3177 sp = &mp->mnt_stat;
3178 vrele(nd.ni_vp);
3179 if ((error = VFS_STATFS(mp, sp, p)) != 0)
3180 return (error);
3181 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
3182 sparc32_from_statfs(sp, &s32);
3183 return (copyout(&s32, (caddr_t)(u_long)SCARG(uap, buf), sizeof(s32)));
3184 }
3185
3186 int
3187 compat_sparc32_fstatfs(p, v, retval)
3188 struct proc *p;
3189 void *v;
3190 register_t *retval;
3191 {
3192 struct compat_sparc32_fstatfs_args /* {
3193 syscallarg(int) fd;
3194 syscallarg(sparc32_statfsp_t) buf;
3195 } */ *uap = v;
3196 struct file *fp;
3197 register struct mount *mp;
3198 register struct statfs *sp;
3199 struct sparc32_statfs s32;
3200 int error;
3201
3202 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
3203 return (error);
3204 mp = ((struct vnode *)fp->f_data)->v_mount;
3205 sp = &mp->mnt_stat;
3206 if ((error = VFS_STATFS(mp, sp, p)) != 0)
3207 return (error);
3208 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
3209 sparc32_from_statfs(sp, &s32);
3210 return (copyout(&s32, (caddr_t)(u_long)SCARG(uap, buf), sizeof(s32)));
3211 }
3212
3213 #if defined(NFS) || defined(NFSSERVER)
3214 int
3215 compat_sparc32_getfh(p, v, retval)
3216 struct proc *p;
3217 void *v;
3218 register_t *retval;
3219 {
3220 struct compat_sparc32_getfh_args /* {
3221 syscallarg(const sparc32_charp) fname;
3222 syscallarg(sparc32_fhandlep_t) fhp;
3223 } */ *uap = v;
3224 struct sys_getfh_args ua;
3225
3226 SPARC32TOP_UAP(fname, const char);
3227 SPARC32TOP_UAP(fhp, struct fhandle);
3228 /* Lucky for us a fhandlep_t doesn't change sizes */
3229 return (sys_getfh(p, &ua, retval));
3230 }
3231 #endif
3232
3233 int
3234 compat_sparc32_sysarch(p, v, retval)
3235 struct proc *p;
3236 void *v;
3237 register_t *retval;
3238 {
3239 struct compat_sparc32_sysarch_args /* {
3240 syscallarg(int) op;
3241 syscallarg(sparc32_voidp) parms;
3242 } */ *uap = v;
3243
3244 switch (SCARG(uap, op)) {
3245 default:
3246 printf("(sparc64) compat_sparc32_sysarch(%d)\n", SCARG(uap, op));
3247 return EINVAL;
3248 }
3249 }
3250
3251 int
3252 compat_sparc32_pread(p, v, retval)
3253 struct proc *p;
3254 void *v;
3255 register_t *retval;
3256 {
3257 struct compat_sparc32_pread_args /* {
3258 syscallarg(int) fd;
3259 syscallarg(sparc32_voidp) buf;
3260 syscallarg(sparc32_size_t) nbyte;
3261 syscallarg(int) pad;
3262 syscallarg(off_t) offset;
3263 } */ *uap = v;
3264 struct sys_pread_args ua;
3265 ssize_t rt;
3266 int error;
3267
3268 SPARC32TO64_UAP(fd);
3269 SPARC32TOP_UAP(buf, void);
3270 SPARC32TOX_UAP(nbyte, size_t);
3271 SPARC32TO64_UAP(pad);
3272 SPARC32TO64_UAP(offset);
3273 error = sys_pread(p, &ua, (register_t *)&rt);
3274 *(sparc32_ssize_t *)retval = rt;
3275 return (error);
3276 }
3277
3278 int
3279 compat_sparc32_pwrite(p, v, retval)
3280 struct proc *p;
3281 void *v;
3282 register_t *retval;
3283 {
3284 struct compat_sparc32_pwrite_args /* {
3285 syscallarg(int) fd;
3286 syscallarg(const sparc32_voidp) buf;
3287 syscallarg(sparc32_size_t) nbyte;
3288 syscallarg(int) pad;
3289 syscallarg(off_t) offset;
3290 } */ *uap = v;
3291 struct sys_pwrite_args ua;
3292 ssize_t rt;
3293 int error;
3294
3295 SPARC32TO64_UAP(fd);
3296 SPARC32TOP_UAP(buf, void);
3297 SPARC32TOX_UAP(nbyte, size_t);
3298 SPARC32TO64_UAP(pad);
3299 SPARC32TO64_UAP(offset);
3300 error = sys_pwrite(p, &ua, (register_t *)&rt);
3301 *(sparc32_ssize_t *)retval = rt;
3302 return (error);
3303 }
3304
3305 #ifdef NTP
3306 int
3307 compat_sparc32_ntp_gettime(p, v, retval)
3308 struct proc *p;
3309 void *v;
3310 register_t *retval;
3311 {
3312 struct compat_sparc32_ntp_gettime_args /* {
3313 syscallarg(sparc32_ntptimevalp_t) ntvp;
3314 } */ *uap = v;
3315 struct sparc32_ntptimeval ntv32;
3316 struct timeval atv;
3317 struct ntptimeval ntv;
3318 int error = 0;
3319 int s;
3320
3321 /* The following are NTP variables */
3322 extern long time_maxerror;
3323 extern long time_esterror;
3324 extern int time_status;
3325 extern int time_state; /* clock state */
3326 extern int time_status; /* clock status bits */
3327
3328 if (SCARG(uap, ntvp)) {
3329 s = splclock();
3330 #ifdef EXT_CLOCK
3331 /*
3332 * The microtime() external clock routine returns a
3333 * status code. If less than zero, we declare an error
3334 * in the clock status word and return the kernel
3335 * (software) time variable. While there are other
3336 * places that call microtime(), this is the only place
3337 * that matters from an application point of view.
3338 */
3339 if (microtime(&atv) < 0) {
3340 time_status |= STA_CLOCKERR;
3341 ntv.time = time;
3342 } else
3343 time_status &= ~STA_CLOCKERR;
3344 #else /* EXT_CLOCK */
3345 microtime(&atv);
3346 #endif /* EXT_CLOCK */
3347 ntv.time = atv;
3348 ntv.maxerror = time_maxerror;
3349 ntv.esterror = time_esterror;
3350 (void) splx(s);
3351
3352 sparc32_from_timeval(&ntv.time, &ntv32.time);
3353 ntv32.maxerror = (sparc32_long)ntv.maxerror;
3354 ntv32.esterror = (sparc32_long)ntv.esterror;
3355 error = copyout((caddr_t)&ntv32, (caddr_t)(u_long)SCARG(uap, ntvp),
3356 sizeof(ntv32));
3357 }
3358 if (!error) {
3359
3360 /*
3361 * Status word error decode. If any of these conditions
3362 * occur, an error is returned, instead of the status
3363 * word. Most applications will care only about the fact
3364 * the system clock may not be trusted, not about the
3365 * details.
3366 *
3367 * Hardware or software error
3368 */
3369 if ((time_status & (STA_UNSYNC | STA_CLOCKERR)) ||
3370
3371 /*
3372 * PPS signal lost when either time or frequency
3373 * synchronization requested
3374 */
3375 (time_status & (STA_PPSFREQ | STA_PPSTIME) &&
3376 !(time_status & STA_PPSSIGNAL)) ||
3377
3378 /*
3379 * PPS jitter exceeded when time synchronization
3380 * requested
3381 */
3382 (time_status & STA_PPSTIME &&
3383 time_status & STA_PPSJITTER) ||
3384
3385 /*
3386 * PPS wander exceeded or calibration error when
3387 * frequency synchronization requested
3388 */
3389 (time_status & STA_PPSFREQ &&
3390 time_status & (STA_PPSWANDER | STA_PPSERROR)))
3391 *retval = TIME_ERROR;
3392 else
3393 *retval = (register_t)time_state;
3394 }
3395 return(error);
3396 }
3397
3398 int
3399 compat_sparc32_ntp_adjtime(p, v, retval)
3400 struct proc *p;
3401 void *v;
3402 register_t *retval;
3403 {
3404 struct compat_sparc32_ntp_adjtime_args /* {
3405 syscallarg(sparc32_timexp_t) tp;
3406 } */ *uap = v;
3407 struct sparc32_timex ntv32;
3408 struct timex ntv;
3409 int error = 0;
3410 int modes;
3411 int s;
3412 extern long time_freq; /* frequency offset (scaled ppm) */
3413 extern long time_maxerror;
3414 extern long time_esterror;
3415 extern int time_state; /* clock state */
3416 extern int time_status; /* clock status bits */
3417 extern long time_constant; /* pll time constant */
3418 extern long time_offset; /* time offset (us) */
3419 extern long time_tolerance; /* frequency tolerance (scaled ppm) */
3420 extern long time_precision; /* clock precision (us) */
3421
3422 if ((error = copyin((caddr_t)(u_long)SCARG(uap, tp), (caddr_t)&ntv32,
3423 sizeof(ntv32))))
3424 return (error);
3425 sparc32_to_timex(&ntv32, &ntv);
3426
3427 /*
3428 * Update selected clock variables - only the superuser can
3429 * change anything. Note that there is no error checking here on
3430 * the assumption the superuser should know what it is doing.
3431 */
3432 modes = ntv.modes;
3433 if (modes != 0 && (error = suser(p->p_ucred, &p->p_acflag)))
3434 return (error);
3435
3436 s = splclock();
3437 if (modes & MOD_FREQUENCY)
3438 #ifdef PPS_SYNC
3439 time_freq = ntv.freq - pps_freq;
3440 #else /* PPS_SYNC */
3441 time_freq = ntv.freq;
3442 #endif /* PPS_SYNC */
3443 if (modes & MOD_MAXERROR)
3444 time_maxerror = ntv.maxerror;
3445 if (modes & MOD_ESTERROR)
3446 time_esterror = ntv.esterror;
3447 if (modes & MOD_STATUS) {
3448 time_status &= STA_RONLY;
3449 time_status |= ntv.status & ~STA_RONLY;
3450 }
3451 if (modes & MOD_TIMECONST)
3452 time_constant = ntv.constant;
3453 if (modes & MOD_OFFSET)
3454 hardupdate(ntv.offset);
3455
3456 /*
3457 * Retrieve all clock variables
3458 */
3459 if (time_offset < 0)
3460 ntv.offset = -(-time_offset >> SHIFT_UPDATE);
3461 else
3462 ntv.offset = time_offset >> SHIFT_UPDATE;
3463 #ifdef PPS_SYNC
3464 ntv.freq = time_freq + pps_freq;
3465 #else /* PPS_SYNC */
3466 ntv.freq = time_freq;
3467 #endif /* PPS_SYNC */
3468 ntv.maxerror = time_maxerror;
3469 ntv.esterror = time_esterror;
3470 ntv.status = time_status;
3471 ntv.constant = time_constant;
3472 ntv.precision = time_precision;
3473 ntv.tolerance = time_tolerance;
3474 #ifdef PPS_SYNC
3475 ntv.shift = pps_shift;
3476 ntv.ppsfreq = pps_freq;
3477 ntv.jitter = pps_jitter >> PPS_AVG;
3478 ntv.stabil = pps_stabil;
3479 ntv.calcnt = pps_calcnt;
3480 ntv.errcnt = pps_errcnt;
3481 ntv.jitcnt = pps_jitcnt;
3482 ntv.stbcnt = pps_stbcnt;
3483 #endif /* PPS_SYNC */
3484 (void)splx(s);
3485
3486 sparc32_from_timeval(&ntv, &ntv32);
3487 error = copyout((caddr_t)&ntv32, (caddr_t)SCARG(uap, tp), sizeof(ntv32));
3488 if (!error) {
3489
3490 /*
3491 * Status word error decode. See comments in
3492 * ntp_gettime() routine.
3493 */
3494 if ((time_status & (STA_UNSYNC | STA_CLOCKERR)) ||
3495 (time_status & (STA_PPSFREQ | STA_PPSTIME) &&
3496 !(time_status & STA_PPSSIGNAL)) ||
3497 (time_status & STA_PPSTIME &&
3498 time_status & STA_PPSJITTER) ||
3499 (time_status & STA_PPSFREQ &&
3500 time_status & (STA_PPSWANDER | STA_PPSERROR)))
3501 *retval = TIME_ERROR;
3502 else
3503 *retval = (register_t)time_state;
3504 }
3505 return error;
3506 }
3507 #endif
3508
3509 int
3510 compat_sparc32_setgid(p, v, retval)
3511 struct proc *p;
3512 void *v;
3513 register_t *retval;
3514 {
3515 struct compat_sparc32_setgid_args /* {
3516 syscallarg(gid_t) gid;
3517 } */ *uap = v;
3518 struct sys_setgid_args ua;
3519
3520 SPARC32TO64_UAP(gid);
3521 return (sys_setgid(p, v, retval));
3522 }
3523
3524 int
3525 compat_sparc32_setegid(p, v, retval)
3526 struct proc *p;
3527 void *v;
3528 register_t *retval;
3529 {
3530 struct compat_sparc32_setegid_args /* {
3531 syscallarg(gid_t) egid;
3532 } */ *uap = v;
3533 struct sys_setegid_args ua;
3534
3535 SPARC32TO64_UAP(egid);
3536 return (sys_setegid(p, v, retval));
3537 }
3538
3539 int
3540 compat_sparc32_seteuid(p, v, retval)
3541 struct proc *p;
3542 void *v;
3543 register_t *retval;
3544 {
3545 struct compat_sparc32_seteuid_args /* {
3546 syscallarg(gid_t) euid;
3547 } */ *uap = v;
3548 struct sys_seteuid_args ua;
3549
3550 SPARC32TO64_UAP(euid);
3551 return (sys_seteuid(p, v, retval));
3552 }
3553
3554 #ifdef LFS
3555 int
3556 compat_sparc32_lfs_bmapv(p, v, retval)
3557 struct proc *p;
3558 void *v;
3559 register_t *retval;
3560 {
3561 #if 0
3562 struct compat_sparc32_lfs_bmapv_args /* {
3563 syscallarg(sparc32_fsid_tp_t) fsidp;
3564 syscallarg(sparc32_block_infop_t) blkiov;
3565 syscallarg(int) blkcnt;
3566 } */ *uap = v;
3567 struct sys_lfs_bmapv_args ua;
3568
3569 SPARC32TOP_UAP(fdidp, struct fsid);
3570 SPARC32TO64_UAP(blkcnt);
3571 /* XXX finish me */
3572 #else
3573
3574 return (ENOSYS); /* XXX */
3575 #endif
3576 }
3577
3578 int
3579 compat_sparc32_lfs_markv(p, v, retval)
3580 struct proc *p;
3581 void *v;
3582 register_t *retval;
3583 {
3584 struct compat_sparc32_lfs_markv_args /* {
3585 syscallarg(sparc32_fsid_tp_t) fsidp;
3586 syscallarg(sparc32_block_infop_t) blkiov;
3587 syscallarg(int) blkcnt;
3588 } */ *uap = v;
3589
3590 return (ENOSYS); /* XXX */
3591 }
3592
3593 int
3594 compat_sparc32_lfs_segclean(p, v, retval)
3595 struct proc *p;
3596 void *v;
3597 register_t *retval;
3598 {
3599 struct compat_sparc32_lfs_segclean_args /* {
3600 syscallarg(sparc32_fsid_tp_t) fsidp;
3601 syscallarg(sparc32_u_long) segment;
3602 } */ *uap = v;
3603 return (ENOSYS); /* XXX */
3604 }
3605
3606 int
3607 compat_sparc32_lfs_segwait(p, v, retval)
3608 struct proc *p;
3609 void *v;
3610 register_t *retval;
3611 {
3612 struct compat_sparc32_lfs_segwait_args /* {
3613 syscallarg(sparc32_fsid_tp_t) fsidp;
3614 syscallarg(sparc32_timevalp_t) tv;
3615 } */ *uap = v;
3616 return (ENOSYS); /* XXX */
3617 }
3618 #endif
3619
3620 int
3621 compat_sparc32_pathconf(p, v, retval)
3622 struct proc *p;
3623 void *v;
3624 register_t *retval;
3625 {
3626 struct compat_sparc32_pathconf_args /* {
3627 syscallarg(int) fd;
3628 syscallarg(int) name;
3629 } */ *uap = v;
3630 struct sys_pathconf_args ua;
3631 long rt;
3632 int error;
3633
3634 SPARC32TOP_UAP(path, const char);
3635 SPARC32TO64_UAP(name);
3636 error = sys_pathconf(p, &ua, (register_t *)&rt);
3637 *(sparc32_long *)retval = (sparc32_long)rt;
3638 return (error);
3639 }
3640
3641 int
3642 compat_sparc32_fpathconf(p, v, retval)
3643 struct proc *p;
3644 void *v;
3645 register_t *retval;
3646 {
3647 struct compat_sparc32_fpathconf_args /* {
3648 syscallarg(int) fd;
3649 syscallarg(int) name;
3650 } */ *uap = v;
3651 struct sys_fpathconf_args ua;
3652 long rt;
3653 int error;
3654
3655 SPARC32TO64_UAP(fd);
3656 SPARC32TO64_UAP(name);
3657 error = sys_fpathconf(p, &ua, (register_t *)&rt);
3658 *(sparc32_long *)retval = (sparc32_long)rt;
3659 return (error);
3660 }
3661
3662 int
3663 compat_sparc32_getrlimit(p, v, retval)
3664 struct proc *p;
3665 void *v;
3666 register_t *retval;
3667 {
3668 struct compat_sparc32_getrlimit_args /* {
3669 syscallarg(int) which;
3670 syscallarg(sparc32_rlimitp_t) rlp;
3671 } */ *uap = v;
3672 int which = SCARG(uap, which);
3673
3674 if ((u_int)which >= RLIM_NLIMITS)
3675 return (EINVAL);
3676 return (copyout(&p->p_rlimit[which], (caddr_t)(u_long)SCARG(uap, rlp),
3677 sizeof(struct rlimit)));
3678 }
3679
3680 int
3681 compat_sparc32_setrlimit(p, v, retval)
3682 struct proc *p;
3683 void *v;
3684 register_t *retval;
3685 {
3686 struct compat_sparc32_setrlimit_args /* {
3687 syscallarg(int) which;
3688 syscallarg(const sparc32_rlimitp_t) rlp;
3689 } */ *uap = v;
3690 int which = SCARG(uap, which);
3691 struct rlimit alim;
3692 int error;
3693
3694 error = copyin((caddr_t)(u_long)SCARG(uap, rlp), &alim, sizeof(struct rlimit));
3695 if (error)
3696 return (error);
3697 return (dosetrlimit(p, which, &alim));
3698 }
3699
3700 int
3701 compat_sparc32_mmap(p, v, retval)
3702 struct proc *p;
3703 void *v;
3704 register_t *retval;
3705 {
3706 struct compat_sparc32_mmap_args /* {
3707 syscallarg(sparc32_voidp) addr;
3708 syscallarg(sparc32_size_t) len;
3709 syscallarg(int) prot;
3710 syscallarg(int) flags;
3711 syscallarg(int) fd;
3712 syscallarg(sparc32_long) pad;
3713 syscallarg(off_t) pos;
3714 } */ *uap = v;
3715 struct sys_mmap_args ua;
3716 void *rt;
3717 int error;
3718
3719 SPARC32TOP_UAP(addr, void);
3720 SPARC32TOX_UAP(len, size_t);
3721 SPARC32TO64_UAP(prot);
3722 SPARC32TO64_UAP(flags);
3723 SPARC32TO64_UAP(fd);
3724 SPARC32TOX_UAP(pad, long);
3725 SPARC32TOX_UAP(pos, off_t);
3726 error = sys_mmap(p, &ua, (register_t *)&rt);
3727 if ((long)rt > (long)UINT_MAX)
3728 printf("compat_sparc32_mmap: retval out of range: 0x%qx",
3729 rt);
3730 *retval = (sparc32_voidp)(u_long)rt;
3731 return (error);
3732 }
3733
3734 int
3735 compat_sparc32_lseek(p, v, retval)
3736 struct proc *p;
3737 void *v;
3738 register_t *retval;
3739 {
3740 struct compat_sparc32_lseek_args /* {
3741 syscallarg(int) fd;
3742 syscallarg(int) pad;
3743 syscallarg(off_t) offset;
3744 syscallarg(int) whence;
3745 } */ *uap = v;
3746 struct sys_lseek_args ua;
3747
3748 SPARC32TO64_UAP(fd);
3749 SPARC32TO64_UAP(pad);
3750 SPARC32TO64_UAP(offset);
3751 SPARC32TO64_UAP(whence);
3752 return (sys_lseek(p, &ua, retval));
3753 }
3754
3755 int
3756 compat_sparc32_truncate(p, v, retval)
3757 struct proc *p;
3758 void *v;
3759 register_t *retval;
3760 {
3761 struct compat_sparc32_truncate_args /* {
3762 syscallarg(const sparc32_charp) path;
3763 syscallarg(int) pad;
3764 syscallarg(off_t) length;
3765 } */ *uap = v;
3766 struct sys_truncate_args ua;
3767
3768 SPARC32TOP_UAP(path, const char);
3769 SPARC32TO64_UAP(pad);
3770 SPARC32TO64_UAP(length);
3771 return (sys_truncate(p, &ua, retval));
3772 }
3773
3774 int
3775 compat_sparc32_ftruncate(p, v, retval)
3776 struct proc *p;
3777 void *v;
3778 register_t *retval;
3779 {
3780 struct compat_sparc32_ftruncate_args /* {
3781 syscallarg(int) fd;
3782 syscallarg(int) pad;
3783 syscallarg(off_t) length;
3784 } */ *uap = v;
3785 struct sys_ftruncate_args ua;
3786
3787 SPARC32TO64_UAP(fd);
3788 SPARC32TO64_UAP(pad);
3789 SPARC32TO64_UAP(length);
3790 return (sys_ftruncate(p, &ua, retval));
3791 }
3792
3793 int
3794 compat_sparc32___sysctl(p, v, retval)
3795 struct proc *p;
3796 void *v;
3797 register_t *retval;
3798 {
3799 struct compat_sparc32___sysctl_args /* {
3800 syscallarg(sparc32_intp) name;
3801 syscallarg(u_int) namelen;
3802 syscallarg(sparc32_voidp) old;
3803 syscallarg(sparc32_size_tp) oldlenp;
3804 syscallarg(sparc32_voidp) new;
3805 syscallarg(sparc32_size_t) newlen;
3806 } */ *uap = v;
3807 int error, dolock = 1;
3808 sparc32_size_t savelen = 0;
3809 size_t oldlen = 0;
3810 sysctlfn *fn;
3811 int name[CTL_MAXNAME];
3812
3813 /*
3814 * Some of these sysctl functions do their own copyin/copyout.
3815 * We need to disable or emulate the ones that need their
3816 * arguments converted.
3817 */
3818
3819 if (SCARG(uap, new) != NULL &&
3820 (error = suser(p->p_ucred, &p->p_acflag)))
3821 return (error);
3822 /*
3823 * all top-level sysctl names are non-terminal
3824 */
3825 if (SCARG(uap, namelen) > CTL_MAXNAME || SCARG(uap, namelen) < 2)
3826 return (EINVAL);
3827 error = copyin((caddr_t)(u_long)SCARG(uap, name), &name,
3828 SCARG(uap, namelen) * sizeof(int));
3829 if (error)
3830 return (error);
3831
3832 switch (name[0]) {
3833 case CTL_KERN:
3834 fn = kern_sysctl;
3835 if (name[2] != KERN_VNODE) /* XXX */
3836 dolock = 0;
3837 break;
3838 case CTL_HW:
3839 fn = hw_sysctl;
3840 break;
3841 case CTL_VM:
3842 fn = uvm_sysctl;
3843 break;
3844 case CTL_NET:
3845 fn = net_sysctl;
3846 break;
3847 case CTL_VFS:
3848 fn = vfs_sysctl;
3849 break;
3850 case CTL_MACHDEP:
3851 fn = cpu_sysctl;
3852 break;
3853 #ifdef DEBUG
3854 case CTL_DEBUG:
3855 fn = debug_sysctl;
3856 break;
3857 #endif
3858 #ifdef DDB
3859 case CTL_DDB:
3860 fn = ddb_sysctl;
3861 break;
3862 #endif
3863 default:
3864 return (EOPNOTSUPP);
3865 }
3866
3867 if (SCARG(uap, oldlenp) &&
3868 (error = copyin((caddr_t)(u_long)SCARG(uap, oldlenp), &savelen, sizeof(savelen))))
3869 return (error);
3870 if (SCARG(uap, old) != NULL) {
3871 if (!uvm_useracc((caddr_t)(u_long)SCARG(uap, old), savelen, B_WRITE))
3872 return (EFAULT);
3873 #if 0 /* XXXXXXXX */
3874 while (memlock.sl_lock) {
3875 memlock.sl_want = 1;
3876 sleep((caddr_t)&memlock, PRIBIO+1);
3877 memlock.sl_locked++;
3878 }
3879 memlock.sl_lock = 1;
3880 #endif /* XXXXXXXX */
3881 if (dolock)
3882 uvm_vslock(p, SCARG(uap, old), savelen);
3883 oldlen = savelen;
3884 }
3885 error = (*fn)(name + 1, SCARG(uap, namelen) - 1, SCARG(uap, old),
3886 &oldlen, SCARG(uap, new), SCARG(uap, newlen), p);
3887 if (SCARG(uap, old) != NULL) {
3888 if (dolock)
3889 uvm_vsunlock(p, SCARG(uap, old), savelen);
3890 #if 0 /* XXXXXXXXXXX */
3891 memlock.sl_lock = 0;
3892 if (memlock.sl_want) {
3893 memlock.sl_want = 0;
3894 wakeup((caddr_t)&memlock);
3895 }
3896 #endif /* XXXXXXXXX */
3897 }
3898 savelen = oldlen;
3899 if (error)
3900 return (error);
3901 if (SCARG(uap, oldlenp))
3902 error = copyout(&savelen, (caddr_t)(u_long)SCARG(uap, oldlenp), sizeof(savelen));
3903 return (error);
3904 }
3905
3906 int
3907 compat_sparc32_mlock(p, v, retval)
3908 struct proc *p;
3909 void *v;
3910 register_t *retval;
3911 {
3912 struct compat_sparc32_mlock_args /* {
3913 syscallarg(const sparc32_voidp) addr;
3914 syscallarg(sparc32_size_t) len;
3915 } */ *uap = v;
3916 struct sys_mlock_args ua;
3917
3918 SPARC32TOP_UAP(addr, const void);
3919 SPARC32TO64_UAP(len);
3920 return (sys_mlock(p, &ua, retval));
3921 }
3922
3923 int
3924 compat_sparc32_munlock(p, v, retval)
3925 struct proc *p;
3926 void *v;
3927 register_t *retval;
3928 {
3929 struct compat_sparc32_munlock_args /* {
3930 syscallarg(const sparc32_voidp) addr;
3931 syscallarg(sparc32_size_t) len;
3932 } */ *uap = v;
3933 struct sys_munlock_args ua;
3934
3935 SPARC32TOP_UAP(addr, const void);
3936 SPARC32TO64_UAP(len);
3937 return (sys_munlock(p, &ua, retval));
3938 }
3939
3940 int
3941 compat_sparc32_undelete(p, v, retval)
3942 struct proc *p;
3943 void *v;
3944 register_t *retval;
3945 {
3946 struct compat_sparc32_undelete_args /* {
3947 syscallarg(const sparc32_charp) path;
3948 } */ *uap = v;
3949 struct sys_undelete_args ua;
3950
3951 SPARC32TOP_UAP(path, const char);
3952 return (sys_undelete(p, &ua, retval));
3953 }
3954
3955 int
3956 compat_sparc32_futimes(p, v, retval)
3957 struct proc *p;
3958 void *v;
3959 register_t *retval;
3960 {
3961 struct compat_sparc32_futimes_args /* {
3962 syscallarg(int) fd;
3963 syscallarg(const sparc32_timevalp_t) tptr;
3964 } */ *uap = v;
3965 int error;
3966 struct file *fp;
3967
3968 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
3969 return (error);
3970
3971 return (change_utimes32((struct vnode *)fp->f_data,
3972 (struct timeval *)(u_long)SCARG(uap, tptr), p));
3973 }
3974
3975 int
3976 compat_sparc32_getpgid(p, v, retval)
3977 struct proc *p;
3978 void *v;
3979 register_t *retval;
3980 {
3981 struct compat_sparc32_getpgid_args /* {
3982 syscallarg(pid_t) pid;
3983 } */ *uap = v;
3984 struct sys_getpgid_args ua;
3985
3986 SPARC32TO64_UAP(pid);
3987 return (sys_getpgid(p, &ua, retval));
3988 }
3989
3990 int
3991 compat_sparc32_reboot(p, v, retval)
3992 struct proc *p;
3993 void *v;
3994 register_t *retval;
3995 {
3996 struct compat_sparc32_reboot_args /* {
3997 syscallarg(int) opt;
3998 syscallarg(sparc32_charp) bootstr;
3999 } */ *uap = v;
4000 struct sys_reboot_args ua;
4001
4002 SPARC32TO64_UAP(opt);
4003 SPARC32TOP_UAP(bootstr, char);
4004 return (sys_reboot(p, &ua, retval));
4005 }
4006
4007 int
4008 compat_sparc32_poll(p, v, retval)
4009 struct proc *p;
4010 void *v;
4011 register_t *retval;
4012 {
4013 struct compat_sparc32_poll_args /* {
4014 syscallarg(sparc32_pollfdp_t) fds;
4015 syscallarg(u_int) nfds;
4016 syscallarg(int) timeout;
4017 } */ *uap = v;
4018 struct sys_poll_args ua;
4019
4020 SPARC32TOP_UAP(fds, struct pollfd);
4021 SPARC32TO64_UAP(nfds);
4022 SPARC32TO64_UAP(timeout);
4023 return (sys_poll(p, &ua, retval));
4024 }
4025
4026 /*
4027 * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
4028 *
4029 * This is BSD. We won't support System V IPC.
4030 * Too much work.
4031 *
4032 * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
4033 */
4034 int
4035 compat_sparc32___semctl(p, v, retval)
4036 struct proc *p;
4037 void *v;
4038 register_t *retval;
4039 {
4040 #if 0
4041 struct compat_sparc32___semctl_args /* {
4042 syscallarg(int) semid;
4043 syscallarg(int) semnum;
4044 syscallarg(int) cmd;
4045 syscallarg(sparc32_semunu_t) arg;
4046 } */ *uap = v;
4047 union sparc32_semun sem32;
4048 int semid = SCARG(uap, semid);
4049 int semnum = SCARG(uap, semnum);
4050 int cmd = SCARG(uap, cmd);
4051 union sparc32_semun *arg = (void*)(u_long)SCARG(uap, arg);
4052 union sparc32_semun real_arg;
4053 struct ucred *cred = p->p_ucred;
4054 int i, rval, eval;
4055 struct sparc32_semid_ds sbuf;
4056 register struct semid_ds *semaptr;
4057
4058 semlock(p);
4059
4060 semid = IPCID_TO_IX(semid);
4061 if (semid < 0 || semid >= seminfo.semmsl)
4062 return(EINVAL);
4063
4064 semaptr = &sema[semid];
4065 if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0 ||
4066 semaptr->sem_perm.seq != IPCID_TO_SEQ(SCARG(uap, semid)))
4067 return(EINVAL);
4068
4069 eval = 0;
4070 rval = 0;
4071
4072 switch (cmd) {
4073 case IPC_RMID:
4074 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_M)) != 0)
4075 return(eval);
4076 semaptr->sem_perm.cuid = cred->cr_uid;
4077 semaptr->sem_perm.uid = cred->cr_uid;
4078 semtot -= semaptr->sem_nsems;
4079 for (i = semaptr->sem_base - sem; i < semtot; i++)
4080 sem[i] = sem[i + semaptr->sem_nsems];
4081 for (i = 0; i < seminfo.semmni; i++) {
4082 if ((sema[i].sem_perm.mode & SEM_ALLOC) &&
4083 sema[i].sem_base > semaptr->sem_base)
4084 sema[i].sem_base -= semaptr->sem_nsems;
4085 }
4086 semaptr->sem_perm.mode = 0;
4087 semundo_clear(semid, -1);
4088 wakeup((caddr_t)semaptr);
4089 break;
4090
4091 case IPC_SET:
4092 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_M)))
4093 return(eval);
4094 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
4095 return(eval);
4096 if ((eval = copyin((caddr_t)(u_long)real_arg.buf, (caddr_t)&sbuf,
4097 sizeof(sbuf))) != 0)
4098 return(eval);
4099 semaptr->sem_perm.uid = sbuf.sem_perm.uid;
4100 semaptr->sem_perm.gid = sbuf.sem_perm.gid;
4101 semaptr->sem_perm.mode = (semaptr->sem_perm.mode & ~0777) |
4102 (sbuf.sem_perm.mode & 0777);
4103 semaptr->sem_ctime = time.tv_sec;
4104 break;
4105
4106 case IPC_STAT:
4107 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
4108 return(eval);
4109 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
4110 return(eval);
4111 eval = copyout((caddr_t)semaptr, (caddr_t)(u_long)real_arg.buf,
4112 sizeof(struct semid_ds));
4113 break;
4114
4115 case GETNCNT:
4116 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
4117 return(eval);
4118 if (semnum < 0 || semnum >= semaptr->sem_nsems)
4119 return(EINVAL);
4120 rval = semaptr->sem_base[semnum].semncnt;
4121 break;
4122
4123 case GETPID:
4124 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
4125 return(eval);
4126 if (semnum < 0 || semnum >= semaptr->sem_nsems)
4127 return(EINVAL);
4128 rval = semaptr->sem_base[semnum].sempid;
4129 break;
4130
4131 case GETVAL:
4132 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
4133 return(eval);
4134 if (semnum < 0 || semnum >= semaptr->sem_nsems)
4135 return(EINVAL);
4136 rval = semaptr->sem_base[semnum].semval;
4137 break;
4138
4139 case GETALL:
4140 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
4141 return(eval);
4142 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
4143 return(eval);
4144 for (i = 0; i < semaptr->sem_nsems; i++) {
4145 eval = copyout((caddr_t)&semaptr->sem_base[i].semval,
4146 &real_arg.array[i], sizeof(real_arg.array[0]));
4147 if (eval != 0)
4148 break;
4149 }
4150 break;
4151
4152 case GETZCNT:
4153 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
4154 return(eval);
4155 if (semnum < 0 || semnum >= semaptr->sem_nsems)
4156 return(EINVAL);
4157 rval = semaptr->sem_base[semnum].semzcnt;
4158 break;
4159
4160 case SETVAL:
4161 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_W)))
4162 return(eval);
4163 if (semnum < 0 || semnum >= semaptr->sem_nsems)
4164 return(EINVAL);
4165 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
4166 return(eval);
4167 semaptr->sem_base[semnum].semval = real_arg.val;
4168 semundo_clear(semid, semnum);
4169 wakeup((caddr_t)semaptr);
4170 break;
4171
4172 case SETALL:
4173 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_W)))
4174 return(eval);
4175 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
4176 return(eval);
4177 for (i = 0; i < semaptr->sem_nsems; i++) {
4178 eval = copyin(&real_arg.array[i],
4179 (caddr_t)&semaptr->sem_base[i].semval,
4180 sizeof(real_arg.array[0]));
4181 if (eval != 0)
4182 break;
4183 }
4184 semundo_clear(semid, -1);
4185 wakeup((caddr_t)semaptr);
4186 break;
4187
4188 default:
4189 return(EINVAL);
4190 }
4191
4192 if (eval == 0)
4193 *retval = rval;
4194 return(eval);
4195 #else
4196 return (ENOSYS);
4197 #endif
4198 }
4199
4200 int
4201 compat_sparc32_semget(p, v, retval)
4202 struct proc *p;
4203 void *v;
4204 register_t *retval;
4205 {
4206 struct compat_sparc32_semget_args /* {
4207 syscallarg(sparc32_key_t) key;
4208 syscallarg(int) nsems;
4209 syscallarg(int) semflg;
4210 } */ *uap = v;
4211 struct sys_semget_args ua;
4212
4213 SPARC32TOX_UAP(key, key_t);
4214 SPARC32TO64_UAP(nsems);
4215 SPARC32TO64_UAP(semflg);
4216 return (sys_semget(p, &ua, retval));
4217 }
4218
4219 int
4220 compat_sparc32_semop(p, v, retval)
4221 struct proc *p;
4222 void *v;
4223 register_t *retval;
4224 {
4225 struct compat_sparc32_semop_args /* {
4226 syscallarg(int) semid;
4227 syscallarg(sparc32_sembufp_t) sops;
4228 syscallarg(sparc32_size_t) nsops;
4229 } */ *uap = v;
4230 struct sys_semop_args ua;
4231
4232 SPARC32TO64_UAP(semid);
4233 SPARC32TOP_UAP(sops, struct sembuf);
4234 SPARC32TOX_UAP(nsops, size_t);
4235 return (sys_semop(p, &ua, retval));
4236 }
4237
4238 int
4239 compat_sparc32_semconfig(p, v, retval)
4240 struct proc *p;
4241 void *v;
4242 register_t *retval;
4243 {
4244 struct compat_sparc32_semconfig_args /* {
4245 syscallarg(int) flag;
4246 } */ *uap = v;
4247 struct sys_semconfig_args ua;
4248
4249 SPARC32TO64_UAP(flag);
4250 return (sys_semconfig(p, &ua, retval));
4251 }
4252
4253 int
4254 compat_sparc32_msgctl(p, v, retval)
4255 struct proc *p;
4256 void *v;
4257 register_t *retval;
4258 {
4259 #if 0
4260 struct compat_sparc32_msgctl_args /* {
4261 syscallarg(int) msqid;
4262 syscallarg(int) cmd;
4263 syscallarg(sparc32_msqid_dsp_t) buf;
4264 } */ *uap = v;
4265 struct sys_msgctl_args ua;
4266 struct msqid_ds ds;
4267 struct sparc32_msqid_ds *ds32p;
4268 int error;
4269
4270 SPARC32TO64_UAP(msqid);
4271 SPARC32TO64_UAP(cmd);
4272 ds32p = (struct sparc32_msqid_ds *)(u_long)SCARG(uap, buf);
4273 if (ds32p) {
4274 SCARG(&ua, buf) = NULL;
4275 sparc32_to_msqid_ds(ds32p, &ds);
4276 } else
4277 SCARG(&ua, buf) = NULL;
4278 error = sys_msgctl(p, &ua, retval);
4279 if (error)
4280 return (error);
4281
4282 if (ds32p)
4283 sparc32_from_msqid_ds(&ds, ds32p);
4284 return (0);
4285 #else
4286 return (ENOSYS);
4287 #endif
4288 }
4289
4290 int
4291 compat_sparc32_msgget(p, v, retval)
4292 struct proc *p;
4293 void *v;
4294 register_t *retval;
4295 {
4296 #if 0
4297 struct compat_sparc32_msgget_args /* {
4298 syscallarg(sparc32_key_t) key;
4299 syscallarg(int) msgflg;
4300 } */ *uap = v;
4301 struct sys_msgget_args ua;
4302
4303 SPARC32TOX_UAP(key, key_t);
4304 SPARC32TO64_UAP(msgflg);
4305 return (sys_msgget(p, &ua, retval));
4306 #else
4307 return (ENOSYS);
4308 #endif
4309 }
4310
4311 int
4312 compat_sparc32_msgsnd(p, v, retval)
4313 struct proc *p;
4314 void *v;
4315 register_t *retval;
4316 {
4317 #if 0
4318 struct compat_sparc32_msgsnd_args /* {
4319 syscallarg(int) msqid;
4320 syscallarg(const sparc32_voidp) msgp;
4321 syscallarg(sparc32_size_t) msgsz;
4322 syscallarg(int) msgflg;
4323 } */ *uap = v;
4324 struct sys_msgsnd_args ua;
4325
4326 SPARC32TO64_UAP(msqid);
4327 SPARC32TOP_UAP(msgp, void);
4328 SPARC32TOX_UAP(msgsz, size_t);
4329 SPARC32TO64_UAP(msgflg);
4330 return (sys_msgsnd(p, &ua, retval));
4331 #else
4332 return (ENOSYS);
4333 #endif
4334 }
4335
4336 int
4337 compat_sparc32_msgrcv(p, v, retval)
4338 struct proc *p;
4339 void *v;
4340 register_t *retval;
4341 {
4342 #if 0
4343 struct compat_sparc32_msgrcv_args /* {
4344 syscallarg(int) msqid;
4345 syscallarg(sparc32_voidp) msgp;
4346 syscallarg(sparc32_size_t) msgsz;
4347 syscallarg(sparc32_long) msgtyp;
4348 syscallarg(int) msgflg;
4349 } */ *uap = v;
4350 struct sys_msgrcv_args ua;
4351 ssize_t rt;
4352 int error;
4353
4354 SPARC32TO64_UAP(msqid);
4355 SPARC32TOP_UAP(msgp, void);
4356 SPARC32TOX_UAP(msgsz, size_t);
4357 SPARC32TOX_UAP(msgtyp, long);
4358 SPARC32TO64_UAP(msgflg);
4359 error = sys_msgrcv(p, &ua, (register_t *)&rt);
4360 *(sparc32_ssize_t *)retval = rt;
4361 return (error);
4362 #else
4363 return (ENOSYS);
4364 #endif
4365 }
4366
4367 int
4368 compat_sparc32_shmat(p, v, retval)
4369 struct proc *p;
4370 void *v;
4371 register_t *retval;
4372 {
4373 #if 0
4374 struct compat_sparc32_shmat_args /* {
4375 syscallarg(int) shmid;
4376 syscallarg(const sparc32_voidp) shmaddr;
4377 syscallarg(int) shmflg;
4378 } */ *uap = v;
4379 struct sys_shmat_args ua;
4380 void *rt;
4381 int error;
4382
4383 SPARC32TO64_UAP(shmid);
4384 SPARC32TOP_UAP(shmaddr, void);
4385 SPARC32TO64_UAP(shmflg);
4386 error = sys_shmat(p, &ua, (register_t *)&rt);
4387 *retval = (sparc32_voidp)(u_long)rt;
4388 return (error);
4389 #else
4390 return (ENOSYS);
4391 #endif
4392 }
4393
4394 int
4395 compat_sparc32_shmctl(p, v, retval)
4396 struct proc *p;
4397 void *v;
4398 register_t *retval;
4399 {
4400 #if 0
4401 struct compat_sparc32_shmctl_args /* {
4402 syscallarg(int) shmid;
4403 syscallarg(int) cmd;
4404 syscallarg(sparc32_shmid_dsp_t) buf;
4405 } */ *uap = v;
4406 struct sys_shmctl_args ua;
4407 struct shmid_ds ds;
4408 struct sparc32_shmid_ds *ds32p;
4409 int error;
4410
4411 SPARC32TO64_UAP(shmid);
4412 SPARC32TO64_UAP(cmd);
4413 ds32p = (struct sparc32_shmid_ds *)(u_long)SCARG(uap, buf);
4414 if (ds32p) {
4415 SCARG(&ua, buf) = NULL;
4416 sparc32_to_shmid_ds(ds32p, &ds);
4417 } else
4418 SCARG(&ua, buf) = NULL;
4419 error = sys_shmctl(p, &ua, retval);
4420 if (error)
4421 return (error);
4422
4423 if (ds32p)
4424 sparc32_from_shmid_ds(&ds, ds32p);
4425 return (0);
4426 #else
4427 return (ENOSYS);
4428 #endif
4429 }
4430
4431 int
4432 compat_sparc32_shmdt(p, v, retval)
4433 struct proc *p;
4434 void *v;
4435 register_t *retval;
4436 {
4437 #if 0
4438 struct compat_sparc32_shmdt_args /* {
4439 syscallarg(const sparc32_voidp) shmaddr;
4440 } */ *uap = v;
4441 struct sys_shmdt_args ua;
4442
4443 SPARC32TOP_UAP(shmaddr, const char);
4444 return (sys_shmdt(p, &ua, retval));
4445 #else
4446 return (ENOSYS);
4447 #endif
4448 }
4449
4450 int
4451 compat_sparc32_shmget(p, v, retval)
4452 struct proc *p;
4453 void *v;
4454 register_t *retval;
4455 {
4456 #if 0
4457 struct compat_sparc32_shmget_args /* {
4458 syscallarg(sparc32_key_t) key;
4459 syscallarg(sparc32_size_t) size;
4460 syscallarg(int) shmflg;
4461 } */ *uap = v;
4462 struct sys_shmget_args ua;
4463
4464 SPARC32TOX_UAP(key, key_t)
4465 SPARC32TOX_UAP(size, size_t)
4466 SPARC32TO64_UAP(shmflg);
4467 return (sys_shmget(p, &ua, retval));
4468 #else
4469 return (ENOSYS);
4470 #endif
4471 }
4472
4473 int
4474 compat_sparc32_clock_gettime(p, v, retval)
4475 struct proc *p;
4476 void *v;
4477 register_t *retval;
4478 {
4479 struct compat_sparc32_clock_gettime_args /* {
4480 syscallarg(sparc32_clockid_t) clock_id;
4481 syscallarg(sparc32_timespecp_t) tp;
4482 } */ *uap = v;
4483 clockid_t clock_id;
4484 struct timeval atv;
4485 struct timespec ats;
4486 struct sparc32_timespec ts32;
4487
4488 clock_id = SCARG(uap, clock_id);
4489 if (clock_id != CLOCK_REALTIME)
4490 return (EINVAL);
4491
4492 microtime(&atv);
4493 TIMEVAL_TO_TIMESPEC(&atv,&ats);
4494 sparc32_from_timespec(&ats, &ts32);
4495
4496 return copyout(&ts32, (caddr_t)(u_long)SCARG(uap, tp), sizeof(ts32));
4497 }
4498
4499 int
4500 compat_sparc32_clock_settime(p, v, retval)
4501 struct proc *p;
4502 void *v;
4503 register_t *retval;
4504 {
4505 struct compat_sparc32_clock_settime_args /* {
4506 syscallarg(sparc32_clockid_t) clock_id;
4507 syscallarg(const sparc32_timespecp_t) tp;
4508 } */ *uap = v;
4509 struct sparc32_timespec ts32;
4510 clockid_t clock_id;
4511 struct timeval atv;
4512 struct timespec ats;
4513 int error;
4514
4515 if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
4516 return (error);
4517
4518 clock_id = SCARG(uap, clock_id);
4519 if (clock_id != CLOCK_REALTIME)
4520 return (EINVAL);
4521
4522 if ((error = copyin((caddr_t)(u_long)SCARG(uap, tp), &ts32, sizeof(ts32))) != 0)
4523 return (error);
4524
4525 sparc32_to_timespec(&ts32, &ats);
4526 TIMESPEC_TO_TIMEVAL(&atv,&ats);
4527 if ((error = settime(&atv)))
4528 return (error);
4529
4530 return 0;
4531 }
4532
4533 int
4534 compat_sparc32_clock_getres(p, v, retval)
4535 struct proc *p;
4536 void *v;
4537 register_t *retval;
4538 {
4539 struct compat_sparc32_clock_getres_args /* {
4540 syscallarg(sparc32_clockid_t) clock_id;
4541 syscallarg(sparc32_timespecp_t) tp;
4542 } */ *uap = v;
4543 struct sparc32_timespec ts32;
4544 clockid_t clock_id;
4545 struct timespec ts;
4546 int error = 0;
4547
4548 clock_id = SCARG(uap, clock_id);
4549 if (clock_id != CLOCK_REALTIME)
4550 return (EINVAL);
4551
4552 if (SCARG(uap, tp)) {
4553 ts.tv_sec = 0;
4554 ts.tv_nsec = 1000000000 / hz;
4555
4556 sparc32_from_timespec(&ts, &ts32);
4557 error = copyout(&ts, (caddr_t)(u_long)SCARG(uap, tp), sizeof(ts));
4558 }
4559
4560 return error;
4561 }
4562
4563 int
4564 compat_sparc32_nanosleep(p, v, retval)
4565 struct proc *p;
4566 void *v;
4567 register_t *retval;
4568 {
4569 struct compat_sparc32_nanosleep_args /* {
4570 syscallarg(const sparc32_timespecp_t) rqtp;
4571 syscallarg(sparc32_timespecp_t) rmtp;
4572 } */ *uap = v;
4573 static int nanowait;
4574 struct sparc32_timespec ts32;
4575 struct timespec rqt;
4576 struct timespec rmt;
4577 struct timeval atv, utv;
4578 int error, s, timo;
4579
4580 error = copyin((caddr_t)(u_long)SCARG(uap, rqtp), (caddr_t)&ts32,
4581 sizeof(ts32));
4582 if (error)
4583 return (error);
4584
4585 sparc32_to_timespec(&ts32, &rqt);
4586 TIMESPEC_TO_TIMEVAL(&atv,&rqt)
4587 if (itimerfix(&atv))
4588 return (EINVAL);
4589
4590 s = splclock();
4591 timeradd(&atv,&time,&atv);
4592 timo = hzto(&atv);
4593 /*
4594 * Avoid inadvertantly sleeping forever
4595 */
4596 if (timo == 0)
4597 timo = 1;
4598 splx(s);
4599
4600 error = tsleep(&nanowait, PWAIT | PCATCH, "nanosleep", timo);
4601 if (error == ERESTART)
4602 error = EINTR;
4603 if (error == EWOULDBLOCK)
4604 error = 0;
4605
4606 if (SCARG(uap, rmtp)) {
4607 int error;
4608
4609 s = splclock();
4610 utv = time;
4611 splx(s);
4612
4613 timersub(&atv, &utv, &utv);
4614 if (utv.tv_sec < 0)
4615 timerclear(&utv);
4616
4617 TIMEVAL_TO_TIMESPEC(&utv,&rmt);
4618 sparc32_from_timespec(&rmt, &ts32);
4619 error = copyout((caddr_t)&ts32, (caddr_t)(u_long)SCARG(uap,rmtp),
4620 sizeof(ts32));
4621 if (error)
4622 return (error);
4623 }
4624
4625 return error;
4626 }
4627
4628 int
4629 compat_sparc32_fdatasync(p, v, retval)
4630 struct proc *p;
4631 void *v;
4632 register_t *retval;
4633 {
4634 struct compat_sparc32_fdatasync_args /* {
4635 syscallarg(int) fd;
4636 } */ *uap = v;
4637 struct sys_fdatasync_args ua;
4638
4639 SPARC32TO64_UAP(fd);
4640
4641 return (sys_fdatasync(p, &ua, retval));
4642 }
4643
4644 int
4645 compat_sparc32___posix_rename(p, v, retval)
4646 struct proc *p;
4647 void *v;
4648 register_t *retval;
4649 {
4650 struct compat_sparc32___posix_rename_args /* {
4651 syscallarg(const sparc32_charp) from;
4652 syscallarg(const sparc32_charp) to;
4653 } */ *uap = v;
4654 struct sys___posix_rename_args ua;
4655
4656 SPARC32TOP_UAP(from, const char *);
4657 SPARC32TOP_UAP(to, const char *);
4658
4659 return (sys___posix_rename(p, &ua, retval));
4660 }
4661
4662 int
4663 compat_sparc32_swapctl(p, v, retval)
4664 struct proc *p;
4665 void *v;
4666 register_t *retval;
4667 {
4668 struct compat_sparc32_swapctl_args /* {
4669 syscallarg(int) cmd;
4670 syscallarg(const sparc32_voidp) arg;
4671 syscallarg(int) misc;
4672 } */ *uap = v;
4673 struct sys_swapctl_args ua;
4674
4675 SPARC32TO64_UAP(cmd);
4676 SPARC32TOP_UAP(arg, const void);
4677 SPARC32TO64_UAP(misc);
4678 return (sys_swapctl(p, &ua, retval));
4679 }
4680
4681 int
4682 compat_sparc32_getdents(p, v, retval)
4683 struct proc *p;
4684 void *v;
4685 register_t *retval;
4686 {
4687 struct compat_sparc32_getdents_args /* {
4688 syscallarg(int) fd;
4689 syscallarg(sparc32_charp) buf;
4690 syscallarg(sparc32_size_t) count;
4691 } */ *uap = v;
4692 struct file *fp;
4693 int error, done;
4694
4695 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
4696 return (error);
4697 if ((fp->f_flag & FREAD) == 0)
4698 return (EBADF);
4699 error = vn_readdir(fp, (caddr_t)(u_long)SCARG(uap, buf), UIO_USERSPACE,
4700 SCARG(uap, count), &done, p, 0, 0);
4701 *retval = done;
4702 return (error);
4703 }
4704
4705
4706 int
4707 compat_sparc32_minherit(p, v, retval)
4708 struct proc *p;
4709 void *v;
4710 register_t *retval;
4711 {
4712 struct compat_sparc32_minherit_args /* {
4713 syscallarg(sparc32_voidp) addr;
4714 syscallarg(sparc32_size_t) len;
4715 syscallarg(int) inherit;
4716 } */ *uap = v;
4717 struct sys_minherit_args ua;
4718
4719 SPARC32TOP_UAP(addr, void);
4720 SPARC32TOX_UAP(len, size_t);
4721 SPARC32TO64_UAP(inherit);
4722 return (sys_minherit(p, &ua, retval));
4723 }
4724
4725 int
4726 compat_sparc32_lchmod(p, v, retval)
4727 struct proc *p;
4728 void *v;
4729 register_t *retval;
4730 {
4731 struct compat_sparc32_lchmod_args /* {
4732 syscallarg(const sparc32_charp) path;
4733 syscallarg(mode_t) mode;
4734 } */ *uap = v;
4735 struct sys_lchmod_args ua;
4736
4737 SPARC32TOP_UAP(path, const char);
4738 SPARC32TO64_UAP(mode);
4739 return (sys_lchmod(p, &ua, retval));
4740 }
4741
4742 int
4743 compat_sparc32_lchown(p, v, retval)
4744 struct proc *p;
4745 void *v;
4746 register_t *retval;
4747 {
4748 struct compat_sparc32_lchown_args /* {
4749 syscallarg(const sparc32_charp) path;
4750 syscallarg(uid_t) uid;
4751 syscallarg(gid_t) gid;
4752 } */ *uap = v;
4753 struct sys_lchown_args ua;
4754
4755 SPARC32TOP_UAP(path, const char);
4756 SPARC32TO64_UAP(uid);
4757 SPARC32TO64_UAP(gid);
4758 return (sys_lchown(p, &ua, retval));
4759 }
4760
4761 int
4762 compat_sparc32_lutimes(p, v, retval)
4763 struct proc *p;
4764 void *v;
4765 register_t *retval;
4766 {
4767 struct compat_sparc32_lutimes_args /* {
4768 syscallarg(const sparc32_charp) path;
4769 syscallarg(const sparc32_timevalp_t) tptr;
4770 } */ *uap = v;
4771 int error;
4772 struct nameidata nd;
4773
4774 NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, (caddr_t)(u_long)SCARG(uap, path), p);
4775 if ((error = namei(&nd)) != 0)
4776 return (error);
4777
4778 error = change_utimes32(nd.ni_vp, (struct timeval *)(u_long)SCARG(uap, tptr), p);
4779
4780 vrele(nd.ni_vp);
4781 return (error);
4782 }
4783
4784
4785 int
4786 compat_sparc32___msync13(p, v, retval)
4787 struct proc *p;
4788 void *v;
4789 register_t *retval;
4790 {
4791 struct compat_sparc32___msync13_args /* {
4792 syscallarg(sparc32_voidp) addr;
4793 syscallarg(sparc32_size_t) len;
4794 syscallarg(int) flags;
4795 } */ *uap = v;
4796 struct sys___msync13_args ua;
4797
4798 SPARC32TOP_UAP(addr, void);
4799 SPARC32TOX_UAP(len, size_t);
4800 SPARC32TO64_UAP(flags);
4801 return (sys___msync13(p, &ua, retval));
4802 }
4803
4804 int
4805 compat_sparc32___stat13(p, v, retval)
4806 struct proc *p;
4807 void *v;
4808 register_t *retval;
4809 {
4810 struct compat_sparc32___stat13_args /* {
4811 syscallarg(const sparc32_charp) path;
4812 syscallarg(sparc32_statp_t) ub;
4813 } */ *uap = v;
4814 struct sparc32_stat sb32;
4815 struct stat sb;
4816 int error;
4817 struct nameidata nd;
4818
4819 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
4820 (caddr_t)(u_long)SCARG(uap, path), p);
4821 if ((error = namei(&nd)) != 0)
4822 return (error);
4823 error = vn_stat(nd.ni_vp, &sb, p);
4824 vput(nd.ni_vp);
4825 if (error)
4826 return (error);
4827 sparc32_from___stat13(&sb, &sb32);
4828 error = copyout(&sb32, (caddr_t)(u_long)SCARG(uap, ub), sizeof(sb32));
4829 return (error);
4830 }
4831
4832 int
4833 compat_sparc32___fstat13(p, v, retval)
4834 struct proc *p;
4835 void *v;
4836 register_t *retval;
4837 {
4838 struct compat_sparc32___fstat13_args /* {
4839 syscallarg(int) fd;
4840 syscallarg(sparc32_statp_t) sb;
4841 } */ *uap = v;
4842 int fd = SCARG(uap, fd);
4843 register struct filedesc *fdp = p->p_fd;
4844 register struct file *fp;
4845 struct sparc32_stat sb32;
4846 struct stat ub;
4847 int error = 0;
4848
4849 if ((u_int)fd >= fdp->fd_nfiles ||
4850 (fp = fdp->fd_ofiles[fd]) == NULL)
4851 return (EBADF);
4852 switch (fp->f_type) {
4853
4854 case DTYPE_VNODE:
4855 error = vn_stat((struct vnode *)fp->f_data, &ub, p);
4856 break;
4857
4858 case DTYPE_SOCKET:
4859 error = soo_stat((struct socket *)fp->f_data, &ub);
4860 break;
4861
4862 default:
4863 panic("fstat");
4864 /*NOTREACHED*/
4865 }
4866 if (error == 0) {
4867 sparc32_from___stat13(&ub, &sb32);
4868 error = copyout(&sb32, (caddr_t)(u_long)SCARG(uap, sb), sizeof(sb32));
4869 }
4870 return (error);
4871 }
4872
4873 int
4874 compat_sparc32___lstat13(p, v, retval)
4875 struct proc *p;
4876 void *v;
4877 register_t *retval;
4878 {
4879 struct compat_sparc32___lstat13_args /* {
4880 syscallarg(const sparc32_charp) path;
4881 syscallarg(sparc32_statp_t) ub;
4882 } */ *uap = v;
4883 struct sparc32_stat sb32;
4884 struct stat sb;
4885 int error;
4886 struct nameidata nd;
4887
4888 NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF, UIO_USERSPACE,
4889 (caddr_t)(u_long)SCARG(uap, path), p);
4890 if ((error = namei(&nd)) != 0)
4891 return (error);
4892 error = vn_stat(nd.ni_vp, &sb, p);
4893 vput(nd.ni_vp);
4894 if (error)
4895 return (error);
4896 sparc32_from___stat13(&sb, &sb32);
4897 error = copyout(&sb32, (caddr_t)(u_long)SCARG(uap, ub), sizeof(sb32));
4898 return (error);
4899 }
4900
4901 int
4902 compat_sparc32___sigaltstack14(p, v, retval)
4903 struct proc *p;
4904 void *v;
4905 register_t *retval;
4906 {
4907 struct compat_sparc32___sigaltstack14_args /* {
4908 syscallarg(const sparc32_sigaltstackp_t) nss;
4909 syscallarg(sparc32_sigaltstackp_t) oss;
4910 } */ *uap = v;
4911 struct sparc32_sigaltstack s32;
4912 struct sigaltstack nss, oss;
4913 int error;
4914
4915 if (SCARG(uap, nss)) {
4916 error = copyin((caddr_t)(u_long)SCARG(uap, nss), &s32, sizeof(s32));
4917 if (error)
4918 return (error);
4919 nss.ss_sp = (void *)(u_long)s32.ss_sp;
4920 nss.ss_size = (size_t)s32.ss_size;
4921 nss.ss_flags = s32.ss_flags;
4922 }
4923 error = sigaltstack1(p,
4924 SCARG(uap, nss) ? &nss : 0, SCARG(uap, oss) ? &oss : 0);
4925 if (error)
4926 return (error);
4927 if (SCARG(uap, oss)) {
4928 s32.ss_sp = (sparc32_voidp)(u_long)oss.ss_sp;
4929 s32.ss_size = (sparc32_size_t)oss.ss_size;
4930 s32.ss_flags = oss.ss_flags;
4931 error = copyout(&s32, (caddr_t)(u_long)SCARG(uap, oss), sizeof(s32));
4932 if (error)
4933 return (error);
4934 }
4935 return (0);
4936 }
4937
4938 int
4939 compat_sparc32___posix_chown(p, v, retval)
4940 struct proc *p;
4941 void *v;
4942 register_t *retval;
4943 {
4944 struct compat_sparc32___posix_chown_args /* {
4945 syscallarg(const sparc32_charp) path;
4946 syscallarg(uid_t) uid;
4947 syscallarg(gid_t) gid;
4948 } */ *uap = v;
4949 struct sys___posix_chown_args ua;
4950
4951 SPARC32TOP_UAP(path, const char);
4952 SPARC32TO64_UAP(uid);
4953 SPARC32TO64_UAP(gid);
4954 return (sys___posix_chown(p, &ua, retval));
4955 }
4956
4957 int
4958 compat_sparc32___posix_fchown(p, v, retval)
4959 struct proc *p;
4960 void *v;
4961 register_t *retval;
4962 {
4963 struct compat_sparc32___posix_fchown_args /* {
4964 syscallarg(int) fd;
4965 syscallarg(uid_t) uid;
4966 syscallarg(gid_t) gid;
4967 } */ *uap = v;
4968 struct sys___posix_fchown_args ua;
4969
4970 SPARC32TO64_UAP(fd);
4971 SPARC32TO64_UAP(uid);
4972 SPARC32TO64_UAP(gid);
4973 return (sys___posix_fchown(p, &ua, retval));
4974 }
4975
4976 int
4977 compat_sparc32___posix_lchown(p, v, retval)
4978 struct proc *p;
4979 void *v;
4980 register_t *retval;
4981 {
4982 struct compat_sparc32___posix_lchown_args /* {
4983 syscallarg(const sparc32_charp) path;
4984 syscallarg(uid_t) uid;
4985 syscallarg(gid_t) gid;
4986 } */ *uap = v;
4987 struct sys___posix_lchown_args ua;
4988
4989 SPARC32TOP_UAP(path, const char);
4990 SPARC32TO64_UAP(uid);
4991 SPARC32TO64_UAP(gid);
4992 return (sys___posix_lchown(p, &ua, retval));
4993 }
4994
4995 int
4996 compat_sparc32_getsid(p, v, retval)
4997 struct proc *p;
4998 void *v;
4999 register_t *retval;
5000 {
5001 struct compat_sparc32_getsid_args /* {
5002 syscallarg(pid_t) pid;
5003 } */ *uap = v;
5004 struct sys_getsid_args ua;
5005
5006 SPARC32TO64_UAP(pid);
5007 return (sys_getsid(p, &ua, retval));
5008 }
5009
5010 int
5011 compat_sparc32_fktrace(p, v, retval)
5012 struct proc *p;
5013 void *v;
5014 register_t *retval;
5015 {
5016 struct compat_sparc32_fktrace_args /* {
5017 syscallarg(const int) fd;
5018 syscallarg(int) ops;
5019 syscallarg(int) facs;
5020 syscallarg(int) pid;
5021 } */ *uap = v;
5022 struct sys_fktrace_args ua;
5023
5024 SPARC32TO64_UAP(fd);
5025 SPARC32TO64_UAP(ops);
5026 SPARC32TO64_UAP(facs);
5027 SPARC32TO64_UAP(pid);
5028 return (sys_fktrace(p, &ua, retval));
5029 }
5030
5031 int
5032 compat_sparc32_preadv(p, v, retval)
5033 struct proc *p;
5034 void *v;
5035 register_t *retval;
5036 {
5037 struct compat_sparc32_preadv_args /* {
5038 syscallarg(int) fd;
5039 syscallarg(const sparc32_iovecp_t) iovp;
5040 syscallarg(int) iovcnt;
5041 syscallarg(int) pad;
5042 syscallarg(off_t) offset;
5043 } */ *uap = v;
5044 struct filedesc *fdp = p->p_fd;
5045 struct file *fp;
5046 struct vnode *vp;
5047 off_t offset;
5048 int error, fd = SCARG(uap, fd);
5049
5050 if ((u_int)fd >= fdp->fd_nfiles ||
5051 (fp = fdp->fd_ofiles[fd]) == NULL ||
5052 (fp->f_flag & FREAD) == 0)
5053 return (EBADF);
5054
5055 vp = (struct vnode *)fp->f_data;
5056 if (fp->f_type != DTYPE_VNODE
5057 || vp->v_type == VFIFO)
5058 return (ESPIPE);
5059
5060 offset = SCARG(uap, offset);
5061
5062 /*
5063 * XXX This works because no file systems actually
5064 * XXX take any action on the seek operation.
5065 */
5066 if ((error = VOP_SEEK(vp, fp->f_offset, offset, fp->f_cred)) != 0)
5067 return (error);
5068
5069 return (dofilereadv32(p, fd, fp, (struct sparc32_iovec *)(u_long)SCARG(uap, iovp), SCARG(uap, iovcnt),
5070 &offset, 0, retval));
5071 }
5072
5073 int
5074 compat_sparc32_pwritev(p, v, retval)
5075 struct proc *p;
5076 void *v;
5077 register_t *retval;
5078 {
5079 struct compat_sparc32_pwritev_args /* {
5080 syscallarg(int) fd;
5081 syscallarg(const sparc32_iovecp_t) iovp;
5082 syscallarg(int) iovcnt;
5083 syscallarg(int) pad;
5084 syscallarg(off_t) offset;
5085 } */ *uap = v;
5086 struct filedesc *fdp = p->p_fd;
5087 struct file *fp;
5088 struct vnode *vp;
5089 off_t offset;
5090 int error, fd = SCARG(uap, fd);
5091
5092 if ((u_int)fd >= fdp->fd_nfiles ||
5093 (fp = fdp->fd_ofiles[fd]) == NULL ||
5094 (fp->f_flag & FWRITE) == 0)
5095 return (EBADF);
5096
5097 vp = (struct vnode *)fp->f_data;
5098 if (fp->f_type != DTYPE_VNODE
5099 || vp->v_type == VFIFO)
5100 return (ESPIPE);
5101
5102 offset = SCARG(uap, offset);
5103
5104 /*
5105 * XXX This works because no file systems actually
5106 * XXX take any action on the seek operation.
5107 */
5108 if ((error = VOP_SEEK(vp, fp->f_offset, offset, fp->f_cred)) != 0)
5109 return (error);
5110
5111 return (dofilewritev32(p, fd, fp, (struct sparc32_iovec *)(u_long)SCARG(uap, iovp), SCARG(uap, iovcnt),
5112 &offset, 0, retval));
5113 }
5114
5115 int
5116 compat_13_compat_sparc32_sigprocmask(p, v, retval)
5117 register struct proc *p;
5118 void *v;
5119 register_t *retval;
5120 {
5121 struct compat_13_compat_sparc32_sigprocmask_args /* {
5122 syscallarg(int) how;
5123 syscallarg(int) mask;
5124 } */ *uap = v;
5125 sigset13_t ness, oess;
5126 sigset_t nbss, obss;
5127 int error;
5128
5129 ness = SCARG(uap, mask);
5130 native_sigset13_to_sigset(&ness, &nbss);
5131 error = sigprocmask1(p, SCARG(uap, how), &nbss, &obss);
5132 if (error)
5133 return (error);
5134 native_sigset_to_sigset13(&obss, &oess);
5135 *retval = oess;
5136 return (0);
5137 }
5138
5139 int
5140 compat_13_compat_sparc32_sigsuspend(p, v, retval)
5141 register struct proc *p;
5142 void *v;
5143 register_t *retval;
5144 {
5145 struct compat_13_compat_sparc32_sigsuspend_args /* {
5146 syscallarg(sigset13_t) mask;
5147 } */ *uap = v;
5148 sigset13_t ess;
5149 sigset_t bss;
5150
5151 ess = SCARG(uap, mask);
5152 native_sigset13_to_sigset(&ess, &bss);
5153 return (sigsuspend1(p, &bss));
5154 }
5155