linux_misc.c revision 1.194.2.3 1 /* $NetBSD: linux_misc.c,v 1.194.2.3 2008/11/20 20:45:38 christos Exp $ */
2
3 /*-
4 * Copyright (c) 1995, 1998, 1999, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Frank van der Linden and Eric Haszlakiewicz; by Jason R. Thorpe
9 * of the Numerical Aerospace Simulation Facility, NASA Ames Research Center.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /*
34 * Linux compatibility module. Try to deal with various Linux system calls.
35 */
36
37 /*
38 * These functions have been moved to multiarch to allow
39 * selection of which machines include them to be
40 * determined by the individual files.linux_<arch> files.
41 *
42 * Function in multiarch:
43 * linux_sys_break : linux_break.c
44 * linux_sys_alarm : linux_misc_notalpha.c
45 * linux_sys_getresgid : linux_misc_notalpha.c
46 * linux_sys_nice : linux_misc_notalpha.c
47 * linux_sys_readdir : linux_misc_notalpha.c
48 * linux_sys_setresgid : linux_misc_notalpha.c
49 * linux_sys_time : linux_misc_notalpha.c
50 * linux_sys_utime : linux_misc_notalpha.c
51 * linux_sys_waitpid : linux_misc_notalpha.c
52 * linux_sys_old_mmap : linux_oldmmap.c
53 * linux_sys_oldolduname : linux_oldolduname.c
54 * linux_sys_oldselect : linux_oldselect.c
55 * linux_sys_olduname : linux_olduname.c
56 * linux_sys_pipe : linux_pipe.c
57 */
58
59 #include <sys/cdefs.h>
60 __KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.194.2.3 2008/11/20 20:45:38 christos Exp $");
61
62 #include <sys/param.h>
63 #include <sys/systm.h>
64 #include <sys/namei.h>
65 #include <sys/proc.h>
66 #include <sys/dirent.h>
67 #include <sys/file.h>
68 #include <sys/stat.h>
69 #include <sys/filedesc.h>
70 #include <sys/ioctl.h>
71 #include <sys/kernel.h>
72 #include <sys/malloc.h>
73 #include <sys/mbuf.h>
74 #include <sys/mman.h>
75 #include <sys/mount.h>
76 #include <sys/prot.h>
77 #include <sys/reboot.h>
78 #include <sys/resource.h>
79 #include <sys/resourcevar.h>
80 #include <sys/select.h>
81 #include <sys/signal.h>
82 #include <sys/signalvar.h>
83 #include <sys/socket.h>
84 #include <sys/time.h>
85 #include <sys/times.h>
86 #include <sys/vnode.h>
87 #include <sys/uio.h>
88 #include <sys/wait.h>
89 #include <sys/utsname.h>
90 #include <sys/unistd.h>
91 #include <sys/vfs_syscalls.h>
92 #include <sys/swap.h> /* for SWAP_ON */
93 #include <sys/sysctl.h> /* for KERN_DOMAINNAME */
94 #include <sys/kauth.h>
95
96 #include <sys/ptrace.h>
97 #include <machine/ptrace.h>
98
99 #include <sys/syscall.h>
100 #include <sys/syscallargs.h>
101
102 #include <compat/linux/common/linux_machdep.h>
103 #include <compat/linux/common/linux_types.h>
104 #include <compat/linux/common/linux_signal.h>
105 #include <compat/linux/common/linux_ipc.h>
106 #include <compat/linux/common/linux_sem.h>
107
108 #include <compat/linux/linux_syscallargs.h>
109
110 #include <compat/linux/common/linux_fcntl.h>
111 #include <compat/linux/common/linux_mmap.h>
112 #include <compat/linux/common/linux_dirent.h>
113 #include <compat/linux/common/linux_util.h>
114 #include <compat/linux/common/linux_misc.h>
115 #ifndef COMPAT_LINUX32
116 #include <compat/linux/common/linux_statfs.h>
117 #include <compat/linux/common/linux_limit.h>
118 #endif
119 #include <compat/linux/common/linux_ptrace.h>
120 #include <compat/linux/common/linux_reboot.h>
121 #include <compat/linux/common/linux_emuldata.h>
122
123 #ifndef COMPAT_LINUX32
124 const int linux_ptrace_request_map[] = {
125 LINUX_PTRACE_TRACEME, PT_TRACE_ME,
126 LINUX_PTRACE_PEEKTEXT, PT_READ_I,
127 LINUX_PTRACE_PEEKDATA, PT_READ_D,
128 LINUX_PTRACE_POKETEXT, PT_WRITE_I,
129 LINUX_PTRACE_POKEDATA, PT_WRITE_D,
130 LINUX_PTRACE_CONT, PT_CONTINUE,
131 LINUX_PTRACE_KILL, PT_KILL,
132 LINUX_PTRACE_ATTACH, PT_ATTACH,
133 LINUX_PTRACE_DETACH, PT_DETACH,
134 # ifdef PT_STEP
135 LINUX_PTRACE_SINGLESTEP, PT_STEP,
136 # endif
137 LINUX_PTRACE_SYSCALL, PT_SYSCALL,
138 -1
139 };
140
141 const struct linux_mnttypes linux_fstypes[] = {
142 { MOUNT_FFS, LINUX_DEFAULT_SUPER_MAGIC },
143 { MOUNT_NFS, LINUX_NFS_SUPER_MAGIC },
144 { MOUNT_MFS, LINUX_DEFAULT_SUPER_MAGIC },
145 { MOUNT_MSDOS, LINUX_MSDOS_SUPER_MAGIC },
146 { MOUNT_LFS, LINUX_DEFAULT_SUPER_MAGIC },
147 { MOUNT_FDESC, LINUX_DEFAULT_SUPER_MAGIC },
148 { MOUNT_PORTAL, LINUX_DEFAULT_SUPER_MAGIC },
149 { MOUNT_NULL, LINUX_DEFAULT_SUPER_MAGIC },
150 { MOUNT_OVERLAY, LINUX_DEFAULT_SUPER_MAGIC },
151 { MOUNT_UMAP, LINUX_DEFAULT_SUPER_MAGIC },
152 { MOUNT_KERNFS, LINUX_DEFAULT_SUPER_MAGIC },
153 { MOUNT_PROCFS, LINUX_PROC_SUPER_MAGIC },
154 { MOUNT_AFS, LINUX_DEFAULT_SUPER_MAGIC },
155 { MOUNT_CD9660, LINUX_ISOFS_SUPER_MAGIC },
156 { MOUNT_UNION, LINUX_DEFAULT_SUPER_MAGIC },
157 { MOUNT_ADOSFS, LINUX_ADFS_SUPER_MAGIC },
158 { MOUNT_EXT2FS, LINUX_EXT2_SUPER_MAGIC },
159 { MOUNT_CFS, LINUX_DEFAULT_SUPER_MAGIC },
160 { MOUNT_CODA, LINUX_CODA_SUPER_MAGIC },
161 { MOUNT_FILECORE, LINUX_DEFAULT_SUPER_MAGIC },
162 { MOUNT_NTFS, LINUX_DEFAULT_SUPER_MAGIC },
163 { MOUNT_SMBFS, LINUX_SMB_SUPER_MAGIC },
164 { MOUNT_PTYFS, LINUX_DEVPTS_SUPER_MAGIC },
165 { MOUNT_TMPFS, LINUX_TMPFS_SUPER_MAGIC }
166 };
167 const int linux_fstypes_cnt = sizeof(linux_fstypes) / sizeof(linux_fstypes[0]);
168
169 # ifdef DEBUG_LINUX
170 #define DPRINTF(a) uprintf a
171 # else
172 #define DPRINTF(a)
173 # endif
174
175 /* Local linux_misc.c functions: */
176 static void linux_to_bsd_mmap_args(struct sys_mmap_args *,
177 const struct linux_sys_mmap_args *);
178 static int linux_mmap(struct lwp *, const struct linux_sys_mmap_args *,
179 register_t *, off_t);
180
181
182 /*
183 * The information on a terminated (or stopped) process needs
184 * to be converted in order for Linux binaries to get a valid signal
185 * number out of it.
186 */
187 int
188 bsd_to_linux_wstat(int st)
189 {
190
191 int sig;
192
193 if (WIFSIGNALED(st)) {
194 sig = WTERMSIG(st);
195 if (sig >= 0 && sig < NSIG)
196 st= (st & ~0177) | native_to_linux_signo[sig];
197 } else if (WIFSTOPPED(st)) {
198 sig = WSTOPSIG(st);
199 if (sig >= 0 && sig < NSIG)
200 st = (st & ~0xff00) |
201 (native_to_linux_signo[sig] << 8);
202 }
203 return st;
204 }
205
206 /*
207 * wait4(2). Passed on to the NetBSD call, surrounded by code to
208 * reserve some space for a NetBSD-style wait status, and converting
209 * it to what Linux wants.
210 */
211 int
212 linux_sys_wait4(struct lwp *l, const struct linux_sys_wait4_args *uap, register_t *retval)
213 {
214 /* {
215 syscallarg(int) pid;
216 syscallarg(int *) status;
217 syscallarg(int) options;
218 syscallarg(struct rusage *) rusage;
219 } */
220 int error, status, options, linux_options, was_zombie;
221 struct rusage ru;
222 int pid = SCARG(uap, pid);
223 proc_t *p;
224
225 linux_options = SCARG(uap, options);
226 options = WOPTSCHECKED;
227 if (linux_options & ~(LINUX_WAIT4_KNOWNFLAGS))
228 return (EINVAL);
229
230 if (linux_options & LINUX_WAIT4_WNOHANG)
231 options |= WNOHANG;
232 if (linux_options & LINUX_WAIT4_WUNTRACED)
233 options |= WUNTRACED;
234 if (linux_options & LINUX_WAIT4_WALL)
235 options |= WALLSIG;
236 if (linux_options & LINUX_WAIT4_WCLONE)
237 options |= WALTSIG;
238 # ifdef DIAGNOSTIC
239 if (linux_options & LINUX_WAIT4_WNOTHREAD)
240 printf("WARNING: %s: linux process %d.%d called "
241 "waitpid with __WNOTHREAD set!",
242 __FILE__, l->l_proc->p_pid, l->l_lid);
243
244 # endif
245
246 error = do_sys_wait(l, &pid, &status, options,
247 SCARG(uap, rusage) != NULL ? &ru : NULL, &was_zombie);
248
249 retval[0] = pid;
250 if (pid == 0)
251 return error;
252
253 p = curproc;
254 mutex_enter(p->p_lock);
255 sigdelset(&p->p_sigpend.sp_set, SIGCHLD); /* XXXAD ksiginfo leak */
256 mutex_exit(p->p_lock);
257
258 if (SCARG(uap, rusage) != NULL)
259 error = copyout(&ru, SCARG(uap, rusage), sizeof(ru));
260
261 if (error == 0 && SCARG(uap, status) != NULL) {
262 status = bsd_to_linux_wstat(status);
263 error = copyout(&status, SCARG(uap, status), sizeof status);
264 }
265
266 return error;
267 }
268
269 /*
270 * Linux brk(2). The check if the new address is >= the old one is
271 * done in the kernel in Linux. NetBSD does it in the library.
272 */
273 int
274 linux_sys_brk(struct lwp *l, const struct linux_sys_brk_args *uap, register_t *retval)
275 {
276 /* {
277 syscallarg(char *) nsize;
278 } */
279 struct proc *p = l->l_proc;
280 char *nbrk = SCARG(uap, nsize);
281 struct sys_obreak_args oba;
282 struct vmspace *vm = p->p_vmspace;
283 struct linux_emuldata *ed = (struct linux_emuldata*)p->p_emuldata;
284
285 SCARG(&oba, nsize) = nbrk;
286
287 if ((void *) nbrk > vm->vm_daddr && sys_obreak(l, &oba, retval) == 0)
288 ed->s->p_break = (char*)nbrk;
289 else
290 nbrk = ed->s->p_break;
291
292 retval[0] = (register_t)nbrk;
293
294 return 0;
295 }
296
297 /*
298 * Implement the fs stat functions. Straightforward.
299 */
300 int
301 linux_sys_statfs(struct lwp *l, const struct linux_sys_statfs_args *uap, register_t *retval)
302 {
303 /* {
304 syscallarg(const char *) path;
305 syscallarg(struct linux_statfs *) sp;
306 } */
307 struct statvfs *sb;
308 struct linux_statfs ltmp;
309 int error;
310
311 sb = STATVFSBUF_GET();
312 error = do_sys_pstatvfs(l, SCARG(uap, path), ST_WAIT, sb);
313 if (error == 0) {
314 bsd_to_linux_statfs(sb, <mp);
315 error = copyout(<mp, SCARG(uap, sp), sizeof ltmp);
316 }
317 STATVFSBUF_PUT(sb);
318
319 return error;
320 }
321
322 int
323 linux_sys_fstatfs(struct lwp *l, const struct linux_sys_fstatfs_args *uap, register_t *retval)
324 {
325 /* {
326 syscallarg(int) fd;
327 syscallarg(struct linux_statfs *) sp;
328 } */
329 struct statvfs *sb;
330 struct linux_statfs ltmp;
331 int error;
332
333 sb = STATVFSBUF_GET();
334 error = do_sys_fstatvfs(l, SCARG(uap, fd), ST_WAIT, sb);
335 if (error == 0) {
336 bsd_to_linux_statfs(sb, <mp);
337 error = copyout(<mp, SCARG(uap, sp), sizeof ltmp);
338 }
339 STATVFSBUF_PUT(sb);
340
341 return error;
342 }
343
344 /*
345 * uname(). Just copy the info from the various strings stored in the
346 * kernel, and put it in the Linux utsname structure. That structure
347 * is almost the same as the NetBSD one, only it has fields 65 characters
348 * long, and an extra domainname field.
349 */
350 int
351 linux_sys_uname(struct lwp *l, const struct linux_sys_uname_args *uap, register_t *retval)
352 {
353 /* {
354 syscallarg(struct linux_utsname *) up;
355 } */
356 struct linux_utsname luts;
357
358 strlcpy(luts.l_sysname, linux_sysname, sizeof(luts.l_sysname));
359 strlcpy(luts.l_nodename, hostname, sizeof(luts.l_nodename));
360 strlcpy(luts.l_release, linux_release, sizeof(luts.l_release));
361 strlcpy(luts.l_version, linux_version, sizeof(luts.l_version));
362 strlcpy(luts.l_machine, LINUX_UNAME_ARCH, sizeof(luts.l_machine));
363 strlcpy(luts.l_domainname, domainname, sizeof(luts.l_domainname));
364
365 return copyout(&luts, SCARG(uap, up), sizeof(luts));
366 }
367
368 /* Used directly on: alpha, mips, ppc, sparc, sparc64 */
369 /* Used indirectly on: arm, i386, m68k */
370
371 /*
372 * New type Linux mmap call.
373 * Only called directly on machines with >= 6 free regs.
374 */
375 int
376 linux_sys_mmap(struct lwp *l, const struct linux_sys_mmap_args *uap, register_t *retval)
377 {
378 /* {
379 syscallarg(unsigned long) addr;
380 syscallarg(size_t) len;
381 syscallarg(int) prot;
382 syscallarg(int) flags;
383 syscallarg(int) fd;
384 syscallarg(linux_off_t) offset;
385 } */
386
387 if (SCARG(uap, offset) & PAGE_MASK)
388 return EINVAL;
389
390 return linux_mmap(l, uap, retval, SCARG(uap, offset));
391 }
392
393 /*
394 * Guts of most architectures' mmap64() implementations. This shares
395 * its list of arguments with linux_sys_mmap().
396 *
397 * The difference in linux_sys_mmap2() is that "offset" is actually
398 * (offset / pagesize), not an absolute byte count. This translation
399 * to pagesize offsets is done inside glibc between the mmap64() call
400 * point, and the actual syscall.
401 */
402 int
403 linux_sys_mmap2(struct lwp *l, const struct linux_sys_mmap2_args *uap, register_t *retval)
404 {
405 /* {
406 syscallarg(unsigned long) addr;
407 syscallarg(size_t) len;
408 syscallarg(int) prot;
409 syscallarg(int) flags;
410 syscallarg(int) fd;
411 syscallarg(linux_off_t) offset;
412 } */
413
414 return linux_mmap(l, uap, retval,
415 ((off_t)SCARG(uap, offset)) << PAGE_SHIFT);
416 }
417
418 /*
419 * Massage arguments and call system mmap(2).
420 */
421 static int
422 linux_mmap(struct lwp *l, const struct linux_sys_mmap_args *uap, register_t *retval, off_t offset)
423 {
424 struct sys_mmap_args cma;
425 int error;
426 size_t mmoff=0;
427
428 linux_to_bsd_mmap_args(&cma, uap);
429 SCARG(&cma, pos) = offset;
430
431 if (SCARG(uap, flags) & LINUX_MAP_GROWSDOWN) {
432 /*
433 * Request for stack-like memory segment. On linux, this
434 * works by mmap()ping (small) segment, which is automatically
435 * extended when page fault happens below the currently
436 * allocated area. We emulate this by allocating (typically
437 * bigger) segment sized at current stack size limit, and
438 * offsetting the requested and returned address accordingly.
439 * Since physical pages are only allocated on-demand, this
440 * is effectively identical.
441 */
442 rlim_t ssl = l->l_proc->p_rlimit[RLIMIT_STACK].rlim_cur;
443
444 if (SCARG(&cma, len) < ssl) {
445 /* Compute the address offset */
446 mmoff = round_page(ssl) - SCARG(uap, len);
447
448 if (SCARG(&cma, addr))
449 SCARG(&cma, addr) = (char *)SCARG(&cma, addr) - mmoff;
450
451 SCARG(&cma, len) = (size_t) ssl;
452 }
453 }
454
455 error = sys_mmap(l, &cma, retval);
456 if (error)
457 return (error);
458
459 /* Shift the returned address for stack-like segment if necessary */
460 retval[0] += mmoff;
461
462 return (0);
463 }
464
465 static void
466 linux_to_bsd_mmap_args(struct sys_mmap_args *cma, const struct linux_sys_mmap_args *uap)
467 {
468 int flags = MAP_TRYFIXED, fl = SCARG(uap, flags);
469
470 flags |= cvtto_bsd_mask(fl, LINUX_MAP_SHARED, MAP_SHARED);
471 flags |= cvtto_bsd_mask(fl, LINUX_MAP_PRIVATE, MAP_PRIVATE);
472 flags |= cvtto_bsd_mask(fl, LINUX_MAP_FIXED, MAP_FIXED);
473 flags |= cvtto_bsd_mask(fl, LINUX_MAP_ANON, MAP_ANON);
474 /* XXX XAX ERH: Any other flags here? There are more defined... */
475
476 SCARG(cma, addr) = (void *)SCARG(uap, addr);
477 SCARG(cma, len) = SCARG(uap, len);
478 SCARG(cma, prot) = SCARG(uap, prot);
479 if (SCARG(cma, prot) & VM_PROT_WRITE) /* XXX */
480 SCARG(cma, prot) |= VM_PROT_READ;
481 SCARG(cma, flags) = flags;
482 SCARG(cma, fd) = flags & MAP_ANON ? -1 : SCARG(uap, fd);
483 SCARG(cma, pad) = 0;
484 }
485
486 #define LINUX_MREMAP_MAYMOVE 1
487 #define LINUX_MREMAP_FIXED 2
488
489 int
490 linux_sys_mremap(struct lwp *l, const struct linux_sys_mremap_args *uap, register_t *retval)
491 {
492 /* {
493 syscallarg(void *) old_address;
494 syscallarg(size_t) old_size;
495 syscallarg(size_t) new_size;
496 syscallarg(u_long) flags;
497 } */
498
499 struct proc *p;
500 struct vm_map *map;
501 vaddr_t oldva;
502 vaddr_t newva;
503 size_t oldsize;
504 size_t newsize;
505 int flags;
506 int uvmflags;
507 int error;
508
509 flags = SCARG(uap, flags);
510 oldva = (vaddr_t)SCARG(uap, old_address);
511 oldsize = round_page(SCARG(uap, old_size));
512 newsize = round_page(SCARG(uap, new_size));
513 if ((flags & ~(LINUX_MREMAP_FIXED|LINUX_MREMAP_MAYMOVE)) != 0) {
514 error = EINVAL;
515 goto done;
516 }
517 if ((flags & LINUX_MREMAP_FIXED) != 0) {
518 if ((flags & LINUX_MREMAP_MAYMOVE) == 0) {
519 error = EINVAL;
520 goto done;
521 }
522 #if 0 /* notyet */
523 newva = SCARG(uap, new_address);
524 uvmflags = MAP_FIXED;
525 #else /* notyet */
526 error = EOPNOTSUPP;
527 goto done;
528 #endif /* notyet */
529 } else if ((flags & LINUX_MREMAP_MAYMOVE) != 0) {
530 uvmflags = 0;
531 } else {
532 newva = oldva;
533 uvmflags = MAP_FIXED;
534 }
535 p = l->l_proc;
536 map = &p->p_vmspace->vm_map;
537 error = uvm_mremap(map, oldva, oldsize, map, &newva, newsize, p,
538 uvmflags);
539
540 done:
541 *retval = (error != 0) ? 0 : (register_t)newva;
542 return error;
543 }
544
545 int
546 linux_sys_mprotect(struct lwp *l, const struct linux_sys_mprotect_args *uap, register_t *retval)
547 {
548 /* {
549 syscallarg(const void *) start;
550 syscallarg(unsigned long) len;
551 syscallarg(int) prot;
552 } */
553 struct vm_map_entry *entry;
554 struct vm_map *map;
555 struct proc *p;
556 vaddr_t end, start, len, stacklim;
557 int prot, grows;
558
559 start = (vaddr_t)SCARG(uap, start);
560 len = round_page(SCARG(uap, len));
561 prot = SCARG(uap, prot);
562 grows = prot & (LINUX_PROT_GROWSDOWN | LINUX_PROT_GROWSUP);
563 prot &= ~grows;
564 end = start + len;
565
566 if (start & PAGE_MASK)
567 return EINVAL;
568 if (end < start)
569 return EINVAL;
570 if (end == start)
571 return 0;
572
573 if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
574 return EINVAL;
575 if (grows == (LINUX_PROT_GROWSDOWN | LINUX_PROT_GROWSUP))
576 return EINVAL;
577
578 p = l->l_proc;
579 map = &p->p_vmspace->vm_map;
580 vm_map_lock(map);
581 # ifdef notdef
582 VM_MAP_RANGE_CHECK(map, start, end);
583 # endif
584 if (!uvm_map_lookup_entry(map, start, &entry) || entry->start > start) {
585 vm_map_unlock(map);
586 return ENOMEM;
587 }
588
589 /*
590 * Approximate the behaviour of PROT_GROWS{DOWN,UP}.
591 */
592
593 stacklim = (vaddr_t)p->p_limit->pl_rlimit[RLIMIT_STACK].rlim_cur;
594 if (grows & LINUX_PROT_GROWSDOWN) {
595 if (USRSTACK - stacklim <= start && start < USRSTACK) {
596 start = USRSTACK - stacklim;
597 } else {
598 start = entry->start;
599 }
600 } else if (grows & LINUX_PROT_GROWSUP) {
601 if (USRSTACK <= end && end < USRSTACK + stacklim) {
602 end = USRSTACK + stacklim;
603 } else {
604 end = entry->end;
605 }
606 }
607 vm_map_unlock(map);
608 return uvm_map_protect(map, start, end, prot, FALSE);
609 }
610
611 /*
612 * This code is partly stolen from src/lib/libc/compat-43/times.c
613 */
614
615 #define CONVTCK(r) (r.tv_sec * hz + r.tv_usec / (1000000 / hz))
616
617 int
618 linux_sys_times(struct lwp *l, const struct linux_sys_times_args *uap, register_t *retval)
619 {
620 /* {
621 syscallarg(struct times *) tms;
622 } */
623 struct proc *p = l->l_proc;
624 struct timeval t;
625 int error;
626
627 if (SCARG(uap, tms)) {
628 struct linux_tms ltms;
629 struct rusage ru;
630
631 mutex_enter(p->p_lock);
632 calcru(p, &ru.ru_utime, &ru.ru_stime, NULL, NULL);
633 ltms.ltms_utime = CONVTCK(ru.ru_utime);
634 ltms.ltms_stime = CONVTCK(ru.ru_stime);
635 ltms.ltms_cutime = CONVTCK(p->p_stats->p_cru.ru_utime);
636 ltms.ltms_cstime = CONVTCK(p->p_stats->p_cru.ru_stime);
637 mutex_exit(p->p_lock);
638
639 if ((error = copyout(<ms, SCARG(uap, tms), sizeof ltms)))
640 return error;
641 }
642
643 getmicrouptime(&t);
644
645 retval[0] = ((linux_clock_t)(CONVTCK(t)));
646 return 0;
647 }
648
649 #undef CONVTCK
650
651 /*
652 * Linux 'readdir' call. This code is mostly taken from the
653 * SunOS getdents call (see compat/sunos/sunos_misc.c), though
654 * an attempt has been made to keep it a little cleaner (failing
655 * miserably, because of the cruft needed if count 1 is passed).
656 *
657 * The d_off field should contain the offset of the next valid entry,
658 * but in Linux it has the offset of the entry itself. We emulate
659 * that bug here.
660 *
661 * Read in BSD-style entries, convert them, and copy them out.
662 *
663 * Note that this doesn't handle union-mounted filesystems.
664 */
665 int
666 linux_sys_getdents(struct lwp *l, const struct linux_sys_getdents_args *uap, register_t *retval)
667 {
668 /* {
669 syscallarg(int) fd;
670 syscallarg(struct linux_dirent *) dent;
671 syscallarg(unsigned int) count;
672 } */
673 struct dirent *bdp;
674 struct vnode *vp;
675 char *inp, *tbuf; /* BSD-format */
676 int len, reclen; /* BSD-format */
677 char *outp; /* Linux-format */
678 int resid, linux_reclen = 0; /* Linux-format */
679 struct file *fp;
680 struct uio auio;
681 struct iovec aiov;
682 struct linux_dirent idb;
683 off_t off; /* true file offset */
684 int buflen, error, eofflag, nbytes, oldcall;
685 struct vattr va;
686 off_t *cookiebuf = NULL, *cookie;
687 int ncookies;
688
689 /* fd_getvnode() will use the descriptor for us */
690 if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
691 return (error);
692
693 if ((fp->f_flag & FREAD) == 0) {
694 error = EBADF;
695 goto out1;
696 }
697
698 vp = (struct vnode *)fp->f_data;
699 if (vp->v_type != VDIR) {
700 error = EINVAL;
701 goto out1;
702 }
703
704 if ((error = VOP_GETATTR(vp, &va, l->l_cred)))
705 goto out1;
706
707 nbytes = SCARG(uap, count);
708 if (nbytes == 1) { /* emulating old, broken behaviour */
709 nbytes = sizeof (idb);
710 buflen = max(va.va_blocksize, nbytes);
711 oldcall = 1;
712 } else {
713 buflen = min(MAXBSIZE, nbytes);
714 if (buflen < va.va_blocksize)
715 buflen = va.va_blocksize;
716 oldcall = 0;
717 }
718 tbuf = malloc(buflen, M_TEMP, M_WAITOK);
719
720 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
721 off = fp->f_offset;
722 again:
723 aiov.iov_base = tbuf;
724 aiov.iov_len = buflen;
725 auio.uio_iov = &aiov;
726 auio.uio_iovcnt = 1;
727 auio.uio_rw = UIO_READ;
728 auio.uio_resid = buflen;
729 auio.uio_offset = off;
730 UIO_SETUP_SYSSPACE(&auio);
731 /*
732 * First we read into the malloc'ed buffer, then
733 * we massage it into user space, one record at a time.
734 */
735 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &cookiebuf,
736 &ncookies);
737 if (error)
738 goto out;
739
740 inp = tbuf;
741 outp = (void *)SCARG(uap, dent);
742 resid = nbytes;
743 if ((len = buflen - auio.uio_resid) == 0)
744 goto eof;
745
746 for (cookie = cookiebuf; len > 0; len -= reclen) {
747 bdp = (struct dirent *)inp;
748 reclen = bdp->d_reclen;
749 if (reclen & 3)
750 panic("linux_readdir");
751 if (bdp->d_fileno == 0) {
752 inp += reclen; /* it is a hole; squish it out */
753 if (cookie)
754 off = *cookie++;
755 else
756 off += reclen;
757 continue;
758 }
759 linux_reclen = LINUX_RECLEN(&idb, bdp->d_namlen);
760 if (reclen > len || resid < linux_reclen) {
761 /* entry too big for buffer, so just stop */
762 outp++;
763 break;
764 }
765 /*
766 * Massage in place to make a Linux-shaped dirent (otherwise
767 * we have to worry about touching user memory outside of
768 * the copyout() call).
769 */
770 idb.d_ino = bdp->d_fileno;
771 /*
772 * The old readdir() call misuses the offset and reclen fields.
773 */
774 if (oldcall) {
775 idb.d_off = (linux_off_t)linux_reclen;
776 idb.d_reclen = (u_short)bdp->d_namlen;
777 } else {
778 if (sizeof (idb.d_off) <= 4 && (off >> 32) != 0) {
779 compat_offseterr(vp, "linux_getdents");
780 error = EINVAL;
781 goto out;
782 }
783 idb.d_off = (linux_off_t)off;
784 idb.d_reclen = (u_short)linux_reclen;
785 }
786 strcpy(idb.d_name, bdp->d_name);
787 if ((error = copyout((void *)&idb, outp, linux_reclen)))
788 goto out;
789 /* advance past this real entry */
790 inp += reclen;
791 if (cookie)
792 off = *cookie++; /* each entry points to itself */
793 else
794 off += reclen;
795 /* advance output past Linux-shaped entry */
796 outp += linux_reclen;
797 resid -= linux_reclen;
798 if (oldcall)
799 break;
800 }
801
802 /* if we squished out the whole block, try again */
803 if (outp == (void *)SCARG(uap, dent))
804 goto again;
805 fp->f_offset = off; /* update the vnode offset */
806
807 if (oldcall)
808 nbytes = resid + linux_reclen;
809
810 eof:
811 *retval = nbytes - resid;
812 out:
813 VOP_UNLOCK(vp, 0);
814 if (cookiebuf)
815 free(cookiebuf, M_TEMP);
816 free(tbuf, M_TEMP);
817 out1:
818 fd_putfile(SCARG(uap, fd));
819 return error;
820 }
821
822 /*
823 * Even when just using registers to pass arguments to syscalls you can
824 * have 5 of them on the i386. So this newer version of select() does
825 * this.
826 */
827 int
828 linux_sys_select(struct lwp *l, const struct linux_sys_select_args *uap, register_t *retval)
829 {
830 /* {
831 syscallarg(int) nfds;
832 syscallarg(fd_set *) readfds;
833 syscallarg(fd_set *) writefds;
834 syscallarg(fd_set *) exceptfds;
835 syscallarg(struct timeval50 *) timeout;
836 } */
837
838 return linux_select1(l, retval, SCARG(uap, nfds), SCARG(uap, readfds),
839 SCARG(uap, writefds), SCARG(uap, exceptfds),
840 (struct linux_timeval *)SCARG(uap, timeout));
841 }
842
843 /*
844 * Common code for the old and new versions of select(). A couple of
845 * things are important:
846 * 1) return the amount of time left in the 'timeout' parameter
847 * 2) select never returns ERESTART on Linux, always return EINTR
848 */
849 int
850 linux_select1(l, retval, nfds, readfds, writefds, exceptfds, timeout)
851 struct lwp *l;
852 register_t *retval;
853 int nfds;
854 fd_set *readfds, *writefds, *exceptfds;
855 struct linux_timeval *timeout;
856 {
857 struct timeval tv0, tv1, utv, *tv = NULL;
858 struct linux_timeval ltv;
859 int error;
860
861 /*
862 * Store current time for computation of the amount of
863 * time left.
864 */
865 if (timeout) {
866 if ((error = copyin(timeout, <v, sizeof(ltv))))
867 return error;
868 utv.tv_sec = ltv.tv_sec;
869 utv.tv_usec = ltv.tv_usec;
870 if (itimerfix(&utv)) {
871 /*
872 * The timeval was invalid. Convert it to something
873 * valid that will act as it does under Linux.
874 */
875 utv.tv_sec += utv.tv_usec / 1000000;
876 utv.tv_usec %= 1000000;
877 if (utv.tv_usec < 0) {
878 utv.tv_sec -= 1;
879 utv.tv_usec += 1000000;
880 }
881 if (utv.tv_sec < 0)
882 timerclear(&utv);
883 }
884 tv = &utv;
885 microtime(&tv0);
886 }
887
888 error = selcommon(l, retval, nfds, readfds, writefds, exceptfds,
889 tv, NULL);
890
891 if (error) {
892 /*
893 * See fs/select.c in the Linux kernel. Without this,
894 * Maelstrom doesn't work.
895 */
896 if (error == ERESTART)
897 error = EINTR;
898 return error;
899 }
900
901 if (timeout) {
902 if (*retval) {
903 /*
904 * Compute how much time was left of the timeout,
905 * by subtracting the current time and the time
906 * before we started the call, and subtracting
907 * that result from the user-supplied value.
908 */
909 microtime(&tv1);
910 timersub(&tv1, &tv0, &tv1);
911 timersub(&utv, &tv1, &utv);
912 if (utv.tv_sec < 0)
913 timerclear(&utv);
914 } else
915 timerclear(&utv);
916 ltv.tv_sec = utv.tv_sec;
917 ltv.tv_usec = utv.tv_usec;
918 if ((error = copyout(<v, timeout, sizeof(ltv))))
919 return error;
920 }
921
922 return 0;
923 }
924
925 /*
926 * Set the 'personality' (emulation mode) for the current process. Only
927 * accept the Linux personality here (0). This call is needed because
928 * the Linux ELF crt0 issues it in an ugly kludge to make sure that
929 * ELF binaries run in Linux mode, not SVR4 mode.
930 */
931 int
932 linux_sys_personality(struct lwp *l, const struct linux_sys_personality_args *uap, register_t *retval)
933 {
934 /* {
935 syscallarg(int) per;
936 } */
937
938 if (SCARG(uap, per) != 0)
939 return EINVAL;
940 retval[0] = 0;
941 return 0;
942 }
943
944 /*
945 * We have nonexistent fsuid equal to uid.
946 * If modification is requested, refuse.
947 */
948 int
949 linux_sys_setfsuid(struct lwp *l, const struct linux_sys_setfsuid_args *uap, register_t *retval)
950 {
951 /* {
952 syscallarg(uid_t) uid;
953 } */
954 uid_t uid;
955
956 uid = SCARG(uap, uid);
957 if (kauth_cred_getuid(l->l_cred) != uid)
958 return sys_nosys(l, uap, retval);
959
960 *retval = uid;
961 return 0;
962 }
963
964 int
965 linux_sys_setfsgid(struct lwp *l, const struct linux_sys_setfsgid_args *uap, register_t *retval)
966 {
967 /* {
968 syscallarg(gid_t) gid;
969 } */
970 gid_t gid;
971
972 gid = SCARG(uap, gid);
973 if (kauth_cred_getgid(l->l_cred) != gid)
974 return sys_nosys(l, uap, retval);
975
976 *retval = gid;
977 return 0;
978 }
979
980 int
981 linux_sys_setresuid(struct lwp *l, const struct linux_sys_setresuid_args *uap, register_t *retval)
982 {
983 /* {
984 syscallarg(uid_t) ruid;
985 syscallarg(uid_t) euid;
986 syscallarg(uid_t) suid;
987 } */
988
989 /*
990 * Note: These checks are a little different than the NetBSD
991 * setreuid(2) call performs. This precisely follows the
992 * behavior of the Linux kernel.
993 */
994
995 return do_setresuid(l, SCARG(uap, ruid), SCARG(uap, euid),
996 SCARG(uap, suid),
997 ID_R_EQ_R | ID_R_EQ_E | ID_R_EQ_S |
998 ID_E_EQ_R | ID_E_EQ_E | ID_E_EQ_S |
999 ID_S_EQ_R | ID_S_EQ_E | ID_S_EQ_S );
1000 }
1001
1002 int
1003 linux_sys_getresuid(struct lwp *l, const struct linux_sys_getresuid_args *uap, register_t *retval)
1004 {
1005 /* {
1006 syscallarg(uid_t *) ruid;
1007 syscallarg(uid_t *) euid;
1008 syscallarg(uid_t *) suid;
1009 } */
1010 kauth_cred_t pc = l->l_cred;
1011 int error;
1012 uid_t uid;
1013
1014 /*
1015 * Linux copies these values out to userspace like so:
1016 *
1017 * 1. Copy out ruid.
1018 * 2. If that succeeds, copy out euid.
1019 * 3. If both of those succeed, copy out suid.
1020 */
1021 uid = kauth_cred_getuid(pc);
1022 if ((error = copyout(&uid, SCARG(uap, ruid), sizeof(uid_t))) != 0)
1023 return (error);
1024
1025 uid = kauth_cred_geteuid(pc);
1026 if ((error = copyout(&uid, SCARG(uap, euid), sizeof(uid_t))) != 0)
1027 return (error);
1028
1029 uid = kauth_cred_getsvuid(pc);
1030
1031 return (copyout(&uid, SCARG(uap, suid), sizeof(uid_t)));
1032 }
1033
1034 int
1035 linux_sys_ptrace(struct lwp *l, const struct linux_sys_ptrace_args *uap, register_t *retval)
1036 {
1037 /* {
1038 i386, m68k, powerpc: T=int
1039 alpha, amd64: T=long
1040 syscallarg(T) request;
1041 syscallarg(T) pid;
1042 syscallarg(T) addr;
1043 syscallarg(T) data;
1044 } */
1045 const int *ptr;
1046 int request;
1047 int error;
1048
1049 ptr = linux_ptrace_request_map;
1050 request = SCARG(uap, request);
1051 while (*ptr != -1)
1052 if (*ptr++ == request) {
1053 struct sys_ptrace_args pta;
1054
1055 SCARG(&pta, req) = *ptr;
1056 SCARG(&pta, pid) = SCARG(uap, pid);
1057 SCARG(&pta, addr) = (void *)SCARG(uap, addr);
1058 SCARG(&pta, data) = SCARG(uap, data);
1059
1060 /*
1061 * Linux ptrace(PTRACE_CONT, pid, 0, 0) means actually
1062 * to continue where the process left off previously.
1063 * The same thing is achieved by addr == (void *) 1
1064 * on NetBSD, so rewrite 'addr' appropriately.
1065 */
1066 if (request == LINUX_PTRACE_CONT && SCARG(uap, addr)==0)
1067 SCARG(&pta, addr) = (void *) 1;
1068
1069 error = sysent[SYS_ptrace].sy_call(l, &pta, retval);
1070 if (error)
1071 return error;
1072 switch (request) {
1073 case LINUX_PTRACE_PEEKTEXT:
1074 case LINUX_PTRACE_PEEKDATA:
1075 error = copyout (retval,
1076 (void *)SCARG(uap, data),
1077 sizeof *retval);
1078 *retval = SCARG(uap, data);
1079 break;
1080 default:
1081 break;
1082 }
1083 return error;
1084 }
1085 else
1086 ptr++;
1087
1088 return LINUX_SYS_PTRACE_ARCH(l, uap, retval);
1089 }
1090
1091 int
1092 linux_sys_reboot(struct lwp *l, const struct linux_sys_reboot_args *uap, register_t *retval)
1093 {
1094 /* {
1095 syscallarg(int) magic1;
1096 syscallarg(int) magic2;
1097 syscallarg(int) cmd;
1098 syscallarg(void *) arg;
1099 } */
1100 struct sys_reboot_args /* {
1101 syscallarg(int) opt;
1102 syscallarg(char *) bootstr;
1103 } */ sra;
1104 int error;
1105
1106 if ((error = kauth_authorize_system(l->l_cred,
1107 KAUTH_SYSTEM_REBOOT, 0, NULL, NULL, NULL)) != 0)
1108 return(error);
1109
1110 if (SCARG(uap, magic1) != LINUX_REBOOT_MAGIC1)
1111 return(EINVAL);
1112 if (SCARG(uap, magic2) != LINUX_REBOOT_MAGIC2 &&
1113 SCARG(uap, magic2) != LINUX_REBOOT_MAGIC2A &&
1114 SCARG(uap, magic2) != LINUX_REBOOT_MAGIC2B)
1115 return(EINVAL);
1116
1117 switch ((unsigned long)SCARG(uap, cmd)) {
1118 case LINUX_REBOOT_CMD_RESTART:
1119 SCARG(&sra, opt) = RB_AUTOBOOT;
1120 break;
1121 case LINUX_REBOOT_CMD_HALT:
1122 SCARG(&sra, opt) = RB_HALT;
1123 break;
1124 case LINUX_REBOOT_CMD_POWER_OFF:
1125 SCARG(&sra, opt) = RB_HALT|RB_POWERDOWN;
1126 break;
1127 case LINUX_REBOOT_CMD_RESTART2:
1128 /* Reboot with an argument. */
1129 SCARG(&sra, opt) = RB_AUTOBOOT|RB_STRING;
1130 SCARG(&sra, bootstr) = SCARG(uap, arg);
1131 break;
1132 case LINUX_REBOOT_CMD_CAD_ON:
1133 return(EINVAL); /* We don't implement ctrl-alt-delete */
1134 case LINUX_REBOOT_CMD_CAD_OFF:
1135 return(0);
1136 default:
1137 return(EINVAL);
1138 }
1139
1140 return(sys_reboot(l, &sra, retval));
1141 }
1142
1143 /*
1144 * Copy of compat_12_sys_swapon().
1145 */
1146 int
1147 linux_sys_swapon(struct lwp *l, const struct linux_sys_swapon_args *uap, register_t *retval)
1148 {
1149 /* {
1150 syscallarg(const char *) name;
1151 } */
1152 struct sys_swapctl_args ua;
1153
1154 SCARG(&ua, cmd) = SWAP_ON;
1155 SCARG(&ua, arg) = (void *)__UNCONST(SCARG(uap, name));
1156 SCARG(&ua, misc) = 0; /* priority */
1157 return (sys_swapctl(l, &ua, retval));
1158 }
1159
1160 /*
1161 * Stop swapping to the file or block device specified by path.
1162 */
1163 int
1164 linux_sys_swapoff(struct lwp *l, const struct linux_sys_swapoff_args *uap, register_t *retval)
1165 {
1166 /* {
1167 syscallarg(const char *) path;
1168 } */
1169 struct sys_swapctl_args ua;
1170
1171 SCARG(&ua, cmd) = SWAP_OFF;
1172 SCARG(&ua, arg) = __UNCONST(SCARG(uap, path)); /*XXXUNCONST*/
1173 return (sys_swapctl(l, &ua, retval));
1174 }
1175
1176 /*
1177 * Copy of compat_09_sys_setdomainname()
1178 */
1179 /* ARGSUSED */
1180 int
1181 linux_sys_setdomainname(struct lwp *l, const struct linux_sys_setdomainname_args *uap, register_t *retval)
1182 {
1183 /* {
1184 syscallarg(char *) domainname;
1185 syscallarg(int) len;
1186 } */
1187 int name[2];
1188
1189 name[0] = CTL_KERN;
1190 name[1] = KERN_DOMAINNAME;
1191 return (old_sysctl(&name[0], 2, 0, 0, SCARG(uap, domainname),
1192 SCARG(uap, len), l));
1193 }
1194
1195 /*
1196 * sysinfo()
1197 */
1198 /* ARGSUSED */
1199 int
1200 linux_sys_sysinfo(struct lwp *l, const struct linux_sys_sysinfo_args *uap, register_t *retval)
1201 {
1202 /* {
1203 syscallarg(struct linux_sysinfo *) arg;
1204 } */
1205 struct linux_sysinfo si;
1206 struct loadavg *la;
1207
1208 si.uptime = time_uptime;
1209 la = &averunnable;
1210 si.loads[0] = la->ldavg[0] * LINUX_SYSINFO_LOADS_SCALE / la->fscale;
1211 si.loads[1] = la->ldavg[1] * LINUX_SYSINFO_LOADS_SCALE / la->fscale;
1212 si.loads[2] = la->ldavg[2] * LINUX_SYSINFO_LOADS_SCALE / la->fscale;
1213 si.totalram = ctob((u_long)physmem);
1214 si.freeram = (u_long)uvmexp.free * uvmexp.pagesize;
1215 si.sharedram = 0; /* XXX */
1216 si.bufferram = (u_long)uvmexp.filepages * uvmexp.pagesize;
1217 si.totalswap = (u_long)uvmexp.swpages * uvmexp.pagesize;
1218 si.freeswap =
1219 (u_long)(uvmexp.swpages - uvmexp.swpginuse) * uvmexp.pagesize;
1220 si.procs = nprocs;
1221
1222 /* The following are only present in newer Linux kernels. */
1223 si.totalbig = 0;
1224 si.freebig = 0;
1225 si.mem_unit = 1;
1226
1227 return (copyout(&si, SCARG(uap, arg), sizeof si));
1228 }
1229
1230 int
1231 linux_sys_getrlimit(struct lwp *l, const struct linux_sys_getrlimit_args *uap, register_t *retval)
1232 {
1233 /* {
1234 syscallarg(int) which;
1235 # ifdef LINUX_LARGEFILE64
1236 syscallarg(struct rlimit *) rlp;
1237 # else
1238 syscallarg(struct orlimit *) rlp;
1239 # endif
1240 } */
1241 # ifdef LINUX_LARGEFILE64
1242 struct rlimit orl;
1243 # else
1244 struct orlimit orl;
1245 # endif
1246 int which;
1247
1248 which = linux_to_bsd_limit(SCARG(uap, which));
1249 if (which < 0)
1250 return -which;
1251
1252 bsd_to_linux_rlimit(&orl, &l->l_proc->p_rlimit[which]);
1253
1254 return copyout(&orl, SCARG(uap, rlp), sizeof(orl));
1255 }
1256
1257 int
1258 linux_sys_setrlimit(struct lwp *l, const struct linux_sys_setrlimit_args *uap, register_t *retval)
1259 {
1260 /* {
1261 syscallarg(int) which;
1262 # ifdef LINUX_LARGEFILE64
1263 syscallarg(struct rlimit *) rlp;
1264 # else
1265 syscallarg(struct orlimit *) rlp;
1266 # endif
1267 } */
1268 struct rlimit rl;
1269 # ifdef LINUX_LARGEFILE64
1270 struct rlimit orl;
1271 # else
1272 struct orlimit orl;
1273 # endif
1274 int error;
1275 int which;
1276
1277 if ((error = copyin(SCARG(uap, rlp), &orl, sizeof(orl))) != 0)
1278 return error;
1279
1280 which = linux_to_bsd_limit(SCARG(uap, which));
1281 if (which < 0)
1282 return -which;
1283
1284 linux_to_bsd_rlimit(&rl, &orl);
1285 return dosetrlimit(l, l->l_proc, which, &rl);
1286 }
1287
1288 # if !defined(__mips__) && !defined(__amd64__)
1289 /* XXX: this doesn't look 100% common, at least mips doesn't have it */
1290 int
1291 linux_sys_ugetrlimit(struct lwp *l, const struct linux_sys_ugetrlimit_args *uap, register_t *retval)
1292 {
1293 return linux_sys_getrlimit(l, (const void *)uap, retval);
1294 }
1295 # endif
1296
1297 /*
1298 * This gets called for unsupported syscalls. The difference to sys_nosys()
1299 * is that process does not get SIGSYS, the call just returns with ENOSYS.
1300 * This is the way Linux does it and glibc depends on this behaviour.
1301 */
1302 int
1303 linux_sys_nosys(struct lwp *l, const void *v, register_t *retval)
1304 {
1305 return (ENOSYS);
1306 }
1307
1308 int
1309 linux_sys_getpriority(struct lwp *l, const struct linux_sys_getpriority_args *uap, register_t *retval)
1310 {
1311 /* {
1312 syscallarg(int) which;
1313 syscallarg(int) who;
1314 } */
1315 struct sys_getpriority_args bsa;
1316 int error;
1317
1318 SCARG(&bsa, which) = SCARG(uap, which);
1319 SCARG(&bsa, who) = SCARG(uap, who);
1320
1321 if ((error = sys_getpriority(l, &bsa, retval)))
1322 return error;
1323
1324 *retval = NZERO - *retval;
1325
1326 return 0;
1327 }
1328
1329 #endif /* !COMPAT_LINUX32 */
1330