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