linux32_unistd.c revision 1.37 1 1.37 njoly /* $NetBSD: linux32_unistd.c,v 1.37 2014/05/04 10:08:53 njoly Exp $ */
2 1.1 manu
3 1.1 manu /*-
4 1.1 manu * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
5 1.1 manu *
6 1.1 manu * Redistribution and use in source and binary forms, with or without
7 1.1 manu * modification, are permitted provided that the following conditions
8 1.1 manu * are met:
9 1.1 manu * 1. Redistributions of source code must retain the above copyright
10 1.1 manu * notice, this list of conditions and the following disclaimer.
11 1.1 manu * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 manu * notice, this list of conditions and the following disclaimer in the
13 1.1 manu * documentation and/or other materials provided with the distribution.
14 1.1 manu * 3. All advertising materials mentioning features or use of this software
15 1.1 manu * must display the following acknowledgement:
16 1.1 manu * This product includes software developed by Emmanuel Dreyfus
17 1.1 manu * 4. The name of the author may not be used to endorse or promote
18 1.1 manu * products derived from this software without specific prior written
19 1.1 manu * permission.
20 1.1 manu *
21 1.1 manu * THIS SOFTWARE IS PROVIDED BY THE THE AUTHOR AND CONTRIBUTORS ``AS IS''
22 1.1 manu * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 1.1 manu * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 1.1 manu * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
25 1.1 manu * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 1.1 manu * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 1.1 manu * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 1.1 manu * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 1.1 manu * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 1.1 manu * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 1.1 manu * POSSIBILITY OF SUCH DAMAGE.
32 1.1 manu */
33 1.1 manu
34 1.1 manu #include <sys/cdefs.h>
35 1.1 manu
36 1.37 njoly __KERNEL_RCSID(0, "$NetBSD: linux32_unistd.c,v 1.37 2014/05/04 10:08:53 njoly Exp $");
37 1.1 manu
38 1.1 manu #include <sys/types.h>
39 1.1 manu #include <sys/param.h>
40 1.1 manu #include <sys/fstypes.h>
41 1.1 manu #include <sys/signal.h>
42 1.1 manu #include <sys/dirent.h>
43 1.1 manu #include <sys/kernel.h>
44 1.1 manu #include <sys/fcntl.h>
45 1.1 manu #include <sys/select.h>
46 1.1 manu #include <sys/proc.h>
47 1.1 manu #include <sys/ucred.h>
48 1.1 manu #include <sys/swap.h>
49 1.26 njoly #include <sys/kauth.h>
50 1.35 christos #include <sys/filedesc.h>
51 1.36 chs #include <sys/vfs_syscalls.h>
52 1.1 manu
53 1.1 manu #include <machine/types.h>
54 1.1 manu
55 1.1 manu #include <sys/syscallargs.h>
56 1.1 manu
57 1.1 manu #include <compat/netbsd32/netbsd32.h>
58 1.1 manu #include <compat/netbsd32/netbsd32_conv.h>
59 1.1 manu
60 1.1 manu #include <compat/linux/common/linux_types.h>
61 1.1 manu #include <compat/linux/common/linux_signal.h>
62 1.1 manu #include <compat/linux/common/linux_machdep.h>
63 1.1 manu #include <compat/linux/common/linux_misc.h>
64 1.1 manu #include <compat/linux/common/linux_oldolduname.h>
65 1.25 ad #include <compat/linux/common/linux_ipc.h>
66 1.25 ad #include <compat/linux/common/linux_sem.h>
67 1.35 christos #include <compat/linux/common/linux_fcntl.h>
68 1.1 manu #include <compat/linux/linux_syscallargs.h>
69 1.1 manu
70 1.1 manu #include <compat/linux32/common/linux32_types.h>
71 1.1 manu #include <compat/linux32/common/linux32_signal.h>
72 1.1 manu #include <compat/linux32/common/linux32_machdep.h>
73 1.36 chs #include <compat/linux32/common/linux32_sched.h>
74 1.1 manu #include <compat/linux32/common/linux32_sysctl.h>
75 1.1 manu #include <compat/linux32/common/linux32_socketcall.h>
76 1.1 manu #include <compat/linux32/linux32_syscallargs.h>
77 1.1 manu
78 1.1 manu static int linux32_select1(struct lwp *, register_t *,
79 1.1 manu int, fd_set *, fd_set *, fd_set *, struct timeval *);
80 1.1 manu
81 1.1 manu int
82 1.17 dsl linux32_sys_brk(struct lwp *l, const struct linux32_sys_brk_args *uap, register_t *retval)
83 1.1 manu {
84 1.17 dsl /* {
85 1.1 manu syscallarg(netbsd32_charp) nsize;
86 1.17 dsl } */
87 1.1 manu struct linux_sys_brk_args ua;
88 1.1 manu
89 1.1 manu NETBSD32TOP_UAP(nsize, char);
90 1.1 manu return linux_sys_brk(l, &ua, retval);
91 1.1 manu }
92 1.1 manu
93 1.1 manu int
94 1.17 dsl linux32_sys_llseek(struct lwp *l, const struct linux32_sys_llseek_args *uap, register_t *retval)
95 1.1 manu {
96 1.17 dsl /* {
97 1.29 njoly syscallarg(int) fd;
98 1.1 manu syscallarg(u_int32_t) ohigh;
99 1.1 manu syscallarg(u_int32_t) olow;
100 1.28 njoly syscallarg(netbsd32_voidp) res;
101 1.29 njoly syscallarg(int) whence;
102 1.17 dsl } */
103 1.1 manu struct linux_sys_llseek_args ua;
104 1.1 manu
105 1.1 manu NETBSD32TO64_UAP(fd);
106 1.1 manu NETBSD32TO64_UAP(ohigh);
107 1.1 manu NETBSD32TO64_UAP(olow);
108 1.28 njoly NETBSD32TOP_UAP(res, void);
109 1.1 manu NETBSD32TO64_UAP(whence);
110 1.1 manu
111 1.1 manu return linux_sys_llseek(l, &ua, retval);
112 1.1 manu }
113 1.1 manu
114 1.1 manu int
115 1.17 dsl linux32_sys_select(struct lwp *l, const struct linux32_sys_select_args *uap, register_t *retval)
116 1.1 manu {
117 1.17 dsl /* {
118 1.1 manu syscallarg(int) nfds;
119 1.1 manu syscallarg(netbsd32_fd_setp_t) readfds;
120 1.1 manu syscallarg(netbsd32_fd_setp_t) writefds;
121 1.1 manu syscallarg(netbsd32_fd_setp_t) exceptfds;
122 1.30 njoly syscallarg(netbsd32_timeval50p_t) timeout;
123 1.17 dsl } */
124 1.1 manu
125 1.1 manu return linux32_select1(l, retval, SCARG(uap, nfds),
126 1.7 dsl SCARG_P32(uap, readfds),
127 1.7 dsl SCARG_P32(uap, writefds),
128 1.7 dsl SCARG_P32(uap, exceptfds),
129 1.7 dsl SCARG_P32(uap, timeout));
130 1.1 manu }
131 1.1 manu
132 1.1 manu int
133 1.17 dsl linux32_sys_oldselect(struct lwp *l, const struct linux32_sys_oldselect_args *uap, register_t *retval)
134 1.1 manu {
135 1.17 dsl /* {
136 1.1 manu syscallarg(linux32_oldselectp_t) lsp;
137 1.17 dsl } */
138 1.1 manu struct linux32_oldselect lsp32;
139 1.1 manu int error;
140 1.1 manu
141 1.7 dsl if ((error = copyin(SCARG_P32(uap, lsp), &lsp32, sizeof(lsp32))) != 0)
142 1.1 manu return error;
143 1.1 manu
144 1.1 manu return linux32_select1(l, retval, lsp32.nfds,
145 1.1 manu NETBSD32PTR64(lsp32.readfds), NETBSD32PTR64(lsp32.writefds),
146 1.1 manu NETBSD32PTR64(lsp32.exceptfds), NETBSD32PTR64(lsp32.timeout));
147 1.1 manu }
148 1.1 manu
149 1.1 manu static int
150 1.31 cegger linux32_select1(struct lwp *l, register_t *retval, int nfds,
151 1.31 cegger fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
152 1.31 cegger struct timeval *timeout)
153 1.1 manu {
154 1.32 christos struct timespec ts0, ts1, uts, *ts = NULL;
155 1.30 njoly struct netbsd32_timeval50 utv32;
156 1.1 manu int error;
157 1.1 manu
158 1.2 skd
159 1.1 manu /*
160 1.1 manu * Store current time for computation of the amount of
161 1.1 manu * time left.
162 1.1 manu */
163 1.1 manu if (timeout) {
164 1.1 manu if ((error = copyin(timeout, &utv32, sizeof(utv32))))
165 1.1 manu return error;
166 1.1 manu
167 1.32 christos uts.tv_sec = utv32.tv_sec;
168 1.32 christos uts.tv_nsec = utv32.tv_usec * 1000;
169 1.1 manu
170 1.32 christos if (itimespecfix(&uts)) {
171 1.1 manu /*
172 1.1 manu * The timeval was invalid. Convert it to something
173 1.1 manu * valid that will act as it does under Linux.
174 1.1 manu */
175 1.32 christos uts.tv_sec += uts.tv_nsec / 1000000000;
176 1.32 christos uts.tv_nsec %= 1000000000;
177 1.32 christos if (uts.tv_nsec < 0) {
178 1.32 christos uts.tv_sec -= 1;
179 1.32 christos uts.tv_nsec += 1000000000;
180 1.1 manu }
181 1.32 christos if (uts.tv_sec < 0)
182 1.32 christos timespecclear(&uts);
183 1.1 manu }
184 1.32 christos nanotime(&ts0);
185 1.32 christos ts = &uts;
186 1.32 christos } else
187 1.32 christos timespecclear(&uts); /* XXX GCC4 */
188 1.1 manu
189 1.34 rmind error = selcommon(retval, nfds, readfds, writefds, exceptfds, ts, NULL);
190 1.1 manu
191 1.1 manu if (error) {
192 1.1 manu /*
193 1.1 manu * See fs/select.c in the Linux kernel. Without this,
194 1.1 manu * Maelstrom doesn't work.
195 1.1 manu */
196 1.1 manu if (error == ERESTART)
197 1.1 manu error = EINTR;
198 1.1 manu return error;
199 1.1 manu }
200 1.1 manu
201 1.1 manu if (timeout) {
202 1.1 manu if (*retval) {
203 1.1 manu /*
204 1.1 manu * Compute how much time was left of the timeout,
205 1.1 manu * by subtracting the current time and the time
206 1.1 manu * before we started the call, and subtracting
207 1.1 manu * that result from the user-supplied value.
208 1.1 manu */
209 1.32 christos nanotime(&ts1);
210 1.32 christos timespecsub(&ts1, &ts0, &ts1);
211 1.32 christos timespecsub(&uts, &ts1, &uts);
212 1.32 christos if (uts.tv_sec < 0)
213 1.32 christos timespecclear(&uts);
214 1.1 manu } else {
215 1.32 christos timespecclear(&uts);
216 1.1 manu }
217 1.1 manu
218 1.32 christos utv32.tv_sec = uts.tv_sec;
219 1.32 christos utv32.tv_usec = uts.tv_nsec / 1000;
220 1.1 manu
221 1.1 manu if ((error = copyout(&utv32, timeout, sizeof(utv32))))
222 1.1 manu return error;
223 1.1 manu }
224 1.1 manu
225 1.1 manu return 0;
226 1.1 manu }
227 1.1 manu
228 1.35 christos static int
229 1.35 christos linux32_pipe(struct lwp *l, int *fd, register_t *retval, int flags)
230 1.1 manu {
231 1.17 dsl /* {
232 1.1 manu syscallarg(netbsd32_intp) fd;
233 1.17 dsl } */
234 1.1 manu int error;
235 1.1 manu int pfds[2];
236 1.1 manu
237 1.1 manu pfds[0] = (int)retval[0];
238 1.1 manu pfds[1] = (int)retval[1];
239 1.1 manu
240 1.35 christos if ((error = copyout(pfds, fd, 2 * sizeof(*fd))) != 0)
241 1.1 manu return error;
242 1.1 manu
243 1.35 christos if (flags & LINUX_O_CLOEXEC) {
244 1.35 christos fd_set_exclose(l, retval[0], true);
245 1.35 christos fd_set_exclose(l, retval[1], true);
246 1.35 christos }
247 1.1 manu retval[0] = 0;
248 1.1 manu retval[1] = 0;
249 1.1 manu
250 1.1 manu return 0;
251 1.1 manu }
252 1.1 manu
253 1.35 christos int
254 1.35 christos linux32_sys_pipe(struct lwp *l, const struct linux32_sys_pipe_args *uap,
255 1.35 christos register_t *retval)
256 1.35 christos {
257 1.35 christos int error;
258 1.35 christos if ((error = pipe1(l, retval, 0)))
259 1.35 christos return error;
260 1.35 christos return linux32_pipe(l, SCARG_P32(uap, fd), retval, 0);
261 1.35 christos }
262 1.35 christos
263 1.35 christos int
264 1.35 christos linux32_sys_pipe2(struct lwp *l, const struct linux32_sys_pipe2_args *uap,
265 1.35 christos register_t *retval)
266 1.35 christos {
267 1.35 christos int flag = 0;
268 1.35 christos int error;
269 1.35 christos
270 1.35 christos switch (SCARG(uap, flags)) {
271 1.35 christos case LINUX_O_CLOEXEC:
272 1.35 christos break;
273 1.35 christos case LINUX_O_NONBLOCK:
274 1.35 christos case LINUX_O_NONBLOCK|LINUX_O_CLOEXEC:
275 1.35 christos flag = O_NONBLOCK;
276 1.35 christos break;
277 1.35 christos default:
278 1.35 christos return EINVAL;
279 1.35 christos }
280 1.35 christos
281 1.35 christos if ((error = pipe1(l, retval, flag)))
282 1.35 christos return error;
283 1.35 christos
284 1.35 christos return linux32_pipe(l, SCARG_P32(uap, fd), retval, SCARG(uap, flags));
285 1.35 christos }
286 1.35 christos
287 1.35 christos int
288 1.35 christos linux32_sys_dup3(struct lwp *l, const struct linux32_sys_dup3_args *uap,
289 1.35 christos register_t *retval)
290 1.35 christos {
291 1.35 christos /* {
292 1.35 christos syscallarg(int) from;
293 1.35 christos syscallarg(int) to;
294 1.35 christos syscallarg(int) flags;
295 1.35 christos } */
296 1.35 christos struct sys_dup2_args ua;
297 1.35 christos int error;
298 1.35 christos
299 1.35 christos NETBSD32TO64_UAP(from);
300 1.35 christos NETBSD32TO64_UAP(to);
301 1.35 christos
302 1.35 christos if ((error = sys_dup2(l, &ua, retval)))
303 1.35 christos return error;
304 1.35 christos
305 1.35 christos if (SCARG(uap, flags) & LINUX_O_CLOEXEC)
306 1.35 christos fd_set_exclose(l, SCARG(uap, to), true);
307 1.35 christos
308 1.35 christos return 0;
309 1.35 christos }
310 1.1 manu
311 1.36 chs
312 1.36 chs int
313 1.36 chs linux32_sys_openat(struct lwp *l, const struct linux32_sys_openat_args *uap, register_t *retval)
314 1.36 chs {
315 1.36 chs /* {
316 1.36 chs syscallarg(int) fd;
317 1.36 chs syscallarg(const netbsd32_charp) path;
318 1.36 chs syscallarg(int) flags;
319 1.36 chs syscallarg(int) mode;
320 1.36 chs } */
321 1.36 chs struct linux_sys_openat_args ua;
322 1.36 chs
323 1.36 chs NETBSD32TO64_UAP(fd);
324 1.36 chs NETBSD32TOP_UAP(path, const char);
325 1.36 chs NETBSD32TO64_UAP(flags);
326 1.36 chs NETBSD32TO64_UAP(mode);
327 1.36 chs
328 1.36 chs return linux_sys_openat(l, &ua, retval);
329 1.36 chs }
330 1.36 chs
331 1.36 chs int
332 1.36 chs linux32_sys_mknodat(struct lwp *l, const struct linux32_sys_mknodat_args *uap, register_t *retval)
333 1.36 chs {
334 1.36 chs /* {
335 1.36 chs syscallarg(int) fd;
336 1.36 chs syscallarg(const netbsd32_charp) path;
337 1.36 chs syscallarg(linux_umode_t) mode;
338 1.36 chs syscallarg(unsigned) dev;
339 1.36 chs } */
340 1.36 chs struct linux_sys_mknodat_args ua;
341 1.36 chs
342 1.36 chs NETBSD32TO64_UAP(fd);
343 1.36 chs NETBSD32TOP_UAP(path, const char);
344 1.36 chs NETBSD32TO64_UAP(mode);
345 1.36 chs NETBSD32TO64_UAP(dev);
346 1.36 chs
347 1.36 chs return linux_sys_mknodat(l, &ua, retval);
348 1.36 chs }
349 1.36 chs
350 1.36 chs int
351 1.36 chs linux32_sys_linkat(struct lwp *l, const struct linux32_sys_linkat_args *uap, register_t *retval)
352 1.36 chs {
353 1.36 chs /* {
354 1.36 chs syscallarg(int) fd1;
355 1.36 chs syscallarg(netbsd32_charp) name1;
356 1.36 chs syscallarg(int) fd2;
357 1.36 chs syscallarg(netbsd32_charp) name2;
358 1.36 chs syscallarg(int) flags;
359 1.36 chs } */
360 1.36 chs int fd1 = SCARG(uap, fd1);
361 1.36 chs const char *name1 = SCARG_P32(uap, name1);
362 1.36 chs int fd2 = SCARG(uap, fd2);
363 1.36 chs const char *name2 = SCARG_P32(uap, name2);
364 1.36 chs int follow;
365 1.36 chs
366 1.36 chs follow = SCARG(uap, flags) & LINUX_AT_SYMLINK_FOLLOW;
367 1.36 chs
368 1.36 chs return do_sys_linkat(l, fd1, name1, fd2, name2, follow, retval);
369 1.36 chs }
370 1.36 chs
371 1.1 manu int
372 1.17 dsl linux32_sys_unlink(struct lwp *l, const struct linux32_sys_unlink_args *uap, register_t *retval)
373 1.1 manu {
374 1.17 dsl /* {
375 1.1 manu syscallarg(const netbsd32_charp) path;
376 1.17 dsl } */
377 1.1 manu struct linux_sys_unlink_args ua;
378 1.1 manu
379 1.1 manu NETBSD32TOP_UAP(path, const char);
380 1.36 chs
381 1.1 manu return linux_sys_unlink(l, &ua, retval);
382 1.1 manu }
383 1.1 manu
384 1.1 manu int
385 1.36 chs linux32_sys_unlinkat(struct lwp *l, const struct linux32_sys_unlinkat_args *uap, register_t *retval)
386 1.36 chs {
387 1.36 chs /* {
388 1.36 chs syscallarg(int) fd;
389 1.36 chs syscallarg(const netbsd32_charp) path;
390 1.36 chs syscallarg(int) flag;
391 1.36 chs } */
392 1.36 chs struct linux_sys_unlinkat_args ua;
393 1.36 chs
394 1.36 chs NETBSD32TO64_UAP(fd);
395 1.36 chs NETBSD32TOP_UAP(path, const char);
396 1.36 chs NETBSD32TO64_UAP(flag);
397 1.36 chs
398 1.36 chs return linux_sys_unlinkat(l, &ua, retval);
399 1.36 chs }
400 1.36 chs
401 1.36 chs int
402 1.36 chs linux32_sys_fchmodat(struct lwp *l, const struct linux32_sys_fchmodat_args *uap, register_t *retval)
403 1.36 chs {
404 1.36 chs /* {
405 1.36 chs syscallarg(int) fd;
406 1.36 chs syscallarg(netbsd_charp) path;
407 1.36 chs syscallarg(linux_umode_t) mode;
408 1.36 chs } */
409 1.36 chs
410 1.36 chs return do_sys_chmodat(l, SCARG(uap, fd), SCARG_P32(uap, path),
411 1.36 chs SCARG(uap, mode), AT_SYMLINK_FOLLOW);
412 1.36 chs }
413 1.36 chs
414 1.36 chs int
415 1.36 chs linux32_sys_fchownat(struct lwp *l, const struct linux32_sys_fchownat_args *uap, register_t *retval)
416 1.36 chs {
417 1.36 chs /* {
418 1.36 chs syscallarg(int) fd;
419 1.36 chs syscallarg(netbsd_charp) path;
420 1.36 chs syscallarg(uid_t) owner;
421 1.36 chs syscallarg(gid_t) group;
422 1.36 chs syscallarg(int) flag;
423 1.36 chs } */
424 1.36 chs int flag;
425 1.36 chs
426 1.36 chs flag = linux_to_bsd_atflags(SCARG(uap, flag));
427 1.36 chs return do_sys_chownat(l, SCARG(uap, fd), SCARG_P32(uap, path),
428 1.36 chs SCARG(uap, owner), SCARG(uap, group), flag);
429 1.36 chs }
430 1.36 chs
431 1.36 chs int
432 1.36 chs linux32_sys_faccessat(struct lwp *l, const struct linux32_sys_faccessat_args *uap, register_t *retval)
433 1.36 chs {
434 1.36 chs /* {
435 1.36 chs syscallarg(int) fd;
436 1.36 chs syscallarg(netbsd_charp) path;
437 1.36 chs syscallarg(int) amode;
438 1.36 chs } */
439 1.36 chs
440 1.36 chs return do_sys_accessat(l, SCARG(uap, fd), SCARG_P32(uap, path),
441 1.36 chs SCARG(uap, amode), AT_SYMLINK_FOLLOW);
442 1.36 chs }
443 1.36 chs
444 1.36 chs int
445 1.36 chs linux32_sys_utimensat(struct lwp *l, const struct linux32_sys_utimensat_args *uap, register_t *retval)
446 1.36 chs {
447 1.36 chs /* {
448 1.36 chs syscallarg(int) fd;
449 1.36 chs syscallarg(const netbsd32_charp) path;
450 1.36 chs syscallarg(const linux32_timespecp_t) times;
451 1.36 chs syscallarg(int) flags;
452 1.36 chs } */
453 1.36 chs int error;
454 1.36 chs struct linux32_timespec lts[2];
455 1.36 chs struct timespec *tsp = NULL, ts[2];
456 1.36 chs
457 1.36 chs if (SCARG_P32(uap, times)) {
458 1.36 chs error = copyin(SCARG_P32(uap, times), <s, sizeof(lts));
459 1.36 chs if (error != 0)
460 1.36 chs return error;
461 1.36 chs linux32_to_native_timespec(&ts[0], <s[0]);
462 1.36 chs linux32_to_native_timespec(&ts[1], <s[1]);
463 1.36 chs tsp = ts;
464 1.36 chs }
465 1.36 chs
466 1.36 chs return linux_do_sys_utimensat(l, SCARG(uap, fd), SCARG_P32(uap, path),
467 1.36 chs tsp, SCARG(uap, flag), retval);
468 1.36 chs }
469 1.36 chs
470 1.36 chs int
471 1.17 dsl linux32_sys_creat(struct lwp *l, const struct linux32_sys_creat_args *uap, register_t *retval)
472 1.1 manu {
473 1.17 dsl /* {
474 1.1 manu syscallarg(const netbsd32_charp) path;
475 1.1 manu syscallarg(int) mode;
476 1.17 dsl } */
477 1.1 manu struct sys_open_args ua;
478 1.1 manu
479 1.1 manu NETBSD32TOP_UAP(path, const char);
480 1.1 manu SCARG(&ua, flags) = O_CREAT | O_TRUNC | O_WRONLY;
481 1.1 manu NETBSD32TO64_UAP(mode);
482 1.1 manu
483 1.1 manu return sys_open(l, &ua, retval);
484 1.1 manu }
485 1.1 manu
486 1.1 manu int
487 1.17 dsl linux32_sys_mknod(struct lwp *l, const struct linux32_sys_mknod_args *uap, register_t *retval)
488 1.1 manu {
489 1.17 dsl /* {
490 1.1 manu syscallarg(const netbsd32_charp) path;
491 1.1 manu syscallarg(int) mode;
492 1.1 manu syscallarg(int) dev;
493 1.17 dsl } */
494 1.1 manu struct linux_sys_mknod_args ua;
495 1.1 manu
496 1.1 manu NETBSD32TOP_UAP(path, const char);
497 1.1 manu NETBSD32TO64_UAP(mode);
498 1.1 manu NETBSD32TO64_UAP(dev);
499 1.1 manu
500 1.1 manu return linux_sys_mknod(l, &ua, retval);
501 1.1 manu }
502 1.1 manu
503 1.1 manu int
504 1.17 dsl linux32_sys_break(struct lwp *l, const struct linux32_sys_break_args *uap, register_t *retval)
505 1.1 manu {
506 1.1 manu #if 0
507 1.17 dsl /* {
508 1.1 manu syscallarg(const netbsd32_charp) nsize;
509 1.17 dsl } */
510 1.1 manu #endif
511 1.1 manu
512 1.1 manu return ENOSYS;
513 1.1 manu }
514 1.1 manu
515 1.1 manu int
516 1.17 dsl linux32_sys_swapon(struct lwp *l, const struct linux32_sys_swapon_args *uap, register_t *retval)
517 1.1 manu {
518 1.17 dsl /* {
519 1.1 manu syscallarg(const netbsd32_charp) name;
520 1.17 dsl } */
521 1.1 manu struct sys_swapctl_args ua;
522 1.1 manu
523 1.1 manu SCARG(&ua, cmd) = SWAP_ON;
524 1.7 dsl SCARG(&ua, arg) = SCARG_P32(uap, name);
525 1.1 manu SCARG(&ua, misc) = 0; /* priority */
526 1.1 manu return (sys_swapctl(l, &ua, retval));
527 1.1 manu }
528 1.1 manu
529 1.1 manu int
530 1.17 dsl linux32_sys_swapoff(struct lwp *l, const struct linux32_sys_swapoff_args *uap, register_t *retval)
531 1.1 manu {
532 1.17 dsl /* {
533 1.1 manu syscallarg(const netbsd32_charp) path;
534 1.17 dsl } */
535 1.1 manu struct sys_swapctl_args ua;
536 1.1 manu
537 1.1 manu SCARG(&ua, cmd) = SWAP_OFF;
538 1.7 dsl SCARG(&ua, arg) = SCARG_P32(uap, path);
539 1.1 manu SCARG(&ua, misc) = 0; /* priority */
540 1.1 manu return (sys_swapctl(l, &ua, retval));
541 1.1 manu }
542 1.1 manu
543 1.1 manu
544 1.1 manu int
545 1.17 dsl linux32_sys_reboot(struct lwp *l, const struct linux32_sys_reboot_args *uap, register_t *retval)
546 1.1 manu {
547 1.17 dsl /* {
548 1.1 manu syscallarg(int) magic1;
549 1.1 manu syscallarg(int) magic2;
550 1.1 manu syscallarg(int) cmd;
551 1.1 manu syscallarg(netbsd32_voidp) arg;
552 1.17 dsl } */
553 1.1 manu struct linux_sys_reboot_args ua;
554 1.1 manu
555 1.1 manu NETBSD32TO64_UAP(magic1);
556 1.1 manu NETBSD32TO64_UAP(magic2);
557 1.1 manu NETBSD32TO64_UAP(cmd);
558 1.1 manu NETBSD32TOP_UAP(arg, void);
559 1.1 manu
560 1.1 manu return linux_sys_reboot(l, &ua, retval);
561 1.1 manu }
562 1.1 manu
563 1.1 manu int
564 1.17 dsl linux32_sys_setresuid(struct lwp *l, const struct linux32_sys_setresuid_args *uap, register_t *retval)
565 1.3 manu {
566 1.17 dsl /* {
567 1.3 manu syscallarg(uid_t) ruid;
568 1.3 manu syscallarg(uid_t) euid;
569 1.3 manu syscallarg(uid_t) suid;
570 1.17 dsl } */
571 1.3 manu struct linux_sys_setresuid_args ua;
572 1.3 manu
573 1.27 njoly NETBSD32TO64_UAP(ruid);
574 1.27 njoly NETBSD32TO64_UAP(euid);
575 1.27 njoly NETBSD32TO64_UAP(suid);
576 1.3 manu
577 1.3 manu return linux_sys_setresuid(l, &ua, retval);
578 1.3 manu }
579 1.3 manu
580 1.3 manu int
581 1.26 njoly linux32_sys_getresuid(struct lwp *l, const struct linux32_sys_getresuid_args *uap, register_t *retval)
582 1.26 njoly {
583 1.26 njoly /* {
584 1.26 njoly syscallarg(linux32_uidp_t) ruid;
585 1.26 njoly syscallarg(linux32_uidp_t) euid;
586 1.26 njoly syscallarg(linux32_uidp_t) suid;
587 1.26 njoly } */
588 1.26 njoly kauth_cred_t pc = l->l_cred;
589 1.26 njoly int error;
590 1.26 njoly uid_t uid;
591 1.26 njoly
592 1.26 njoly uid = kauth_cred_getuid(pc);
593 1.26 njoly if ((error = copyout(&uid, SCARG_P32(uap, ruid), sizeof(uid_t))) != 0)
594 1.26 njoly return error;
595 1.26 njoly
596 1.26 njoly uid = kauth_cred_geteuid(pc);
597 1.26 njoly if ((error = copyout(&uid, SCARG_P32(uap, euid), sizeof(uid_t))) != 0)
598 1.26 njoly return error;
599 1.26 njoly
600 1.26 njoly uid = kauth_cred_getsvuid(pc);
601 1.26 njoly return copyout(&uid, SCARG_P32(uap, suid), sizeof(uid_t));
602 1.26 njoly }
603 1.26 njoly
604 1.26 njoly int
605 1.17 dsl linux32_sys_setresgid(struct lwp *l, const struct linux32_sys_setresgid_args *uap, register_t *retval)
606 1.3 manu {
607 1.17 dsl /* {
608 1.3 manu syscallarg(gid_t) rgid;
609 1.3 manu syscallarg(gid_t) egid;
610 1.3 manu syscallarg(gid_t) sgid;
611 1.17 dsl } */
612 1.3 manu struct linux_sys_setresgid_args ua;
613 1.3 manu
614 1.27 njoly NETBSD32TO64_UAP(rgid);
615 1.27 njoly NETBSD32TO64_UAP(egid);
616 1.27 njoly NETBSD32TO64_UAP(sgid);
617 1.3 manu
618 1.3 manu return linux_sys_setresgid(l, &ua, retval);
619 1.3 manu }
620 1.13 njoly
621 1.13 njoly int
622 1.26 njoly linux32_sys_getresgid(struct lwp *l, const struct linux32_sys_getresgid_args *uap, register_t *retval)
623 1.26 njoly {
624 1.26 njoly /* {
625 1.26 njoly syscallarg(linux32_gidp_t) rgid;
626 1.26 njoly syscallarg(linux32_gidp_t) egid;
627 1.26 njoly syscallarg(linux32_gidp_t) sgid;
628 1.26 njoly } */
629 1.26 njoly kauth_cred_t pc = l->l_cred;
630 1.26 njoly int error;
631 1.26 njoly gid_t gid;
632 1.26 njoly
633 1.26 njoly gid = kauth_cred_getgid(pc);
634 1.26 njoly if ((error = copyout(&gid, SCARG_P32(uap, rgid), sizeof(gid_t))) != 0)
635 1.26 njoly return error;
636 1.26 njoly
637 1.26 njoly gid = kauth_cred_getegid(pc);
638 1.26 njoly if ((error = copyout(&gid, SCARG_P32(uap, egid), sizeof(gid_t))) != 0)
639 1.26 njoly return error;
640 1.26 njoly
641 1.26 njoly gid = kauth_cred_getsvgid(pc);
642 1.26 njoly return copyout(&gid, SCARG_P32(uap, sgid), sizeof(gid_t));
643 1.26 njoly }
644 1.26 njoly
645 1.26 njoly int
646 1.17 dsl linux32_sys_nice(struct lwp *l, const struct linux32_sys_nice_args *uap, register_t *retval)
647 1.13 njoly {
648 1.17 dsl /* {
649 1.13 njoly syscallarg(int) incr;
650 1.17 dsl } */
651 1.24 njoly struct proc *p = l->l_proc;
652 1.22 njoly struct sys_setpriority_args bsa;
653 1.33 njoly int error;
654 1.13 njoly
655 1.13 njoly SCARG(&bsa, which) = PRIO_PROCESS;
656 1.13 njoly SCARG(&bsa, who) = 0;
657 1.24 njoly SCARG(&bsa, prio) = p->p_nice - NZERO + SCARG(uap, incr);
658 1.13 njoly
659 1.33 njoly error = sys_setpriority(l, &bsa, retval);
660 1.33 njoly return (error) ? EPERM : 0;
661 1.13 njoly }
662 1.13 njoly
663 1.13 njoly int
664 1.17 dsl linux32_sys_alarm(struct lwp *l, const struct linux32_sys_alarm_args *uap, register_t *retval)
665 1.13 njoly {
666 1.17 dsl /* {
667 1.13 njoly syscallarg(unsigned int) secs;
668 1.17 dsl } */
669 1.13 njoly struct linux_sys_alarm_args ua;
670 1.13 njoly
671 1.13 njoly NETBSD32TO64_UAP(secs);
672 1.13 njoly
673 1.13 njoly return linux_sys_alarm(l, &ua, retval);
674 1.13 njoly }
675 1.13 njoly
676 1.13 njoly int
677 1.17 dsl linux32_sys_fdatasync(struct lwp *l, const struct linux32_sys_fdatasync_args *uap, register_t *retval)
678 1.13 njoly {
679 1.17 dsl /* {
680 1.13 njoly syscallarg(int) fd;
681 1.17 dsl } */
682 1.13 njoly struct linux_sys_fdatasync_args ua;
683 1.13 njoly
684 1.13 njoly NETBSD32TO64_UAP(fd);
685 1.13 njoly
686 1.13 njoly return linux_sys_fdatasync(l, &ua, retval);
687 1.13 njoly }
688 1.13 njoly
689 1.13 njoly int
690 1.17 dsl linux32_sys_setfsuid(struct lwp *l, const struct linux32_sys_setfsuid_args *uap, register_t *retval)
691 1.13 njoly {
692 1.17 dsl /* {
693 1.13 njoly syscallarg(uid_t) uid;
694 1.17 dsl } */
695 1.13 njoly struct linux_sys_setfsuid_args ua;
696 1.13 njoly
697 1.13 njoly NETBSD32TO64_UAP(uid);
698 1.13 njoly
699 1.13 njoly return linux_sys_setfsuid(l, &ua, retval);
700 1.13 njoly }
701 1.13 njoly
702 1.13 njoly int
703 1.18 njoly linux32_sys_setfsgid(struct lwp *l, const struct linux32_sys_setfsgid_args *uap, register_t *retval)
704 1.18 njoly {
705 1.18 njoly /* {
706 1.18 njoly syscallarg(gid_t) gid;
707 1.18 njoly } */
708 1.18 njoly struct linux_sys_setfsgid_args ua;
709 1.18 njoly
710 1.18 njoly NETBSD32TO64_UAP(gid);
711 1.18 njoly
712 1.18 njoly return linux_sys_setfsgid(l, &ua, retval);
713 1.18 njoly }
714 1.20 dsl
715 1.20 dsl /*
716 1.20 dsl * pread(2).
717 1.20 dsl */
718 1.20 dsl int
719 1.20 dsl linux32_sys_pread(struct lwp *l,
720 1.20 dsl const struct linux32_sys_pread_args *uap, register_t *retval)
721 1.20 dsl {
722 1.20 dsl /* {
723 1.20 dsl syscallarg(int) fd;
724 1.21 njoly syscallarg(netbsd32_voidp) buf;
725 1.20 dsl syscallarg(netbsd32_size_t) nbyte;
726 1.37 njoly syscallarg(netbsd32_off_t) offset;
727 1.20 dsl } */
728 1.20 dsl struct sys_pread_args pra;
729 1.20 dsl
730 1.20 dsl SCARG(&pra, fd) = SCARG(uap, fd);
731 1.21 njoly SCARG(&pra, buf) = SCARG_P32(uap, buf);
732 1.20 dsl SCARG(&pra, nbyte) = SCARG(uap, nbyte);
733 1.37 njoly SCARG(&pra, PAD) = 0;
734 1.20 dsl SCARG(&pra, offset) = SCARG(uap, offset);
735 1.20 dsl
736 1.20 dsl return sys_pread(l, &pra, retval);
737 1.20 dsl }
738 1.20 dsl
739 1.20 dsl /*
740 1.20 dsl * pwrite(2).
741 1.20 dsl */
742 1.20 dsl int
743 1.20 dsl linux32_sys_pwrite(struct lwp *l,
744 1.20 dsl const struct linux32_sys_pwrite_args *uap, register_t *retval)
745 1.20 dsl {
746 1.20 dsl /* {
747 1.20 dsl syscallarg(int) fd;
748 1.21 njoly syscallarg(const netbsd32_voidp) buf;
749 1.20 dsl syscallarg(netbsd32_size_t) nbyte;
750 1.37 njoly syscallarg(netbsd32_off_t) offset;
751 1.20 dsl } */
752 1.20 dsl struct sys_pwrite_args pra;
753 1.20 dsl
754 1.20 dsl SCARG(&pra, fd) = SCARG(uap, fd);
755 1.21 njoly SCARG(&pra, buf) = SCARG_P32(uap, buf);
756 1.20 dsl SCARG(&pra, nbyte) = SCARG(uap, nbyte);
757 1.37 njoly SCARG(&pra, PAD) = 0;
758 1.20 dsl SCARG(&pra, offset) = SCARG(uap, offset);
759 1.20 dsl
760 1.20 dsl return sys_pwrite(l, &pra, retval);
761 1.20 dsl }
762 1.20 dsl
763