freebsd_sched.c revision 1.3 1 1.3 elad /* $NetBSD: freebsd_sched.c,v 1.3 2006/05/14 21:24:49 elad Exp $ */
2 1.1 gmcgarry
3 1.1 gmcgarry /*-
4 1.1 gmcgarry * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 1.1 gmcgarry * All rights reserved.
6 1.1 gmcgarry *
7 1.1 gmcgarry * This code is derived from software contributed to The NetBSD Foundation
8 1.1 gmcgarry * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.1 gmcgarry * NASA Ames Research Center; by Matthias Scheler.
10 1.1 gmcgarry *
11 1.1 gmcgarry * Redistribution and use in source and binary forms, with or without
12 1.1 gmcgarry * modification, are permitted provided that the following conditions
13 1.1 gmcgarry * are met:
14 1.1 gmcgarry * 1. Redistributions of source code must retain the above copyright
15 1.1 gmcgarry * notice, this list of conditions and the following disclaimer.
16 1.1 gmcgarry * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 gmcgarry * notice, this list of conditions and the following disclaimer in the
18 1.1 gmcgarry * documentation and/or other materials provided with the distribution.
19 1.1 gmcgarry * 3. All advertising materials mentioning features or use of this software
20 1.1 gmcgarry * must display the following acknowledgement:
21 1.1 gmcgarry * This product includes software developed by the NetBSD
22 1.1 gmcgarry * Foundation, Inc. and its contributors.
23 1.1 gmcgarry * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.1 gmcgarry * contributors may be used to endorse or promote products derived
25 1.1 gmcgarry * from this software without specific prior written permission.
26 1.1 gmcgarry *
27 1.1 gmcgarry * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.1 gmcgarry * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.1 gmcgarry * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.1 gmcgarry * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.1 gmcgarry * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.1 gmcgarry * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.1 gmcgarry * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.1 gmcgarry * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.1 gmcgarry * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.1 gmcgarry * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.1 gmcgarry * POSSIBILITY OF SUCH DAMAGE.
38 1.1 gmcgarry */
39 1.1 gmcgarry
40 1.1 gmcgarry /*
41 1.1 gmcgarry * FreeBSD compatibility module. Try to deal with scheduler related syscalls.
42 1.1 gmcgarry */
43 1.1 gmcgarry
44 1.1 gmcgarry #include <sys/cdefs.h>
45 1.3 elad __KERNEL_RCSID(0, "$NetBSD: freebsd_sched.c,v 1.3 2006/05/14 21:24:49 elad Exp $");
46 1.1 gmcgarry
47 1.1 gmcgarry #include <sys/param.h>
48 1.1 gmcgarry #include <sys/mount.h>
49 1.1 gmcgarry #include <sys/proc.h>
50 1.1 gmcgarry #include <sys/systm.h>
51 1.1 gmcgarry #include <sys/syscallargs.h>
52 1.3 elad #include <sys/kauth.h>
53 1.1 gmcgarry
54 1.1 gmcgarry #include <machine/cpu.h>
55 1.1 gmcgarry
56 1.1 gmcgarry #include <compat/freebsd/freebsd_syscallargs.h>
57 1.1 gmcgarry #include <compat/freebsd/freebsd_sched.h>
58 1.1 gmcgarry
59 1.1 gmcgarry int
60 1.2 thorpej freebsd_sys_yield(l, v, retval)
61 1.2 thorpej struct lwp *l;
62 1.1 gmcgarry void *v;
63 1.1 gmcgarry register_t *retval;
64 1.1 gmcgarry {
65 1.1 gmcgarry
66 1.1 gmcgarry yield();
67 1.1 gmcgarry return 0;
68 1.1 gmcgarry }
69 1.1 gmcgarry
70 1.1 gmcgarry int
71 1.2 thorpej freebsd_sys_sched_setparam(l, v, retval)
72 1.2 thorpej struct lwp *l;
73 1.1 gmcgarry void *v;
74 1.1 gmcgarry register_t *retval;
75 1.1 gmcgarry {
76 1.1 gmcgarry struct freebsd_sys_sched_setparam_args /* {
77 1.1 gmcgarry syscallarg(pid_t) pid;
78 1.1 gmcgarry syscallarg(const struct freebsd_sched_param *) sp;
79 1.1 gmcgarry } */ *uap = v;
80 1.1 gmcgarry int error;
81 1.1 gmcgarry struct freebsd_sched_param lp;
82 1.1 gmcgarry struct proc *p;
83 1.1 gmcgarry
84 1.1 gmcgarry /*
85 1.1 gmcgarry * We only check for valid parameters and return afterwards.
86 1.1 gmcgarry */
87 1.1 gmcgarry if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL)
88 1.1 gmcgarry return EINVAL;
89 1.1 gmcgarry
90 1.1 gmcgarry error = copyin(SCARG(uap, sp), &lp, sizeof(lp));
91 1.1 gmcgarry if (error)
92 1.1 gmcgarry return error;
93 1.1 gmcgarry
94 1.1 gmcgarry if (SCARG(uap, pid) != 0) {
95 1.3 elad kauth_cred_t pc = l->l_proc->p_cred;
96 1.1 gmcgarry
97 1.1 gmcgarry if ((p = pfind(SCARG(uap, pid))) == NULL)
98 1.1 gmcgarry return ESRCH;
99 1.2 thorpej if (!(l->l_proc == p ||
100 1.3 elad kauth_cred_geteuid(pc) == 0 ||
101 1.3 elad kauth_cred_getuid(pc) == kauth_cred_getuid(p->p_cred) ||
102 1.3 elad kauth_cred_geteuid(pc) == kauth_cred_getuid(p->p_cred) ||
103 1.3 elad kauth_cred_getuid(pc) == kauth_cred_geteuid(p->p_cred) ||
104 1.3 elad kauth_cred_geteuid(pc) == kauth_cred_geteuid(p->p_cred)))
105 1.1 gmcgarry return EPERM;
106 1.1 gmcgarry }
107 1.1 gmcgarry
108 1.1 gmcgarry return 0;
109 1.1 gmcgarry }
110 1.1 gmcgarry
111 1.1 gmcgarry int
112 1.2 thorpej freebsd_sys_sched_getparam(l, v, retval)
113 1.2 thorpej struct lwp *l;
114 1.1 gmcgarry void *v;
115 1.1 gmcgarry register_t *retval;
116 1.1 gmcgarry {
117 1.1 gmcgarry struct freebsd_sys_sched_getparam_args /* {
118 1.1 gmcgarry syscallarg(pid_t) pid;
119 1.1 gmcgarry syscallarg(struct freebsd_sched_param *) sp;
120 1.1 gmcgarry } */ *uap = v;
121 1.1 gmcgarry struct proc *p;
122 1.1 gmcgarry struct freebsd_sched_param lp;
123 1.1 gmcgarry
124 1.1 gmcgarry /*
125 1.1 gmcgarry * We only check for valid parameters and return a dummy
126 1.1 gmcgarry * priority afterwards.
127 1.1 gmcgarry */
128 1.1 gmcgarry if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL)
129 1.1 gmcgarry return EINVAL;
130 1.1 gmcgarry
131 1.1 gmcgarry if (SCARG(uap, pid) != 0) {
132 1.3 elad kauth_cred_t pc = l->l_proc->p_cred;
133 1.1 gmcgarry
134 1.1 gmcgarry if ((p = pfind(SCARG(uap, pid))) == NULL)
135 1.1 gmcgarry return ESRCH;
136 1.2 thorpej if (!(l->l_proc == p ||
137 1.3 elad kauth_cred_geteuid(pc) == 0 ||
138 1.3 elad kauth_cred_getuid(pc) == kauth_cred_getuid(p->p_cred) ||
139 1.3 elad kauth_cred_geteuid(pc) == kauth_cred_getuid(p->p_cred) ||
140 1.3 elad kauth_cred_getuid(pc) == kauth_cred_geteuid(p->p_cred) ||
141 1.3 elad kauth_cred_geteuid(pc) == kauth_cred_geteuid(p->p_cred)))
142 1.1 gmcgarry return EPERM;
143 1.1 gmcgarry }
144 1.1 gmcgarry
145 1.1 gmcgarry lp.sched_priority = 0;
146 1.1 gmcgarry return copyout(&lp, SCARG(uap, sp), sizeof(lp));
147 1.1 gmcgarry }
148 1.1 gmcgarry
149 1.1 gmcgarry int
150 1.2 thorpej freebsd_sys_sched_setscheduler(l, v, retval)
151 1.2 thorpej struct lwp *l;
152 1.1 gmcgarry void *v;
153 1.1 gmcgarry register_t *retval;
154 1.1 gmcgarry {
155 1.1 gmcgarry struct freebsd_sys_sched_setscheduler_args /* {
156 1.1 gmcgarry syscallarg(pid_t) pid;
157 1.1 gmcgarry syscallarg(int) policy;
158 1.1 gmcgarry syscallarg(cont struct freebsd_sched_scheduler *) sp;
159 1.1 gmcgarry } */ *uap = v;
160 1.1 gmcgarry int error;
161 1.1 gmcgarry struct freebsd_sched_param lp;
162 1.1 gmcgarry struct proc *p;
163 1.1 gmcgarry
164 1.1 gmcgarry /*
165 1.1 gmcgarry * We only check for valid parameters and return afterwards.
166 1.1 gmcgarry */
167 1.1 gmcgarry if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL)
168 1.1 gmcgarry return EINVAL;
169 1.1 gmcgarry
170 1.1 gmcgarry error = copyin(SCARG(uap, sp), &lp, sizeof(lp));
171 1.1 gmcgarry if (error)
172 1.1 gmcgarry return error;
173 1.1 gmcgarry
174 1.1 gmcgarry if (SCARG(uap, pid) != 0) {
175 1.3 elad kauth_cred_t pc = l->l_proc->p_cred;
176 1.1 gmcgarry
177 1.1 gmcgarry if ((p = pfind(SCARG(uap, pid))) == NULL)
178 1.1 gmcgarry return ESRCH;
179 1.2 thorpej if (!(l->l_proc == p ||
180 1.3 elad kauth_cred_geteuid(pc) == 0 ||
181 1.3 elad kauth_cred_getuid(pc) == kauth_cred_getuid(p->p_cred) ||
182 1.3 elad kauth_cred_geteuid(pc) == kauth_cred_getuid(p->p_cred) ||
183 1.3 elad kauth_cred_getuid(pc) == kauth_cred_geteuid(p->p_cred) ||
184 1.3 elad kauth_cred_geteuid(pc) == kauth_cred_geteuid(p->p_cred)))
185 1.1 gmcgarry return EPERM;
186 1.1 gmcgarry }
187 1.1 gmcgarry
188 1.1 gmcgarry /*
189 1.1 gmcgarry * We can't emulate anything put the default scheduling policy.
190 1.1 gmcgarry */
191 1.1 gmcgarry if (SCARG(uap, policy) != FREEBSD_SCHED_OTHER || lp.sched_priority != 0)
192 1.1 gmcgarry return EINVAL;
193 1.1 gmcgarry
194 1.1 gmcgarry return 0;
195 1.1 gmcgarry }
196 1.1 gmcgarry
197 1.1 gmcgarry int
198 1.2 thorpej freebsd_sys_sched_getscheduler(l, v, retval)
199 1.2 thorpej struct lwp *l;
200 1.1 gmcgarry void *v;
201 1.1 gmcgarry register_t *retval;
202 1.1 gmcgarry {
203 1.1 gmcgarry struct freebsd_sys_sched_getscheduler_args /* {
204 1.1 gmcgarry syscallarg(pid_t) pid;
205 1.1 gmcgarry } */ *uap = v;
206 1.1 gmcgarry struct proc *p;
207 1.1 gmcgarry
208 1.1 gmcgarry *retval = -1;
209 1.1 gmcgarry
210 1.1 gmcgarry /*
211 1.1 gmcgarry * We only check for valid parameters and return afterwards.
212 1.1 gmcgarry */
213 1.1 gmcgarry if (SCARG(uap, pid) != 0) {
214 1.3 elad kauth_cred_t pc = l->l_proc->p_cred;
215 1.1 gmcgarry
216 1.1 gmcgarry if ((p = pfind(SCARG(uap, pid))) == NULL)
217 1.1 gmcgarry return ESRCH;
218 1.2 thorpej if (!(l->l_proc == p ||
219 1.3 elad kauth_cred_geteuid(pc) == 0 ||
220 1.3 elad kauth_cred_getuid(pc) == kauth_cred_getuid(p->p_cred) ||
221 1.3 elad kauth_cred_geteuid(pc) == kauth_cred_getuid(p->p_cred) ||
222 1.3 elad kauth_cred_getuid(pc) == kauth_cred_geteuid(p->p_cred) ||
223 1.3 elad kauth_cred_geteuid(pc) == kauth_cred_geteuid(p->p_cred)))
224 1.1 gmcgarry return EPERM;
225 1.1 gmcgarry }
226 1.1 gmcgarry
227 1.1 gmcgarry /*
228 1.1 gmcgarry * We can't emulate anything put the default scheduling policy.
229 1.1 gmcgarry */
230 1.1 gmcgarry *retval = FREEBSD_SCHED_OTHER;
231 1.1 gmcgarry return 0;
232 1.1 gmcgarry }
233 1.1 gmcgarry
234 1.1 gmcgarry int
235 1.2 thorpej freebsd_sys_sched_yield(l, v, retval)
236 1.2 thorpej struct lwp *l;
237 1.1 gmcgarry void *v;
238 1.1 gmcgarry register_t *retval;
239 1.1 gmcgarry {
240 1.1 gmcgarry
241 1.1 gmcgarry yield();
242 1.1 gmcgarry return 0;
243 1.1 gmcgarry }
244 1.1 gmcgarry
245 1.1 gmcgarry int
246 1.2 thorpej freebsd_sys_sched_get_priority_max(l, v, retval)
247 1.2 thorpej struct lwp *l;
248 1.1 gmcgarry void *v;
249 1.1 gmcgarry register_t *retval;
250 1.1 gmcgarry {
251 1.1 gmcgarry struct freebsd_sys_sched_get_priority_max_args /* {
252 1.1 gmcgarry syscallarg(int) policy;
253 1.1 gmcgarry } */ *uap = v;
254 1.1 gmcgarry
255 1.1 gmcgarry /*
256 1.1 gmcgarry * We can't emulate anything put the default scheduling policy.
257 1.1 gmcgarry */
258 1.1 gmcgarry if (SCARG(uap, policy) != FREEBSD_SCHED_OTHER) {
259 1.1 gmcgarry *retval = -1;
260 1.1 gmcgarry return EINVAL;
261 1.1 gmcgarry }
262 1.1 gmcgarry
263 1.1 gmcgarry *retval = 0;
264 1.1 gmcgarry return 0;
265 1.1 gmcgarry }
266 1.1 gmcgarry
267 1.1 gmcgarry int
268 1.2 thorpej freebsd_sys_sched_get_priority_min(l, v, retval)
269 1.2 thorpej struct lwp *l;
270 1.1 gmcgarry void *v;
271 1.1 gmcgarry register_t *retval;
272 1.1 gmcgarry {
273 1.1 gmcgarry struct freebsd_sys_sched_get_priority_min_args /* {
274 1.1 gmcgarry syscallarg(int) policy;
275 1.1 gmcgarry } */ *uap = v;
276 1.1 gmcgarry
277 1.1 gmcgarry /*
278 1.1 gmcgarry * We can't emulate anything put the default scheduling policy.
279 1.1 gmcgarry */
280 1.1 gmcgarry if (SCARG(uap, policy) != FREEBSD_SCHED_OTHER) {
281 1.1 gmcgarry *retval = -1;
282 1.1 gmcgarry return EINVAL;
283 1.1 gmcgarry }
284 1.1 gmcgarry
285 1.1 gmcgarry *retval = 0;
286 1.1 gmcgarry return 0;
287 1.1 gmcgarry }
288