1 /*-
2 * Copyright (c) 2002 Doug Rabson
3 * Copyright (c) 1994-1995 Søren Schmidt
4 * 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 * in this position and unchanged.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD: releng/6.2/sys/compat/linux/linux_misc.c 162570 2006-09-23 10:36:57Z netchild $");
32
33 #include "opt_mac.h"
34
35 #include <sys/param.h>
36 #include <sys/blist.h>
37 #include <sys/fcntl.h>
38 #if defined(__i386__) || defined(__alpha__)
39 #include <sys/imgact_aout.h>
40 #endif
41 #include <sys/jail.h>
42 #include <sys/kernel.h>
43 #include <sys/limits.h>
44 #include <sys/lock.h>
45 #include <sys/mac.h>
46 #include <sys/malloc.h>
47 #include <sys/mman.h>
48 #include <sys/mount.h>
49 #include <sys/mutex.h>
50 #include <sys/namei.h>
51 #include <sys/proc.h>
52 #include <sys/reboot.h>
53 #include <sys/resourcevar.h>
54 #include <sys/signalvar.h>
55 #include <sys/stat.h>
56 #include <sys/syscallsubr.h>
57 #include <sys/sysctl.h>
58 #include <sys/sysproto.h>
59 #include <sys/systm.h>
60 #include <sys/time.h>
61 #include <sys/vmmeter.h>
62 #include <sys/vnode.h>
63 #include <sys/wait.h>
64
65 #include <vm/vm.h>
66 #include <vm/pmap.h>
67 #include <vm/vm_kern.h>
68 #include <vm/vm_map.h>
69 #include <vm/vm_extern.h>
70 #include <vm/vm_object.h>
71 #include <vm/swap_pager.h>
72
73 #include <posix4/sched.h>
74
75 #include "opt_compat.h"
76
77 #include <compat/linux/linux_sysproto.h>
78
79 #ifdef COMPAT_LINUX32
80 #include <machine/../linux32/linux.h>
81 #include <machine/../linux32/linux32_proto.h>
82 #else
83 #include <machine/../linux/linux.h>
84 #include <machine/../linux/linux_proto.h>
85 #endif
86
87 #include <compat/linux/linux_mib.h>
88 #include <compat/linux/linux_util.h>
89
90 #ifdef __i386__
91 #include <machine/cputypes.h>
92 #endif
93
94 #ifdef __alpha__
95 #define BSD_TO_LINUX_SIGNAL(sig) (sig)
96 #else
97 #define BSD_TO_LINUX_SIGNAL(sig) \
98 (((sig) <= LINUX_SIGTBLSZ) ? bsd_to_linux_signal[_SIG_IDX(sig)] : sig)
99 #endif
100
101 #ifndef __alpha__
102 static unsigned int linux_to_bsd_resource[LINUX_RLIM_NLIMITS] = {
103 RLIMIT_CPU, RLIMIT_FSIZE, RLIMIT_DATA, RLIMIT_STACK,
104 RLIMIT_CORE, RLIMIT_RSS, RLIMIT_NPROC, RLIMIT_NOFILE,
105 RLIMIT_MEMLOCK, -1
106 };
107 #endif /*!__alpha__*/
108
109 struct l_sysinfo {
110 l_long uptime; /* Seconds since boot */
111 l_ulong loads[3]; /* 1, 5, and 15 minute load averages */
112 #define LINUX_SYSINFO_LOADS_SCALE 65536
113 l_ulong totalram; /* Total usable main memory size */
114 l_ulong freeram; /* Available memory size */
115 l_ulong sharedram; /* Amount of shared memory */
116 l_ulong bufferram; /* Memory used by buffers */
117 l_ulong totalswap; /* Total swap space size */
118 l_ulong freeswap; /* swap space still available */
119 l_ushort procs; /* Number of current processes */
120 l_ulong totalbig;
121 l_ulong freebig;
122 l_uint mem_unit;
123 char _f[6]; /* Pads structure to 64 bytes */
124 };
125 #ifndef __alpha__
126 int
127 linux_sysinfo(struct thread *td, struct linux_sysinfo_args *args)
128 {
129 struct l_sysinfo sysinfo;
130 vm_object_t object;
131 int i, j;
132 struct timespec ts;
133
134 getnanouptime(&ts);
135 if (ts.tv_nsec != 0)
136 ts.tv_sec++;
137 sysinfo.uptime = ts.tv_sec;
138
139 /* Use the information from the mib to get our load averages */
140 for (i = 0; i < 3; i++)
141 sysinfo.loads[i] = averunnable.ldavg[i] *
142 LINUX_SYSINFO_LOADS_SCALE / averunnable.fscale;
143
144 sysinfo.totalram = physmem * PAGE_SIZE;
145 sysinfo.freeram = sysinfo.totalram - cnt.v_wire_count * PAGE_SIZE;
146
147 sysinfo.sharedram = 0;
148 mtx_lock(&vm_object_list_mtx);
149 TAILQ_FOREACH(object, &vm_object_list, object_list)
150 if (object->shadow_count > 1)
151 sysinfo.sharedram += object->resident_page_count;
152 mtx_unlock(&vm_object_list_mtx);
153
154 sysinfo.sharedram *= PAGE_SIZE;
155 sysinfo.bufferram = 0;
156
157 swap_pager_status(&i, &j);
158 sysinfo.totalswap= i * PAGE_SIZE;
159 sysinfo.freeswap = (i - j) * PAGE_SIZE;
160
161 sysinfo.procs = nprocs;
162
163 /* The following are only present in newer Linux kernels. */
164 sysinfo.totalbig = 0;
165 sysinfo.freebig = 0;
166 sysinfo.mem_unit = 1;
167
168 return copyout(&sysinfo, args->info, sizeof(sysinfo));
169 }
170 #endif /*!__alpha__*/
171
172 #ifndef __alpha__
173 int
174 linux_alarm(struct thread *td, struct linux_alarm_args *args)
175 {
176 struct itimerval it, old_it;
177 int error;
178
179 #ifdef DEBUG
180 if (ldebug(alarm))
181 printf(ARGS(alarm, "%u"), args->secs);
182 #endif
183
184 if (args->secs > 100000000)
185 return (EINVAL);
186
187 it.it_value.tv_sec = (long)args->secs;
188 it.it_value.tv_usec = 0;
189 it.it_interval.tv_sec = 0;
190 it.it_interval.tv_usec = 0;
191 error = kern_setitimer(td, ITIMER_REAL, &it, &old_it);
192 if (error)
193 return (error);
194 if (timevalisset(&old_it.it_value)) {
195 if (old_it.it_value.tv_usec != 0)
196 old_it.it_value.tv_sec++;
197 td->td_retval[0] = old_it.it_value.tv_sec;
198 }
199 return (0);
200 }
201 #endif /*!__alpha__*/
202
203 int
204 linux_brk(struct thread *td, struct linux_brk_args *args)
205 {
206 struct vmspace *vm = td->td_proc->p_vmspace;
207 vm_offset_t new, old;
208 struct obreak_args /* {
209 char * nsize;
210 } */ tmp;
211
212 #ifdef DEBUG
213 if (ldebug(brk))
214 printf(ARGS(brk, "%p"), (void *)(uintptr_t)args->dsend);
215 #endif
216 old = (vm_offset_t)vm->vm_daddr + ctob(vm->vm_dsize);
217 new = (vm_offset_t)args->dsend;
218 tmp.nsize = (char *) new;
219 if (((caddr_t)new > vm->vm_daddr) && !obreak(td, &tmp))
220 td->td_retval[0] = (long)new;
221 else
222 td->td_retval[0] = (long)old;
223
224 return 0;
225 }
226
227 #if defined(__i386__) || defined(__alpha__)
228
229 int
230 linux_uselib(struct thread *td, struct linux_uselib_args *args)
231 {
232 struct nameidata ni;
233 struct vnode *vp;
234 struct exec *a_out;
235 struct vattr attr;
236 vm_offset_t vmaddr;
237 unsigned long file_offset;
238 vm_offset_t buffer;
239 unsigned long bss_size;
240 char *library;
241 int error;
242 int locked;
243
244 LCONVPATHEXIST(td, args->library, &library);
245
246 #ifdef DEBUG
247 if (ldebug(uselib))
248 printf(ARGS(uselib, "%s"), library);
249 #endif
250
251 a_out = NULL;
252 locked = 0;
253 vp = NULL;
254
255 /*
256 * XXX: This code should make use of vn_open(), rather than doing
257 * all this stuff itself.
258 */
259 NDINIT(&ni, LOOKUP, ISOPEN|FOLLOW|LOCKLEAF, UIO_SYSSPACE, library, td);
260 error = namei(&ni);
261 LFREEPATH(library);
262 if (error)
263 goto cleanup;
264
265 vp = ni.ni_vp;
266 /*
267 * XXX - This looks like a bogus check. A LOCKLEAF namei should not
268 * succeed without returning a vnode.
269 */
270 if (vp == NULL) {
271 error = ENOEXEC; /* ?? */
272 goto cleanup;
273 }
274 NDFREE(&ni, NDF_ONLY_PNBUF);
275
276 /*
277 * From here on down, we have a locked vnode that must be unlocked.
278 */
279 locked++;
280
281 /* Writable? */
282 if (vp->v_writecount) {
283 error = ETXTBSY;
284 goto cleanup;
285 }
286
287 /* Executable? */
288 error = VOP_GETATTR(vp, &attr, td->td_ucred, td);
289 if (error)
290 goto cleanup;
291
292 if ((vp->v_mount->mnt_flag & MNT_NOEXEC) ||
293 ((attr.va_mode & 0111) == 0) || (attr.va_type != VREG)) {
294 error = ENOEXEC;
295 goto cleanup;
296 }
297
298 /* Sensible size? */
299 if (attr.va_size == 0) {
300 error = ENOEXEC;
301 goto cleanup;
302 }
303
304 /* Can we access it? */
305 error = VOP_ACCESS(vp, VEXEC, td->td_ucred, td);
306 if (error)
307 goto cleanup;
308
309 /*
310 * XXX: This should use vn_open() so that it is properly authorized,
311 * and to reduce code redundancy all over the place here.
312 */
313 #ifdef MAC
314 error = mac_check_vnode_open(td->td_ucred, vp, FREAD);
315 if (error)
316 goto cleanup;
317 #endif
318 error = VOP_OPEN(vp, FREAD, td->td_ucred, td, -1);
319 if (error)
320 goto cleanup;
321
322 /* Pull in executable header into kernel_map */
323 error = vm_mmap(kernel_map, (vm_offset_t *)&a_out, PAGE_SIZE,
324 VM_PROT_READ, VM_PROT_READ, 0, OBJT_VNODE, vp, 0);
325 /*
326 * Lock no longer needed
327 */
328 locked = 0;
329 VOP_UNLOCK(vp, 0, td);
330
331 if (error)
332 goto cleanup;
333
334 /* Is it a Linux binary ? */
335 if (((a_out->a_magic >> 16) & 0xff) != 0x64) {
336 error = ENOEXEC;
337 goto cleanup;
338 }
339
340 /*
341 * While we are here, we should REALLY do some more checks
342 */
343
344 /* Set file/virtual offset based on a.out variant. */
345 switch ((int)(a_out->a_magic & 0xffff)) {
346 case 0413: /* ZMAGIC */
347 file_offset = 1024;
348 break;
349 case 0314: /* QMAGIC */
350 file_offset = 0;
351 break;
352 default:
353 error = ENOEXEC;
354 goto cleanup;
355 }
356
357 bss_size = round_page(a_out->a_bss);
358
359 /* Check various fields in header for validity/bounds. */
360 if (a_out->a_text & PAGE_MASK || a_out->a_data & PAGE_MASK) {
361 error = ENOEXEC;
362 goto cleanup;
363 }
364
365 /* text + data can't exceed file size */
366 if (a_out->a_data + a_out->a_text > attr.va_size) {
367 error = EFAULT;
368 goto cleanup;
369 }
370
371 /*
372 * text/data/bss must not exceed limits
373 * XXX - this is not complete. it should check current usage PLUS
374 * the resources needed by this library.
375 */
376 PROC_LOCK(td->td_proc);
377 if (a_out->a_text > maxtsiz ||
378 a_out->a_data + bss_size > lim_cur(td->td_proc, RLIMIT_DATA)) {
379 PROC_UNLOCK(td->td_proc);
380 error = ENOMEM;
381 goto cleanup;
382 }
383 PROC_UNLOCK(td->td_proc);
384
385 mp_fixme("Unlocked vflags access.");
386 /* prevent more writers */
387 vp->v_vflag |= VV_TEXT;
388
389 /*
390 * Check if file_offset page aligned. Currently we cannot handle
391 * misalinged file offsets, and so we read in the entire image
392 * (what a waste).
393 */
394 if (file_offset & PAGE_MASK) {
395 #ifdef DEBUG
396 printf("uselib: Non page aligned binary %lu\n", file_offset);
397 #endif
398 /* Map text+data read/write/execute */
399
400 /* a_entry is the load address and is page aligned */
401 vmaddr = trunc_page(a_out->a_entry);
402
403 /* get anon user mapping, read+write+execute */
404 error = vm_map_find(&td->td_proc->p_vmspace->vm_map, NULL, 0,
405 &vmaddr, a_out->a_text + a_out->a_data, FALSE, VM_PROT_ALL,
406 VM_PROT_ALL, 0);
407 if (error)
408 goto cleanup;
409
410 /* map file into kernel_map */
411 error = vm_mmap(kernel_map, &buffer,
412 round_page(a_out->a_text + a_out->a_data + file_offset),
413 VM_PROT_READ, VM_PROT_READ, 0, OBJT_VNODE, vp,
414 trunc_page(file_offset));
415 if (error)
416 goto cleanup;
417
418 /* copy from kernel VM space to user space */
419 error = copyout(PTRIN(buffer + file_offset),
420 (void *)vmaddr, a_out->a_text + a_out->a_data);
421
422 /* release temporary kernel space */
423 vm_map_remove(kernel_map, buffer, buffer +
424 round_page(a_out->a_text + a_out->a_data + file_offset));
425
426 if (error)
427 goto cleanup;
428 } else {
429 #ifdef DEBUG
430 printf("uselib: Page aligned binary %lu\n", file_offset);
431 #endif
432 /*
433 * for QMAGIC, a_entry is 20 bytes beyond the load address
434 * to skip the executable header
435 */
436 vmaddr = trunc_page(a_out->a_entry);
437
438 /*
439 * Map it all into the process's space as a single
440 * copy-on-write "data" segment.
441 */
442 error = vm_mmap(&td->td_proc->p_vmspace->vm_map, &vmaddr,
443 a_out->a_text + a_out->a_data, VM_PROT_ALL, VM_PROT_ALL,
444 MAP_PRIVATE | MAP_FIXED, OBJT_VNODE, vp, file_offset);
445 if (error)
446 goto cleanup;
447 }
448 #ifdef DEBUG
449 printf("mem=%08lx = %08lx %08lx\n", (long)vmaddr, ((long*)vmaddr)[0],
450 ((long*)vmaddr)[1]);
451 #endif
452 if (bss_size != 0) {
453 /* Calculate BSS start address */
454 vmaddr = trunc_page(a_out->a_entry) + a_out->a_text +
455 a_out->a_data;
456
457 /* allocate some 'anon' space */
458 error = vm_map_find(&td->td_proc->p_vmspace->vm_map, NULL, 0,
459 &vmaddr, bss_size, FALSE, VM_PROT_ALL, VM_PROT_ALL, 0);
460 if (error)
461 goto cleanup;
462 }
463
464 cleanup:
465 /* Unlock vnode if needed */
466 if (locked)
467 VOP_UNLOCK(vp, 0, td);
468
469 /* Release the kernel mapping. */
470 if (a_out)
471 vm_map_remove(kernel_map, (vm_offset_t)a_out,
472 (vm_offset_t)a_out + PAGE_SIZE);
473
474 return error;
475 }
476
477 #endif /* __i386__ || __alpha__ */
478
479 int
480 linux_select(struct thread *td, struct linux_select_args *args)
481 {
482 l_timeval ltv;
483 struct timeval tv0, tv1, utv, *tvp;
484 int error;
485
486 #ifdef DEBUG
487 if (ldebug(select))
488 printf(ARGS(select, "%d, %p, %p, %p, %p"), args->nfds,
489 (void *)args->readfds, (void *)args->writefds,
490 (void *)args->exceptfds, (void *)args->timeout);
491 #endif
492
493 /*
494 * Store current time for computation of the amount of
495 * time left.
496 */
497 if (args->timeout) {
498 if ((error = copyin(args->timeout, <v, sizeof(ltv))))
499 goto select_out;
500 utv.tv_sec = ltv.tv_sec;
501 utv.tv_usec = ltv.tv_usec;
502 #ifdef DEBUG
503 if (ldebug(select))
504 printf(LMSG("incoming timeout (%ld/%ld)"),
505 utv.tv_sec, utv.tv_usec);
506 #endif
507
508 if (itimerfix(&utv)) {
509 /*
510 * The timeval was invalid. Convert it to something
511 * valid that will act as it does under Linux.
512 */
513 utv.tv_sec += utv.tv_usec / 1000000;
514 utv.tv_usec %= 1000000;
515 if (utv.tv_usec < 0) {
516 utv.tv_sec -= 1;
517 utv.tv_usec += 1000000;
518 }
519 if (utv.tv_sec < 0)
520 timevalclear(&utv);
521 }
522 microtime(&tv0);
523 tvp = &utv;
524 } else
525 tvp = NULL;
526
527 error = kern_select(td, args->nfds, args->readfds, args->writefds,
528 args->exceptfds, tvp);
529
530 #ifdef DEBUG
531 if (ldebug(select))
532 printf(LMSG("real select returns %d"), error);
533 #endif
534 if (error) {
535 /*
536 * See fs/select.c in the Linux kernel. Without this,
537 * Maelstrom doesn't work.
538 */
539 if (error == ERESTART)
540 error = EINTR;
541 goto select_out;
542 }
543
544 if (args->timeout) {
545 if (td->td_retval[0]) {
546 /*
547 * Compute how much time was left of the timeout,
548 * by subtracting the current time and the time
549 * before we started the call, and subtracting
550 * that result from the user-supplied value.
551 */
552 microtime(&tv1);
553 timevalsub(&tv1, &tv0);
554 timevalsub(&utv, &tv1);
555 if (utv.tv_sec < 0)
556 timevalclear(&utv);
557 } else
558 timevalclear(&utv);
559 #ifdef DEBUG
560 if (ldebug(select))
561 printf(LMSG("outgoing timeout (%ld/%ld)"),
562 utv.tv_sec, utv.tv_usec);
563 #endif
564 ltv.tv_sec = utv.tv_sec;
565 ltv.tv_usec = utv.tv_usec;
566 if ((error = copyout(<v, args->timeout, sizeof(ltv))))
567 goto select_out;
568 }
569
570 select_out:
571 #ifdef DEBUG
572 if (ldebug(select))
573 printf(LMSG("select_out -> %d"), error);
574 #endif
575 return error;
576 }
577
578 int
579 linux_mremap(struct thread *td, struct linux_mremap_args *args)
580 {
581 struct munmap_args /* {
582 void *addr;
583 size_t len;
584 } */ bsd_args;
585 int error = 0;
586
587 #ifdef DEBUG
588 if (ldebug(mremap))
589 printf(ARGS(mremap, "%p, %08lx, %08lx, %08lx"),
590 (void *)(uintptr_t)args->addr,
591 (unsigned long)args->old_len,
592 (unsigned long)args->new_len,
593 (unsigned long)args->flags);
594 #endif
595 args->new_len = round_page(args->new_len);
596 args->old_len = round_page(args->old_len);
597
598 if (args->new_len > args->old_len) {
599 td->td_retval[0] = 0;
600 return ENOMEM;
601 }
602
603 if (args->new_len < args->old_len) {
604 bsd_args.addr =
605 (caddr_t)((uintptr_t)args->addr + args->new_len);
606 bsd_args.len = args->old_len - args->new_len;
607 error = munmap(td, &bsd_args);
608 }
609
610 td->td_retval[0] = error ? 0 : (uintptr_t)args->addr;
611 return error;
612 }
613
614 #define LINUX_MS_ASYNC 0x0001
615 #define LINUX_MS_INVALIDATE 0x0002
616 #define LINUX_MS_SYNC 0x0004
617
618 int
619 linux_msync(struct thread *td, struct linux_msync_args *args)
620 {
621 struct msync_args bsd_args;
622
623 bsd_args.addr = (caddr_t)(uintptr_t)args->addr;
624 bsd_args.len = (uintptr_t)args->len;
625 bsd_args.flags = args->fl & ~LINUX_MS_SYNC;
626
627 return msync(td, &bsd_args);
628 }
629
630 #ifndef __alpha__
631 int
632 linux_time(struct thread *td, struct linux_time_args *args)
633 {
634 struct timeval tv;
635 l_time_t tm;
636 int error;
637
638 #ifdef DEBUG
639 if (ldebug(time))
640 printf(ARGS(time, "*"));
641 #endif
642
643 microtime(&tv);
644 tm = tv.tv_sec;
645 if (args->tm && (error = copyout(&tm, args->tm, sizeof(tm))))
646 return error;
647 td->td_retval[0] = tm;
648 return 0;
649 }
650 #endif /*!__alpha__*/
651
652 struct l_times_argv {
653 l_long tms_utime;
654 l_long tms_stime;
655 l_long tms_cutime;
656 l_long tms_cstime;
657 };
658
659 #ifdef __alpha__
660 #define CLK_TCK 1024 /* Linux uses 1024 on alpha */
661 #else
662 #define CLK_TCK 100 /* Linux uses 100 */
663 #endif
664
665 #define CONVTCK(r) (r.tv_sec * CLK_TCK + r.tv_usec / (1000000 / CLK_TCK))
666
667 int
668 linux_times(struct thread *td, struct linux_times_args *args)
669 {
670 struct timeval tv, utime, stime, cutime, cstime;
671 struct l_times_argv tms;
672 struct proc *p;
673 int error;
674
675 #ifdef DEBUG
676 if (ldebug(times))
677 printf(ARGS(times, "*"));
678 #endif
679
680 if (args->buf != NULL) {
681 p = td->td_proc;
682 PROC_LOCK(p);
683 calcru(p, &utime, &stime);
684 calccru(p, &cutime, &cstime);
685 PROC_UNLOCK(p);
686
687 tms.tms_utime = CONVTCK(utime);
688 tms.tms_stime = CONVTCK(stime);
689
690 tms.tms_cutime = CONVTCK(cutime);
691 tms.tms_cstime = CONVTCK(cstime);
692
693 if ((error = copyout(&tms, args->buf, sizeof(tms))))
694 return error;
695 }
696
697 microuptime(&tv);
698 td->td_retval[0] = (int)CONVTCK(tv);
699 return 0;
700 }
701
702 int
703 linux_newuname(struct thread *td, struct linux_newuname_args *args)
704 {
705 struct l_new_utsname utsname;
706 char osname[LINUX_MAX_UTSNAME];
707 char osrelease[LINUX_MAX_UTSNAME];
708 char *p;
709
710 #ifdef DEBUG
711 if (ldebug(newuname))
712 printf(ARGS(newuname, "*"));
713 #endif
714
715 linux_get_osname(td, osname);
716 linux_get_osrelease(td, osrelease);
717
718 bzero(&utsname, sizeof(utsname));
719 strlcpy(utsname.sysname, osname, LINUX_MAX_UTSNAME);
720 getcredhostname(td->td_ucred, utsname.nodename, LINUX_MAX_UTSNAME);
721 strlcpy(utsname.release, osrelease, LINUX_MAX_UTSNAME);
722 strlcpy(utsname.version, version, LINUX_MAX_UTSNAME);
723 for (p = utsname.version; *p != '\0'; ++p)
724 if (*p == '\n') {
725 *p = '\0';
726 break;
727 }
728 #ifdef __i386__
729 {
730 const char *class;
731 switch (cpu_class) {
732 case CPUCLASS_686:
733 class = "i686";
734 break;
735 case CPUCLASS_586:
736 class = "i586";
737 break;
738 case CPUCLASS_486:
739 class = "i486";
740 break;
741 default:
742 class = "i386";
743 }
744 strlcpy(utsname.machine, class, LINUX_MAX_UTSNAME);
745 }
746 #elif defined(__amd64__) /* XXX: Linux can change 'personality'. */
747 #ifdef COMPAT_LINUX32
748 strlcpy(utsname.machine, "i686", LINUX_MAX_UTSNAME);
749 #else
750 strlcpy(utsname.machine, "x86_64", LINUX_MAX_UTSNAME);
751 #endif /* COMPAT_LINUX32 */
752 #else /* something other than i386 or amd64 - assume we and Linux agree */
753 strlcpy(utsname.machine, machine, LINUX_MAX_UTSNAME);
754 #endif /* __i386__ */
755 strlcpy(utsname.domainname, domainname, LINUX_MAX_UTSNAME);
756
757 return (copyout(&utsname, args->buf, sizeof(utsname)));
758 }
759
760 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
761 struct l_utimbuf {
762 l_time_t l_actime;
763 l_time_t l_modtime;
764 };
765
766 int
767 linux_utime(struct thread *td, struct linux_utime_args *args)
768 {
769 struct timeval tv[2], *tvp;
770 struct l_utimbuf lut;
771 char *fname;
772 int error;
773
774 LCONVPATHEXIST(td, args->fname, &fname);
775
776 #ifdef DEBUG
777 if (ldebug(utime))
778 printf(ARGS(utime, "%s, *"), fname);
779 #endif
780
781 if (args->times) {
782 if ((error = copyin(args->times, &lut, sizeof lut))) {
783 LFREEPATH(fname);
784 return error;
785 }
786 tv[0].tv_sec = lut.l_actime;
787 tv[0].tv_usec = 0;
788 tv[1].tv_sec = lut.l_modtime;
789 tv[1].tv_usec = 0;
790 tvp = tv;
791 } else
792 tvp = NULL;
793
794 error = kern_utimes(td, fname, UIO_SYSSPACE, tvp, UIO_SYSSPACE);
795 LFREEPATH(fname);
796 return (error);
797 }
798 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
799
800 #define __WCLONE 0x80000000
801
802 #ifndef __alpha__
803 int
804 linux_waitpid(struct thread *td, struct linux_waitpid_args *args)
805 {
806 int error, options, tmpstat;
807
808 #ifdef DEBUG
809 if (ldebug(waitpid))
810 printf(ARGS(waitpid, "%d, %p, %d"),
811 args->pid, (void *)args->status, args->options);
812 #endif
813
814 options = (args->options & (WNOHANG | WUNTRACED));
815 /* WLINUXCLONE should be equal to __WCLONE, but we make sure */
816 if (args->options & __WCLONE)
817 options |= WLINUXCLONE;
818
819 error = kern_wait(td, args->pid, &tmpstat, options, NULL);
820 if (error)
821 return error;
822
823 if (args->status) {
824 tmpstat &= 0xffff;
825 if (WIFSIGNALED(tmpstat))
826 tmpstat = (tmpstat & 0xffffff80) |
827 BSD_TO_LINUX_SIGNAL(WTERMSIG(tmpstat));
828 else if (WIFSTOPPED(tmpstat))
829 tmpstat = (tmpstat & 0xffff00ff) |
830 (BSD_TO_LINUX_SIGNAL(WSTOPSIG(tmpstat)) << 8);
831 return copyout(&tmpstat, args->status, sizeof(int));
832 }
833
834 return 0;
835 }
836 #endif /*!__alpha__*/
837
838 int
839 linux_wait4(struct thread *td, struct linux_wait4_args *args)
840 {
841 int error, options, tmpstat;
842 struct rusage ru, *rup;
843 struct proc *p;
844
845 #ifdef DEBUG
846 if (ldebug(wait4))
847 printf(ARGS(wait4, "%d, %p, %d, %p"),
848 args->pid, (void *)args->status, args->options,
849 (void *)args->rusage);
850 #endif
851
852 options = (args->options & (WNOHANG | WUNTRACED));
853 /* WLINUXCLONE should be equal to __WCLONE, but we make sure */
854 if (args->options & __WCLONE)
855 options |= WLINUXCLONE;
856
857 if (args->rusage != NULL)
858 rup = &ru;
859 else
860 rup = NULL;
861 error = kern_wait(td, args->pid, &tmpstat, options, rup);
862 if (error)
863 return error;
864
865 p = td->td_proc;
866 PROC_LOCK(p);
867 SIGDELSET(p->p_siglist, SIGCHLD);
868 PROC_UNLOCK(p);
869
870 if (args->status) {
871 tmpstat &= 0xffff;
872 if (WIFSIGNALED(tmpstat))
873 tmpstat = (tmpstat & 0xffffff80) |
874 BSD_TO_LINUX_SIGNAL(WTERMSIG(tmpstat));
875 else if (WIFSTOPPED(tmpstat))
876 tmpstat = (tmpstat & 0xffff00ff) |
877 (BSD_TO_LINUX_SIGNAL(WSTOPSIG(tmpstat)) << 8);
878 error = copyout(&tmpstat, args->status, sizeof(int));
879 }
880 if (args->rusage != NULL && error == 0)
881 error = copyout(&ru, args->rusage, sizeof(ru));
882
883 return (error);
884 }
885
886 int
887 linux_mknod(struct thread *td, struct linux_mknod_args *args)
888 {
889 char *path;
890 int error;
891
892 LCONVPATHCREAT(td, args->path, &path);
893
894 #ifdef DEBUG
895 if (ldebug(mknod))
896 printf(ARGS(mknod, "%s, %d, %d"), path, args->mode, args->dev);
897 #endif
898
899 if (args->mode & S_IFIFO)
900 error = kern_mkfifo(td, path, UIO_SYSSPACE, args->mode);
901 else
902 error = kern_mknod(td, path, UIO_SYSSPACE, args->mode,
903 args->dev);
904 LFREEPATH(path);
905 return (error);
906 }
907
908 /*
909 * UGH! This is just about the dumbest idea I've ever heard!!
910 */
911 int
912 linux_personality(struct thread *td, struct linux_personality_args *args)
913 {
914 #ifdef DEBUG
915 if (ldebug(personality))
916 printf(ARGS(personality, "%lu"), (unsigned long)args->per);
917 #endif
918 #ifndef __alpha__
919 if (args->per != 0)
920 return EINVAL;
921 #endif
922
923 /* Yes Jim, it's still a Linux... */
924 td->td_retval[0] = 0;
925 return 0;
926 }
927
928 struct l_itimerval {
929 l_timeval it_interval;
930 l_timeval it_value;
931 };
932
933 #define B2L_ITIMERVAL(bip, lip) \
934 (bip)->it_interval.tv_sec = (lip)->it_interval.tv_sec; \
935 (bip)->it_interval.tv_usec = (lip)->it_interval.tv_usec; \
936 (bip)->it_value.tv_sec = (lip)->it_value.tv_sec; \
937 (bip)->it_value.tv_usec = (lip)->it_value.tv_usec;
938
939 int
940 linux_setitimer(struct thread *td, struct linux_setitimer_args *uap)
941 {
942 int error;
943 struct l_itimerval ls;
944 struct itimerval aitv, oitv;
945
946 #ifdef DEBUG
947 if (ldebug(setitimer))
948 printf(ARGS(setitimer, "%p, %p"),
949 (void *)uap->itv, (void *)uap->oitv);
950 #endif
951
952 if (uap->itv == NULL) {
953 uap->itv = uap->oitv;
954 return (linux_getitimer(td, (struct linux_getitimer_args *)uap));
955 }
956
957 error = copyin(uap->itv, &ls, sizeof(ls));
958 if (error != 0)
959 return (error);
960 B2L_ITIMERVAL(&aitv, &ls);
961 #ifdef DEBUG
962 if (ldebug(setitimer)) {
963 printf("setitimer: value: sec: %ld, usec: %ld\n",
964 aitv.it_value.tv_sec, aitv.it_value.tv_usec);
965 printf("setitimer: interval: sec: %ld, usec: %ld\n",
966 aitv.it_interval.tv_sec, aitv.it_interval.tv_usec);
967 }
968 #endif
969 error = kern_setitimer(td, uap->which, &aitv, &oitv);
970 if (error != 0 || uap->oitv == NULL)
971 return (error);
972 B2L_ITIMERVAL(&ls, &oitv);
973
974 return (copyout(&ls, uap->oitv, sizeof(ls)));
975 }
976
977 int
978 linux_getitimer(struct thread *td, struct linux_getitimer_args *uap)
979 {
980 int error;
981 struct l_itimerval ls;
982 struct itimerval aitv;
983
984 #ifdef DEBUG
985 if (ldebug(getitimer))
986 printf(ARGS(getitimer, "%p"), (void *)uap->itv);
987 #endif
988 error = kern_getitimer(td, uap->which, &aitv);
989 if (error != 0)
990 return (error);
991 B2L_ITIMERVAL(&ls, &aitv);
992 return (copyout(&ls, uap->itv, sizeof(ls)));
993 }
994
995 #ifndef __alpha__
996 int
997 linux_nice(struct thread *td, struct linux_nice_args *args)
998 {
999 struct setpriority_args bsd_args;
1000
1001 bsd_args.which = PRIO_PROCESS;
1002 bsd_args.who = 0; /* current process */
1003 bsd_args.prio = args->inc;
1004 return setpriority(td, &bsd_args);
1005 }
1006 #endif /*!__alpha__*/
1007
1008 int
1009 linux_setgroups(struct thread *td, struct linux_setgroups_args *args)
1010 {
1011 struct ucred *newcred, *oldcred;
1012 l_gid_t linux_gidset[NGROUPS];
1013 gid_t *bsd_gidset;
1014 int ngrp, error;
1015 struct proc *p;
1016
1017 ngrp = args->gidsetsize;
1018 if (ngrp < 0 || ngrp >= NGROUPS)
1019 return (EINVAL);
1020 error = copyin(args->grouplist, linux_gidset, ngrp * sizeof(l_gid_t));
1021 if (error)
1022 return (error);
1023 newcred = crget();
1024 p = td->td_proc;
1025 PROC_LOCK(p);
1026 oldcred = p->p_ucred;
1027
1028 /*
1029 * cr_groups[0] holds egid. Setting the whole set from
1030 * the supplied set will cause egid to be changed too.
1031 * Keep cr_groups[0] unchanged to prevent that.
1032 */
1033
1034 if ((error = suser_cred(oldcred, SUSER_ALLOWJAIL)) != 0) {
1035 PROC_UNLOCK(p);
1036 crfree(newcred);
1037 return (error);
1038 }
1039
1040 crcopy(newcred, oldcred);
1041 if (ngrp > 0) {
1042 newcred->cr_ngroups = ngrp + 1;
1043
1044 bsd_gidset = newcred->cr_groups;
1045 ngrp--;
1046 while (ngrp >= 0) {
1047 bsd_gidset[ngrp + 1] = linux_gidset[ngrp];
1048 ngrp--;
1049 }
1050 }
1051 else
1052 newcred->cr_ngroups = 1;
1053
1054 setsugid(p);
1055 p->p_ucred = newcred;
1056 PROC_UNLOCK(p);
1057 crfree(oldcred);
1058 return (0);
1059 }
1060
1061 int
1062 linux_getgroups(struct thread *td, struct linux_getgroups_args *args)
1063 {
1064 struct ucred *cred;
1065 l_gid_t linux_gidset[NGROUPS];
1066 gid_t *bsd_gidset;
1067 int bsd_gidsetsz, ngrp, error;
1068
1069 cred = td->td_ucred;
1070 bsd_gidset = cred->cr_groups;
1071 bsd_gidsetsz = cred->cr_ngroups - 1;
1072
1073 /*
1074 * cr_groups[0] holds egid. Returning the whole set
1075 * here will cause a duplicate. Exclude cr_groups[0]
1076 * to prevent that.
1077 */
1078
1079 if ((ngrp = args->gidsetsize) == 0) {
1080 td->td_retval[0] = bsd_gidsetsz;
1081 return (0);
1082 }
1083
1084 if (ngrp < bsd_gidsetsz)
1085 return (EINVAL);
1086
1087 ngrp = 0;
1088 while (ngrp < bsd_gidsetsz) {
1089 linux_gidset[ngrp] = bsd_gidset[ngrp + 1];
1090 ngrp++;
1091 }
1092
1093 if ((error = copyout(linux_gidset, args->grouplist,
1094 ngrp * sizeof(l_gid_t))))
1095 return (error);
1096
1097 td->td_retval[0] = ngrp;
1098 return (0);
1099 }
1100
1101 #ifndef __alpha__
1102 int
1103 linux_setrlimit(struct thread *td, struct linux_setrlimit_args *args)
1104 {
1105 struct rlimit bsd_rlim;
1106 struct l_rlimit rlim;
1107 u_int which;
1108 int error;
1109
1110 #ifdef DEBUG
1111 if (ldebug(setrlimit))
1112 printf(ARGS(setrlimit, "%d, %p"),
1113 args->resource, (void *)args->rlim);
1114 #endif
1115
1116 if (args->resource >= LINUX_RLIM_NLIMITS)
1117 return (EINVAL);
1118
1119 which = linux_to_bsd_resource[args->resource];
1120 if (which == -1)
1121 return (EINVAL);
1122
1123 error = copyin(args->rlim, &rlim, sizeof(rlim));
1124 if (error)
1125 return (error);
1126
1127 bsd_rlim.rlim_cur = (rlim_t)rlim.rlim_cur;
1128 bsd_rlim.rlim_max = (rlim_t)rlim.rlim_max;
1129 return (kern_setrlimit(td, which, &bsd_rlim));
1130 }
1131
1132 int
1133 linux_old_getrlimit(struct thread *td, struct linux_old_getrlimit_args *args)
1134 {
1135 struct l_rlimit rlim;
1136 struct proc *p = td->td_proc;
1137 struct rlimit bsd_rlim;
1138 u_int which;
1139
1140 #ifdef DEBUG
1141 if (ldebug(old_getrlimit))
1142 printf(ARGS(old_getrlimit, "%d, %p"),
1143 args->resource, (void *)args->rlim);
1144 #endif
1145
1146 if (args->resource >= LINUX_RLIM_NLIMITS)
1147 return (EINVAL);
1148
1149 which = linux_to_bsd_resource[args->resource];
1150 if (which == -1)
1151 return (EINVAL);
1152
1153 PROC_LOCK(p);
1154 lim_rlimit(p, which, &bsd_rlim);
1155 PROC_UNLOCK(p);
1156
1157 #ifdef COMPAT_LINUX32
1158 rlim.rlim_cur = (unsigned int)bsd_rlim.rlim_cur;
1159 if (rlim.rlim_cur == UINT_MAX)
1160 rlim.rlim_cur = INT_MAX;
1161 rlim.rlim_max = (unsigned int)bsd_rlim.rlim_max;
1162 if (rlim.rlim_max == UINT_MAX)
1163 rlim.rlim_max = INT_MAX;
1164 #else
1165 rlim.rlim_cur = (unsigned long)bsd_rlim.rlim_cur;
1166 if (rlim.rlim_cur == ULONG_MAX)
1167 rlim.rlim_cur = LONG_MAX;
1168 rlim.rlim_max = (unsigned long)bsd_rlim.rlim_max;
1169 if (rlim.rlim_max == ULONG_MAX)
1170 rlim.rlim_max = LONG_MAX;
1171 #endif
1172 return (copyout(&rlim, args->rlim, sizeof(rlim)));
1173 }
1174
1175 int
1176 linux_getrlimit(struct thread *td, struct linux_getrlimit_args *args)
1177 {
1178 struct l_rlimit rlim;
1179 struct proc *p = td->td_proc;
1180 struct rlimit bsd_rlim;
1181 u_int which;
1182
1183 #ifdef DEBUG
1184 if (ldebug(getrlimit))
1185 printf(ARGS(getrlimit, "%d, %p"),
1186 args->resource, (void *)args->rlim);
1187 #endif
1188
1189 if (args->resource >= LINUX_RLIM_NLIMITS)
1190 return (EINVAL);
1191
1192 which = linux_to_bsd_resource[args->resource];
1193 if (which == -1)
1194 return (EINVAL);
1195
1196 PROC_LOCK(p);
1197 lim_rlimit(p, which, &bsd_rlim);
1198 PROC_UNLOCK(p);
1199
1200 rlim.rlim_cur = (l_ulong)bsd_rlim.rlim_cur;
1201 rlim.rlim_max = (l_ulong)bsd_rlim.rlim_max;
1202 return (copyout(&rlim, args->rlim, sizeof(rlim)));
1203 }
1204 #endif /*!__alpha__*/
1205
1206 int
1207 linux_sched_setscheduler(struct thread *td,
1208 struct linux_sched_setscheduler_args *args)
1209 {
1210 struct sched_setscheduler_args bsd;
1211
1212 #ifdef DEBUG
1213 if (ldebug(sched_setscheduler))
1214 printf(ARGS(sched_setscheduler, "%d, %d, %p"),
1215 args->pid, args->policy, (const void *)args->param);
1216 #endif
1217
1218 switch (args->policy) {
1219 case LINUX_SCHED_OTHER:
1220 bsd.policy = SCHED_OTHER;
1221 break;
1222 case LINUX_SCHED_FIFO:
1223 bsd.policy = SCHED_FIFO;
1224 break;
1225 case LINUX_SCHED_RR:
1226 bsd.policy = SCHED_RR;
1227 break;
1228 default:
1229 return EINVAL;
1230 }
1231
1232 bsd.pid = args->pid;
1233 bsd.param = (struct sched_param *)args->param;
1234 return sched_setscheduler(td, &bsd);
1235 }
1236
1237 int
1238 linux_sched_getscheduler(struct thread *td,
1239 struct linux_sched_getscheduler_args *args)
1240 {
1241 struct sched_getscheduler_args bsd;
1242 int error;
1243
1244 #ifdef DEBUG
1245 if (ldebug(sched_getscheduler))
1246 printf(ARGS(sched_getscheduler, "%d"), args->pid);
1247 #endif
1248
1249 bsd.pid = args->pid;
1250 error = sched_getscheduler(td, &bsd);
1251
1252 switch (td->td_retval[0]) {
1253 case SCHED_OTHER:
1254 td->td_retval[0] = LINUX_SCHED_OTHER;
1255 break;
1256 case SCHED_FIFO:
1257 td->td_retval[0] = LINUX_SCHED_FIFO;
1258 break;
1259 case SCHED_RR:
1260 td->td_retval[0] = LINUX_SCHED_RR;
1261 break;
1262 }
1263
1264 return error;
1265 }
1266
1267 int
1268 linux_sched_get_priority_max(struct thread *td,
1269 struct linux_sched_get_priority_max_args *args)
1270 {
1271 struct sched_get_priority_max_args bsd;
1272
1273 #ifdef DEBUG
1274 if (ldebug(sched_get_priority_max))
1275 printf(ARGS(sched_get_priority_max, "%d"), args->policy);
1276 #endif
1277
1278 switch (args->policy) {
1279 case LINUX_SCHED_OTHER:
1280 bsd.policy = SCHED_OTHER;
1281 break;
1282 case LINUX_SCHED_FIFO:
1283 bsd.policy = SCHED_FIFO;
1284 break;
1285 case LINUX_SCHED_RR:
1286 bsd.policy = SCHED_RR;
1287 break;
1288 default:
1289 return EINVAL;
1290 }
1291 return sched_get_priority_max(td, &bsd);
1292 }
1293
1294 int
1295 linux_sched_get_priority_min(struct thread *td,
1296 struct linux_sched_get_priority_min_args *args)
1297 {
1298 struct sched_get_priority_min_args bsd;
1299
1300 #ifdef DEBUG
1301 if (ldebug(sched_get_priority_min))
1302 printf(ARGS(sched_get_priority_min, "%d"), args->policy);
1303 #endif
1304
1305 switch (args->policy) {
1306 case LINUX_SCHED_OTHER:
1307 bsd.policy = SCHED_OTHER;
1308 break;
1309 case LINUX_SCHED_FIFO:
1310 bsd.policy = SCHED_FIFO;
1311 break;
1312 case LINUX_SCHED_RR:
1313 bsd.policy = SCHED_RR;
1314 break;
1315 default:
1316 return EINVAL;
1317 }
1318 return sched_get_priority_min(td, &bsd);
1319 }
1320
1321 #define REBOOT_CAD_ON 0x89abcdef
1322 #define REBOOT_CAD_OFF 0
1323 #define REBOOT_HALT 0xcdef0123
1324 #define REBOOT_RESTART 0x01234567
1325 #define REBOOT_RESTART2 0xA1B2C3D4
1326 #define REBOOT_POWEROFF 0x4321FEDC
1327 #define REBOOT_MAGIC1 0xfee1dead
1328 #define REBOOT_MAGIC2 0x28121969
1329 #define REBOOT_MAGIC2A 0x05121996
1330 #define REBOOT_MAGIC2B 0x16041998
1331
1332 int
1333 linux_reboot(struct thread *td, struct linux_reboot_args *args)
1334 {
1335 struct reboot_args bsd_args;
1336
1337 #ifdef DEBUG
1338 if (ldebug(reboot))
1339 printf(ARGS(reboot, "0x%x"), args->cmd);
1340 #endif
1341
1342 if (args->magic1 != REBOOT_MAGIC1)
1343 return EINVAL;
1344
1345 switch (args->magic2) {
1346 case REBOOT_MAGIC2:
1347 case REBOOT_MAGIC2A:
1348 case REBOOT_MAGIC2B:
1349 break;
1350 default:
1351 return EINVAL;
1352 }
1353
1354 switch (args->cmd) {
1355 case REBOOT_CAD_ON:
1356 case REBOOT_CAD_OFF:
1357 return suser(td);
1358 case REBOOT_HALT:
1359 bsd_args.opt = RB_HALT;
1360 break;
1361 case REBOOT_RESTART:
1362 case REBOOT_RESTART2:
1363 bsd_args.opt = 0;
1364 break;
1365 case REBOOT_POWEROFF:
1366 bsd_args.opt = RB_POWEROFF;
1367 break;
1368 default:
1369 return EINVAL;
1370 }
1371 return reboot(td, &bsd_args);
1372 }
1373
1374 #ifndef __alpha__
1375
1376 /*
1377 * The FreeBSD native getpid(2), getgid(2) and getuid(2) also modify
1378 * td->td_retval[1] when COMPAT_43 is defined. This
1379 * globbers registers that are assumed to be preserved. The following
1380 * lightweight syscalls fixes this. See also linux_getgid16() and
1381 * linux_getuid16() in linux_uid16.c.
1382 *
1383 * linux_getpid() - MP SAFE
1384 * linux_getgid() - MP SAFE
1385 * linux_getuid() - MP SAFE
1386 */
1387
1388 int
1389 linux_getpid(struct thread *td, struct linux_getpid_args *args)
1390 {
1391
1392 td->td_retval[0] = td->td_proc->p_pid;
1393 return (0);
1394 }
1395
1396 int
1397 linux_getgid(struct thread *td, struct linux_getgid_args *args)
1398 {
1399
1400 td->td_retval[0] = td->td_ucred->cr_rgid;
1401 return (0);
1402 }
1403
1404 int
1405 linux_getuid(struct thread *td, struct linux_getuid_args *args)
1406 {
1407
1408 td->td_retval[0] = td->td_ucred->cr_ruid;
1409 return (0);
1410 }
1411
1412 #endif /*!__alpha__*/
1413
1414 int
1415 linux_getsid(struct thread *td, struct linux_getsid_args *args)
1416 {
1417 struct getsid_args bsd;
1418 bsd.pid = args->pid;
1419 return getsid(td, &bsd);
1420 }
1421
1422 int
1423 linux_nosys(struct thread *td, struct nosys_args *ignore)
1424 {
1425
1426 return (ENOSYS);
1427 }
1428
1429 int
1430 linux_getpriority(struct thread *td, struct linux_getpriority_args *args)
1431 {
1432 struct getpriority_args bsd_args;
1433 int error;
1434
1435 bsd_args.which = args->which;
1436 bsd_args.who = args->who;
1437 error = getpriority(td, &bsd_args);
1438 td->td_retval[0] = 20 - td->td_retval[0];
1439 return error;
1440 }
Cache object: e6c566245c1a0586d04535db9867d930
|