netbsd32_wait.c revision 1.20 1 /* $NetBSD: netbsd32_wait.c,v 1.20 2009/01/11 02:45:49 christos Exp $ */
2
3 /*
4 * Copyright (c) 1998, 2001 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 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: netbsd32_wait.c,v 1.20 2009/01/11 02:45:49 christos Exp $");
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/mount.h>
35 #include <sys/time.h>
36 #include <sys/wait.h>
37 #include <sys/ptrace.h>
38 #include <sys/resourcevar.h>
39 #include <sys/vnode.h>
40 #include <sys/pool.h>
41 #include <sys/proc.h>
42 #include <sys/dirent.h>
43
44 #include <compat/netbsd32/netbsd32.h>
45 #include <compat/netbsd32/netbsd32_syscallargs.h>
46 #include <compat/netbsd32/netbsd32_conv.h>
47
48 int
49 netbsd32___wait450(struct lwp *l, const struct netbsd32___wait450_args *uap,
50 register_t *retval)
51 {
52 /* {
53 syscallarg(int) pid;
54 syscallarg(netbsd32_intp) status;
55 syscallarg(int) options;
56 syscallarg(netbsd32_rusagep_t) rusage;
57 } */
58 int status, error;
59 int was_zombie;
60 struct rusage ru;
61 struct netbsd32_rusage ru32;
62 int pid = SCARG(uap, pid);
63
64 error = do_sys_wait(l, &pid, &status, SCARG(uap, options),
65 SCARG_P32(uap, rusage) != NULL ? &ru : NULL, &was_zombie);
66
67 retval[0] = pid;
68 if (pid == 0)
69 return error;
70
71 if (SCARG_P32(uap, rusage)) {
72 netbsd32_from_rusage(&ru, &ru32);
73 error = copyout(&ru32, SCARG_P32(uap, rusage), sizeof(ru32));
74 }
75
76 if (error == 0 && SCARG_P32(uap, status))
77 error = copyout(&status, SCARG_P32(uap, status), sizeof(status));
78
79 return error;
80 }
81
82
83 int
84 netbsd32___getrusage50(struct lwp *l,
85 const struct netbsd32___getrusage50_args *uap, register_t *retval)
86 {
87 /* {
88 syscallarg(int) who;
89 syscallarg(netbsd32_rusagep_t) rusage;
90 } */
91 struct proc *p = l->l_proc;
92 struct rusage *rup;
93 struct netbsd32_rusage ru;
94
95 switch (SCARG(uap, who)) {
96
97 case RUSAGE_SELF:
98 rup = &p->p_stats->p_ru;
99 mutex_enter(p->p_lock);
100 calcru(p, &rup->ru_utime, &rup->ru_stime, NULL, NULL);
101 mutex_exit(p->p_lock);
102 break;
103
104 case RUSAGE_CHILDREN:
105 rup = &p->p_stats->p_cru;
106 break;
107
108 default:
109 return (EINVAL);
110 }
111 netbsd32_from_rusage(rup, &ru);
112 return copyout(&ru, SCARG_P32(uap, rusage), sizeof(ru));
113 }
114