kern_50.c revision 1.1 1 1.1 njoly /* $NetBSD: kern_50.c,v 1.1 2014/04/04 18:17:36 njoly Exp $ */
2 1.1 njoly
3 1.1 njoly /*-
4 1.1 njoly * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
5 1.1 njoly * All rights reserved.
6 1.1 njoly *
7 1.1 njoly * This code is derived from software contributed to The NetBSD Foundation
8 1.1 njoly * by Christos Zoulas.
9 1.1 njoly *
10 1.1 njoly * Redistribution and use in source and binary forms, with or without
11 1.1 njoly * modification, are permitted provided that the following conditions
12 1.1 njoly * are met:
13 1.1 njoly * 1. Redistributions of source code must retain the above copyright
14 1.1 njoly * notice, this list of conditions and the following disclaimer.
15 1.1 njoly * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 njoly * notice, this list of conditions and the following disclaimer in the
17 1.1 njoly * documentation and/or other materials provided with the distribution.
18 1.1 njoly *
19 1.1 njoly * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 njoly * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 njoly * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 njoly * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 njoly * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 njoly * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 njoly * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 njoly * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 njoly * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 njoly * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 njoly * POSSIBILITY OF SUCH DAMAGE.
30 1.1 njoly */
31 1.1 njoly #include <sys/cdefs.h>
32 1.1 njoly __KERNEL_RCSID(0, "$NetBSD: kern_50.c,v 1.1 2014/04/04 18:17:36 njoly Exp $");
33 1.1 njoly
34 1.1 njoly #include <sys/param.h>
35 1.1 njoly #include <sys/lwp.h>
36 1.1 njoly #include <sys/proc.h>
37 1.1 njoly #include <sys/syscallargs.h>
38 1.1 njoly
39 1.1 njoly #include <compat/sys/resource.h>
40 1.1 njoly #include <compat/sys/time.h>
41 1.1 njoly
42 1.1 njoly int
43 1.1 njoly compat_50_sys__lwp_park(struct lwp *l,
44 1.1 njoly const struct compat_50_sys__lwp_park_args *uap, register_t *retval)
45 1.1 njoly {
46 1.1 njoly /* {
47 1.1 njoly syscallarg(const struct timespec50 *) ts;
48 1.1 njoly syscallarg(lwpid_t) unpark;
49 1.1 njoly syscallarg(const void *) hint;
50 1.1 njoly syscallarg(const void *) unparkhint;
51 1.1 njoly } */
52 1.1 njoly struct timespec ts, *tsp;
53 1.1 njoly struct timespec50 ts50;
54 1.1 njoly int error;
55 1.1 njoly
56 1.1 njoly if (SCARG(uap, ts) == NULL)
57 1.1 njoly tsp = NULL;
58 1.1 njoly else {
59 1.1 njoly error = copyin(SCARG(uap, ts), &ts50, sizeof(ts50));
60 1.1 njoly if (error != 0)
61 1.1 njoly return error;
62 1.1 njoly timespec50_to_timespec(&ts50, &ts);
63 1.1 njoly tsp = &ts;
64 1.1 njoly }
65 1.1 njoly
66 1.1 njoly if (SCARG(uap, unpark) != 0) {
67 1.1 njoly error = lwp_unpark(SCARG(uap, unpark), SCARG(uap, unparkhint));
68 1.1 njoly if (error != 0)
69 1.1 njoly return error;
70 1.1 njoly }
71 1.1 njoly
72 1.1 njoly return lwp_park(CLOCK_REALTIME, TIMER_ABSTIME, tsp, SCARG(uap, hint));
73 1.1 njoly }
74 1.1 njoly
75 1.1 njoly static int
76 1.1 njoly tscopyin(const void *u, void *s, size_t len)
77 1.1 njoly {
78 1.1 njoly struct timespec50 ts50;
79 1.1 njoly int error;
80 1.1 njoly
81 1.1 njoly KASSERT(len == sizeof(struct timespec));
82 1.1 njoly error = copyin(u, &ts50, sizeof(ts50));
83 1.1 njoly if (error)
84 1.1 njoly return error;
85 1.1 njoly timespec50_to_timespec(&ts50, s);
86 1.1 njoly return 0;
87 1.1 njoly }
88 1.1 njoly
89 1.1 njoly static int
90 1.1 njoly tscopyout(const void *s, void *u, size_t len)
91 1.1 njoly {
92 1.1 njoly struct timespec50 ts50;
93 1.1 njoly
94 1.1 njoly KASSERT(len == sizeof(struct timespec));
95 1.1 njoly timespec_to_timespec50(s, &ts50);
96 1.1 njoly return copyout(&ts50, u, sizeof(ts50));
97 1.1 njoly }
98 1.1 njoly
99 1.1 njoly int
100 1.1 njoly compat_50_sys___sigtimedwait(struct lwp *l,
101 1.1 njoly const struct compat_50_sys___sigtimedwait_args *uap, register_t *retval)
102 1.1 njoly {
103 1.1 njoly int res;
104 1.1 njoly
105 1.1 njoly res = sigtimedwait1(l,
106 1.1 njoly (const struct sys_____sigtimedwait50_args *)uap, retval, copyin,
107 1.1 njoly copyout, tscopyin, tscopyout);
108 1.1 njoly if (!res)
109 1.1 njoly *retval = 0; /* XXX NetBSD<=5 was not POSIX compliant */
110 1.1 njoly return res;
111 1.1 njoly }
112 1.1 njoly
113 1.1 njoly int
114 1.1 njoly compat_50_sys_wait4(struct lwp *l, const struct compat_50_sys_wait4_args *uap,
115 1.1 njoly register_t *retval)
116 1.1 njoly {
117 1.1 njoly /* {
118 1.1 njoly syscallarg(int) pid;
119 1.1 njoly syscallarg(int *) status;
120 1.1 njoly syscallarg(int) options;
121 1.1 njoly syscallarg(struct rusage50 *) rusage;
122 1.1 njoly } */
123 1.1 njoly int status, error, pid = SCARG(uap, pid);
124 1.1 njoly struct rusage50 ru50;
125 1.1 njoly struct rusage ru;
126 1.1 njoly
127 1.1 njoly error = do_sys_wait(&pid, &status, SCARG(uap, options),
128 1.1 njoly SCARG(uap, rusage) != NULL ? &ru : NULL);
129 1.1 njoly
130 1.1 njoly retval[0] = pid;
131 1.1 njoly if (pid == 0)
132 1.1 njoly return error;
133 1.1 njoly
134 1.1 njoly if (SCARG(uap, rusage)) {
135 1.1 njoly rusage_to_rusage50(&ru, &ru50);
136 1.1 njoly error = copyout(&ru50, SCARG(uap, rusage), sizeof(ru50));
137 1.1 njoly }
138 1.1 njoly
139 1.1 njoly if (error == 0 && SCARG(uap, status))
140 1.1 njoly error = copyout(&status, SCARG(uap, status), sizeof(status));
141 1.1 njoly
142 1.1 njoly return error;
143 1.1 njoly }
144