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