netbsd32_netbsd.c revision 1.7 1 /* $NetBSD: netbsd32_netbsd.c,v 1.7 1998/12/18 13:18:43 drochner 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 #if defined(UVM)
3843 fn = uvm_sysctl;
3844 #else
3845 fn = vm_sysctl;
3846 #endif
3847 break;
3848 case CTL_NET:
3849 fn = net_sysctl;
3850 break;
3851 case CTL_VFS:
3852 fn = vfs_sysctl;
3853 break;
3854 case CTL_MACHDEP:
3855 fn = cpu_sysctl;
3856 break;
3857 #ifdef DEBUG
3858 case CTL_DEBUG:
3859 fn = debug_sysctl;
3860 break;
3861 #endif
3862 #ifdef DDB
3863 case CTL_DDB:
3864 fn = ddb_sysctl;
3865 break;
3866 #endif
3867 default:
3868 return (EOPNOTSUPP);
3869 }
3870
3871 if (SCARG(uap, oldlenp) &&
3872 (error = copyin((caddr_t)(u_long)SCARG(uap, oldlenp), &savelen, sizeof(savelen))))
3873 return (error);
3874 if (SCARG(uap, old) != NULL) {
3875 #if defined(UVM)
3876 if (!uvm_useracc((caddr_t)(u_long)SCARG(uap, old), savelen, B_WRITE))
3877 #else
3878 if (!useracc(SCARG(uap, old), savelen, B_WRITE))
3879 #endif
3880 return (EFAULT);
3881 #if 0 /* XXXXXXXX */
3882 while (memlock.sl_lock) {
3883 memlock.sl_want = 1;
3884 sleep((caddr_t)&memlock, PRIBIO+1);
3885 memlock.sl_locked++;
3886 }
3887 memlock.sl_lock = 1;
3888 #endif /* XXXXXXXX */
3889 if (dolock)
3890 #if defined(UVM)
3891 uvm_vslock(p, SCARG(uap, old), savelen);
3892 #else
3893 vslock(p, SCARG(uap, old), savelen);
3894 #endif
3895 oldlen = savelen;
3896 }
3897 error = (*fn)(name + 1, SCARG(uap, namelen) - 1, SCARG(uap, old),
3898 &oldlen, SCARG(uap, new), SCARG(uap, newlen), p);
3899 if (SCARG(uap, old) != NULL) {
3900 if (dolock)
3901 #if defined(UVM)
3902 uvm_vsunlock(p, SCARG(uap, old), savelen);
3903 #else
3904 vsunlock(p, SCARG(uap, old), savelen);
3905 #endif
3906 #if 0 /* XXXXXXXXXXX */
3907 memlock.sl_lock = 0;
3908 if (memlock.sl_want) {
3909 memlock.sl_want = 0;
3910 wakeup((caddr_t)&memlock);
3911 }
3912 #endif /* XXXXXXXXX */
3913 }
3914 savelen = oldlen;
3915 if (error)
3916 return (error);
3917 if (SCARG(uap, oldlenp))
3918 error = copyout(&savelen, (caddr_t)(u_long)SCARG(uap, oldlenp), sizeof(savelen));
3919 return (error);
3920 }
3921
3922 int
3923 compat_sparc32_mlock(p, v, retval)
3924 struct proc *p;
3925 void *v;
3926 register_t *retval;
3927 {
3928 struct compat_sparc32_mlock_args /* {
3929 syscallarg(const sparc32_voidp) addr;
3930 syscallarg(sparc32_size_t) len;
3931 } */ *uap = v;
3932 struct sys_mlock_args ua;
3933
3934 SPARC32TOP_UAP(addr, const void);
3935 SPARC32TO64_UAP(len);
3936 return (sys_mlock(p, &ua, retval));
3937 }
3938
3939 int
3940 compat_sparc32_munlock(p, v, retval)
3941 struct proc *p;
3942 void *v;
3943 register_t *retval;
3944 {
3945 struct compat_sparc32_munlock_args /* {
3946 syscallarg(const sparc32_voidp) addr;
3947 syscallarg(sparc32_size_t) len;
3948 } */ *uap = v;
3949 struct sys_munlock_args ua;
3950
3951 SPARC32TOP_UAP(addr, const void);
3952 SPARC32TO64_UAP(len);
3953 return (sys_munlock(p, &ua, retval));
3954 }
3955
3956 int
3957 compat_sparc32_undelete(p, v, retval)
3958 struct proc *p;
3959 void *v;
3960 register_t *retval;
3961 {
3962 struct compat_sparc32_undelete_args /* {
3963 syscallarg(const sparc32_charp) path;
3964 } */ *uap = v;
3965 struct sys_undelete_args ua;
3966
3967 SPARC32TOP_UAP(path, const char);
3968 return (sys_undelete(p, &ua, retval));
3969 }
3970
3971 int
3972 compat_sparc32_futimes(p, v, retval)
3973 struct proc *p;
3974 void *v;
3975 register_t *retval;
3976 {
3977 struct compat_sparc32_futimes_args /* {
3978 syscallarg(int) fd;
3979 syscallarg(const sparc32_timevalp_t) tptr;
3980 } */ *uap = v;
3981 int error;
3982 struct file *fp;
3983
3984 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
3985 return (error);
3986
3987 return (change_utimes32((struct vnode *)fp->f_data,
3988 (struct timeval *)(u_long)SCARG(uap, tptr), p));
3989 }
3990
3991 int
3992 compat_sparc32_getpgid(p, v, retval)
3993 struct proc *p;
3994 void *v;
3995 register_t *retval;
3996 {
3997 struct compat_sparc32_getpgid_args /* {
3998 syscallarg(pid_t) pid;
3999 } */ *uap = v;
4000 struct sys_getpgid_args ua;
4001
4002 SPARC32TO64_UAP(pid);
4003 return (sys_getpgid(p, &ua, retval));
4004 }
4005
4006 int
4007 compat_sparc32_reboot(p, v, retval)
4008 struct proc *p;
4009 void *v;
4010 register_t *retval;
4011 {
4012 struct compat_sparc32_reboot_args /* {
4013 syscallarg(int) opt;
4014 syscallarg(sparc32_charp) bootstr;
4015 } */ *uap = v;
4016 struct sys_reboot_args ua;
4017
4018 SPARC32TO64_UAP(opt);
4019 SPARC32TOP_UAP(bootstr, char);
4020 return (sys_reboot(p, &ua, retval));
4021 }
4022
4023 int
4024 compat_sparc32_poll(p, v, retval)
4025 struct proc *p;
4026 void *v;
4027 register_t *retval;
4028 {
4029 struct compat_sparc32_poll_args /* {
4030 syscallarg(sparc32_pollfdp_t) fds;
4031 syscallarg(u_int) nfds;
4032 syscallarg(int) timeout;
4033 } */ *uap = v;
4034 struct sys_poll_args ua;
4035
4036 SPARC32TOP_UAP(fds, struct pollfd);
4037 SPARC32TO64_UAP(nfds);
4038 SPARC32TO64_UAP(timeout);
4039 return (sys_poll(p, &ua, retval));
4040 }
4041
4042 /*
4043 * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
4044 *
4045 * This is BSD. We won't support System V IPC.
4046 * Too much work.
4047 *
4048 * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
4049 */
4050 int
4051 compat_sparc32___semctl(p, v, retval)
4052 struct proc *p;
4053 void *v;
4054 register_t *retval;
4055 {
4056 #if 0
4057 struct compat_sparc32___semctl_args /* {
4058 syscallarg(int) semid;
4059 syscallarg(int) semnum;
4060 syscallarg(int) cmd;
4061 syscallarg(sparc32_semunu_t) arg;
4062 } */ *uap = v;
4063 union sparc32_semun sem32;
4064 int semid = SCARG(uap, semid);
4065 int semnum = SCARG(uap, semnum);
4066 int cmd = SCARG(uap, cmd);
4067 union sparc32_semun *arg = (void*)(u_long)SCARG(uap, arg);
4068 union sparc32_semun real_arg;
4069 struct ucred *cred = p->p_ucred;
4070 int i, rval, eval;
4071 struct sparc32_semid_ds sbuf;
4072 register struct semid_ds *semaptr;
4073
4074 semlock(p);
4075
4076 semid = IPCID_TO_IX(semid);
4077 if (semid < 0 || semid >= seminfo.semmsl)
4078 return(EINVAL);
4079
4080 semaptr = &sema[semid];
4081 if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0 ||
4082 semaptr->sem_perm.seq != IPCID_TO_SEQ(SCARG(uap, semid)))
4083 return(EINVAL);
4084
4085 eval = 0;
4086 rval = 0;
4087
4088 switch (cmd) {
4089 case IPC_RMID:
4090 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_M)) != 0)
4091 return(eval);
4092 semaptr->sem_perm.cuid = cred->cr_uid;
4093 semaptr->sem_perm.uid = cred->cr_uid;
4094 semtot -= semaptr->sem_nsems;
4095 for (i = semaptr->sem_base - sem; i < semtot; i++)
4096 sem[i] = sem[i + semaptr->sem_nsems];
4097 for (i = 0; i < seminfo.semmni; i++) {
4098 if ((sema[i].sem_perm.mode & SEM_ALLOC) &&
4099 sema[i].sem_base > semaptr->sem_base)
4100 sema[i].sem_base -= semaptr->sem_nsems;
4101 }
4102 semaptr->sem_perm.mode = 0;
4103 semundo_clear(semid, -1);
4104 wakeup((caddr_t)semaptr);
4105 break;
4106
4107 case IPC_SET:
4108 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_M)))
4109 return(eval);
4110 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
4111 return(eval);
4112 if ((eval = copyin((caddr_t)(u_long)real_arg.buf, (caddr_t)&sbuf,
4113 sizeof(sbuf))) != 0)
4114 return(eval);
4115 semaptr->sem_perm.uid = sbuf.sem_perm.uid;
4116 semaptr->sem_perm.gid = sbuf.sem_perm.gid;
4117 semaptr->sem_perm.mode = (semaptr->sem_perm.mode & ~0777) |
4118 (sbuf.sem_perm.mode & 0777);
4119 semaptr->sem_ctime = time.tv_sec;
4120 break;
4121
4122 case IPC_STAT:
4123 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
4124 return(eval);
4125 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
4126 return(eval);
4127 eval = copyout((caddr_t)semaptr, (caddr_t)(u_long)real_arg.buf,
4128 sizeof(struct semid_ds));
4129 break;
4130
4131 case GETNCNT:
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].semncnt;
4137 break;
4138
4139 case GETPID:
4140 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
4141 return(eval);
4142 if (semnum < 0 || semnum >= semaptr->sem_nsems)
4143 return(EINVAL);
4144 rval = semaptr->sem_base[semnum].sempid;
4145 break;
4146
4147 case GETVAL:
4148 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
4149 return(eval);
4150 if (semnum < 0 || semnum >= semaptr->sem_nsems)
4151 return(EINVAL);
4152 rval = semaptr->sem_base[semnum].semval;
4153 break;
4154
4155 case GETALL:
4156 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
4157 return(eval);
4158 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
4159 return(eval);
4160 for (i = 0; i < semaptr->sem_nsems; i++) {
4161 eval = copyout((caddr_t)&semaptr->sem_base[i].semval,
4162 &real_arg.array[i], sizeof(real_arg.array[0]));
4163 if (eval != 0)
4164 break;
4165 }
4166 break;
4167
4168 case GETZCNT:
4169 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
4170 return(eval);
4171 if (semnum < 0 || semnum >= semaptr->sem_nsems)
4172 return(EINVAL);
4173 rval = semaptr->sem_base[semnum].semzcnt;
4174 break;
4175
4176 case SETVAL:
4177 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_W)))
4178 return(eval);
4179 if (semnum < 0 || semnum >= semaptr->sem_nsems)
4180 return(EINVAL);
4181 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
4182 return(eval);
4183 semaptr->sem_base[semnum].semval = real_arg.val;
4184 semundo_clear(semid, semnum);
4185 wakeup((caddr_t)semaptr);
4186 break;
4187
4188 case SETALL:
4189 if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_W)))
4190 return(eval);
4191 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
4192 return(eval);
4193 for (i = 0; i < semaptr->sem_nsems; i++) {
4194 eval = copyin(&real_arg.array[i],
4195 (caddr_t)&semaptr->sem_base[i].semval,
4196 sizeof(real_arg.array[0]));
4197 if (eval != 0)
4198 break;
4199 }
4200 semundo_clear(semid, -1);
4201 wakeup((caddr_t)semaptr);
4202 break;
4203
4204 default:
4205 return(EINVAL);
4206 }
4207
4208 if (eval == 0)
4209 *retval = rval;
4210 return(eval);
4211 #else
4212 return (ENOSYS);
4213 #endif
4214 }
4215
4216 int
4217 compat_sparc32_semget(p, v, retval)
4218 struct proc *p;
4219 void *v;
4220 register_t *retval;
4221 {
4222 struct compat_sparc32_semget_args /* {
4223 syscallarg(sparc32_key_t) key;
4224 syscallarg(int) nsems;
4225 syscallarg(int) semflg;
4226 } */ *uap = v;
4227 struct sys_semget_args ua;
4228
4229 SPARC32TOX_UAP(key, key_t);
4230 SPARC32TO64_UAP(nsems);
4231 SPARC32TO64_UAP(semflg);
4232 return (sys_semget(p, &ua, retval));
4233 }
4234
4235 int
4236 compat_sparc32_semop(p, v, retval)
4237 struct proc *p;
4238 void *v;
4239 register_t *retval;
4240 {
4241 struct compat_sparc32_semop_args /* {
4242 syscallarg(int) semid;
4243 syscallarg(sparc32_sembufp_t) sops;
4244 syscallarg(sparc32_size_t) nsops;
4245 } */ *uap = v;
4246 struct sys_semop_args ua;
4247
4248 SPARC32TO64_UAP(semid);
4249 SPARC32TOP_UAP(sops, struct sembuf);
4250 SPARC32TOX_UAP(nsops, size_t);
4251 return (sys_semop(p, &ua, retval));
4252 }
4253
4254 int
4255 compat_sparc32_semconfig(p, v, retval)
4256 struct proc *p;
4257 void *v;
4258 register_t *retval;
4259 {
4260 struct compat_sparc32_semconfig_args /* {
4261 syscallarg(int) flag;
4262 } */ *uap = v;
4263 struct sys_semconfig_args ua;
4264
4265 SPARC32TO64_UAP(flag);
4266 return (sys_semconfig(p, &ua, retval));
4267 }
4268
4269 int
4270 compat_sparc32_msgctl(p, v, retval)
4271 struct proc *p;
4272 void *v;
4273 register_t *retval;
4274 {
4275 #if 0
4276 struct compat_sparc32_msgctl_args /* {
4277 syscallarg(int) msqid;
4278 syscallarg(int) cmd;
4279 syscallarg(sparc32_msqid_dsp_t) buf;
4280 } */ *uap = v;
4281 struct sys_msgctl_args ua;
4282 struct msqid_ds ds;
4283 struct sparc32_msqid_ds *ds32p;
4284 int error;
4285
4286 SPARC32TO64_UAP(msqid);
4287 SPARC32TO64_UAP(cmd);
4288 ds32p = (struct sparc32_msqid_ds *)(u_long)SCARG(uap, buf);
4289 if (ds32p) {
4290 SCARG(&ua, buf) = NULL;
4291 sparc32_to_msqid_ds(ds32p, &ds);
4292 } else
4293 SCARG(&ua, buf) = NULL;
4294 error = sys_msgctl(p, &ua, retval);
4295 if (error)
4296 return (error);
4297
4298 if (ds32p)
4299 sparc32_from_msqid_ds(&ds, ds32p);
4300 return (0);
4301 #else
4302 return (ENOSYS);
4303 #endif
4304 }
4305
4306 int
4307 compat_sparc32_msgget(p, v, retval)
4308 struct proc *p;
4309 void *v;
4310 register_t *retval;
4311 {
4312 #if 0
4313 struct compat_sparc32_msgget_args /* {
4314 syscallarg(sparc32_key_t) key;
4315 syscallarg(int) msgflg;
4316 } */ *uap = v;
4317 struct sys_msgget_args ua;
4318
4319 SPARC32TOX_UAP(key, key_t);
4320 SPARC32TO64_UAP(msgflg);
4321 return (sys_msgget(p, &ua, retval));
4322 #else
4323 return (ENOSYS);
4324 #endif
4325 }
4326
4327 int
4328 compat_sparc32_msgsnd(p, v, retval)
4329 struct proc *p;
4330 void *v;
4331 register_t *retval;
4332 {
4333 #if 0
4334 struct compat_sparc32_msgsnd_args /* {
4335 syscallarg(int) msqid;
4336 syscallarg(const sparc32_voidp) msgp;
4337 syscallarg(sparc32_size_t) msgsz;
4338 syscallarg(int) msgflg;
4339 } */ *uap = v;
4340 struct sys_msgsnd_args ua;
4341
4342 SPARC32TO64_UAP(msqid);
4343 SPARC32TOP_UAP(msgp, void);
4344 SPARC32TOX_UAP(msgsz, size_t);
4345 SPARC32TO64_UAP(msgflg);
4346 return (sys_msgsnd(p, &ua, retval));
4347 #else
4348 return (ENOSYS);
4349 #endif
4350 }
4351
4352 int
4353 compat_sparc32_msgrcv(p, v, retval)
4354 struct proc *p;
4355 void *v;
4356 register_t *retval;
4357 {
4358 #if 0
4359 struct compat_sparc32_msgrcv_args /* {
4360 syscallarg(int) msqid;
4361 syscallarg(sparc32_voidp) msgp;
4362 syscallarg(sparc32_size_t) msgsz;
4363 syscallarg(sparc32_long) msgtyp;
4364 syscallarg(int) msgflg;
4365 } */ *uap = v;
4366 struct sys_msgrcv_args ua;
4367 ssize_t rt;
4368 int error;
4369
4370 SPARC32TO64_UAP(msqid);
4371 SPARC32TOP_UAP(msgp, void);
4372 SPARC32TOX_UAP(msgsz, size_t);
4373 SPARC32TOX_UAP(msgtyp, long);
4374 SPARC32TO64_UAP(msgflg);
4375 error = sys_msgrcv(p, &ua, (register_t *)&rt);
4376 *(sparc32_ssize_t *)retval = rt;
4377 return (error);
4378 #else
4379 return (ENOSYS);
4380 #endif
4381 }
4382
4383 int
4384 compat_sparc32_shmat(p, v, retval)
4385 struct proc *p;
4386 void *v;
4387 register_t *retval;
4388 {
4389 #if 0
4390 struct compat_sparc32_shmat_args /* {
4391 syscallarg(int) shmid;
4392 syscallarg(const sparc32_voidp) shmaddr;
4393 syscallarg(int) shmflg;
4394 } */ *uap = v;
4395 struct sys_shmat_args ua;
4396 void *rt;
4397 int error;
4398
4399 SPARC32TO64_UAP(shmid);
4400 SPARC32TOP_UAP(shmaddr, void);
4401 SPARC32TO64_UAP(shmflg);
4402 error = sys_shmat(p, &ua, (register_t *)&rt);
4403 *retval = (sparc32_voidp)(u_long)rt;
4404 return (error);
4405 #else
4406 return (ENOSYS);
4407 #endif
4408 }
4409
4410 int
4411 compat_sparc32_shmctl(p, v, retval)
4412 struct proc *p;
4413 void *v;
4414 register_t *retval;
4415 {
4416 #if 0
4417 struct compat_sparc32_shmctl_args /* {
4418 syscallarg(int) shmid;
4419 syscallarg(int) cmd;
4420 syscallarg(sparc32_shmid_dsp_t) buf;
4421 } */ *uap = v;
4422 struct sys_shmctl_args ua;
4423 struct shmid_ds ds;
4424 struct sparc32_shmid_ds *ds32p;
4425 int error;
4426
4427 SPARC32TO64_UAP(shmid);
4428 SPARC32TO64_UAP(cmd);
4429 ds32p = (struct sparc32_shmid_ds *)(u_long)SCARG(uap, buf);
4430 if (ds32p) {
4431 SCARG(&ua, buf) = NULL;
4432 sparc32_to_shmid_ds(ds32p, &ds);
4433 } else
4434 SCARG(&ua, buf) = NULL;
4435 error = sys_shmctl(p, &ua, retval);
4436 if (error)
4437 return (error);
4438
4439 if (ds32p)
4440 sparc32_from_shmid_ds(&ds, ds32p);
4441 return (0);
4442 #else
4443 return (ENOSYS);
4444 #endif
4445 }
4446
4447 int
4448 compat_sparc32_shmdt(p, v, retval)
4449 struct proc *p;
4450 void *v;
4451 register_t *retval;
4452 {
4453 #if 0
4454 struct compat_sparc32_shmdt_args /* {
4455 syscallarg(const sparc32_voidp) shmaddr;
4456 } */ *uap = v;
4457 struct sys_shmdt_args ua;
4458
4459 SPARC32TOP_UAP(shmaddr, const char);
4460 return (sys_shmdt(p, &ua, retval));
4461 #else
4462 return (ENOSYS);
4463 #endif
4464 }
4465
4466 int
4467 compat_sparc32_shmget(p, v, retval)
4468 struct proc *p;
4469 void *v;
4470 register_t *retval;
4471 {
4472 #if 0
4473 struct compat_sparc32_shmget_args /* {
4474 syscallarg(sparc32_key_t) key;
4475 syscallarg(sparc32_size_t) size;
4476 syscallarg(int) shmflg;
4477 } */ *uap = v;
4478 struct sys_shmget_args ua;
4479
4480 SPARC32TOX_UAP(key, key_t)
4481 SPARC32TOX_UAP(size, size_t)
4482 SPARC32TO64_UAP(shmflg);
4483 return (sys_shmget(p, &ua, retval));
4484 #else
4485 return (ENOSYS);
4486 #endif
4487 }
4488
4489 int
4490 compat_sparc32_clock_gettime(p, v, retval)
4491 struct proc *p;
4492 void *v;
4493 register_t *retval;
4494 {
4495 struct compat_sparc32_clock_gettime_args /* {
4496 syscallarg(sparc32_clockid_t) clock_id;
4497 syscallarg(sparc32_timespecp_t) tp;
4498 } */ *uap = v;
4499 clockid_t clock_id;
4500 struct timeval atv;
4501 struct timespec ats;
4502 struct sparc32_timespec ts32;
4503
4504 clock_id = SCARG(uap, clock_id);
4505 if (clock_id != CLOCK_REALTIME)
4506 return (EINVAL);
4507
4508 microtime(&atv);
4509 TIMEVAL_TO_TIMESPEC(&atv,&ats);
4510 sparc32_from_timespec(&ats, &ts32);
4511
4512 return copyout(&ts32, (caddr_t)(u_long)SCARG(uap, tp), sizeof(ts32));
4513 }
4514
4515 int
4516 compat_sparc32_clock_settime(p, v, retval)
4517 struct proc *p;
4518 void *v;
4519 register_t *retval;
4520 {
4521 struct compat_sparc32_clock_settime_args /* {
4522 syscallarg(sparc32_clockid_t) clock_id;
4523 syscallarg(const sparc32_timespecp_t) tp;
4524 } */ *uap = v;
4525 struct sparc32_timespec ts32;
4526 clockid_t clock_id;
4527 struct timeval atv;
4528 struct timespec ats;
4529 int error;
4530
4531 if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
4532 return (error);
4533
4534 clock_id = SCARG(uap, clock_id);
4535 if (clock_id != CLOCK_REALTIME)
4536 return (EINVAL);
4537
4538 if ((error = copyin((caddr_t)(u_long)SCARG(uap, tp), &ts32, sizeof(ts32))) != 0)
4539 return (error);
4540
4541 sparc32_to_timespec(&ts32, &ats);
4542 TIMESPEC_TO_TIMEVAL(&atv,&ats);
4543 if ((error = settime(&atv)))
4544 return (error);
4545
4546 return 0;
4547 }
4548
4549 int
4550 compat_sparc32_clock_getres(p, v, retval)
4551 struct proc *p;
4552 void *v;
4553 register_t *retval;
4554 {
4555 struct compat_sparc32_clock_getres_args /* {
4556 syscallarg(sparc32_clockid_t) clock_id;
4557 syscallarg(sparc32_timespecp_t) tp;
4558 } */ *uap = v;
4559 struct sparc32_timespec ts32;
4560 clockid_t clock_id;
4561 struct timespec ts;
4562 int error = 0;
4563
4564 clock_id = SCARG(uap, clock_id);
4565 if (clock_id != CLOCK_REALTIME)
4566 return (EINVAL);
4567
4568 if (SCARG(uap, tp)) {
4569 ts.tv_sec = 0;
4570 ts.tv_nsec = 1000000000 / hz;
4571
4572 sparc32_from_timespec(&ts, &ts32);
4573 error = copyout(&ts, (caddr_t)(u_long)SCARG(uap, tp), sizeof(ts));
4574 }
4575
4576 return error;
4577 }
4578
4579 int
4580 compat_sparc32_nanosleep(p, v, retval)
4581 struct proc *p;
4582 void *v;
4583 register_t *retval;
4584 {
4585 struct compat_sparc32_nanosleep_args /* {
4586 syscallarg(const sparc32_timespecp_t) rqtp;
4587 syscallarg(sparc32_timespecp_t) rmtp;
4588 } */ *uap = v;
4589 static int nanowait;
4590 struct sparc32_timespec ts32;
4591 struct timespec rqt;
4592 struct timespec rmt;
4593 struct timeval atv, utv;
4594 int error, s, timo;
4595
4596 error = copyin((caddr_t)(u_long)SCARG(uap, rqtp), (caddr_t)&ts32,
4597 sizeof(ts32));
4598 if (error)
4599 return (error);
4600
4601 sparc32_to_timespec(&ts32, &rqt);
4602 TIMESPEC_TO_TIMEVAL(&atv,&rqt)
4603 if (itimerfix(&atv))
4604 return (EINVAL);
4605
4606 s = splclock();
4607 timeradd(&atv,&time,&atv);
4608 timo = hzto(&atv);
4609 /*
4610 * Avoid inadvertantly sleeping forever
4611 */
4612 if (timo == 0)
4613 timo = 1;
4614 splx(s);
4615
4616 error = tsleep(&nanowait, PWAIT | PCATCH, "nanosleep", timo);
4617 if (error == ERESTART)
4618 error = EINTR;
4619 if (error == EWOULDBLOCK)
4620 error = 0;
4621
4622 if (SCARG(uap, rmtp)) {
4623 int error;
4624
4625 s = splclock();
4626 utv = time;
4627 splx(s);
4628
4629 timersub(&atv, &utv, &utv);
4630 if (utv.tv_sec < 0)
4631 timerclear(&utv);
4632
4633 TIMEVAL_TO_TIMESPEC(&utv,&rmt);
4634 sparc32_from_timespec(&rmt, &ts32);
4635 error = copyout((caddr_t)&ts32, (caddr_t)(u_long)SCARG(uap,rmtp),
4636 sizeof(ts32));
4637 if (error)
4638 return (error);
4639 }
4640
4641 return error;
4642 }
4643
4644 int
4645 compat_sparc32_fdatasync(p, v, retval)
4646 struct proc *p;
4647 void *v;
4648 register_t *retval;
4649 {
4650 struct compat_sparc32_fdatasync_args /* {
4651 syscallarg(int) fd;
4652 } */ *uap = v;
4653 struct sys_fdatasync_args ua;
4654
4655 SPARC32TO64_UAP(fd);
4656
4657 return (sys_fdatasync(p, &ua, retval));
4658 }
4659
4660 int
4661 compat_sparc32___posix_rename(p, v, retval)
4662 struct proc *p;
4663 void *v;
4664 register_t *retval;
4665 {
4666 struct compat_sparc32___posix_rename_args /* {
4667 syscallarg(const sparc32_charp) from;
4668 syscallarg(const sparc32_charp) to;
4669 } */ *uap = v;
4670 struct sys___posix_rename_args ua;
4671
4672 SPARC32TOP_UAP(from, const char *);
4673 SPARC32TOP_UAP(to, const char *);
4674
4675 return (sys___posix_rename(p, &ua, retval));
4676 }
4677
4678 int
4679 compat_sparc32_swapctl(p, v, retval)
4680 struct proc *p;
4681 void *v;
4682 register_t *retval;
4683 {
4684 struct compat_sparc32_swapctl_args /* {
4685 syscallarg(int) cmd;
4686 syscallarg(const sparc32_voidp) arg;
4687 syscallarg(int) misc;
4688 } */ *uap = v;
4689 struct sys_swapctl_args ua;
4690
4691 SPARC32TO64_UAP(cmd);
4692 SPARC32TOP_UAP(arg, const void);
4693 SPARC32TO64_UAP(misc);
4694 return (sys_swapctl(p, &ua, retval));
4695 }
4696
4697 int
4698 compat_sparc32_getdents(p, v, retval)
4699 struct proc *p;
4700 void *v;
4701 register_t *retval;
4702 {
4703 struct compat_sparc32_getdents_args /* {
4704 syscallarg(int) fd;
4705 syscallarg(sparc32_charp) buf;
4706 syscallarg(sparc32_size_t) count;
4707 } */ *uap = v;
4708 struct file *fp;
4709 int error, done;
4710
4711 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
4712 return (error);
4713 if ((fp->f_flag & FREAD) == 0)
4714 return (EBADF);
4715 error = vn_readdir(fp, (caddr_t)(u_long)SCARG(uap, buf), UIO_USERSPACE,
4716 SCARG(uap, count), &done, p, 0, 0);
4717 *retval = done;
4718 return (error);
4719 }
4720
4721
4722 int
4723 compat_sparc32_minherit(p, v, retval)
4724 struct proc *p;
4725 void *v;
4726 register_t *retval;
4727 {
4728 struct compat_sparc32_minherit_args /* {
4729 syscallarg(sparc32_voidp) addr;
4730 syscallarg(sparc32_size_t) len;
4731 syscallarg(int) inherit;
4732 } */ *uap = v;
4733 struct sys_minherit_args ua;
4734
4735 SPARC32TOP_UAP(addr, void);
4736 SPARC32TOX_UAP(len, size_t);
4737 SPARC32TO64_UAP(inherit);
4738 return (sys_minherit(p, &ua, retval));
4739 }
4740
4741 int
4742 compat_sparc32_lchmod(p, v, retval)
4743 struct proc *p;
4744 void *v;
4745 register_t *retval;
4746 {
4747 struct compat_sparc32_lchmod_args /* {
4748 syscallarg(const sparc32_charp) path;
4749 syscallarg(mode_t) mode;
4750 } */ *uap = v;
4751 struct sys_lchmod_args ua;
4752
4753 SPARC32TOP_UAP(path, const char);
4754 SPARC32TO64_UAP(mode);
4755 return (sys_lchmod(p, &ua, retval));
4756 }
4757
4758 int
4759 compat_sparc32_lchown(p, v, retval)
4760 struct proc *p;
4761 void *v;
4762 register_t *retval;
4763 {
4764 struct compat_sparc32_lchown_args /* {
4765 syscallarg(const sparc32_charp) path;
4766 syscallarg(uid_t) uid;
4767 syscallarg(gid_t) gid;
4768 } */ *uap = v;
4769 struct sys_lchown_args ua;
4770
4771 SPARC32TOP_UAP(path, const char);
4772 SPARC32TO64_UAP(uid);
4773 SPARC32TO64_UAP(gid);
4774 return (sys_lchown(p, &ua, retval));
4775 }
4776
4777 int
4778 compat_sparc32_lutimes(p, v, retval)
4779 struct proc *p;
4780 void *v;
4781 register_t *retval;
4782 {
4783 struct compat_sparc32_lutimes_args /* {
4784 syscallarg(const sparc32_charp) path;
4785 syscallarg(const sparc32_timevalp_t) tptr;
4786 } */ *uap = v;
4787 int error;
4788 struct nameidata nd;
4789
4790 NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, (caddr_t)(u_long)SCARG(uap, path), p);
4791 if ((error = namei(&nd)) != 0)
4792 return (error);
4793
4794 error = change_utimes32(nd.ni_vp, (struct timeval *)(u_long)SCARG(uap, tptr), p);
4795
4796 vrele(nd.ni_vp);
4797 return (error);
4798 }
4799
4800
4801 int
4802 compat_sparc32___msync13(p, v, retval)
4803 struct proc *p;
4804 void *v;
4805 register_t *retval;
4806 {
4807 struct compat_sparc32___msync13_args /* {
4808 syscallarg(sparc32_voidp) addr;
4809 syscallarg(sparc32_size_t) len;
4810 syscallarg(int) flags;
4811 } */ *uap = v;
4812 struct sys___msync13_args ua;
4813
4814 SPARC32TOP_UAP(addr, void);
4815 SPARC32TOX_UAP(len, size_t);
4816 SPARC32TO64_UAP(flags);
4817 return (sys___msync13(p, &ua, retval));
4818 }
4819
4820 int
4821 compat_sparc32___stat13(p, v, retval)
4822 struct proc *p;
4823 void *v;
4824 register_t *retval;
4825 {
4826 struct compat_sparc32___stat13_args /* {
4827 syscallarg(const sparc32_charp) path;
4828 syscallarg(sparc32_statp_t) ub;
4829 } */ *uap = v;
4830 struct sparc32_stat sb32;
4831 struct stat sb;
4832 int error;
4833 struct nameidata nd;
4834
4835 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
4836 (caddr_t)(u_long)SCARG(uap, path), p);
4837 if ((error = namei(&nd)) != 0)
4838 return (error);
4839 error = vn_stat(nd.ni_vp, &sb, p);
4840 vput(nd.ni_vp);
4841 if (error)
4842 return (error);
4843 sparc32_from___stat13(&sb, &sb32);
4844 error = copyout(&sb32, (caddr_t)(u_long)SCARG(uap, ub), sizeof(sb32));
4845 return (error);
4846 }
4847
4848 int
4849 compat_sparc32___fstat13(p, v, retval)
4850 struct proc *p;
4851 void *v;
4852 register_t *retval;
4853 {
4854 struct compat_sparc32___fstat13_args /* {
4855 syscallarg(int) fd;
4856 syscallarg(sparc32_statp_t) sb;
4857 } */ *uap = v;
4858 int fd = SCARG(uap, fd);
4859 register struct filedesc *fdp = p->p_fd;
4860 register struct file *fp;
4861 struct sparc32_stat sb32;
4862 struct stat ub;
4863 int error = 0;
4864
4865 if ((u_int)fd >= fdp->fd_nfiles ||
4866 (fp = fdp->fd_ofiles[fd]) == NULL)
4867 return (EBADF);
4868 switch (fp->f_type) {
4869
4870 case DTYPE_VNODE:
4871 error = vn_stat((struct vnode *)fp->f_data, &ub, p);
4872 break;
4873
4874 case DTYPE_SOCKET:
4875 error = soo_stat((struct socket *)fp->f_data, &ub);
4876 break;
4877
4878 default:
4879 panic("fstat");
4880 /*NOTREACHED*/
4881 }
4882 if (error == 0) {
4883 sparc32_from___stat13(&ub, &sb32);
4884 error = copyout(&sb32, (caddr_t)(u_long)SCARG(uap, sb), sizeof(sb32));
4885 }
4886 return (error);
4887 }
4888
4889 int
4890 compat_sparc32___lstat13(p, v, retval)
4891 struct proc *p;
4892 void *v;
4893 register_t *retval;
4894 {
4895 struct compat_sparc32___lstat13_args /* {
4896 syscallarg(const sparc32_charp) path;
4897 syscallarg(sparc32_statp_t) ub;
4898 } */ *uap = v;
4899 struct sparc32_stat sb32;
4900 struct stat sb;
4901 int error;
4902 struct nameidata nd;
4903
4904 NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF, UIO_USERSPACE,
4905 (caddr_t)(u_long)SCARG(uap, path), p);
4906 if ((error = namei(&nd)) != 0)
4907 return (error);
4908 error = vn_stat(nd.ni_vp, &sb, p);
4909 vput(nd.ni_vp);
4910 if (error)
4911 return (error);
4912 sparc32_from___stat13(&sb, &sb32);
4913 error = copyout(&sb32, (caddr_t)(u_long)SCARG(uap, ub), sizeof(sb32));
4914 return (error);
4915 }
4916
4917 int
4918 compat_sparc32___sigaltstack14(p, v, retval)
4919 struct proc *p;
4920 void *v;
4921 register_t *retval;
4922 {
4923 struct compat_sparc32___sigaltstack14_args /* {
4924 syscallarg(const sparc32_sigaltstackp_t) nss;
4925 syscallarg(sparc32_sigaltstackp_t) oss;
4926 } */ *uap = v;
4927 struct sparc32_sigaltstack s32;
4928 struct sigaltstack nss, oss;
4929 int error;
4930
4931 if (SCARG(uap, nss)) {
4932 error = copyin((caddr_t)(u_long)SCARG(uap, nss), &s32, sizeof(s32));
4933 if (error)
4934 return (error);
4935 nss.ss_sp = (void *)(u_long)s32.ss_sp;
4936 nss.ss_size = (size_t)s32.ss_size;
4937 nss.ss_flags = s32.ss_flags;
4938 }
4939 error = sigaltstack1(p,
4940 SCARG(uap, nss) ? &nss : 0, SCARG(uap, oss) ? &oss : 0);
4941 if (error)
4942 return (error);
4943 if (SCARG(uap, oss)) {
4944 s32.ss_sp = (sparc32_voidp)(u_long)oss.ss_sp;
4945 s32.ss_size = (sparc32_size_t)oss.ss_size;
4946 s32.ss_flags = oss.ss_flags;
4947 error = copyout(&s32, (caddr_t)(u_long)SCARG(uap, oss), sizeof(s32));
4948 if (error)
4949 return (error);
4950 }
4951 return (0);
4952 }
4953
4954 int
4955 compat_sparc32___posix_chown(p, v, retval)
4956 struct proc *p;
4957 void *v;
4958 register_t *retval;
4959 {
4960 struct compat_sparc32___posix_chown_args /* {
4961 syscallarg(const sparc32_charp) path;
4962 syscallarg(uid_t) uid;
4963 syscallarg(gid_t) gid;
4964 } */ *uap = v;
4965 struct sys___posix_chown_args ua;
4966
4967 SPARC32TOP_UAP(path, const char);
4968 SPARC32TO64_UAP(uid);
4969 SPARC32TO64_UAP(gid);
4970 return (sys___posix_chown(p, &ua, retval));
4971 }
4972
4973 int
4974 compat_sparc32___posix_fchown(p, v, retval)
4975 struct proc *p;
4976 void *v;
4977 register_t *retval;
4978 {
4979 struct compat_sparc32___posix_fchown_args /* {
4980 syscallarg(int) fd;
4981 syscallarg(uid_t) uid;
4982 syscallarg(gid_t) gid;
4983 } */ *uap = v;
4984 struct sys___posix_fchown_args ua;
4985
4986 SPARC32TO64_UAP(fd);
4987 SPARC32TO64_UAP(uid);
4988 SPARC32TO64_UAP(gid);
4989 return (sys___posix_fchown(p, &ua, retval));
4990 }
4991
4992 int
4993 compat_sparc32___posix_lchown(p, v, retval)
4994 struct proc *p;
4995 void *v;
4996 register_t *retval;
4997 {
4998 struct compat_sparc32___posix_lchown_args /* {
4999 syscallarg(const sparc32_charp) path;
5000 syscallarg(uid_t) uid;
5001 syscallarg(gid_t) gid;
5002 } */ *uap = v;
5003 struct sys___posix_lchown_args ua;
5004
5005 SPARC32TOP_UAP(path, const char);
5006 SPARC32TO64_UAP(uid);
5007 SPARC32TO64_UAP(gid);
5008 return (sys___posix_lchown(p, &ua, retval));
5009 }
5010
5011 int
5012 compat_sparc32_getsid(p, v, retval)
5013 struct proc *p;
5014 void *v;
5015 register_t *retval;
5016 {
5017 struct compat_sparc32_getsid_args /* {
5018 syscallarg(pid_t) pid;
5019 } */ *uap = v;
5020 struct sys_getsid_args ua;
5021
5022 SPARC32TO64_UAP(pid);
5023 return (sys_getsid(p, &ua, retval));
5024 }
5025
5026 int
5027 compat_sparc32_fktrace(p, v, retval)
5028 struct proc *p;
5029 void *v;
5030 register_t *retval;
5031 {
5032 struct compat_sparc32_fktrace_args /* {
5033 syscallarg(const int) fd;
5034 syscallarg(int) ops;
5035 syscallarg(int) facs;
5036 syscallarg(int) pid;
5037 } */ *uap = v;
5038 struct sys_fktrace_args ua;
5039
5040 SPARC32TO64_UAP(fd);
5041 SPARC32TO64_UAP(ops);
5042 SPARC32TO64_UAP(facs);
5043 SPARC32TO64_UAP(pid);
5044 return (sys_fktrace(p, &ua, retval));
5045 }
5046
5047 int
5048 compat_sparc32_preadv(p, v, retval)
5049 struct proc *p;
5050 void *v;
5051 register_t *retval;
5052 {
5053 struct compat_sparc32_preadv_args /* {
5054 syscallarg(int) fd;
5055 syscallarg(const sparc32_iovecp_t) iovp;
5056 syscallarg(int) iovcnt;
5057 syscallarg(int) pad;
5058 syscallarg(off_t) offset;
5059 } */ *uap = v;
5060 struct filedesc *fdp = p->p_fd;
5061 struct file *fp;
5062 struct vnode *vp;
5063 off_t offset;
5064 int error, fd = SCARG(uap, fd);
5065
5066 if ((u_int)fd >= fdp->fd_nfiles ||
5067 (fp = fdp->fd_ofiles[fd]) == NULL ||
5068 (fp->f_flag & FREAD) == 0)
5069 return (EBADF);
5070
5071 vp = (struct vnode *)fp->f_data;
5072 if (fp->f_type != DTYPE_VNODE
5073 || vp->v_type == VFIFO)
5074 return (ESPIPE);
5075
5076 offset = SCARG(uap, offset);
5077
5078 /*
5079 * XXX This works because no file systems actually
5080 * XXX take any action on the seek operation.
5081 */
5082 if ((error = VOP_SEEK(vp, fp->f_offset, offset, fp->f_cred)) != 0)
5083 return (error);
5084
5085 return (dofilereadv32(p, fd, fp, (struct sparc32_iovec *)(u_long)SCARG(uap, iovp), SCARG(uap, iovcnt),
5086 &offset, 0, retval));
5087 }
5088
5089 int
5090 compat_sparc32_pwritev(p, v, retval)
5091 struct proc *p;
5092 void *v;
5093 register_t *retval;
5094 {
5095 struct compat_sparc32_pwritev_args /* {
5096 syscallarg(int) fd;
5097 syscallarg(const sparc32_iovecp_t) iovp;
5098 syscallarg(int) iovcnt;
5099 syscallarg(int) pad;
5100 syscallarg(off_t) offset;
5101 } */ *uap = v;
5102 struct filedesc *fdp = p->p_fd;
5103 struct file *fp;
5104 struct vnode *vp;
5105 off_t offset;
5106 int error, fd = SCARG(uap, fd);
5107
5108 if ((u_int)fd >= fdp->fd_nfiles ||
5109 (fp = fdp->fd_ofiles[fd]) == NULL ||
5110 (fp->f_flag & FWRITE) == 0)
5111 return (EBADF);
5112
5113 vp = (struct vnode *)fp->f_data;
5114 if (fp->f_type != DTYPE_VNODE
5115 || vp->v_type == VFIFO)
5116 return (ESPIPE);
5117
5118 offset = SCARG(uap, offset);
5119
5120 /*
5121 * XXX This works because no file systems actually
5122 * XXX take any action on the seek operation.
5123 */
5124 if ((error = VOP_SEEK(vp, fp->f_offset, offset, fp->f_cred)) != 0)
5125 return (error);
5126
5127 return (dofilewritev32(p, fd, fp, (struct sparc32_iovec *)(u_long)SCARG(uap, iovp), SCARG(uap, iovcnt),
5128 &offset, 0, retval));
5129 }
5130
5131
5132
5133 int
5134 compat_13_compat_sparc32_sigprocmask(p, v, retval)
5135 register struct proc *p;
5136 void *v;
5137 register_t *retval;
5138 {
5139 struct compat_13_compat_sparc32_sigprocmask_args /* {
5140 syscallarg(int) how;
5141 syscallarg(int) mask;
5142 } */ *uap = v;
5143 sigset13_t ness, oess;
5144 sigset_t nbss, obss;
5145 int error;
5146
5147 ness = SCARG(uap, mask);
5148 native_sigset13_to_sigset(&ness, &nbss);
5149 error = sigprocmask1(p, SCARG(uap, how), &nbss, &obss);
5150 if (error)
5151 return (error);
5152 native_sigset_to_sigset13(&obss, &oess);
5153 *retval = oess;
5154 return (0);
5155 }
5156
5157
5158 int
5159 compat_13_compat_sparc32_sigsuspend(p, v, retval)
5160 register struct proc *p;
5161 void *v;
5162 register_t *retval;
5163 {
5164 struct compat_13_compat_sparc32_sigsuspend_args /* {
5165 syscallarg(sigset13_t) mask;
5166 } */ *uap = v;
5167 sigset13_t ess;
5168 sigset_t bss;
5169
5170 ess = SCARG(uap, mask);
5171 native_sigset13_to_sigset(&ess, &bss);
5172 return (sigsuspend1(p, &bss));
5173 }
5174