netbsd32_wait.c revision 1.9 1 1.9 christos /* $NetBSD: netbsd32_wait.c,v 1.9 2005/08/19 04:24:38 christos Exp $ */
2 1.1 mrg
3 1.1 mrg /*
4 1.1 mrg * Copyright (c) 1998, 2001 Matthew R. Green
5 1.1 mrg * All rights reserved.
6 1.1 mrg *
7 1.1 mrg * Redistribution and use in source and binary forms, with or without
8 1.1 mrg * modification, are permitted provided that the following conditions
9 1.1 mrg * are met:
10 1.1 mrg * 1. Redistributions of source code must retain the above copyright
11 1.1 mrg * notice, this list of conditions and the following disclaimer.
12 1.1 mrg * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 mrg * notice, this list of conditions and the following disclaimer in the
14 1.1 mrg * documentation and/or other materials provided with the distribution.
15 1.1 mrg * 3. The name of the author may not be used to endorse or promote products
16 1.1 mrg * derived from this software without specific prior written permission.
17 1.1 mrg *
18 1.1 mrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1 mrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1 mrg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1 mrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.1 mrg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 1.1 mrg * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 1.1 mrg * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 1.1 mrg * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 1.1 mrg * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 1.1 mrg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 1.1 mrg * SUCH DAMAGE.
29 1.1 mrg */
30 1.2 lukem
31 1.2 lukem #include <sys/cdefs.h>
32 1.9 christos __KERNEL_RCSID(0, "$NetBSD: netbsd32_wait.c,v 1.9 2005/08/19 04:24:38 christos Exp $");
33 1.1 mrg
34 1.1 mrg #include <sys/param.h>
35 1.1 mrg #include <sys/systm.h>
36 1.1 mrg #include <sys/mount.h>
37 1.1 mrg #include <sys/time.h>
38 1.1 mrg #include <sys/wait.h>
39 1.1 mrg #include <sys/ptrace.h>
40 1.1 mrg #include <sys/resourcevar.h>
41 1.1 mrg #include <sys/vnode.h>
42 1.1 mrg #include <sys/pool.h>
43 1.1 mrg #include <sys/proc.h>
44 1.9 christos #include <sys/dirent.h>
45 1.1 mrg
46 1.1 mrg #include <compat/netbsd32/netbsd32.h>
47 1.1 mrg #include <compat/netbsd32/netbsd32_syscallargs.h>
48 1.1 mrg #include <compat/netbsd32/netbsd32_conv.h>
49 1.1 mrg
50 1.1 mrg int
51 1.5 thorpej netbsd32_wait4(l, v, retval)
52 1.5 thorpej struct lwp *l;
53 1.1 mrg void *v;
54 1.1 mrg register_t *retval;
55 1.1 mrg {
56 1.1 mrg struct netbsd32_wait4_args /* {
57 1.1 mrg syscallarg(int) pid;
58 1.1 mrg syscallarg(netbsd32_intp) status;
59 1.1 mrg syscallarg(int) options;
60 1.1 mrg syscallarg(netbsd32_rusagep_t) rusage;
61 1.1 mrg } */ *uap = v;
62 1.8 cube struct sys_wait4_args ua;
63 1.8 cube caddr_t sg;
64 1.8 cube struct rusage *ruup = NULL;
65 1.8 cube int error;
66 1.8 cube
67 1.8 cube if (SCARG(uap, rusage)) {
68 1.8 cube sg = stackgap_init(l->l_proc, sizeof(*ruup));
69 1.8 cube ruup = (struct rusage *)stackgap_alloc(l->l_proc, &sg,
70 1.8 cube sizeof(*ruup));
71 1.8 cube if (ruup == NULL)
72 1.8 cube return ENOMEM;
73 1.8 cube }
74 1.8 cube
75 1.8 cube NETBSD32TO64_UAP(pid);
76 1.8 cube NETBSD32TOP_UAP(status, int);
77 1.8 cube NETBSD32TO64_UAP(options);
78 1.8 cube SCARG(&ua, rusage) = ruup;
79 1.1 mrg
80 1.8 cube error = sys_wait4(l, &ua, retval);
81 1.8 cube if (error)
82 1.6 dsl return error;
83 1.6 dsl
84 1.8 cube if (ruup != NULL) {
85 1.8 cube struct netbsd32_rusage ru32;
86 1.8 cube struct rusage rus;
87 1.8 cube
88 1.8 cube error = copyin(ruup, &rus, sizeof(rus));
89 1.8 cube if (error)
90 1.8 cube return error;
91 1.8 cube netbsd32_from_rusage(&rus, &ru32);
92 1.8 cube error = copyout(&ru32, NETBSD32PTR64(SCARG(uap, rusage)),
93 1.8 cube sizeof(ru32));
94 1.1 mrg }
95 1.6 dsl
96 1.8 cube return error;
97 1.1 mrg }
98 1.1 mrg
99 1.1 mrg int
100 1.5 thorpej netbsd32_getrusage(l, v, retval)
101 1.5 thorpej struct lwp *l;
102 1.1 mrg void *v;
103 1.1 mrg register_t *retval;
104 1.1 mrg {
105 1.1 mrg struct netbsd32_getrusage_args /* {
106 1.1 mrg syscallarg(int) who;
107 1.1 mrg syscallarg(netbsd32_rusagep_t) rusage;
108 1.1 mrg } */ *uap = v;
109 1.5 thorpej struct proc *p = l->l_proc;
110 1.1 mrg struct rusage *rup;
111 1.1 mrg struct netbsd32_rusage ru;
112 1.1 mrg
113 1.1 mrg switch (SCARG(uap, who)) {
114 1.1 mrg
115 1.1 mrg case RUSAGE_SELF:
116 1.1 mrg rup = &p->p_stats->p_ru;
117 1.1 mrg calcru(p, &rup->ru_utime, &rup->ru_stime, NULL);
118 1.1 mrg break;
119 1.1 mrg
120 1.1 mrg case RUSAGE_CHILDREN:
121 1.1 mrg rup = &p->p_stats->p_cru;
122 1.1 mrg break;
123 1.1 mrg
124 1.1 mrg default:
125 1.1 mrg return (EINVAL);
126 1.1 mrg }
127 1.1 mrg netbsd32_from_rusage(rup, &ru);
128 1.4 scw return (copyout(&ru, (caddr_t)NETBSD32PTR64(SCARG(uap, rusage)),
129 1.4 scw sizeof(ru)));
130 1.1 mrg }
131