1 /* $NetBSD: svr4_32_misc.c,v 1.25 2003/11/12 21:07:38 dsl Exp $ */
2
3 /*-
4 * Copyright (c) 1994 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * SVR4 compatibility module.
41 *
42 * SVR4 system calls that are implemented differently in BSD are
43 * handled here.
44 */
45
46 #include <sys/cdefs.h>
47 __KERNEL_RCSID(0, "$NetBSD: svr4_32_misc.c,v 1.25 2003/11/12 21:07:38 dsl Exp $");
48
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/namei.h>
52 #include <sys/dirent.h>
53 #include <sys/proc.h>
54 #include <sys/file.h>
55 #include <sys/stat.h>
56 #include <sys/time.h>
57 #include <sys/filedesc.h>
58 #include <sys/ioctl.h>
59 #include <sys/kernel.h>
60 #include <sys/malloc.h>
61 #include <sys/pool.h>
62 #include <sys/mbuf.h>
63 #include <sys/mman.h>
64 #include <sys/mount.h>
65 #include <sys/resource.h>
66 #include <sys/resourcevar.h>
67 #include <sys/socket.h>
68 #include <sys/vnode.h>
69 #include <sys/uio.h>
70 #include <sys/wait.h>
71 #include <sys/utsname.h>
72 #include <sys/unistd.h>
73 #include <sys/times.h>
74 #include <sys/sem.h>
75 #include <sys/msg.h>
76 #include <sys/ptrace.h>
77 #include <sys/signalvar.h>
78
79 #include <netinet/in.h>
80 #include <sys/sa.h>
81 #include <sys/syscallargs.h>
82
83 #include <miscfs/specfs/specdev.h>
84
85 #include <compat/svr4_32/svr4_32_types.h>
86 #include <compat/svr4_32/svr4_32_signal.h>
87 #include <compat/svr4_32/svr4_32_lwp.h>
88 #include <compat/svr4_32/svr4_32_ucontext.h>
89 #include <compat/svr4_32/svr4_32_syscallargs.h>
90 #include <compat/svr4_32/svr4_32_util.h>
91 #include <compat/svr4_32/svr4_32_time.h>
92 #include <compat/svr4_32/svr4_32_dirent.h>
93 #include <compat/svr4/svr4_ulimit.h>
94 #include <compat/svr4_32/svr4_32_hrt.h>
95 #include <compat/svr4/svr4_wait.h>
96 #include <compat/svr4_32/svr4_32_statvfs.h>
97 #include <compat/svr4/svr4_sysconfig.h>
98 #include <compat/svr4_32/svr4_32_acl.h>
99 #include <compat/svr4/svr4_mman.h>
100
101 #include <machine/cpu.h>
102
103 #include <uvm/uvm_extern.h>
104
105 static int svr4_to_bsd_mmap_flags __P((int));
106
107 static __inline clock_t timeval_to_clock_t __P((struct timeval *));
108 static int svr4_32_setinfo __P((struct proc *, int, svr4_32_siginfo_tp));
109
110 struct svr4_32_hrtcntl_args;
111 static int svr4_32_hrtcntl __P((struct proc *, struct svr4_32_hrtcntl_args *,
112 register_t *));
113 static void bsd_statfs_to_svr4_32_statvfs __P((const struct statfs *,
114 struct svr4_32_statvfs *));
115 static void bsd_statfs_to_svr4_32_statvfs64 __P((const struct statfs *,
116 struct svr4_32_statvfs64 *));
117 #define svr4_32_pfind(pid) p_find((pid), PFIND_UNLOCK | PFIND_ZOMBIE)
118
119 static int svr4_32_mknod __P((struct lwp *, register_t *, const char *,
120 svr4_32_mode_t, svr4_32_dev_t));
121
122 int
123 svr4_32_sys_wait(l, v, retval)
124 struct lwp *l;
125 void *v;
126 register_t *retval;
127 {
128 struct svr4_32_sys_wait_args *uap = v;
129 struct proc *p = l->l_proc;
130 struct sys_wait4_args w4;
131 int error;
132 size_t sz = sizeof(*SCARG(&w4, status));
133 int st, sig;
134
135 SCARG(&w4, rusage) = NULL;
136 SCARG(&w4, options) = 0;
137
138 if (SCARG(uap, status) == 0) {
139 caddr_t sg = stackgap_init(p, 0);
140
141 SCARG(&w4, status) = stackgap_alloc(p, &sg, sz);
142 }
143 else
144 SCARG(&w4, status) = (int *)(u_long)SCARG(uap, status);
145
146 SCARG(&w4, pid) = WAIT_ANY;
147
148 if ((error = sys_wait4(l, &w4, retval)) != 0)
149 return error;
150
151 if ((error = copyin(SCARG(&w4, status), &st, sizeof(st))) != 0)
152 return error;
153
154 if (WIFSIGNALED(st)) {
155 sig = WTERMSIG(st);
156 if (sig >= 0 && sig < NSIG)
157 st = (st & ~0177) | native_to_svr4_signo[sig];
158 } else if (WIFSTOPPED(st)) {
159 sig = WSTOPSIG(st);
160 if (sig >= 0 && sig < NSIG)
161 st = (st & ~0xff00) | (native_to_svr4_signo[sig] << 8);
162 }
163
164 /*
165 * It looks like wait(2) on svr4/solaris/2.4 returns
166 * the status in retval[1], and the pid on retval[0].
167 */
168 retval[1] = st;
169
170 if (SCARG(uap, status))
171 if ((error = copyout(&st, (caddr_t)(u_long)SCARG(uap, status),
172 sizeof(st))) != 0)
173 return error;
174
175 return 0;
176 }
177
178
179 int
180 svr4_32_sys_execv(l, v, retval)
181 struct lwp *l;
182 void *v;
183 register_t *retval;
184 {
185 struct svr4_32_sys_execv_args /* {
186 syscallarg(char *) path;
187 syscallarg(char **) argv;
188 } */ *uap = v;
189 struct netbsd32_execve_args_noconst {
190 syscallarg(netbsd32_charp) path;
191 syscallarg(netbsd32_charpp) argp;
192 syscallarg(netbsd32_charpp) envp;
193 } ap;
194
195 SCARG(&ap, path) = SCARG(uap, path);
196 SCARG(&ap, argp) = SCARG(uap, argp);
197 SCARG(&ap, envp) = 0;
198
199 return netbsd32_execve(l, &ap, retval);
200 }
201
202 #if 0
203 int
204 svr4_32_sys_execve(p, v, retval)
205 struct proc *p;
206 void *v;
207 register_t *retval;
208 {
209 struct svr4_32_sys_execve_args /* {
210 syscallarg(const char *) path;
211 syscallarg(char **) argv;
212 syscallarg(char **) envp;
213 } */ *uap = v;
214 struct sys_execve_args ap;
215 caddr_t sg;
216
217 sg = stackgap_init(p, 0);
218
219 SCARG(&ap, path) = (const char *)(u_long)SCARG(uap, path);
220 CHECK_ALT_EXIST(p, &sg, SCARG(&ap, path));
221 SCARG(&ap, argp) = (char **)(u_long)SCARG(uap, argp);
222 SCARG(&ap, envp) = (char **)(u_long)SCARG(uap, envp);
223
224 return netbsd32_execve(p, &ap, retval);
225 }
226 #endif
227
228 int
229 svr4_32_sys_time(l, v, retval)
230 struct lwp *l;
231 void *v;
232 register_t *retval;
233 {
234 struct svr4_32_sys_time_args *uap = v;
235 int error = 0;
236 struct timeval tv;
237 struct netbsd32_timeval ntv;
238
239 microtime(&tv);
240 ntv.tv_sec = tv.tv_sec;
241 ntv.tv_usec = tv.tv_usec;
242 if (SCARG(uap, t))
243 error = copyout(&ntv.tv_sec, (caddr_t)(u_long)SCARG(uap, t),
244 sizeof(ntv.tv_sec));
245 *retval = (int) ntv.tv_sec;
246
247 return error;
248 }
249
250
251 /*
252 * Read SVR4-style directory entries. We suck them into kernel space so
253 * that they can be massaged before being copied out to user code. Like
254 * SunOS, we squish out `empty' entries.
255 *
256 * This is quite ugly, but what do you expect from compatibility code?
257 */
258 int
259 svr4_32_sys_getdents64(l, v, retval)
260 struct lwp *l;
261 void *v;
262 register_t *retval;
263 {
264 struct svr4_32_sys_getdents64_args *uap = v;
265 struct proc *p = l->l_proc;
266 struct dirent *bdp;
267 struct vnode *vp;
268 caddr_t inp, buf; /* BSD-format */
269 int len, reclen; /* BSD-format */
270 caddr_t outp; /* SVR4-format */
271 int resid, svr4_32_reclen; /* SVR4-format */
272 struct file *fp;
273 struct uio auio;
274 struct iovec aiov;
275 struct svr4_32_dirent64 idb;
276 off_t off; /* true file offset */
277 int buflen, error, eofflag;
278 off_t *cookiebuf = NULL, *cookie;
279 int ncookies;
280
281 /* getvnode() will use the descriptor for us */
282 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
283 return (error);
284
285 if ((fp->f_flag & FREAD) == 0) {
286 error = EBADF;
287 goto out1;
288 }
289
290 vp = (struct vnode *)fp->f_data;
291 if (vp->v_type != VDIR) {
292 error = EINVAL;
293 goto out1;
294 }
295
296 buflen = min(MAXBSIZE, SCARG(uap, nbytes));
297 buf = malloc(buflen, M_TEMP, M_WAITOK);
298 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
299 off = fp->f_offset;
300 again:
301 aiov.iov_base = buf;
302 aiov.iov_len = buflen;
303 auio.uio_iov = &aiov;
304 auio.uio_iovcnt = 1;
305 auio.uio_rw = UIO_READ;
306 auio.uio_segflg = UIO_SYSSPACE;
307 auio.uio_procp = p;
308 auio.uio_resid = buflen;
309 auio.uio_offset = off;
310 /*
311 * First we read into the malloc'ed buffer, then
312 * we massage it into user space, one record at a time.
313 */
314 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &cookiebuf,
315 &ncookies);
316 if (error)
317 goto out;
318
319 inp = buf;
320 outp = (char *)(u_long) SCARG(uap, dp);
321 resid = SCARG(uap, nbytes);
322 if ((len = buflen - auio.uio_resid) == 0)
323 goto eof;
324
325 for (cookie = cookiebuf; len > 0; len -= reclen) {
326 bdp = (struct dirent *)inp;
327 reclen = bdp->d_reclen;
328 if (reclen & 3)
329 panic("svr4_32_getdents64: bad reclen");
330 if (bdp->d_fileno == 0) {
331 inp += reclen; /* it is a hole; squish it out */
332 off = *cookie++;
333 continue;
334 }
335 svr4_32_reclen = SVR4_RECLEN(&idb, bdp->d_namlen);
336 if (reclen > len || resid < svr4_32_reclen) {
337 /* entry too big for buffer, so just stop */
338 outp++;
339 break;
340 }
341 off = *cookie++; /* each entry points to the next */
342 /*
343 * Massage in place to make a SVR4-shaped dirent (otherwise
344 * we have to worry about touching user memory outside of
345 * the copyout() call).
346 */
347 idb.d_ino = (svr4_32_ino64_t)bdp->d_fileno;
348 idb.d_off = (svr4_32_off64_t)off;
349 idb.d_reclen = (u_short)svr4_32_reclen;
350 strlcpy(idb.d_name, bdp->d_name, sizeof(idb.d_name));
351 if ((error = copyout((caddr_t)&idb, outp, svr4_32_reclen)))
352 goto out;
353 /* advance past this real entry */
354 inp += reclen;
355 /* advance output past SVR4-shaped entry */
356 outp += svr4_32_reclen;
357 resid -= svr4_32_reclen;
358 }
359
360 /* if we squished out the whole block, try again */
361 if (outp == (char *)(u_long) SCARG(uap, dp))
362 goto again;
363 fp->f_offset = off; /* update the vnode offset */
364
365 eof:
366 *retval = SCARG(uap, nbytes) - resid;
367 out:
368 VOP_UNLOCK(vp, 0);
369 if (cookiebuf)
370 free(cookiebuf, M_TEMP);
371 free(buf, M_TEMP);
372 out1:
373 FILE_UNUSE(fp, p);
374 return error;
375 }
376
377
378 int
379 svr4_32_sys_getdents(l, v, retval)
380 struct lwp *l;
381 void *v;
382 register_t *retval;
383 {
384 struct svr4_32_sys_getdents_args *uap = v;
385 struct proc *p = l->l_proc;
386 struct dirent *bdp;
387 struct vnode *vp;
388 caddr_t inp, buf; /* BSD-format */
389 int len, reclen; /* BSD-format */
390 caddr_t outp; /* SVR4-format */
391 int resid, svr4_reclen; /* SVR4-format */
392 struct file *fp;
393 struct uio auio;
394 struct iovec aiov;
395 struct svr4_32_dirent idb;
396 off_t off; /* true file offset */
397 int buflen, error, eofflag;
398 off_t *cookiebuf = NULL, *cookie;
399 int ncookies;
400
401 /* getvnode() will use the descriptor for us */
402 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
403 return (error);
404
405 if ((fp->f_flag & FREAD) == 0) {
406 error = EBADF;
407 goto out1;
408 }
409
410 vp = (struct vnode *)fp->f_data;
411 if (vp->v_type != VDIR) {
412 error = EINVAL;
413 goto out1;
414 }
415
416 buflen = min(MAXBSIZE, SCARG(uap, nbytes));
417 buf = malloc(buflen, M_TEMP, M_WAITOK);
418 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
419 off = fp->f_offset;
420 again:
421 aiov.iov_base = buf;
422 aiov.iov_len = buflen;
423 auio.uio_iov = &aiov;
424 auio.uio_iovcnt = 1;
425 auio.uio_rw = UIO_READ;
426 auio.uio_segflg = UIO_SYSSPACE;
427 auio.uio_procp = p;
428 auio.uio_resid = buflen;
429 auio.uio_offset = off;
430 /*
431 * First we read into the malloc'ed buffer, then
432 * we massage it into user space, one record at a time.
433 */
434 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &cookiebuf,
435 &ncookies);
436 if (error)
437 goto out;
438
439 inp = buf;
440 outp = (caddr_t)(u_long)SCARG(uap, buf);
441 resid = SCARG(uap, nbytes);
442 if ((len = buflen - auio.uio_resid) == 0)
443 goto eof;
444
445 for (cookie = cookiebuf; len > 0; len -= reclen) {
446 bdp = (struct dirent *)inp;
447 reclen = bdp->d_reclen;
448 if (reclen & 3)
449 panic("svr4_32_getdents: bad reclen");
450 off = *cookie++; /* each entry points to the next */
451 if ((off >> 32) != 0) {
452 compat_offseterr(vp, "svr4_32_getdents");
453 error = EINVAL;
454 goto out;
455 }
456 if (bdp->d_fileno == 0) {
457 inp += reclen; /* it is a hole; squish it out */
458 continue;
459 }
460 svr4_reclen = SVR4_RECLEN(&idb, bdp->d_namlen);
461 if (reclen > len || resid < svr4_reclen) {
462 /* entry too big for buffer, so just stop */
463 outp++;
464 break;
465 }
466 /*
467 * Massage in place to make a SVR4-shaped dirent (otherwise
468 * we have to worry about touching user memory outside of
469 * the copyout() call).
470 */
471 idb.d_ino = (svr4_32_ino_t)bdp->d_fileno;
472 idb.d_off = (svr4_32_off_t)off;
473 idb.d_reclen = (u_short)svr4_reclen;
474 strlcpy(idb.d_name, bdp->d_name, sizeof(idb.d_name));
475 if ((error = copyout((caddr_t)&idb, outp, svr4_reclen)))
476 goto out;
477 /* advance past this real entry */
478 inp += reclen;
479 /* advance output past SVR4-shaped entry */
480 outp += svr4_reclen;
481 resid -= svr4_reclen;
482 }
483
484 /* if we squished out the whole block, try again */
485 if (outp == (caddr_t)(u_long)SCARG(uap, buf))
486 goto again;
487 fp->f_offset = off; /* update the vnode offset */
488
489 eof:
490 *retval = SCARG(uap, nbytes) - resid;
491 out:
492 VOP_UNLOCK(vp, 0);
493 if (cookiebuf)
494 free(cookiebuf, M_TEMP);
495 free(buf, M_TEMP);
496 out1:
497 FILE_UNUSE(fp, p);
498 return error;
499 }
500
501
502 static int
503 svr4_to_bsd_mmap_flags(f)
504 int f;
505 {
506 int type = f & SVR4_MAP_TYPE;
507 int nf;
508
509 if (type != MAP_PRIVATE && type != MAP_SHARED)
510 return -1;
511
512 nf = f & SVR4_MAP_COPYFLAGS;
513 if (f & SVR4_MAP_ANON)
514 nf |= MAP_ANON;
515
516 return nf;
517 }
518
519
520 int
521 svr4_32_sys_mmap(l, v, retval)
522 struct lwp *l;
523 void *v;
524 register_t *retval;
525 {
526 struct svr4_32_sys_mmap_args *uap = v;
527 struct sys_mmap_args mm;
528 int error;
529 /*
530 * Verify the arguments.
531 */
532 if (SCARG(uap, prot) & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
533 return EINVAL; /* XXX still needed? */
534
535 if (SCARG(uap, len) == 0)
536 return EINVAL;
537
538 if ((SCARG(&mm, flags) = svr4_to_bsd_mmap_flags(SCARG(uap, flags))) == -1)
539 return EINVAL;
540
541 SCARG(&mm, prot) = SCARG(uap, prot);
542 SCARG(&mm, len) = SCARG(uap, len);
543 SCARG(&mm, fd) = SCARG(uap, fd);
544 SCARG(&mm, addr) = (void *)(u_long)SCARG(uap, addr);
545 SCARG(&mm, pos) = SCARG(uap, pos);
546
547 error = sys_mmap(l, &mm, retval);
548 if ((u_long)*retval > (u_long)UINT_MAX) {
549 printf("svr4_32_mmap: retval out of range: 0x%lx",
550 (u_long)*retval);
551 /* Should try to recover and return an error here. */
552 }
553 return (error);
554 }
555
556
557 int
558 svr4_32_sys_mmap64(l, v, retval)
559 struct lwp *l;
560 void *v;
561 register_t *retval;
562 {
563 struct svr4_32_sys_mmap64_args *uap = v;
564 struct sys_mmap_args mm;
565 int error;
566 /*
567 * Verify the arguments.
568 */
569 if (SCARG(uap, prot) & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
570 return EINVAL; /* XXX still needed? */
571
572 if (SCARG(uap, len) == 0)
573 return EINVAL;
574
575 if ((SCARG(&mm, flags) = svr4_to_bsd_mmap_flags(SCARG(uap, flags))) == -1)
576 return EINVAL;
577
578 SCARG(&mm, prot) = SCARG(uap, prot);
579 SCARG(&mm, len) = SCARG(uap, len);
580 SCARG(&mm, fd) = SCARG(uap, fd);
581 SCARG(&mm, addr) = (void *)(u_long)SCARG(uap, addr);
582 SCARG(&mm, pos) = SCARG(uap, pos);
583
584 error = sys_mmap(l, &mm, retval);
585 if ((u_long)*retval > (u_long)UINT_MAX) {
586 printf("svr4_32_mmap64: retval out of range: 0x%lx",
587 (u_long)*retval);
588 /* Should try to recover and return an error here. */
589 }
590 return (error);
591 }
592
593
594 static int
595 svr4_32_mknod(l, retval, path, mode, dev)
596 struct lwp *l;
597 register_t *retval;
598 const char *path;
599 svr4_32_mode_t mode;
600 svr4_32_dev_t dev;
601 {
602 caddr_t sg = stackgap_init(l->l_proc, 0);
603
604 CHECK_ALT_CREAT(l->l_proc, &sg, path);
605
606 if (S_ISFIFO(mode)) {
607 struct sys_mkfifo_args ap;
608 SCARG(&ap, path) = path;
609 SCARG(&ap, mode) = mode;
610 return sys_mkfifo(l, &ap, retval);
611 } else {
612 struct sys_mknod_args ap;
613 SCARG(&ap, path) = path;
614 SCARG(&ap, mode) = mode;
615 SCARG(&ap, dev) = dev;
616 return sys_mknod(l, &ap, retval);
617 }
618 }
619
620
621 int
622 svr4_32_sys_mknod(l, v, retval)
623 struct lwp *l;
624 void *v;
625 register_t *retval;
626 {
627 struct svr4_32_sys_mknod_args *uap = v;
628 return svr4_32_mknod(l, retval,
629 (caddr_t)(u_long)SCARG(uap, path), SCARG(uap, mode),
630 svr4_32_to_bsd_odev_t(SCARG(uap, dev)));
631 }
632
633
634 int
635 svr4_32_sys_xmknod(l, v, retval)
636 struct lwp *l;
637 void *v;
638 register_t *retval;
639 {
640 struct svr4_32_sys_xmknod_args *uap = v;
641 return svr4_32_mknod(l, retval,
642 (caddr_t)(u_long)SCARG(uap, path), SCARG(uap, mode),
643 svr4_32_to_bsd_dev_t(SCARG(uap, dev)));
644 }
645
646
647 int
648 svr4_32_sys_vhangup(l, v, retval)
649 struct lwp *l;
650 void *v;
651 register_t *retval;
652 {
653 return 0;
654 }
655
656
657 int
658 svr4_32_sys_sysconfig(l, v, retval)
659 struct lwp *l;
660 void *v;
661 register_t *retval;
662 {
663 struct svr4_32_sys_sysconfig_args *uap = v;
664 extern int maxfiles;
665
666 switch (SCARG(uap, name)) {
667 case SVR4_CONFIG_NGROUPS:
668 *retval = NGROUPS_MAX;
669 break;
670 case SVR4_CONFIG_CHILD_MAX:
671 *retval = maxproc;
672 break;
673 case SVR4_CONFIG_OPEN_FILES:
674 *retval = maxfiles;
675 break;
676 case SVR4_CONFIG_POSIX_VER:
677 *retval = 198808;
678 break;
679 case SVR4_CONFIG_PAGESIZE:
680 *retval = PAGE_SIZE;
681 break;
682 case SVR4_CONFIG_CLK_TCK:
683 *retval = 60; /* should this be `hz', ie. 100? */
684 break;
685 case SVR4_CONFIG_XOPEN_VER:
686 *retval = 2; /* XXX: What should that be? */
687 break;
688 case SVR4_CONFIG_PROF_TCK:
689 *retval = 60; /* XXX: What should that be? */
690 break;
691 case SVR4_CONFIG_NPROC_CONF:
692 *retval = 1; /* Only one processor for now */
693 break;
694 case SVR4_CONFIG_NPROC_ONLN:
695 *retval = 1; /* And it better be online */
696 break;
697 case SVR4_CONFIG_AIO_LISTIO_MAX:
698 case SVR4_CONFIG_AIO_MAX:
699 case SVR4_CONFIG_AIO_PRIO_DELTA_MAX:
700 *retval = 0; /* No aio support */
701 break;
702 case SVR4_CONFIG_DELAYTIMER_MAX:
703 *retval = 0; /* No delaytimer support */
704 break;
705 case SVR4_CONFIG_MQ_OPEN_MAX:
706 #ifdef SYSVMSG
707 *retval = msginfo.msgmni;
708 #else
709 *retval = 0;
710 #endif
711 break;
712 case SVR4_CONFIG_MQ_PRIO_MAX:
713 *retval = 0; /* XXX: Don't know */
714 break;
715 case SVR4_CONFIG_RTSIG_MAX:
716 *retval = 0;
717 break;
718 case SVR4_CONFIG_SEM_NSEMS_MAX:
719 #ifdef SYSVSEM
720 *retval = seminfo.semmni;
721 #else
722 *retval = 0;
723 #endif
724 break;
725 case SVR4_CONFIG_SEM_VALUE_MAX:
726 #ifdef SYSVSEM
727 *retval = seminfo.semvmx;
728 #else
729 *retval = 0;
730 #endif
731 break;
732 case SVR4_CONFIG_SIGQUEUE_MAX:
733 *retval = 0; /* XXX: Don't know */
734 break;
735 case SVR4_CONFIG_SIGRT_MIN:
736 case SVR4_CONFIG_SIGRT_MAX:
737 *retval = 0; /* No real time signals */
738 break;
739 case SVR4_CONFIG_TIMER_MAX:
740 *retval = 3; /* XXX: real, virtual, profiling */
741 break;
742 case SVR4_CONFIG_PHYS_PAGES:
743 *retval = uvmexp.free; /* XXX: free instead of total */
744 break;
745 case SVR4_CONFIG_AVPHYS_PAGES:
746 *retval = uvmexp.active; /* XXX: active instead of avg */
747 break;
748 case SVR4_CONFIG_COHERENCY:
749 *retval = 0; /* XXX */
750 break;
751 case SVR4_CONFIG_SPLIT_CACHE:
752 *retval = 0; /* XXX */
753 break;
754 case SVR4_CONFIG_ICACHESZ:
755 *retval = 256; /* XXX */
756 break;
757 case SVR4_CONFIG_DCACHESZ:
758 *retval = 256; /* XXX */
759 break;
760 case SVR4_CONFIG_ICACHELINESZ:
761 *retval = 64; /* XXX */
762 break;
763 case SVR4_CONFIG_DCACHELINESZ:
764 *retval = 64; /* XXX */
765 break;
766 case SVR4_CONFIG_ICACHEBLKSZ:
767 *retval = 64; /* XXX */
768 break;
769 case SVR4_CONFIG_DCACHEBLKSZ:
770 *retval = 64; /* XXX */
771 break;
772 case SVR4_CONFIG_DCACHETBLKSZ:
773 *retval = 64; /* XXX */
774 break;
775 case SVR4_CONFIG_ICACHE_ASSOC:
776 *retval = 1; /* XXX */
777 break;
778 case SVR4_CONFIG_DCACHE_ASSOC:
779 *retval = 1; /* XXX */
780 break;
781 case SVR4_CONFIG_MAXPID:
782 *retval = PID_MAX;
783 break;
784 case SVR4_CONFIG_STACK_PROT:
785 *retval = PROT_READ|PROT_WRITE|PROT_EXEC;
786 break;
787 default:
788 return EINVAL;
789 }
790 return 0;
791 }
792
793
794 /* ARGSUSED */
795 int
796 svr4_32_sys_break(l, v, retval)
797 struct lwp *l;
798 void *v;
799 register_t *retval;
800 {
801 struct svr4_32_sys_break_args *uap = v;
802 struct proc *p = l->l_proc;
803 struct vmspace *vm = p->p_vmspace;
804 vaddr_t new, old;
805 int error;
806
807 old = (vaddr_t) vm->vm_daddr;
808 new = round_page((vaddr_t)SCARG(uap, nsize));
809
810 if (new - old > p->p_rlimit[RLIMIT_DATA].rlim_cur && new > old)
811 return ENOMEM;
812
813 old = round_page(old + ctob(vm->vm_dsize));
814 DPRINTF(("break(2): dsize = %x ctob %x\n",
815 vm->vm_dsize, ctob(vm->vm_dsize)));
816
817 if (new > old) {
818 error = uvm_map(&vm->vm_map, &old, new - old, NULL,
819 UVM_UNKNOWN_OFFSET, 0,
820 UVM_MAPFLAG(UVM_PROT_ALL, UVM_PROT_ALL, UVM_INH_COPY,
821 UVM_ADV_NORMAL,
822 UVM_FLAG_AMAPPAD|UVM_FLAG_FIXED|
823 UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW));
824 if (error) {
825 uprintf("sbrk: grow failed, return = %d\n", error);
826 return error;
827 }
828 vm->vm_dsize += btoc(new - old);
829 } else if (new < old) {
830 uvm_deallocate(&vm->vm_map, new, old - new);
831 vm->vm_dsize -= btoc(old - new);
832 }
833 return 0;
834 }
835
836
837 static __inline clock_t
838 timeval_to_clock_t(tv)
839 struct timeval *tv;
840 {
841 return tv->tv_sec * hz + tv->tv_usec / (1000000 / hz);
842 }
843
844
845 int
846 svr4_32_sys_times(l, v, retval)
847 struct lwp *l;
848 void *v;
849 register_t *retval;
850 {
851 struct svr4_32_sys_times_args *uap = v;
852 struct proc *p = l->l_proc;
853 int error;
854 struct tms tms;
855 struct timeval t;
856 struct rusage *ru;
857 struct rusage r;
858 struct sys_getrusage_args ga;
859
860 caddr_t sg = stackgap_init(p, 0);
861 ru = stackgap_alloc(p, &sg, sizeof(struct rusage));
862
863 SCARG(&ga, who) = RUSAGE_SELF;
864 SCARG(&ga, rusage) = ru;
865
866 error = sys_getrusage(l, &ga, retval);
867 if (error)
868 return error;
869
870 if ((error = copyin(ru, &r, sizeof r)) != 0)
871 return error;
872
873 tms.tms_utime = timeval_to_clock_t(&r.ru_utime);
874 tms.tms_stime = timeval_to_clock_t(&r.ru_stime);
875
876 SCARG(&ga, who) = RUSAGE_CHILDREN;
877 error = sys_getrusage(l, &ga, retval);
878 if (error)
879 return error;
880
881 if ((error = copyin(ru, &r, sizeof r)) != 0)
882 return error;
883
884 tms.tms_cutime = timeval_to_clock_t(&r.ru_utime);
885 tms.tms_cstime = timeval_to_clock_t(&r.ru_stime);
886
887 microtime(&t);
888 *retval = timeval_to_clock_t(&t);
889
890 return copyout(&tms, (caddr_t)(u_long)SCARG(uap, tp), sizeof(tms));
891 }
892
893
894 int
895 svr4_32_sys_ulimit(l, v, retval)
896 struct lwp *l;
897 void *v;
898 register_t *retval;
899 {
900 struct svr4_32_sys_ulimit_args *uap = v;
901 struct proc *p = l->l_proc;
902
903 switch (SCARG(uap, cmd)) {
904 case SVR4_GFILLIM:
905 *retval = p->p_rlimit[RLIMIT_FSIZE].rlim_cur / 512;
906 if (*retval == -1)
907 *retval = 0x7fffffff;
908 return 0;
909
910 case SVR4_SFILLIM:
911 {
912 int error;
913 struct sys_setrlimit_args srl;
914 struct rlimit krl;
915 caddr_t sg = stackgap_init(p, 0);
916 struct rlimit *url = (struct rlimit *)
917 stackgap_alloc(p, &sg, sizeof *url);
918
919 krl.rlim_cur = SCARG(uap, newlimit) * 512;
920 krl.rlim_max = p->p_rlimit[RLIMIT_FSIZE].rlim_max;
921
922 error = copyout(&krl, url, sizeof(*url));
923 if (error)
924 return error;
925
926 SCARG(&srl, which) = RLIMIT_FSIZE;
927 SCARG(&srl, rlp) = url;
928
929 error = sys_setrlimit(l, &srl, retval);
930 if (error)
931 return error;
932
933 *retval = p->p_rlimit[RLIMIT_FSIZE].rlim_cur;
934 if (*retval == -1)
935 *retval = 0x7fffffff;
936 return 0;
937 }
938
939 case SVR4_GMEMLIM:
940 {
941 struct vmspace *vm = p->p_vmspace;
942 register_t r = p->p_rlimit[RLIMIT_DATA].rlim_cur;
943
944 if (r == -1)
945 r = 0x7fffffff;
946 r += (long) vm->vm_daddr;
947 if (r < 0)
948 r = 0x7fffffff;
949 *retval = r;
950 return 0;
951 }
952
953 case SVR4_GDESLIM:
954 *retval = p->p_rlimit[RLIMIT_NOFILE].rlim_cur;
955 if (*retval == -1)
956 *retval = 0x7fffffff;
957 return 0;
958
959 default:
960 return EINVAL;
961 }
962 }
963
964
965 int
966 svr4_32_sys_pgrpsys(l, v, retval)
967 struct lwp *l;
968 void *v;
969 register_t *retval;
970 {
971 struct svr4_32_sys_pgrpsys_args *uap = v;
972 struct proc *p = l->l_proc;
973
974 switch (SCARG(uap, cmd)) {
975 case 1: /* setpgrp() */
976 /*
977 * SVR4 setpgrp() (which takes no arguments) has the
978 * semantics that the session ID is also created anew, so
979 * in almost every sense, setpgrp() is identical to
980 * setsid() for SVR4. (Under BSD, the difference is that
981 * a setpgid(0,0) will not create a new session.)
982 */
983 sys_setsid(l, NULL, retval);
984 /*FALLTHROUGH*/
985
986 case 0: /* getpgrp() */
987 *retval = p->p_pgrp->pg_id;
988 return 0;
989
990 case 2: /* getsid(pid) */
991 if (SCARG(uap, pid) != 0 &&
992 (p = svr4_32_pfind(SCARG(uap, pid))) == NULL)
993 return ESRCH;
994 /*
995 * This has already been initialized to the pid of
996 * the session leader.
997 */
998 *retval = (register_t) p->p_session->s_sid;
999 return 0;
1000
1001 case 3: /* setsid() */
1002 return sys_setsid(l, NULL, retval);
1003
1004 case 4: /* getpgid(pid) */
1005
1006 if (SCARG(uap, pid) != 0 &&
1007 (p = svr4_32_pfind(SCARG(uap, pid))) == NULL)
1008 return ESRCH;
1009
1010 *retval = (int) p->p_pgrp->pg_id;
1011 return 0;
1012
1013 case 5: /* setpgid(pid, pgid); */
1014 {
1015 struct sys_setpgid_args sa;
1016
1017 SCARG(&sa, pid) = SCARG(uap, pid);
1018 SCARG(&sa, pgid) = SCARG(uap, pgid);
1019 return sys_setpgid(l, &sa, retval);
1020 }
1021
1022 default:
1023 return EINVAL;
1024 }
1025 }
1026
1027 struct svr4_32_hrtcntl_args {
1028 syscallarg(int) cmd;
1029 syscallarg(int) fun;
1030 syscallarg(int) clk;
1031 syscallarg(svr4_32_hrt_interval_tp) iv;
1032 syscallarg(svr4_32_hrt_time_tp) ti;
1033 };
1034
1035
1036 static int
1037 svr4_32_hrtcntl(p, uap, retval)
1038 struct proc *p;
1039 struct svr4_32_hrtcntl_args *uap;
1040 register_t *retval;
1041 {
1042 switch (SCARG(uap, fun)) {
1043 case SVR4_HRT_CNTL_RES:
1044 DPRINTF(("htrcntl(RES)\n"));
1045 *retval = SVR4_HRT_USEC;
1046 return 0;
1047
1048 case SVR4_HRT_CNTL_TOFD:
1049 DPRINTF(("htrcntl(TOFD)\n"));
1050 {
1051 struct timeval tv;
1052 svr4_hrt_time_t t;
1053 if (SCARG(uap, clk) != SVR4_HRT_CLK_STD) {
1054 DPRINTF(("clk == %d\n", SCARG(uap, clk)));
1055 return EINVAL;
1056 }
1057 if (SCARG(uap, ti) == 0) {
1058 DPRINTF(("ti NULL\n"));
1059 return EINVAL;
1060 }
1061 microtime(&tv);
1062 t.h_sec = tv.tv_sec;
1063 t.h_rem = tv.tv_usec;
1064 t.h_res = SVR4_HRT_USEC;
1065 return copyout(&t, (caddr_t)(u_long)SCARG(uap, ti),
1066 sizeof(t));
1067 }
1068
1069 case SVR4_HRT_CNTL_START:
1070 DPRINTF(("htrcntl(START)\n"));
1071 return ENOSYS;
1072
1073 case SVR4_HRT_CNTL_GET:
1074 DPRINTF(("htrcntl(GET)\n"));
1075 return ENOSYS;
1076 default:
1077 DPRINTF(("Bad htrcntl command %d\n", SCARG(uap, fun)));
1078 return ENOSYS;
1079 }
1080 }
1081
1082
1083 int
1084 svr4_32_sys_hrtsys(l, v, retval)
1085 struct lwp *l;
1086 void *v;
1087 register_t *retval;
1088 {
1089 struct svr4_32_sys_hrtsys_args *uap = v;
1090
1091 switch (SCARG(uap, cmd)) {
1092 case SVR4_HRT_CNTL:
1093 return svr4_32_hrtcntl(l->l_proc, (struct svr4_32_hrtcntl_args *) uap,
1094 retval);
1095
1096 case SVR4_HRT_ALRM:
1097 DPRINTF(("hrtalarm\n"));
1098 return ENOSYS;
1099
1100 case SVR4_HRT_SLP:
1101 DPRINTF(("hrtsleep\n"));
1102 return ENOSYS;
1103
1104 case SVR4_HRT_CAN:
1105 DPRINTF(("hrtcancel\n"));
1106 return ENOSYS;
1107
1108 default:
1109 DPRINTF(("Bad hrtsys command %d\n", SCARG(uap, cmd)));
1110 return EINVAL;
1111 }
1112 }
1113
1114
1115 static int
1116 svr4_32_setinfo(p, st, si)
1117 struct proc *p;
1118 int st;
1119 svr4_32_siginfo_tp si;
1120 {
1121 svr4_32_siginfo_t *s = (svr4_32_siginfo_t *)(u_long)si;
1122 svr4_32_siginfo_t i;
1123 int sig;
1124
1125 memset(&i, 0, sizeof(i));
1126
1127 i.si_signo = SVR4_SIGCHLD;
1128 i.si_errno = 0; /* XXX? */
1129
1130 if (p) {
1131 i.si_pid = p->p_pid;
1132 if (p->p_stat == SZOMB) {
1133 i.si_stime = p->p_ru->ru_stime.tv_sec;
1134 i.si_utime = p->p_ru->ru_utime.tv_sec;
1135 }
1136 else {
1137 i.si_stime = p->p_stats->p_ru.ru_stime.tv_sec;
1138 i.si_utime = p->p_stats->p_ru.ru_utime.tv_sec;
1139 }
1140 }
1141
1142 if (WIFEXITED(st)) {
1143 i.si_status = WEXITSTATUS(st);
1144 i.si_code = SVR4_CLD_EXITED;
1145 } else if (WIFSTOPPED(st)) {
1146 sig = WSTOPSIG(st);
1147 if (sig >= 0 && sig < NSIG)
1148 i.si_status = native_to_svr4_signo[sig];
1149
1150 if (i.si_status == SVR4_SIGCONT)
1151 i.si_code = SVR4_CLD_CONTINUED;
1152 else
1153 i.si_code = SVR4_CLD_STOPPED;
1154 } else {
1155 sig = WTERMSIG(st);
1156 if (sig >= 0 && sig < NSIG)
1157 i.si_status = native_to_svr4_signo[sig];
1158
1159 if (WCOREDUMP(st))
1160 i.si_code = SVR4_CLD_DUMPED;
1161 else
1162 i.si_code = SVR4_CLD_KILLED;
1163 }
1164
1165 DPRINTF(("siginfo [pid %ld signo %d code %d errno %d status %d]\n",
1166 i.si_pid, i.si_signo, i.si_code, i.si_errno, i.si_status));
1167
1168 return copyout(&i, s, sizeof(i));
1169 }
1170
1171
1172 int
1173 svr4_32_sys_waitsys(l, v, retval)
1174 struct lwp *l;
1175 void *v;
1176 register_t *retval;
1177 {
1178 struct svr4_32_sys_waitsys_args *uap = v;
1179 struct proc *parent = l->l_proc;
1180 int options, error;
1181 struct proc *child;
1182
1183 switch (SCARG(uap, grp)) {
1184 case SVR4_P_PID:
1185 break;
1186
1187 case SVR4_P_PGID:
1188 SCARG(uap, id) = -parent->p_pgid;
1189 break;
1190
1191 case SVR4_P_ALL:
1192 SCARG(uap, id) = WAIT_ANY;
1193 break;
1194
1195 default:
1196 return EINVAL;
1197 }
1198
1199 DPRINTF(("waitsys(%d, %d, %p, %x)\n",
1200 SCARG(uap, grp), SCARG(uap, id),
1201 SCARG(uap, info), SCARG(uap, options)));
1202
1203 /* Translate options */
1204 options = 0;
1205 if (SCARG(uap, options) & SVR4_WNOWAIT)
1206 options |= WNOWAIT;
1207 if (SCARG(uap, options) & SVR4_WNOHANG)
1208 options |= WNOHANG;
1209 if ((SCARG(uap, options) & (SVR4_WEXITED|SVR4_WTRAPPED)) == 0)
1210 options |= WNOZOMBIE;
1211 if (SCARG(uap, options) & (SVR4_WSTOPPED|SVR4_WCONTINUED))
1212 options |= WUNTRACED;
1213
1214 error = find_stopped_child(parent, SCARG(uap, id), options, &child);
1215 if (error != 0)
1216 return error;
1217 *retval = 0;
1218 if (child == NULL)
1219 return svr4_32_setinfo(NULL, 0, SCARG(uap, info));
1220
1221 if (child->p_stat == SZOMB) {
1222 DPRINTF(("found %d\n", child->p_pid));
1223 error = svr4_32_setinfo(child, child->p_xstat, SCARG(uap,info));
1224 if (error)
1225 return error;
1226
1227 if ((SCARG(uap, options) & SVR4_WNOWAIT)) {
1228 DPRINTF(("Don't wait\n"));
1229 return 0;
1230 }
1231
1232 proc_free(child);
1233 return 0;
1234 }
1235
1236 DPRINTF(("jobcontrol %d\n", child->p_pid));
1237 return svr4_32_setinfo(child, W_STOPCODE(child->p_xstat),
1238 SCARG(uap, info));
1239 }
1240
1241
1242 static void
1243 bsd_statfs_to_svr4_32_statvfs(bfs, sfs)
1244 const struct statfs *bfs;
1245 struct svr4_32_statvfs *sfs;
1246 {
1247 sfs->f_bsize = bfs->f_iosize; /* XXX */
1248 sfs->f_frsize = bfs->f_bsize;
1249 sfs->f_blocks = bfs->f_blocks;
1250 sfs->f_bfree = bfs->f_bfree;
1251 sfs->f_bavail = bfs->f_bavail;
1252 sfs->f_files = bfs->f_files;
1253 sfs->f_ffree = bfs->f_ffree;
1254 sfs->f_favail = bfs->f_ffree;
1255 sfs->f_fsid = bfs->f_fsid.val[0];
1256 memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype));
1257 sfs->f_flag = 0;
1258 if (bfs->f_flags & MNT_RDONLY)
1259 sfs->f_flag |= SVR4_ST_RDONLY;
1260 if (bfs->f_flags & MNT_NOSUID)
1261 sfs->f_flag |= SVR4_ST_NOSUID;
1262 sfs->f_namemax = MAXNAMLEN;
1263 memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */
1264 memset(sfs->f_filler, 0, sizeof(sfs->f_filler));
1265 }
1266
1267
1268 static void
1269 bsd_statfs_to_svr4_32_statvfs64(bfs, sfs)
1270 const struct statfs *bfs;
1271 struct svr4_32_statvfs64 *sfs;
1272 {
1273 sfs->f_bsize = bfs->f_iosize; /* XXX */
1274 sfs->f_frsize = bfs->f_bsize;
1275 sfs->f_blocks = bfs->f_blocks;
1276 sfs->f_bfree = bfs->f_bfree;
1277 sfs->f_bavail = bfs->f_bavail;
1278 sfs->f_files = bfs->f_files;
1279 sfs->f_ffree = bfs->f_ffree;
1280 sfs->f_favail = bfs->f_ffree;
1281 sfs->f_fsid = bfs->f_fsid.val[0];
1282 memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype));
1283 sfs->f_flag = 0;
1284 if (bfs->f_flags & MNT_RDONLY)
1285 sfs->f_flag |= SVR4_ST_RDONLY;
1286 if (bfs->f_flags & MNT_NOSUID)
1287 sfs->f_flag |= SVR4_ST_NOSUID;
1288 sfs->f_namemax = MAXNAMLEN;
1289 memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */
1290 memset(sfs->f_filler, 0, sizeof(sfs->f_filler));
1291 }
1292
1293
1294 int
1295 svr4_32_sys_statvfs(l, v, retval)
1296 struct lwp *l;
1297 void *v;
1298 register_t *retval;
1299 {
1300 struct svr4_32_sys_statvfs_args *uap = v;
1301 struct proc *p = l->l_proc;
1302 struct sys_statfs_args fs_args;
1303 caddr_t sg = stackgap_init(p, 0);
1304 struct statfs *fs = stackgap_alloc(p, &sg, sizeof(struct statfs));
1305 struct statfs bfs;
1306 struct svr4_32_statvfs sfs;
1307 int error;
1308
1309 SCARG(&fs_args, path) = (caddr_t)(u_long)SCARG(uap, path);
1310 CHECK_ALT_EXIST(p, &sg, SCARG(&fs_args, path));
1311 SCARG(&fs_args, buf) = fs;
1312
1313 if ((error = sys_statfs(l, &fs_args, retval)) != 0)
1314 return error;
1315
1316 if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0)
1317 return error;
1318
1319 bsd_statfs_to_svr4_32_statvfs(&bfs, &sfs);
1320
1321 return copyout(&sfs, (caddr_t)(u_long)SCARG(uap, fs), sizeof(sfs));
1322 }
1323
1324
1325 int
1326 svr4_32_sys_fstatvfs(l, v, retval)
1327 struct lwp *l;
1328 void *v;
1329 register_t *retval;
1330 {
1331 struct svr4_32_sys_fstatvfs_args *uap = v;
1332 struct proc *p = l->l_proc;
1333 struct sys_fstatfs_args fs_args;
1334 caddr_t sg = stackgap_init(p, 0);
1335 struct statfs *fs = stackgap_alloc(p, &sg, sizeof(struct statfs));
1336 struct statfs bfs;
1337 struct svr4_32_statvfs sfs;
1338 int error;
1339
1340 SCARG(&fs_args, fd) = SCARG(uap, fd);
1341 SCARG(&fs_args, buf) = fs;
1342
1343 if ((error = sys_fstatfs(l, &fs_args, retval)) != 0)
1344 return error;
1345
1346 if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0)
1347 return error;
1348
1349 bsd_statfs_to_svr4_32_statvfs(&bfs, &sfs);
1350
1351 return copyout(&sfs, (caddr_t)(u_long)SCARG(uap, fs), sizeof(sfs));
1352 }
1353
1354
1355 int
1356 svr4_32_sys_statvfs64(l, v, retval)
1357 struct lwp *l;
1358 void *v;
1359 register_t *retval;
1360 {
1361 struct svr4_32_sys_statvfs64_args *uap = v;
1362 struct sys_statfs_args fs_args;
1363 struct proc *p = l->l_proc;
1364 caddr_t sg = stackgap_init(p, 0);
1365 struct statfs *fs = stackgap_alloc(p, &sg, sizeof(struct statfs));
1366 struct statfs bfs;
1367 struct svr4_32_statvfs64 sfs;
1368 int error;
1369
1370 SCARG(&fs_args, path) = (caddr_t)(u_long)SCARG(uap, path);
1371 CHECK_ALT_EXIST(p, &sg, SCARG(&fs_args, path));
1372 SCARG(&fs_args, buf) = fs;
1373
1374 if ((error = sys_statfs(l, &fs_args, retval)) != 0)
1375 return error;
1376
1377 if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0)
1378 return error;
1379
1380 bsd_statfs_to_svr4_32_statvfs64(&bfs, &sfs);
1381
1382 return copyout(&sfs, (caddr_t)(u_long)SCARG(uap, fs), sizeof(sfs));
1383 }
1384
1385
1386 int
1387 svr4_32_sys_fstatvfs64(l, v, retval)
1388 struct lwp *l;
1389 void *v;
1390 register_t *retval;
1391 {
1392 struct svr4_32_sys_fstatvfs64_args *uap = v;
1393 struct proc *p = l->l_proc;
1394 struct sys_fstatfs_args fs_args;
1395 caddr_t sg = stackgap_init(p, 0);
1396 struct statfs *fs = stackgap_alloc(p, &sg, sizeof(struct statfs));
1397 struct statfs bfs;
1398 struct svr4_32_statvfs64 sfs;
1399 int error;
1400
1401 SCARG(&fs_args, fd) = SCARG(uap, fd);
1402 SCARG(&fs_args, buf) = fs;
1403
1404 if ((error = sys_fstatfs(l, &fs_args, retval)) != 0)
1405 return error;
1406
1407 if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0)
1408 return error;
1409
1410 bsd_statfs_to_svr4_32_statvfs64(&bfs, &sfs);
1411
1412 return copyout(&sfs, (caddr_t)(u_long)SCARG(uap, fs), sizeof(sfs));
1413 }
1414
1415
1416 int
1417 svr4_32_sys_alarm(l, v, retval)
1418 struct lwp *l;
1419 void *v;
1420 register_t *retval;
1421 {
1422 struct svr4_32_sys_alarm_args *uap = v;
1423 struct proc *p = l->l_proc;
1424 int error;
1425 struct itimerval *ntp, *otp, tp;
1426 struct sys_setitimer_args sa;
1427 caddr_t sg = stackgap_init(p, 0);
1428
1429 ntp = stackgap_alloc(p, &sg, sizeof(struct itimerval));
1430 otp = stackgap_alloc(p, &sg, sizeof(struct itimerval));
1431
1432 timerclear(&tp.it_interval);
1433 tp.it_value.tv_sec = SCARG(uap, sec);
1434 tp.it_value.tv_usec = 0;
1435
1436 if ((error = copyout(&tp, ntp, sizeof(tp))) != 0)
1437 return error;
1438
1439 SCARG(&sa, which) = ITIMER_REAL;
1440 SCARG(&sa, itv) = ntp;
1441 SCARG(&sa, oitv) = otp;
1442
1443 if ((error = sys_setitimer(l, &sa, retval)) != 0)
1444 return error;
1445
1446 if ((error = copyin(otp, &tp, sizeof(tp))) != 0)
1447 return error;
1448
1449 if (tp.it_value.tv_usec)
1450 tp.it_value.tv_sec++;
1451
1452 *retval = (register_t) tp.it_value.tv_sec;
1453
1454 return 0;
1455 }
1456
1457
1458 int
1459 svr4_32_sys_gettimeofday(l, v, retval)
1460 struct lwp *l;
1461 void *v;
1462 register_t *retval;
1463 {
1464 struct svr4_32_sys_gettimeofday_args *uap = v;
1465
1466 if (SCARG(uap, tp)) {
1467 struct timeval atv;
1468
1469 microtime(&atv);
1470 return copyout(&atv, (caddr_t)(u_long)SCARG(uap, tp), sizeof (atv));
1471 }
1472
1473 return 0;
1474 }
1475
1476
1477 int
1478 svr4_32_sys_facl(l, v, retval)
1479 struct lwp *l;
1480 void *v;
1481 register_t *retval;
1482 {
1483 struct svr4_32_sys_facl_args *uap = v;
1484
1485 *retval = 0;
1486
1487 switch (SCARG(uap, cmd)) {
1488 case SVR4_SYS_SETACL:
1489 /* We don't support acls on any filesystem */
1490 return ENOSYS;
1491
1492 case SVR4_SYS_GETACL:
1493 return copyout(retval, &SCARG(uap, num),
1494 sizeof(SCARG(uap, num)));
1495
1496 case SVR4_SYS_GETACLCNT:
1497 return 0;
1498
1499 default:
1500 return EINVAL;
1501 }
1502 }
1503
1504
1505 int
1506 svr4_32_sys_acl(l, v, retval)
1507 struct lwp *l;
1508 void *v;
1509 register_t *retval;
1510 {
1511 return svr4_32_sys_facl(l, v, retval); /* XXX: for now the same */
1512 }
1513
1514
1515 int
1516 svr4_32_sys_auditsys(l, v, retval)
1517 struct lwp *l;
1518 void *v;
1519 register_t *retval;
1520 {
1521 /*
1522 * XXX: Big brother is *not* watching.
1523 */
1524 return 0;
1525 }
1526
1527
1528 int
1529 svr4_32_sys_memcntl(l, v, retval)
1530 struct lwp *l;
1531 void *v;
1532 register_t *retval;
1533 {
1534 struct svr4_32_sys_memcntl_args *uap = v;
1535 switch (SCARG(uap, cmd)) {
1536 case SVR4_MC_SYNC:
1537 {
1538 struct sys___msync13_args msa;
1539
1540 SCARG(&msa, addr) = (void *)(u_long)SCARG(uap, addr);
1541 SCARG(&msa, len) = SCARG(uap, len);
1542 SCARG(&msa, flags) = (int)(u_long)SCARG(uap, arg);
1543
1544 return sys___msync13(l, &msa, retval);
1545 }
1546 case SVR4_MC_ADVISE:
1547 {
1548 struct sys_madvise_args maa;
1549
1550 SCARG(&maa, addr) = (void *)(u_long)SCARG(uap, addr);
1551 SCARG(&maa, len) = SCARG(uap, len);
1552 SCARG(&maa, behav) = (int)(u_long)SCARG(uap, arg);
1553
1554 return sys_madvise(l, &maa, retval);
1555 }
1556 case SVR4_MC_LOCK:
1557 case SVR4_MC_UNLOCK:
1558 case SVR4_MC_LOCKAS:
1559 case SVR4_MC_UNLOCKAS:
1560 return EOPNOTSUPP;
1561 default:
1562 return ENOSYS;
1563 }
1564 }
1565
1566
1567 int
1568 svr4_32_sys_nice(l, v, retval)
1569 struct lwp *l;
1570 void *v;
1571 register_t *retval;
1572 {
1573 struct svr4_32_sys_nice_args *uap = v;
1574 struct sys_setpriority_args ap;
1575 int error;
1576
1577 SCARG(&ap, which) = PRIO_PROCESS;
1578 SCARG(&ap, who) = 0;
1579 SCARG(&ap, prio) = SCARG(uap, prio);
1580
1581 if ((error = sys_setpriority(l, &ap, retval)) != 0)
1582 return error;
1583
1584 if ((error = sys_getpriority(l, &ap, retval)) != 0)
1585 return error;
1586
1587 return 0;
1588 }
1589
1590
1591 int
1592 svr4_32_sys_resolvepath(l, v, retval)
1593 struct lwp *l;
1594 void *v;
1595 register_t *retval;
1596 {
1597 struct svr4_32_sys_resolvepath_args *uap = v;
1598 struct proc *p = l->l_proc;
1599 struct nameidata nd;
1600 int error;
1601 size_t len;
1602
1603 NDINIT(&nd, LOOKUP, NOFOLLOW | SAVENAME, UIO_USERSPACE,
1604 (const char *)(u_long)SCARG(uap, path), p);
1605
1606 if ((error = namei(&nd)) != 0)
1607 return error;
1608
1609 if ((error = copyoutstr(nd.ni_cnd.cn_pnbuf,
1610 (caddr_t)(u_long)SCARG(uap, buf),
1611 SCARG(uap, bufsiz), &len)) != 0)
1612 goto bad;
1613
1614 *retval = len;
1615 bad:
1616 vrele(nd.ni_vp);
1617 PNBUF_PUT(nd.ni_cnd.cn_pnbuf);
1618 return error;
1619 }
Cache object: 6d9117ce8cbde89699f9ba6eb026ecdd
|