xref: /netbsd-src/sys/compat/linux32/common/linux32_unistd.c (revision 0df165c04d0a9ca1adde9ed2b890344c937954a6)
1 /*	$NetBSD: linux32_unistd.c,v 1.14 2007/11/16 12:56:50 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.14 2007/11/16 12:56:50 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 
50 #include <machine/types.h>
51 
52 #include <sys/syscallargs.h>
53 
54 #include <compat/netbsd32/netbsd32.h>
55 #include <compat/netbsd32/netbsd32_conv.h>
56 #include <compat/netbsd32/netbsd32_syscallargs.h>
57 
58 #include <compat/linux/common/linux_types.h>
59 #include <compat/linux/common/linux_signal.h>
60 #include <compat/linux/common/linux_machdep.h>
61 #include <compat/linux/common/linux_misc.h>
62 #include <compat/linux/common/linux_oldolduname.h>
63 #include <compat/linux/linux_syscallargs.h>
64 
65 #include <compat/linux32/common/linux32_types.h>
66 #include <compat/linux32/common/linux32_signal.h>
67 #include <compat/linux32/common/linux32_machdep.h>
68 #include <compat/linux32/common/linux32_sysctl.h>
69 #include <compat/linux32/common/linux32_socketcall.h>
70 #include <compat/linux32/linux32_syscallargs.h>
71 
72 static int linux32_select1(struct lwp *, register_t *,
73     int, fd_set *, fd_set *, fd_set *, struct timeval *);
74 
75 int
76 linux32_sys_brk(l, v, retval)
77 	struct lwp *l;
78 	void *v;
79 	register_t *retval;
80 {
81 	struct linux32_sys_brk_args /* {
82 		syscallarg(netbsd32_charp) nsize;
83 	} */ *uap = v;
84 	struct linux_sys_brk_args ua;
85 
86 	NETBSD32TOP_UAP(nsize, char);
87 	return linux_sys_brk(l, &ua, retval);
88 }
89 
90 int
91 linux32_sys_llseek(l, v, retval)
92 	struct lwp *l;
93 	void *v;
94 	register_t *retval;
95 {
96 	struct linux32_sys_llseek_args /* {
97 		syscallcarg(int) fd;
98                 syscallarg(u_int32_t) ohigh;
99                 syscallarg(u_int32_t) olow;
100 		syscallarg(netbsd32_void *) res;
101 		syscallcarg(int) whence;
102 	} */ *uap = v;
103 	struct linux_sys_llseek_args ua;
104 
105 	NETBSD32TO64_UAP(fd);
106 	NETBSD32TO64_UAP(ohigh);
107 	NETBSD32TO64_UAP(olow);
108 	NETBSD32TOP_UAP(res, char);
109 	NETBSD32TO64_UAP(whence);
110 
111 	return linux_sys_llseek(l, &ua, retval);
112 }
113 
114 int
115 linux32_sys_select(l, v, retval)
116 	struct lwp *l;
117 	void *v;
118 	register_t *retval;
119 {
120 	struct linux32_sys_select_args /* {
121 		syscallarg(int) nfds;
122 		syscallarg(netbsd32_fd_setp_t) readfds;
123 		syscallarg(netbsd32_fd_setp_t) writefds;
124 		syscallarg(netbsd32_fd_setp_t) exceptfds;
125 		syscallarg(netbsd32_timevalp_t) timeout;
126 	} */ *uap = v;
127 
128 	return linux32_select1(l, retval, SCARG(uap, nfds),
129 	    SCARG_P32(uap, readfds),
130 	    SCARG_P32(uap, writefds),
131 	    SCARG_P32(uap, exceptfds),
132 	    SCARG_P32(uap, timeout));
133 }
134 
135 int
136 linux32_sys_oldselect(l, v, retval)
137 	struct lwp *l;
138 	void *v;
139 	register_t *retval;
140 {
141 	struct linux32_sys_oldselect_args /* {
142 		syscallarg(linux32_oldselectp_t) lsp;
143 	} */ *uap = v;
144 	struct linux32_oldselect lsp32;
145 	int error;
146 
147 	if ((error = copyin(SCARG_P32(uap, lsp), &lsp32, sizeof(lsp32))) != 0)
148 		return error;
149 
150 	return linux32_select1(l, retval, lsp32.nfds,
151 	     NETBSD32PTR64(lsp32.readfds), NETBSD32PTR64(lsp32.writefds),
152 	     NETBSD32PTR64(lsp32.exceptfds), NETBSD32PTR64(lsp32.timeout));
153 }
154 
155 static int
156 linux32_select1(l, retval, nfds, readfds, writefds, exceptfds, timeout)
157         struct lwp *l;
158         register_t *retval;
159         int nfds;
160         fd_set *readfds, *writefds, *exceptfds;
161         struct timeval *timeout;
162 {
163 	struct timeval tv0, tv1, utv, *tv = NULL;
164 	struct netbsd32_timeval utv32;
165 	int error;
166 
167 	timerclear(&utv); /* XXX GCC4 */
168 
169 	/*
170 	 * Store current time for computation of the amount of
171 	 * time left.
172 	 */
173 	if (timeout) {
174 		if ((error = copyin(timeout, &utv32, sizeof(utv32))))
175 			return error;
176 
177 		netbsd32_to_timeval(&utv32, &utv);
178 
179 		if (itimerfix(&utv)) {
180 			/*
181 			 * The timeval was invalid.  Convert it to something
182 			 * valid that will act as it does under Linux.
183 			 */
184 			utv.tv_sec += utv.tv_usec / 1000000;
185 			utv.tv_usec %= 1000000;
186 			if (utv.tv_usec < 0) {
187 				utv.tv_sec -= 1;
188 				utv.tv_usec += 1000000;
189 			}
190 			if (utv.tv_sec < 0)
191 				timerclear(&utv);
192 		}
193 		microtime(&tv0);
194 		tv = &utv;
195 	}
196 
197 	error = selcommon(l, retval, nfds,
198 	    readfds, writefds, exceptfds, tv, NULL);
199 
200 	if (error) {
201 		/*
202 		 * See fs/select.c in the Linux kernel.  Without this,
203 		 * Maelstrom doesn't work.
204 		 */
205 		if (error == ERESTART)
206 			error = EINTR;
207 		return error;
208 	}
209 
210 	if (timeout) {
211 		if (*retval) {
212 			/*
213 			 * Compute how much time was left of the timeout,
214 			 * by subtracting the current time and the time
215 			 * before we started the call, and subtracting
216 			 * that result from the user-supplied value.
217 			 */
218 			microtime(&tv1);
219 			timersub(&tv1, &tv0, &tv1);
220 			timersub(&utv, &tv1, &utv);
221 			if (utv.tv_sec < 0)
222 				timerclear(&utv);
223 		} else {
224 			timerclear(&utv);
225 		}
226 
227 		netbsd32_from_timeval(&utv, &utv32);
228 
229 		if ((error = copyout(&utv32, timeout, sizeof(utv32))))
230 			return error;
231 	}
232 
233 	return 0;
234 }
235 
236 int
237 linux32_sys_pipe(l, v, retval)
238 	struct lwp *l;
239 	void *v;
240 	register_t *retval;
241 {
242 	struct linux32_sys_pipe_args /* {
243 		syscallarg(netbsd32_intp) fd;
244 	} */ *uap = v;
245 	int error;
246 	int pfds[2];
247 
248 	if ((error = sys_pipe(l, 0, retval)))
249 		return error;
250 
251 	pfds[0] = (int)retval[0];
252 	pfds[1] = (int)retval[1];
253 
254 	if ((error = copyout(pfds, SCARG_P32(uap, fd), 2 * sizeof (int))) != 0)
255 		return error;
256 
257 	retval[0] = 0;
258 	retval[1] = 0;
259 
260 	return 0;
261 }
262 
263 
264 int
265 linux32_sys_unlink(l, v, retval)
266 	struct lwp *l;
267 	void *v;
268 	register_t *retval;
269 {
270 	struct linux32_sys_unlink_args /* {
271 		syscallarg(const netbsd32_charp) path;
272 	} */ *uap = v;
273 	struct linux_sys_unlink_args ua;
274 
275 	NETBSD32TOP_UAP(path, const char);
276 
277 	return linux_sys_unlink(l, &ua, retval);
278 }
279 
280 int
281 linux32_sys_creat(l, v, retval)
282 	struct lwp *l;
283 	void *v;
284 	register_t *retval;
285 {
286 	struct linux32_sys_creat_args /* {
287 		syscallarg(const netbsd32_charp) path;
288 		syscallarg(int) mode;
289 	} */ *uap = v;
290 	struct sys_open_args ua;
291 
292 	NETBSD32TOP_UAP(path, const char);
293 	SCARG(&ua, flags) = O_CREAT | O_TRUNC | O_WRONLY;
294 	NETBSD32TO64_UAP(mode);
295 
296 	return sys_open(l, &ua, retval);
297 }
298 
299 int
300 linux32_sys_mknod(l, v, retval)
301 	struct lwp *l;
302 	void *v;
303 	register_t *retval;
304 {
305 	struct linux32_sys_mknod_args /* {
306 		syscallarg(const netbsd32_charp) path;
307 		syscallarg(int) mode;
308 		syscallarg(int) dev;
309 	} */ *uap = v;
310 	struct linux_sys_mknod_args ua;
311 
312 	NETBSD32TOP_UAP(path, const char);
313 	NETBSD32TO64_UAP(mode);
314 	NETBSD32TO64_UAP(dev);
315 
316 	return linux_sys_mknod(l, &ua, retval);
317 }
318 
319 int
320 linux32_sys_chown16(l, v, retval)
321 	struct lwp *l;
322 	void *v;
323 	register_t *retval;
324 {
325 	struct linux32_sys_chown16_args /* {
326 		syscallarg(const netbsd32_charp) path;
327 		syscallarg(int) uid;
328 		syscallarg(int) gid;
329 	} */ *uap = v;
330         struct sys___posix_chown_args ua;
331 
332 	NETBSD32TOP_UAP(path, const char);
333 
334         if ((linux32_uid_t)SCARG(uap, uid) == (linux32_uid_t)-1)
335         	SCARG(&ua, uid) = (uid_t)-1;
336 	else
337         	SCARG(&ua, uid) = SCARG(uap, uid);
338 
339         if ((linux32_gid_t)SCARG(uap, gid) == (linux32_gid_t)-1)
340         	SCARG(&ua, gid) = (gid_t)-1;
341 	else
342         	SCARG(&ua, gid) = SCARG(uap, gid);
343 
344         return sys___posix_chown(l, &ua, retval);
345 }
346 
347 int
348 linux32_sys_lchown16(l, v, retval)
349 	struct lwp *l;
350 	void *v;
351 	register_t *retval;
352 {
353 	struct linux32_sys_lchown16_args /* {
354 		syscallarg(const netbsd32_charp) path;
355 		syscallarg(int) uid;
356 		syscallarg(int) gid;
357 	} */ *uap = v;
358         struct sys___posix_lchown_args ua;
359 
360 	NETBSD32TOP_UAP(path, const char);
361 
362         if ((linux32_uid_t)SCARG(uap, uid) == (linux32_uid_t)-1)
363         	SCARG(&ua, uid) = (uid_t)-1;
364 	else
365         	SCARG(&ua, uid) = SCARG(uap, uid);
366 
367         if ((linux32_gid_t)SCARG(uap, gid) == (linux32_gid_t)-1)
368         	SCARG(&ua, gid) = (gid_t)-1;
369 	else
370         	SCARG(&ua, gid) = SCARG(uap, gid);
371 
372         return sys___posix_lchown(l, &ua, retval);
373 }
374 
375 int
376 linux32_sys_break(l, v, retval)
377 	struct lwp *l;
378 	void *v;
379 	register_t *retval;
380 {
381 #if 0
382 	struct linux32_sys_break_args /* {
383 		syscallarg(const netbsd32_charp) nsize;
384 	} */ *uap = v;
385 #endif
386 
387 	return ENOSYS;
388 }
389 
390 int
391 linux32_sys_rename(l, v, retval)
392 	struct lwp *l;
393 	void *v;
394 	register_t *retval;
395 {
396 	struct linux32_sys_rename_args /* {
397 		syscallarg(const netbsd32_charp) from;
398 		syscallarg(const netbsd32_charp) to;
399 	} */ *uap = v;
400 	struct sys_rename_args ua;
401 
402 	NETBSD32TOP_UAP(from, const char);
403 	NETBSD32TOP_UAP(to, const char);
404 
405 	return sys___posix_rename(l, &ua, retval);
406 }
407 
408 int
409 linux32_sys_getgroups16(l, v, retval)
410 	struct lwp *l;
411 	void *v;
412 	register_t *retval;
413 {
414 	struct linux32_sys_getgroups16_args /* {
415 		syscallarg(int) gidsetsize;
416 		syscallarg(linux32_gidp_t) gidset;
417 	} */ *uap = v;
418 	struct linux_sys_getgroups16_args ua;
419 
420 	NETBSD32TO64_UAP(gidsetsize);
421 	NETBSD32TOP_UAP(gidset, linux_gid_t);
422 
423 	return linux_sys_getgroups16(l, &ua, retval);
424 }
425 
426 int
427 linux32_sys_setgroups16(l, v, retval)
428 	struct lwp *l;
429 	void *v;
430 	register_t *retval;
431 {
432 	struct linux32_sys_setgroups16_args /* {
433 		syscallarg(int) gidsetsize;
434 		syscallarg(linux32_gidp_t) gidset;
435 	} */ *uap = v;
436 	struct linux_sys_setgroups16_args ua;
437 
438 	NETBSD32TO64_UAP(gidsetsize);
439 	NETBSD32TOP_UAP(gidset, linux_gid_t);
440 
441 	return linux_sys_setgroups16(l, &ua, retval);
442 }
443 
444 int
445 linux32_sys_swapon(l, v, retval)
446 	struct lwp *l;
447 	void *v;
448 	register_t *retval;
449 {
450 	struct linux32_sys_swapon_args /* {
451 		syscallarg(const netbsd32_charp) name;
452 	} */ *uap = v;
453 	struct sys_swapctl_args ua;
454 
455         SCARG(&ua, cmd) = SWAP_ON;
456         SCARG(&ua, arg) = SCARG_P32(uap, name);
457         SCARG(&ua, misc) = 0;   /* priority */
458         return (sys_swapctl(l, &ua, retval));
459 }
460 
461 int
462 linux32_sys_swapoff(l, v, retval)
463 	struct lwp *l;
464 	void *v;
465 	register_t *retval;
466 {
467 	struct linux32_sys_swapoff_args /* {
468 		syscallarg(const netbsd32_charp) path;
469 	} */ *uap = v;
470 	struct sys_swapctl_args ua;
471 
472         SCARG(&ua, cmd) = SWAP_OFF;
473         SCARG(&ua, arg) = SCARG_P32(uap, path);
474         SCARG(&ua, misc) = 0;   /* priority */
475         return (sys_swapctl(l, &ua, retval));
476 }
477 
478 
479 int
480 linux32_sys_reboot(l, v, retval)
481 	struct lwp *l;
482 	void *v;
483 	register_t *retval;
484 {
485 	struct linux32_sys_reboot_args /* {
486 		syscallarg(int) magic1;
487 		syscallarg(int) magic2;
488 		syscallarg(int) cmd;
489 		syscallarg(netbsd32_voidp) arg;
490 	} */ *uap = v;
491 	struct linux_sys_reboot_args ua;
492 
493 	NETBSD32TO64_UAP(magic1);
494 	NETBSD32TO64_UAP(magic2);
495 	NETBSD32TO64_UAP(cmd);
496 	NETBSD32TOP_UAP(arg, void);
497 
498 	return linux_sys_reboot(l, &ua, retval);
499 }
500 
501 int
502 linux32_sys_truncate(l, v, retval)
503 	struct lwp *l;
504 	void *v;
505 	register_t *retval;
506 {
507 	struct linux32_sys_truncate_args /* {
508 		syscallarg(const netbsd32_charp) path;
509 		syscallarg(netbsd32_charp) buf;
510 		syscallarg(int) count;
511 	} */ *uap = v;
512 	struct compat_43_sys_truncate_args ua;
513 
514 	NETBSD32TOP_UAP(path, const char);
515 	NETBSD32TO64_UAP(length);
516 
517 	return compat_43_sys_truncate(l, &ua, retval);
518 }
519 
520 int
521 linux32_sys_fchown16(l, v, retval)
522 	struct lwp *l;
523 	void *v;
524 	register_t *retval;
525 {
526 	struct linux32_sys_fchown16_args /* {
527 		syscallarg(int) fd;
528 		syscallarg(int) uid;
529 		syscallarg(int) gid;
530 	} */ *uap = v;
531         struct sys___posix_fchown_args ua;
532 
533 	SCARG(&ua, fd) = SCARG(uap, fd);
534 
535         if ((linux32_uid_t)SCARG(uap, uid) == (linux32_uid_t)-1)
536         	SCARG(&ua, uid) = (uid_t)-1;
537 	else
538         	SCARG(&ua, uid) = SCARG(uap, uid);
539 
540         if ((linux32_gid_t)SCARG(uap, gid) == (linux32_gid_t)-1)
541         	SCARG(&ua, gid) = (gid_t)-1;
542 	else
543         	SCARG(&ua, gid) = SCARG(uap, gid);
544 
545         return sys___posix_fchown(l, &ua, retval);
546 }
547 
548 int
549 linux32_sys_setresuid(l, v, retval)
550 	struct lwp *l;
551 	void *v;
552 	register_t *retval;
553 {
554 	struct linux32_sys_setresuid_args /* {
555 		syscallarg(uid_t) ruid;
556 		syscallarg(uid_t) euid;
557 		syscallarg(uid_t) suid;
558 	} */ *uap = v;
559 	struct linux_sys_setresuid_args ua;
560 
561 	SCARG(&ua, ruid) = (SCARG(uap, ruid) == -1) ? -1 : SCARG(uap, ruid);
562 	SCARG(&ua, euid) = (SCARG(uap, euid) == -1) ? -1 : SCARG(uap, euid);
563 	SCARG(&ua, suid) = (SCARG(uap, suid) == -1) ? -1 : SCARG(uap, suid);
564 
565 	return linux_sys_setresuid(l, &ua, retval);
566 }
567 
568 int
569 linux32_sys_setresgid(l, v, retval)
570 	struct lwp *l;
571 	void *v;
572 	register_t *retval;
573 {
574 	struct linux32_sys_setresgid_args /* {
575 		syscallarg(gid_t) rgid;
576 		syscallarg(gid_t) egid;
577 		syscallarg(gid_t) sgid;
578 	} */ *uap = v;
579 	struct linux_sys_setresgid_args ua;
580 
581 	SCARG(&ua, rgid) = (SCARG(uap, rgid) == -1) ? -1 : SCARG(uap, rgid);
582 	SCARG(&ua, egid) = (SCARG(uap, egid) == -1) ? -1 : SCARG(uap, egid);
583 	SCARG(&ua, sgid) = (SCARG(uap, sgid) == -1) ? -1 : SCARG(uap, sgid);
584 
585 	return linux_sys_setresgid(l, &ua, retval);
586 }
587 
588 int
589 linux32_sys_nice(l, v, retval)
590 	struct lwp *l;
591 	void *v;
592 	register_t *retval;
593 {
594 	struct linux32_sys_nice_args /* {
595 		syscallarg(int) incr;
596 	} */ *uap = v;
597 	struct netbsd32_setpriority_args bsa;
598 
599 	SCARG(&bsa, which) = PRIO_PROCESS;
600 	SCARG(&bsa, who) = 0;
601 	SCARG(&bsa, prio) = SCARG(uap, incr);
602 
603 	return netbsd32_setpriority(l, &bsa, retval);
604 }
605 
606 int
607 linux32_sys_alarm(l, v, retval)
608 	struct lwp *l;
609 	void *v;
610 	register_t *retval;
611 {
612 	struct linux32_sys_alarm_args /* {
613 		syscallarg(unsigned int) secs;
614 	} */ *uap = v;
615 	struct linux_sys_alarm_args ua;
616 
617 	NETBSD32TO64_UAP(secs);
618 
619 	return linux_sys_alarm(l, &ua, retval);
620 }
621 
622 int
623 linux32_sys_fdatasync(l, v, retval)
624 	struct lwp *l;
625 	void *v;
626 	register_t *retval;
627 {
628 	struct linux32_sys_fdatasync_args /* {
629 		syscallarg(int) fd;
630 	} */ *uap = v;
631 	struct linux_sys_fdatasync_args ua;
632 
633 	NETBSD32TO64_UAP(fd);
634 
635 	return linux_sys_fdatasync(l, &ua, retval);
636 }
637 
638 int
639 linux32_sys_setfsuid(l, v, retval)
640 	struct lwp *l;
641 	void *v;
642 	register_t *retval;
643 {
644 	struct linux32_sys_setfsuid_args /* {
645 		syscallarg(uid_t) uid;
646 	} */ *uap = v;
647 	struct linux_sys_setfsuid_args ua;
648 
649 	NETBSD32TO64_UAP(uid);
650 
651 	return linux_sys_setfsuid(l, &ua, retval);
652 }
653 
654 int
655 linux32_sys_setreuid16(l, v, retval)
656 	struct lwp *l;
657 	void *v;
658 	register_t *retval;
659 {
660 	struct linux32_sys_setreuid16_args /* {
661 		syscallarg(int) ruid;
662 		syscallarg(int) euid;
663 	} */ *uap = v;
664 	struct sys_setreuid_args bsa;
665 
666 	if ((linux32_uid_t)SCARG(uap, ruid) == (linux32_uid_t)-1)
667 		SCARG(&bsa, ruid) = (uid_t)-1;
668 	else
669 		SCARG(&bsa, ruid) = SCARG(uap, ruid);
670 	if ((linux32_uid_t)SCARG(uap, euid) == (linux32_uid_t)-1)
671 		SCARG(&bsa, euid) = (uid_t)-1;
672 	else
673 		SCARG(&bsa, euid) = SCARG(uap, euid);
674 
675 	return sys_setreuid(l, &bsa, retval);
676 }
677 
678 int
679 linux32_sys_setregid16(l, v, retval)
680 	struct lwp *l;
681 	void *v;
682 	register_t *retval;
683 {
684 	struct linux32_sys_setregid16_args /* {
685 		syscallarg(int) rgid;
686 		syscallarg(int) egid;
687 	} */ *uap = v;
688 	struct sys_setregid_args bsa;
689 
690 	if ((linux32_gid_t)SCARG(uap, rgid) == (linux32_gid_t)-1)
691 		SCARG(&bsa, rgid) = (gid_t)-1;
692 	else
693 		SCARG(&bsa, rgid) = SCARG(uap, rgid);
694 	if ((linux32_gid_t)SCARG(uap, egid) == (linux32_gid_t)-1)
695 		SCARG(&bsa, egid) = (gid_t)-1;
696 	else
697 		SCARG(&bsa, egid) = SCARG(uap, egid);
698 
699 	return sys_setregid(l, &bsa, retval);
700 }
701 
702 int
703 linux32_sys_setresuid16(l, v, retval)
704 	struct lwp *l;
705 	void *v;
706 	register_t *retval;
707 {
708 	struct linux32_sys_setresuid16_args /* {
709 		syscallarg(uid_t) ruid;
710 		syscallarg(uid_t) euid;
711 		syscallarg(uid_t) suid;
712 	} */ *uap = v;
713 	struct linux32_sys_setresuid_args lsa;
714 
715 	if ((linux32_uid_t)SCARG(uap, ruid) == (linux32_uid_t)-1)
716 		SCARG(&lsa, ruid) = (uid_t)-1;
717 	else
718 		SCARG(&lsa, ruid) = SCARG(uap, ruid);
719 	if ((linux32_uid_t)SCARG(uap, euid) == (linux32_uid_t)-1)
720 		SCARG(&lsa, euid) = (uid_t)-1;
721 	else
722 		SCARG(&lsa, euid) = SCARG(uap, euid);
723 	if ((linux32_uid_t)SCARG(uap, suid) == (linux32_uid_t)-1)
724 		SCARG(&lsa, suid) = (uid_t)-1;
725 	else
726 		SCARG(&lsa, suid) = SCARG(uap, euid);
727 
728 	return linux32_sys_setresuid(l, &lsa, retval);
729 }
730 
731 int
732 linux32_sys_setresgid16(l, v, retval)
733 	struct lwp *l;
734 	void *v;
735 	register_t *retval;
736 {
737 	struct linux32_sys_setresgid16_args /* {
738 		syscallarg(gid_t) rgid;
739 		syscallarg(gid_t) egid;
740 		syscallarg(gid_t) sgid;
741 	} */ *uap = v;
742 	struct linux32_sys_setresgid_args lsa;
743 
744 	if ((linux32_gid_t)SCARG(uap, rgid) == (linux32_gid_t)-1)
745 		SCARG(&lsa, rgid) = (gid_t)-1;
746 	else
747 		SCARG(&lsa, rgid) = SCARG(uap, rgid);
748 	if ((linux32_gid_t)SCARG(uap, egid) == (linux32_gid_t)-1)
749 		SCARG(&lsa, egid) = (gid_t)-1;
750 	else
751 		SCARG(&lsa, egid) = SCARG(uap, egid);
752 	if ((linux32_gid_t)SCARG(uap, sgid) == (linux32_gid_t)-1)
753 		SCARG(&lsa, sgid) = (gid_t)-1;
754 	else
755 		SCARG(&lsa, sgid) = SCARG(uap, sgid);
756 
757 	return linux32_sys_setresgid(l, &lsa, retval);
758 }
759