xref: /netbsd-src/sys/compat/linux32/common/linux32_sched.c (revision 33fa5ccbbf17bc2390e2d136c34926c6f93ac5d1)
1*33fa5ccbSchs /*	$NetBSD: linux32_sched.c,v 1.9 2010/07/07 01:30:35 chs Exp $ */
2ee0c5b44Smanu 
3ee0c5b44Smanu /*-
4ee0c5b44Smanu  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
5ee0c5b44Smanu  *
6ee0c5b44Smanu  * Redistribution and use in source and binary forms, with or without
7ee0c5b44Smanu  * modification, are permitted provided that the following conditions
8ee0c5b44Smanu  * are met:
9ee0c5b44Smanu  * 1. Redistributions of source code must retain the above copyright
10ee0c5b44Smanu  *    notice, this list of conditions and the following disclaimer.
11ee0c5b44Smanu  * 2. Redistributions in binary form must reproduce the above copyright
12ee0c5b44Smanu  *    notice, this list of conditions and the following disclaimer in the
13ee0c5b44Smanu  *    documentation and/or other materials provided with the distribution.
14ee0c5b44Smanu  * 3. All advertising materials mentioning features or use of this software
15ee0c5b44Smanu  *    must display the following acknowledgement:
16ee0c5b44Smanu  *	This product includes software developed by Emmanuel Dreyfus
17ee0c5b44Smanu  * 4. The name of the author may not be used to endorse or promote
18ee0c5b44Smanu  *    products derived from this software without specific prior written
19ee0c5b44Smanu  *    permission.
20ee0c5b44Smanu  *
21ee0c5b44Smanu  * THIS SOFTWARE IS PROVIDED BY THE THE AUTHOR AND CONTRIBUTORS ``AS IS''
22ee0c5b44Smanu  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23ee0c5b44Smanu  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24ee0c5b44Smanu  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
25ee0c5b44Smanu  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26ee0c5b44Smanu  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27ee0c5b44Smanu  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28ee0c5b44Smanu  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29ee0c5b44Smanu  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30ee0c5b44Smanu  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31ee0c5b44Smanu  * POSSIBILITY OF SUCH DAMAGE.
32ee0c5b44Smanu  */
33ee0c5b44Smanu 
34ee0c5b44Smanu #include <sys/cdefs.h>
35ee0c5b44Smanu 
36*33fa5ccbSchs __KERNEL_RCSID(0, "$NetBSD: linux32_sched.c,v 1.9 2010/07/07 01:30:35 chs Exp $");
37ee0c5b44Smanu 
38ee0c5b44Smanu #include <sys/types.h>
39ee0c5b44Smanu #include <sys/param.h>
40ee0c5b44Smanu #include <sys/fstypes.h>
41ee0c5b44Smanu #include <sys/signal.h>
42ee0c5b44Smanu #include <sys/dirent.h>
43ee0c5b44Smanu #include <sys/kernel.h>
44ee0c5b44Smanu #include <sys/fcntl.h>
45ee0c5b44Smanu #include <sys/select.h>
46ee0c5b44Smanu #include <sys/proc.h>
47ee0c5b44Smanu #include <sys/ucred.h>
48ee0c5b44Smanu #include <sys/swap.h>
49ee0c5b44Smanu 
50ee0c5b44Smanu #include <machine/types.h>
51ee0c5b44Smanu 
52ee0c5b44Smanu #include <sys/syscallargs.h>
53ee0c5b44Smanu 
54ee0c5b44Smanu #include <compat/netbsd32/netbsd32.h>
55ee0c5b44Smanu #include <compat/netbsd32/netbsd32_conv.h>
56ee0c5b44Smanu #include <compat/netbsd32/netbsd32_syscallargs.h>
57ee0c5b44Smanu 
58ee0c5b44Smanu #include <compat/linux/common/linux_types.h>
59ee0c5b44Smanu #include <compat/linux/common/linux_signal.h>
60ee0c5b44Smanu #include <compat/linux/common/linux_machdep.h>
61ee0c5b44Smanu #include <compat/linux/common/linux_misc.h>
62*33fa5ccbSchs #include <compat/linux/common/linux_sched.h>
6392ce8c6aSad #include <compat/linux/common/linux_ipc.h>
6492ce8c6aSad #include <compat/linux/common/linux_sem.h>
65ee0c5b44Smanu #include <compat/linux/linux_syscallargs.h>
66ee0c5b44Smanu 
67ee0c5b44Smanu #include <compat/linux32/common/linux32_types.h>
68ee0c5b44Smanu #include <compat/linux32/common/linux32_signal.h>
69ee0c5b44Smanu #include <compat/linux32/common/linux32_machdep.h>
70ee0c5b44Smanu #include <compat/linux32/common/linux32_sysctl.h>
71ee0c5b44Smanu #include <compat/linux32/common/linux32_socketcall.h>
72ee0c5b44Smanu #include <compat/linux32/linux32_syscallargs.h>
73ee0c5b44Smanu 
74ee0c5b44Smanu int
linux32_sys_clone(struct lwp * l,const struct linux32_sys_clone_args * uap,register_t * retval)757e2790cfSdsl linux32_sys_clone(struct lwp *l, const struct linux32_sys_clone_args *uap, register_t *retval)
76ee0c5b44Smanu {
777e2790cfSdsl 	/* {
78ee0c5b44Smanu 		syscallarg(int) flags;
79ee0c5b44Smanu 		syscallarg(netbsd32_voidp) stack;
80*33fa5ccbSchs 		syscallarg(netbsd32_voidp) parent_tidptr;
81*33fa5ccbSchs 		syscallarg(netbsd32_voidp) tls;
82*33fa5ccbSchs 		syscallarg(netbsd32_voidp) child_tidptr;
837e2790cfSdsl 	} */
84ee0c5b44Smanu 	struct linux_sys_clone_args ua;
85ee0c5b44Smanu 
86ee0c5b44Smanu 	NETBSD32TO64_UAP(flags);
87ee0c5b44Smanu 	NETBSD32TOP_UAP(stack, void *);
88*33fa5ccbSchs 	NETBSD32TOP_UAP(parent_tidptr, void *);
89*33fa5ccbSchs 	NETBSD32TOP_UAP(tls, void *);
90*33fa5ccbSchs 	NETBSD32TOP_UAP(child_tidptr, void *);
91ee0c5b44Smanu 	return linux_sys_clone(l, &ua, retval);
92ee0c5b44Smanu }
93ee0c5b44Smanu 
94ee0c5b44Smanu int
linux32_sys_sched_getscheduler(struct lwp * l,const struct linux32_sys_sched_getscheduler_args * uap,register_t * retval)957e2790cfSdsl linux32_sys_sched_getscheduler(struct lwp *l, const struct linux32_sys_sched_getscheduler_args *uap, register_t *retval)
96b32d95bfSnjoly {
977e2790cfSdsl 	/* {
98b32d95bfSnjoly 		syscallarg(pid_t) pid;
997e2790cfSdsl 	} */
100b32d95bfSnjoly 	struct linux_sys_sched_getscheduler_args ua;
101b32d95bfSnjoly 
102b32d95bfSnjoly 	NETBSD32TO64_UAP(pid);
103b32d95bfSnjoly 	return linux_sys_sched_getscheduler(l, &ua, retval);
104b32d95bfSnjoly }
105b32d95bfSnjoly 
106b32d95bfSnjoly int
linux32_sys_sched_setscheduler(struct lwp * l,const struct linux32_sys_sched_setscheduler_args * uap,register_t * retval)1077e2790cfSdsl linux32_sys_sched_setscheduler(struct lwp *l, const struct linux32_sys_sched_setscheduler_args *uap, register_t *retval)
108ee0c5b44Smanu {
1097e2790cfSdsl 	/* {
110ee0c5b44Smanu 		syscallarg(int) pid;
111ee0c5b44Smanu 		syscallarg(int) policy;
112ee0c5b44Smanu 		syscallarg(const linux32_sched_paramp_t) sp;
1137e2790cfSdsl 	} */
114ee0c5b44Smanu 	struct linux_sys_sched_setscheduler_args ua;
115ee0c5b44Smanu 
116ee0c5b44Smanu 	NETBSD32TO64_UAP(pid);
117ee0c5b44Smanu 	NETBSD32TO64_UAP(policy);
118ee0c5b44Smanu 	NETBSD32TOP_UAP(sp, const struct linux_sched_param);
119ee0c5b44Smanu 	return linux_sys_sched_setscheduler(l, &ua, retval);
120ee0c5b44Smanu }
121717102f4Smanu 
122717102f4Smanu int
linux32_sys_sched_getparam(struct lwp * l,const struct linux32_sys_sched_getparam_args * uap,register_t * retval)1237e2790cfSdsl linux32_sys_sched_getparam(struct lwp *l, const struct linux32_sys_sched_getparam_args *uap, register_t *retval)
124717102f4Smanu {
1257e2790cfSdsl 	/* {
126717102f4Smanu 		syscallarg(pid_t) pid;
127*33fa5ccbSchs 		syscallarg(linux32_sched_paramp_t) sp;
1287e2790cfSdsl 	} */
129717102f4Smanu 	struct linux_sys_sched_getparam_args ua;
130717102f4Smanu 
131717102f4Smanu 	NETBSD32TO64_UAP(pid);
132717102f4Smanu 	NETBSD32TOP_UAP(sp, struct linux_sched_param);
133717102f4Smanu 	return linux_sys_sched_getparam(l, &ua, retval);
134717102f4Smanu }
135717102f4Smanu 
136b32d95bfSnjoly int
linux32_sys_sched_setparam(struct lwp * l,const struct linux32_sys_sched_setparam_args * uap,register_t * retval)137*33fa5ccbSchs linux32_sys_sched_setparam(struct lwp *l, const struct linux32_sys_sched_setparam_args *uap, register_t *retval)
138*33fa5ccbSchs {
139*33fa5ccbSchs 	/* {
140*33fa5ccbSchs 		syscallarg(pid_t) pid;
141*33fa5ccbSchs 		syscallarg(const linux32_sched_paramp_t) sp;
142*33fa5ccbSchs 	} */
143*33fa5ccbSchs 	struct linux_sys_sched_setparam_args ua;
144*33fa5ccbSchs 
145*33fa5ccbSchs 	NETBSD32TO64_UAP(pid);
146*33fa5ccbSchs 	NETBSD32TOP_UAP(sp, const struct linux_sched_param);
147*33fa5ccbSchs 	return linux_sys_sched_setparam(l, &ua, retval);
148*33fa5ccbSchs }
149*33fa5ccbSchs 
150*33fa5ccbSchs int
linux32_sys_exit_group(struct lwp * l,const struct linux32_sys_exit_group_args * uap,register_t * retval)1517e2790cfSdsl linux32_sys_exit_group(struct lwp *l, const struct linux32_sys_exit_group_args *uap, register_t *retval)
152b32d95bfSnjoly {
1537e2790cfSdsl 	/* {
154b32d95bfSnjoly 		syscallarg(int) error_code;
1557e2790cfSdsl 	} */
156b32d95bfSnjoly 	struct linux_sys_exit_group_args ua;
157b32d95bfSnjoly 
158b32d95bfSnjoly 	NETBSD32TO64_UAP(error_code);
159b32d95bfSnjoly 	return linux_sys_exit_group(l, &ua, retval);
160b32d95bfSnjoly }
161aba77104Snjoly 
162aba77104Snjoly int
linux32_sys_exit(struct lwp * l,const struct linux32_sys_exit_args * uap,register_t * retval)163*33fa5ccbSchs linux32_sys_exit(struct lwp *l, const struct linux32_sys_exit_args *uap, register_t *retval)
164*33fa5ccbSchs {
165*33fa5ccbSchs 
166*33fa5ccbSchs 	/* {
167*33fa5ccbSchs 		syscallarg(int) rval;
168*33fa5ccbSchs 	} */
169*33fa5ccbSchs 	struct linux_sys_exit_args ua;
170*33fa5ccbSchs 
171*33fa5ccbSchs 	NETBSD32TO64_UAP(rval);
172*33fa5ccbSchs 	return linux_sys_exit(l, &ua, retval);
173*33fa5ccbSchs }
174*33fa5ccbSchs 
175*33fa5ccbSchs int
linux32_sys_sched_get_priority_max(struct lwp * l,const struct linux32_sys_sched_get_priority_max_args * uap,register_t * retval)176aba77104Snjoly linux32_sys_sched_get_priority_max(struct lwp *l, const struct linux32_sys_sched_get_priority_max_args *uap, register_t *retval)
177aba77104Snjoly {
178aba77104Snjoly 	/* {
179aba77104Snjoly 		syscallarg(int) policy;
180aba77104Snjoly 	} */
181aba77104Snjoly 
182aba77104Snjoly 	struct linux_sys_sched_get_priority_max_args ua;
183aba77104Snjoly 
184aba77104Snjoly 	NETBSD32TO64_UAP(policy);
185aba77104Snjoly 	return linux_sys_sched_get_priority_max(l, &ua, retval);
186aba77104Snjoly }
187aba77104Snjoly 
188aba77104Snjoly int
linux32_sys_sched_get_priority_min(struct lwp * l,const struct linux32_sys_sched_get_priority_min_args * uap,register_t * retval)189aba77104Snjoly linux32_sys_sched_get_priority_min(struct lwp *l, const struct linux32_sys_sched_get_priority_min_args *uap, register_t *retval)
190aba77104Snjoly {
191aba77104Snjoly 	/* {
192aba77104Snjoly 		syscallarg(int) policy;
193aba77104Snjoly 	} */
194aba77104Snjoly 
195aba77104Snjoly 	struct linux_sys_sched_get_priority_min_args ua;
196aba77104Snjoly 
197aba77104Snjoly 	NETBSD32TO64_UAP(policy);
198aba77104Snjoly 	return linux_sys_sched_get_priority_min(l, &ua, retval);
199aba77104Snjoly }
200*33fa5ccbSchs 
201*33fa5ccbSchs 
202*33fa5ccbSchs int
linux32_sys_set_tid_address(struct lwp * l,const struct linux32_sys_set_tid_address_args * uap,register_t * retval)203*33fa5ccbSchs linux32_sys_set_tid_address(struct lwp *l, const struct linux32_sys_set_tid_address_args *uap, register_t *retval)
204*33fa5ccbSchs {
205*33fa5ccbSchs 	/* {
206*33fa5ccbSchs 		syscallarg(linux32_intp_t) tid;
207*33fa5ccbSchs 	} */
208*33fa5ccbSchs 	struct linux_sys_set_tid_address_args ua;
209*33fa5ccbSchs 
210*33fa5ccbSchs 	NETBSD32TOP_UAP(tid, int);
211*33fa5ccbSchs 	return linux_sys_set_tid_address(l, &ua, retval);
212*33fa5ccbSchs }
213*33fa5ccbSchs 
214*33fa5ccbSchs int
linux32_sys_sched_getaffinity(struct lwp * l,const struct linux32_sys_sched_getaffinity_args * uap,register_t * retval)215*33fa5ccbSchs linux32_sys_sched_getaffinity(struct lwp *l, const struct linux32_sys_sched_getaffinity_args *uap, register_t *retval)
216*33fa5ccbSchs {
217*33fa5ccbSchs 	/* {
218*33fa5ccbSchs 		syscallarg(linux_pid_t) pid;
219*33fa5ccbSchs 		syscallarg(unsigned int) len;
220*33fa5ccbSchs 		syscallarg(linux32_longp_t) mask;
221*33fa5ccbSchs 	} */
222*33fa5ccbSchs 	struct linux_sys_sched_getaffinity_args ua;
223*33fa5ccbSchs 
224*33fa5ccbSchs 	NETBSD32TO64_UAP(pid);
225*33fa5ccbSchs 	NETBSD32TO64_UAP(len);
226*33fa5ccbSchs 	NETBSD32TOP_UAP(mask, long);
227*33fa5ccbSchs 	return linux_sys_sched_getaffinity(l, &ua, retval);
228*33fa5ccbSchs }
229*33fa5ccbSchs 
230*33fa5ccbSchs int
linux32_sys_sched_setaffinity(struct lwp * l,const struct linux32_sys_sched_setaffinity_args * uap,register_t * retval)231*33fa5ccbSchs linux32_sys_sched_setaffinity(struct lwp *l, const struct linux32_sys_sched_setaffinity_args *uap, register_t *retval)
232*33fa5ccbSchs {
233*33fa5ccbSchs 	/* {
234*33fa5ccbSchs 		syscallarg(linux_pid_t) pid;
235*33fa5ccbSchs 		syscallarg(unsigned int) len;
236*33fa5ccbSchs 		syscallarg(linux32_longp_t) mask;
237*33fa5ccbSchs 	} */
238*33fa5ccbSchs 	struct linux_sys_sched_setaffinity_args ua;
239*33fa5ccbSchs 
240*33fa5ccbSchs 	NETBSD32TO64_UAP(pid);
241*33fa5ccbSchs 	NETBSD32TO64_UAP(len);
242*33fa5ccbSchs 	NETBSD32TOP_UAP(mask, long);
243*33fa5ccbSchs 	return linux_sys_sched_setaffinity(l, &ua, retval);
244*33fa5ccbSchs }
245*33fa5ccbSchs 
246*33fa5ccbSchs int
linux32_sys_tkill(struct lwp * l,const struct linux32_sys_tkill_args * uap,register_t * retval)247*33fa5ccbSchs linux32_sys_tkill(struct lwp *l, const struct linux32_sys_tkill_args *uap, register_t *retval)
248*33fa5ccbSchs {
249*33fa5ccbSchs 	/* {
250*33fa5ccbSchs 		syscallarg(int) tid;
251*33fa5ccbSchs 		syscallarg(int) sig;
252*33fa5ccbSchs 	} */
253*33fa5ccbSchs 	struct linux_sys_tkill_args ua;
254*33fa5ccbSchs 
255*33fa5ccbSchs 	NETBSD32TO64_UAP(tid);
256*33fa5ccbSchs 	NETBSD32TO64_UAP(sig);
257*33fa5ccbSchs 	return linux_sys_tkill(l, &ua, retval);
258*33fa5ccbSchs }
259*33fa5ccbSchs 
260*33fa5ccbSchs int
linux32_sys_tgkill(struct lwp * l,const struct linux32_sys_tgkill_args * uap,register_t * retval)261*33fa5ccbSchs linux32_sys_tgkill(struct lwp *l, const struct linux32_sys_tgkill_args *uap, register_t *retval)
262*33fa5ccbSchs {
263*33fa5ccbSchs 	/* {
264*33fa5ccbSchs 		syscallarg(int) tgid;
265*33fa5ccbSchs 		syscallarg(int) tid;
266*33fa5ccbSchs 		syscallarg(int) sig;
267*33fa5ccbSchs 	} */
268*33fa5ccbSchs 	struct linux_sys_tgkill_args ua;
269*33fa5ccbSchs 
270*33fa5ccbSchs 	NETBSD32TO64_UAP(tgid);
271*33fa5ccbSchs 	NETBSD32TO64_UAP(tid);
272*33fa5ccbSchs 	NETBSD32TO64_UAP(sig);
273*33fa5ccbSchs 	return linux_sys_tgkill(l, &ua, retval);
274*33fa5ccbSchs }
275