kern_50.c revision 1.3 1 1.3 ad /* $NetBSD: kern_50.c,v 1.3 2020/01/29 15:47:51 ad Exp $ */
2 1.1 njoly
3 1.1 njoly /*-
4 1.3 ad * Copyright (c) 2008, 2009, 2020 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.3 ad __KERNEL_RCSID(0, "$NetBSD: kern_50.c,v 1.3 2020/01/29 15:47:51 ad Exp $");
33 1.2 pgoyette
34 1.2 pgoyette #if defined(_KERNEL_OPT)
35 1.2 pgoyette #include "opt_compat_netbsd.h"
36 1.2 pgoyette #endif
37 1.1 njoly
38 1.1 njoly #include <sys/param.h>
39 1.1 njoly #include <sys/lwp.h>
40 1.1 njoly #include <sys/proc.h>
41 1.2 pgoyette #include <sys/syscall.h>
42 1.2 pgoyette #include <sys/syscallvar.h>
43 1.1 njoly #include <sys/syscallargs.h>
44 1.1 njoly
45 1.1 njoly #include <compat/sys/resource.h>
46 1.1 njoly #include <compat/sys/time.h>
47 1.1 njoly
48 1.2 pgoyette #include <compat/common/compat_mod.h>
49 1.2 pgoyette
50 1.2 pgoyette static const struct syscall_package kern_50_syscalls[] = {
51 1.2 pgoyette { SYS_compat_50__lwp_park, 0, (sy_call_t *)compat_50_sys__lwp_park },
52 1.2 pgoyette { SYS_compat_50___sigtimedwait, 0,
53 1.2 pgoyette (sy_call_t *)compat_50_sys___sigtimedwait },
54 1.2 pgoyette { SYS_compat_50_wait4, 0, (sy_call_t *)compat_50_sys_wait4 },
55 1.2 pgoyette { 0, 0, NULL }
56 1.2 pgoyette };
57 1.2 pgoyette
58 1.1 njoly int
59 1.1 njoly compat_50_sys__lwp_park(struct lwp *l,
60 1.1 njoly const struct compat_50_sys__lwp_park_args *uap, register_t *retval)
61 1.1 njoly {
62 1.1 njoly /* {
63 1.1 njoly syscallarg(const struct timespec50 *) ts;
64 1.1 njoly syscallarg(lwpid_t) unpark;
65 1.1 njoly syscallarg(const void *) hint;
66 1.1 njoly syscallarg(const void *) unparkhint;
67 1.1 njoly } */
68 1.1 njoly struct timespec ts, *tsp;
69 1.1 njoly struct timespec50 ts50;
70 1.1 njoly int error;
71 1.1 njoly
72 1.1 njoly if (SCARG(uap, ts) == NULL)
73 1.1 njoly tsp = NULL;
74 1.1 njoly else {
75 1.1 njoly error = copyin(SCARG(uap, ts), &ts50, sizeof(ts50));
76 1.1 njoly if (error != 0)
77 1.1 njoly return error;
78 1.1 njoly timespec50_to_timespec(&ts50, &ts);
79 1.1 njoly tsp = &ts;
80 1.1 njoly }
81 1.1 njoly
82 1.1 njoly if (SCARG(uap, unpark) != 0) {
83 1.3 ad error = lwp_unpark(&SCARG(uap, unpark), 1);
84 1.1 njoly if (error != 0)
85 1.1 njoly return error;
86 1.1 njoly }
87 1.1 njoly
88 1.3 ad return lwp_park(CLOCK_REALTIME, TIMER_ABSTIME, tsp);
89 1.1 njoly }
90 1.1 njoly
91 1.1 njoly static int
92 1.1 njoly tscopyin(const void *u, void *s, size_t len)
93 1.1 njoly {
94 1.1 njoly struct timespec50 ts50;
95 1.1 njoly int error;
96 1.1 njoly
97 1.1 njoly KASSERT(len == sizeof(struct timespec));
98 1.1 njoly error = copyin(u, &ts50, sizeof(ts50));
99 1.1 njoly if (error)
100 1.1 njoly return error;
101 1.1 njoly timespec50_to_timespec(&ts50, s);
102 1.1 njoly return 0;
103 1.1 njoly }
104 1.1 njoly
105 1.1 njoly static int
106 1.1 njoly tscopyout(const void *s, void *u, size_t len)
107 1.1 njoly {
108 1.1 njoly struct timespec50 ts50;
109 1.1 njoly
110 1.1 njoly KASSERT(len == sizeof(struct timespec));
111 1.1 njoly timespec_to_timespec50(s, &ts50);
112 1.1 njoly return copyout(&ts50, u, sizeof(ts50));
113 1.1 njoly }
114 1.1 njoly
115 1.1 njoly int
116 1.1 njoly compat_50_sys___sigtimedwait(struct lwp *l,
117 1.1 njoly const struct compat_50_sys___sigtimedwait_args *uap, register_t *retval)
118 1.1 njoly {
119 1.1 njoly int res;
120 1.1 njoly
121 1.1 njoly res = sigtimedwait1(l,
122 1.1 njoly (const struct sys_____sigtimedwait50_args *)uap, retval, copyin,
123 1.1 njoly copyout, tscopyin, tscopyout);
124 1.1 njoly if (!res)
125 1.1 njoly *retval = 0; /* XXX NetBSD<=5 was not POSIX compliant */
126 1.1 njoly return res;
127 1.1 njoly }
128 1.1 njoly
129 1.1 njoly int
130 1.1 njoly compat_50_sys_wait4(struct lwp *l, const struct compat_50_sys_wait4_args *uap,
131 1.1 njoly register_t *retval)
132 1.1 njoly {
133 1.1 njoly /* {
134 1.1 njoly syscallarg(int) pid;
135 1.1 njoly syscallarg(int *) status;
136 1.1 njoly syscallarg(int) options;
137 1.1 njoly syscallarg(struct rusage50 *) rusage;
138 1.1 njoly } */
139 1.1 njoly int status, error, pid = SCARG(uap, pid);
140 1.1 njoly struct rusage50 ru50;
141 1.1 njoly struct rusage ru;
142 1.1 njoly
143 1.1 njoly error = do_sys_wait(&pid, &status, SCARG(uap, options),
144 1.1 njoly SCARG(uap, rusage) != NULL ? &ru : NULL);
145 1.1 njoly
146 1.1 njoly retval[0] = pid;
147 1.1 njoly if (pid == 0)
148 1.1 njoly return error;
149 1.1 njoly
150 1.1 njoly if (SCARG(uap, rusage)) {
151 1.1 njoly rusage_to_rusage50(&ru, &ru50);
152 1.1 njoly error = copyout(&ru50, SCARG(uap, rusage), sizeof(ru50));
153 1.1 njoly }
154 1.1 njoly
155 1.1 njoly if (error == 0 && SCARG(uap, status))
156 1.1 njoly error = copyout(&status, SCARG(uap, status), sizeof(status));
157 1.1 njoly
158 1.1 njoly return error;
159 1.1 njoly }
160 1.2 pgoyette
161 1.2 pgoyette int
162 1.2 pgoyette kern_50_init(void)
163 1.2 pgoyette {
164 1.2 pgoyette
165 1.2 pgoyette return syscall_establish(NULL, kern_50_syscalls);
166 1.2 pgoyette }
167 1.2 pgoyette
168 1.2 pgoyette int
169 1.2 pgoyette kern_50_fini(void)
170 1.2 pgoyette {
171 1.2 pgoyette
172 1.2 pgoyette return syscall_disestablish(NULL, kern_50_syscalls);
173 1.2 pgoyette }
174