2 * Copyright (c) 2002 Doug Rabson
3 * Copyright (c) 1994-1995 Søren Schmidt
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
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.
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include "opt_compat.h"
34 #include "opt_kdtrace.h"
36 #include <sys/param.h>
37 #include <sys/blist.h>
38 #include <sys/fcntl.h>
40 #include <sys/imgact_aout.h>
43 #include <sys/kernel.h>
44 #include <sys/limits.h>
46 #include <sys/malloc.h>
48 #include <sys/mount.h>
49 #include <sys/mutex.h>
50 #include <sys/namei.h>
53 #include <sys/reboot.h>
54 #include <sys/racct.h>
55 #include <sys/resourcevar.h>
56 #include <sys/sched.h>
57 #include <sys/signalvar.h>
59 #include <sys/syscallsubr.h>
60 #include <sys/sysctl.h>
61 #include <sys/sysproto.h>
62 #include <sys/systm.h>
64 #include <sys/vmmeter.h>
65 #include <sys/vnode.h>
67 #include <sys/cpuset.h>
69 #include <security/mac/mac_framework.h>
73 #include <vm/vm_kern.h>
74 #include <vm/vm_map.h>
75 #include <vm/vm_extern.h>
76 #include <vm/vm_object.h>
77 #include <vm/swap_pager.h>
80 #include <machine/../linux32/linux.h>
81 #include <machine/../linux32/linux32_proto.h>
83 #include <machine/../linux/linux.h>
84 #include <machine/../linux/linux_proto.h>
87 #include <compat/linux/linux_file.h>
88 #include <compat/linux/linux_mib.h>
89 #include <compat/linux/linux_signal.h>
90 #include <compat/linux/linux_util.h>
91 #include <compat/linux/linux_sysproto.h>
92 #include <compat/linux/linux_emul.h>
93 #include <compat/linux/linux_misc.h>
95 int stclohz; /* Statistics clock frequency */
97 static unsigned int linux_to_bsd_resource[LINUX_RLIM_NLIMITS] = {
98 RLIMIT_CPU, RLIMIT_FSIZE, RLIMIT_DATA, RLIMIT_STACK,
99 RLIMIT_CORE, RLIMIT_RSS, RLIMIT_NPROC, RLIMIT_NOFILE,
100 RLIMIT_MEMLOCK, RLIMIT_AS
104 l_long uptime; /* Seconds since boot */
105 l_ulong loads[3]; /* 1, 5, and 15 minute load averages */
106 #define LINUX_SYSINFO_LOADS_SCALE 65536
107 l_ulong totalram; /* Total usable main memory size */
108 l_ulong freeram; /* Available memory size */
109 l_ulong sharedram; /* Amount of shared memory */
110 l_ulong bufferram; /* Memory used by buffers */
111 l_ulong totalswap; /* Total swap space size */
112 l_ulong freeswap; /* swap space still available */
113 l_ushort procs; /* Number of current processes */
118 char _f[20-2*sizeof(l_long)-sizeof(l_int)]; /* padding */
121 linux_sysinfo(struct thread *td, struct linux_sysinfo_args *args)
123 struct l_sysinfo sysinfo;
131 sysinfo.uptime = ts.tv_sec;
133 /* Use the information from the mib to get our load averages */
134 for (i = 0; i < 3; i++)
135 sysinfo.loads[i] = averunnable.ldavg[i] *
136 LINUX_SYSINFO_LOADS_SCALE / averunnable.fscale;
138 sysinfo.totalram = physmem * PAGE_SIZE;
139 sysinfo.freeram = sysinfo.totalram - cnt.v_wire_count * PAGE_SIZE;
141 sysinfo.sharedram = 0;
142 mtx_lock(&vm_object_list_mtx);
143 TAILQ_FOREACH(object, &vm_object_list, object_list)
144 if (object->shadow_count > 1)
145 sysinfo.sharedram += object->resident_page_count;
146 mtx_unlock(&vm_object_list_mtx);
148 sysinfo.sharedram *= PAGE_SIZE;
149 sysinfo.bufferram = 0;
151 swap_pager_status(&i, &j);
152 sysinfo.totalswap = i * PAGE_SIZE;
153 sysinfo.freeswap = (i - j) * PAGE_SIZE;
155 sysinfo.procs = nprocs;
157 /* The following are only present in newer Linux kernels. */
158 sysinfo.totalbig = 0;
160 sysinfo.mem_unit = 1;
162 return (copyout(&sysinfo, args->info, sizeof(sysinfo)));
166 linux_alarm(struct thread *td, struct linux_alarm_args *args)
168 struct itimerval it, old_it;
174 printf(ARGS(alarm, "%u"), args->secs);
182 it.it_value.tv_sec = (long) secs;
183 it.it_value.tv_usec = 0;
184 it.it_interval.tv_sec = 0;
185 it.it_interval.tv_usec = 0;
186 error = kern_setitimer(td, ITIMER_REAL, &it, &old_it);
189 if (timevalisset(&old_it.it_value)) {
190 if (old_it.it_value.tv_usec != 0)
191 old_it.it_value.tv_sec++;
192 td->td_retval[0] = old_it.it_value.tv_sec;
198 linux_brk(struct thread *td, struct linux_brk_args *args)
200 struct vmspace *vm = td->td_proc->p_vmspace;
201 vm_offset_t new, old;
202 struct obreak_args /* {
208 printf(ARGS(brk, "%p"), (void *)(uintptr_t)args->dsend);
210 old = (vm_offset_t)vm->vm_daddr + ctob(vm->vm_dsize);
211 new = (vm_offset_t)args->dsend;
212 tmp.nsize = (char *)new;
213 if (((caddr_t)new > vm->vm_daddr) && !sys_obreak(td, &tmp))
214 td->td_retval[0] = (long)new;
216 td->td_retval[0] = (long)old;
221 #if defined(__i386__)
222 /* XXX: what about amd64/linux32? */
225 linux_uselib(struct thread *td, struct linux_uselib_args *args)
232 unsigned long file_offset;
233 unsigned long bss_size;
236 int error, locked, writecount;
238 LCONVPATHEXIST(td, args->library, &library);
242 printf(ARGS(uselib, "%s"), library);
249 NDINIT(&ni, LOOKUP, ISOPEN | FOLLOW | LOCKLEAF | AUDITVNODE1,
250 UIO_SYSSPACE, library, td);
257 NDFREE(&ni, NDF_ONLY_PNBUF);
260 * From here on down, we have a locked vnode that must be unlocked.
261 * XXX: The code below largely duplicates exec_check_permissions().
266 error = VOP_GET_WRITECOUNT(vp, &writecount);
269 if (writecount != 0) {
275 error = VOP_GETATTR(vp, &attr, td->td_ucred);
279 if ((vp->v_mount->mnt_flag & MNT_NOEXEC) ||
280 ((attr.va_mode & 0111) == 0) || (attr.va_type != VREG)) {
281 /* EACCESS is what exec(2) returns. */
287 if (attr.va_size == 0) {
292 /* Can we access it? */
293 error = VOP_ACCESS(vp, VEXEC, td->td_ucred, td);
298 * XXX: This should use vn_open() so that it is properly authorized,
299 * and to reduce code redundancy all over the place here.
300 * XXX: Not really, it duplicates far more of exec_check_permissions()
304 error = mac_vnode_check_open(td->td_ucred, vp, VREAD);
308 error = VOP_OPEN(vp, FREAD, td->td_ucred, td, NULL);
312 /* Pull in executable header into exec_map */
313 error = vm_mmap(exec_map, (vm_offset_t *)&a_out, PAGE_SIZE,
314 VM_PROT_READ, VM_PROT_READ, 0, OBJT_VNODE, vp, 0);
318 /* Is it a Linux binary ? */
319 if (((a_out->a_magic >> 16) & 0xff) != 0x64) {
325 * While we are here, we should REALLY do some more checks
328 /* Set file/virtual offset based on a.out variant. */
329 switch ((int)(a_out->a_magic & 0xffff)) {
330 case 0413: /* ZMAGIC */
333 case 0314: /* QMAGIC */
341 bss_size = round_page(a_out->a_bss);
343 /* Check various fields in header for validity/bounds. */
344 if (a_out->a_text & PAGE_MASK || a_out->a_data & PAGE_MASK) {
349 /* text + data can't exceed file size */
350 if (a_out->a_data + a_out->a_text > attr.va_size) {
356 * text/data/bss must not exceed limits
357 * XXX - this is not complete. it should check current usage PLUS
358 * the resources needed by this library.
360 PROC_LOCK(td->td_proc);
361 if (a_out->a_text > maxtsiz ||
362 a_out->a_data + bss_size > lim_cur(td->td_proc, RLIMIT_DATA) ||
363 racct_set(td->td_proc, RACCT_DATA, a_out->a_data +
365 PROC_UNLOCK(td->td_proc);
369 PROC_UNLOCK(td->td_proc);
372 * Prevent more writers.
373 * XXX: Note that if any of the VM operations fail below we don't
379 * Lock no longer needed
385 * Check if file_offset page aligned. Currently we cannot handle
386 * misalinged file offsets, and so we read in the entire image
389 if (file_offset & PAGE_MASK) {
391 printf("uselib: Non page aligned binary %lu\n", file_offset);
393 /* Map text+data read/write/execute */
395 /* a_entry is the load address and is page aligned */
396 vmaddr = trunc_page(a_out->a_entry);
398 /* get anon user mapping, read+write+execute */
399 error = vm_map_find(&td->td_proc->p_vmspace->vm_map, NULL, 0,
400 &vmaddr, a_out->a_text + a_out->a_data, 0, VMFS_NO_SPACE,
401 VM_PROT_ALL, VM_PROT_ALL, 0);
405 error = vn_rdwr(UIO_READ, vp, (void *)vmaddr, file_offset,
406 a_out->a_text + a_out->a_data, UIO_USERSPACE, 0,
407 td->td_ucred, NOCRED, &aresid, td);
416 printf("uselib: Page aligned binary %lu\n", file_offset);
419 * for QMAGIC, a_entry is 20 bytes beyond the load address
420 * to skip the executable header
422 vmaddr = trunc_page(a_out->a_entry);
425 * Map it all into the process's space as a single
426 * copy-on-write "data" segment.
428 error = vm_mmap(&td->td_proc->p_vmspace->vm_map, &vmaddr,
429 a_out->a_text + a_out->a_data, VM_PROT_ALL, VM_PROT_ALL,
430 MAP_PRIVATE | MAP_FIXED, OBJT_VNODE, vp, file_offset);
435 printf("mem=%08lx = %08lx %08lx\n", (long)vmaddr, ((long *)vmaddr)[0],
436 ((long *)vmaddr)[1]);
439 /* Calculate BSS start address */
440 vmaddr = trunc_page(a_out->a_entry) + a_out->a_text +
443 /* allocate some 'anon' space */
444 error = vm_map_find(&td->td_proc->p_vmspace->vm_map, NULL, 0,
445 &vmaddr, bss_size, 0, VMFS_NO_SPACE, VM_PROT_ALL,
452 /* Unlock vnode if needed */
456 /* Release the temporary mapping. */
458 kmap_free_wakeup(exec_map, (vm_offset_t)a_out, PAGE_SIZE);
463 #endif /* __i386__ */
466 linux_select(struct thread *td, struct linux_select_args *args)
469 struct timeval tv0, tv1, utv, *tvp;
474 printf(ARGS(select, "%d, %p, %p, %p, %p"), args->nfds,
475 (void *)args->readfds, (void *)args->writefds,
476 (void *)args->exceptfds, (void *)args->timeout);
480 * Store current time for computation of the amount of
484 if ((error = copyin(args->timeout, <v, sizeof(ltv))))
486 utv.tv_sec = ltv.tv_sec;
487 utv.tv_usec = ltv.tv_usec;
490 printf(LMSG("incoming timeout (%jd/%ld)"),
491 (intmax_t)utv.tv_sec, utv.tv_usec);
494 if (itimerfix(&utv)) {
496 * The timeval was invalid. Convert it to something
497 * valid that will act as it does under Linux.
499 utv.tv_sec += utv.tv_usec / 1000000;
500 utv.tv_usec %= 1000000;
501 if (utv.tv_usec < 0) {
503 utv.tv_usec += 1000000;
513 error = kern_select(td, args->nfds, args->readfds, args->writefds,
514 args->exceptfds, tvp, sizeof(l_int) * 8);
518 printf(LMSG("real select returns %d"), error);
524 if (td->td_retval[0]) {
526 * Compute how much time was left of the timeout,
527 * by subtracting the current time and the time
528 * before we started the call, and subtracting
529 * that result from the user-supplied value.
532 timevalsub(&tv1, &tv0);
533 timevalsub(&utv, &tv1);
540 printf(LMSG("outgoing timeout (%jd/%ld)"),
541 (intmax_t)utv.tv_sec, utv.tv_usec);
543 ltv.tv_sec = utv.tv_sec;
544 ltv.tv_usec = utv.tv_usec;
545 if ((error = copyout(<v, args->timeout, sizeof(ltv))))
552 printf(LMSG("select_out -> %d"), error);
558 linux_mremap(struct thread *td, struct linux_mremap_args *args)
560 struct munmap_args /* {
568 printf(ARGS(mremap, "%p, %08lx, %08lx, %08lx"),
569 (void *)(uintptr_t)args->addr,
570 (unsigned long)args->old_len,
571 (unsigned long)args->new_len,
572 (unsigned long)args->flags);
575 if (args->flags & ~(LINUX_MREMAP_FIXED | LINUX_MREMAP_MAYMOVE)) {
576 td->td_retval[0] = 0;
581 * Check for the page alignment.
582 * Linux defines PAGE_MASK to be FreeBSD ~PAGE_MASK.
584 if (args->addr & PAGE_MASK) {
585 td->td_retval[0] = 0;
589 args->new_len = round_page(args->new_len);
590 args->old_len = round_page(args->old_len);
592 if (args->new_len > args->old_len) {
593 td->td_retval[0] = 0;
597 if (args->new_len < args->old_len) {
599 (caddr_t)((uintptr_t)args->addr + args->new_len);
600 bsd_args.len = args->old_len - args->new_len;
601 error = sys_munmap(td, &bsd_args);
604 td->td_retval[0] = error ? 0 : (uintptr_t)args->addr;
608 #define LINUX_MS_ASYNC 0x0001
609 #define LINUX_MS_INVALIDATE 0x0002
610 #define LINUX_MS_SYNC 0x0004
613 linux_msync(struct thread *td, struct linux_msync_args *args)
615 struct msync_args bsd_args;
617 bsd_args.addr = (caddr_t)(uintptr_t)args->addr;
618 bsd_args.len = (uintptr_t)args->len;
619 bsd_args.flags = args->fl & ~LINUX_MS_SYNC;
621 return (sys_msync(td, &bsd_args));
625 linux_time(struct thread *td, struct linux_time_args *args)
633 printf(ARGS(time, "*"));
638 if (args->tm && (error = copyout(&tm, args->tm, sizeof(tm))))
640 td->td_retval[0] = tm;
644 struct l_times_argv {
647 l_clock_t tms_cutime;
648 l_clock_t tms_cstime;
653 * Glibc versions prior to 2.2.1 always use hard-coded CLK_TCK value.
654 * Since 2.2.1 Glibc uses value exported from kernel via AT_CLKTCK
655 * auxiliary vector entry.
659 #define CONVOTCK(r) (r.tv_sec * CLK_TCK + r.tv_usec / (1000000 / CLK_TCK))
660 #define CONVNTCK(r) (r.tv_sec * stclohz + r.tv_usec / (1000000 / stclohz))
662 #define CONVTCK(r) (linux_kernver(td) >= LINUX_KERNVER_2004000 ? \
663 CONVNTCK(r) : CONVOTCK(r))
666 linux_times(struct thread *td, struct linux_times_args *args)
668 struct timeval tv, utime, stime, cutime, cstime;
669 struct l_times_argv tms;
675 printf(ARGS(times, "*"));
678 if (args->buf != NULL) {
682 calcru(p, &utime, &stime);
684 calccru(p, &cutime, &cstime);
687 tms.tms_utime = CONVTCK(utime);
688 tms.tms_stime = CONVTCK(stime);
690 tms.tms_cutime = CONVTCK(cutime);
691 tms.tms_cstime = CONVTCK(cstime);
693 if ((error = copyout(&tms, args->buf, sizeof(tms))))
698 td->td_retval[0] = (int)CONVTCK(tv);
703 linux_newuname(struct thread *td, struct linux_newuname_args *args)
705 struct l_new_utsname utsname;
706 char osname[LINUX_MAX_UTSNAME];
707 char osrelease[LINUX_MAX_UTSNAME];
711 if (ldebug(newuname))
712 printf(ARGS(newuname, "*"));
715 linux_get_osname(td, osname);
716 linux_get_osrelease(td, osrelease);
718 bzero(&utsname, sizeof(utsname));
719 strlcpy(utsname.sysname, osname, LINUX_MAX_UTSNAME);
720 getcredhostname(td->td_ucred, utsname.nodename, LINUX_MAX_UTSNAME);
721 getcreddomainname(td->td_ucred, utsname.domainname, LINUX_MAX_UTSNAME);
722 strlcpy(utsname.release, osrelease, LINUX_MAX_UTSNAME);
723 strlcpy(utsname.version, version, LINUX_MAX_UTSNAME);
724 for (p = utsname.version; *p != '\0'; ++p)
729 strlcpy(utsname.machine, linux_platform, LINUX_MAX_UTSNAME);
731 return (copyout(&utsname, args->buf, sizeof(utsname)));
734 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
741 linux_utime(struct thread *td, struct linux_utime_args *args)
743 struct timeval tv[2], *tvp;
744 struct l_utimbuf lut;
748 LCONVPATHEXIST(td, args->fname, &fname);
752 printf(ARGS(utime, "%s, *"), fname);
756 if ((error = copyin(args->times, &lut, sizeof lut))) {
760 tv[0].tv_sec = lut.l_actime;
762 tv[1].tv_sec = lut.l_modtime;
768 error = kern_utimes(td, fname, UIO_SYSSPACE, tvp, UIO_SYSSPACE);
774 linux_utimes(struct thread *td, struct linux_utimes_args *args)
777 struct timeval tv[2], *tvp = NULL;
781 LCONVPATHEXIST(td, args->fname, &fname);
785 printf(ARGS(utimes, "%s, *"), fname);
788 if (args->tptr != NULL) {
789 if ((error = copyin(args->tptr, ltv, sizeof ltv))) {
793 tv[0].tv_sec = ltv[0].tv_sec;
794 tv[0].tv_usec = ltv[0].tv_usec;
795 tv[1].tv_sec = ltv[1].tv_sec;
796 tv[1].tv_usec = ltv[1].tv_usec;
800 error = kern_utimes(td, fname, UIO_SYSSPACE, tvp, UIO_SYSSPACE);
806 linux_futimesat(struct thread *td, struct linux_futimesat_args *args)
809 struct timeval tv[2], *tvp = NULL;
813 dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
814 LCONVPATHEXIST_AT(td, args->filename, &fname, dfd);
817 if (ldebug(futimesat))
818 printf(ARGS(futimesat, "%s, *"), fname);
821 if (args->utimes != NULL) {
822 if ((error = copyin(args->utimes, ltv, sizeof ltv))) {
826 tv[0].tv_sec = ltv[0].tv_sec;
827 tv[0].tv_usec = ltv[0].tv_usec;
828 tv[1].tv_sec = ltv[1].tv_sec;
829 tv[1].tv_usec = ltv[1].tv_usec;
833 error = kern_utimesat(td, dfd, fname, UIO_SYSSPACE, tvp, UIO_SYSSPACE);
837 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
840 linux_common_wait(struct thread *td, int pid, int *status,
841 int options, struct rusage *ru)
845 error = kern_wait(td, pid, &tmpstat, options, ru);
851 if (WIFSIGNALED(tmpstat))
852 tmpstat = (tmpstat & 0xffffff80) |
853 BSD_TO_LINUX_SIGNAL(WTERMSIG(tmpstat));
854 else if (WIFSTOPPED(tmpstat))
855 tmpstat = (tmpstat & 0xffff00ff) |
856 (BSD_TO_LINUX_SIGNAL(WSTOPSIG(tmpstat)) << 8);
857 error = copyout(&tmpstat, status, sizeof(int));
864 linux_waitpid(struct thread *td, struct linux_waitpid_args *args)
870 printf(ARGS(waitpid, "%d, %p, %d"),
871 args->pid, (void *)args->status, args->options);
874 * this is necessary because the test in kern_wait doesn't work
875 * because we mess with the options here
877 if (args->options & ~(WUNTRACED | WNOHANG | WCONTINUED | __WCLONE))
880 options = (args->options & (WNOHANG | WUNTRACED));
881 /* WLINUXCLONE should be equal to __WCLONE, but we make sure */
882 if (args->options & __WCLONE)
883 options |= WLINUXCLONE;
885 return (linux_common_wait(td, args->pid, args->status, options, NULL));
889 linux_wait4(struct thread *td, struct linux_wait4_args *args)
892 struct rusage ru, *rup;
896 printf(ARGS(wait4, "%d, %p, %d, %p"),
897 args->pid, (void *)args->status, args->options,
898 (void *)args->rusage);
901 options = (args->options & (WNOHANG | WUNTRACED));
902 /* WLINUXCLONE should be equal to __WCLONE, but we make sure */
903 if (args->options & __WCLONE)
904 options |= WLINUXCLONE;
906 if (args->rusage != NULL)
910 error = linux_common_wait(td, args->pid, args->status, options, rup);
913 if (args->rusage != NULL)
914 error = linux_copyout_rusage(&ru, args->rusage);
919 linux_waitid(struct thread *td, struct linux_waitid_args *args)
921 int status, options, sig;
922 struct __wrusage wru;
930 linux_to_bsd_waitopts(args->options, &options);
932 if (options & ~(WNOHANG | WNOWAIT | WEXITED | WUNTRACED | WCONTINUED))
934 if (!(options & (WEXITED | WUNTRACED | WCONTINUED)))
937 switch (args->idtype) {
955 error = kern_wait6(td, idtype, args->id, &status, options,
959 if (args->rusage != NULL) {
960 error = linux_copyout_rusage(&wru.wru_children,
965 if (args->info != NULL) {
967 if (td->td_retval[0] == 0)
968 bzero(&lsi, sizeof(lsi));
970 sig = BSD_TO_LINUX_SIGNAL(siginfo.si_signo);
971 siginfo_to_lsiginfo(&siginfo, &lsi, sig);
973 error = copyout(&lsi, args->info, sizeof(lsi));
975 td->td_retval[0] = 0;
981 linux_mknod(struct thread *td, struct linux_mknod_args *args)
986 LCONVPATHCREAT(td, args->path, &path);
990 printf(ARGS(mknod, "%s, %d, %d"), path, args->mode, args->dev);
993 switch (args->mode & S_IFMT) {
996 error = kern_mkfifo(td, path, UIO_SYSSPACE, args->mode);
1001 error = kern_mknod(td, path, UIO_SYSSPACE, args->mode,
1010 args->mode |= S_IFREG;
1013 error = kern_open(td, path, UIO_SYSSPACE,
1014 O_WRONLY | O_CREAT | O_TRUNC, args->mode);
1016 kern_close(td, td->td_retval[0]);
1028 linux_mknodat(struct thread *td, struct linux_mknodat_args *args)
1033 dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
1034 LCONVPATHCREAT_AT(td, args->filename, &path, dfd);
1037 if (ldebug(mknodat))
1038 printf(ARGS(mknodat, "%s, %d, %d"), path, args->mode, args->dev);
1041 switch (args->mode & S_IFMT) {
1044 error = kern_mkfifoat(td, dfd, path, UIO_SYSSPACE, args->mode);
1049 error = kern_mknodat(td, dfd, path, UIO_SYSSPACE, args->mode,
1058 args->mode |= S_IFREG;
1061 error = kern_openat(td, dfd, path, UIO_SYSSPACE,
1062 O_WRONLY | O_CREAT | O_TRUNC, args->mode);
1064 kern_close(td, td->td_retval[0]);
1076 * UGH! This is just about the dumbest idea I've ever heard!!
1079 linux_personality(struct thread *td, struct linux_personality_args *args)
1082 if (ldebug(personality))
1083 printf(ARGS(personality, "%lu"), (unsigned long)args->per);
1088 /* Yes Jim, it's still a Linux... */
1089 td->td_retval[0] = 0;
1093 struct l_itimerval {
1094 l_timeval it_interval;
1098 #define B2L_ITIMERVAL(bip, lip) \
1099 (bip)->it_interval.tv_sec = (lip)->it_interval.tv_sec; \
1100 (bip)->it_interval.tv_usec = (lip)->it_interval.tv_usec; \
1101 (bip)->it_value.tv_sec = (lip)->it_value.tv_sec; \
1102 (bip)->it_value.tv_usec = (lip)->it_value.tv_usec;
1105 linux_setitimer(struct thread *td, struct linux_setitimer_args *uap)
1108 struct l_itimerval ls;
1109 struct itimerval aitv, oitv;
1112 if (ldebug(setitimer))
1113 printf(ARGS(setitimer, "%p, %p"),
1114 (void *)uap->itv, (void *)uap->oitv);
1117 if (uap->itv == NULL) {
1118 uap->itv = uap->oitv;
1119 return (linux_getitimer(td, (struct linux_getitimer_args *)uap));
1122 error = copyin(uap->itv, &ls, sizeof(ls));
1125 B2L_ITIMERVAL(&aitv, &ls);
1127 if (ldebug(setitimer)) {
1128 printf("setitimer: value: sec: %jd, usec: %ld\n",
1129 (intmax_t)aitv.it_value.tv_sec, aitv.it_value.tv_usec);
1130 printf("setitimer: interval: sec: %jd, usec: %ld\n",
1131 (intmax_t)aitv.it_interval.tv_sec, aitv.it_interval.tv_usec);
1134 error = kern_setitimer(td, uap->which, &aitv, &oitv);
1135 if (error != 0 || uap->oitv == NULL)
1137 B2L_ITIMERVAL(&ls, &oitv);
1139 return (copyout(&ls, uap->oitv, sizeof(ls)));
1143 linux_getitimer(struct thread *td, struct linux_getitimer_args *uap)
1146 struct l_itimerval ls;
1147 struct itimerval aitv;
1150 if (ldebug(getitimer))
1151 printf(ARGS(getitimer, "%p"), (void *)uap->itv);
1153 error = kern_getitimer(td, uap->which, &aitv);
1156 B2L_ITIMERVAL(&ls, &aitv);
1157 return (copyout(&ls, uap->itv, sizeof(ls)));
1161 linux_nice(struct thread *td, struct linux_nice_args *args)
1163 struct setpriority_args bsd_args;
1165 bsd_args.which = PRIO_PROCESS;
1166 bsd_args.who = 0; /* current process */
1167 bsd_args.prio = args->inc;
1168 return (sys_setpriority(td, &bsd_args));
1172 linux_setgroups(struct thread *td, struct linux_setgroups_args *args)
1174 struct ucred *newcred, *oldcred;
1175 l_gid_t *linux_gidset;
1180 ngrp = args->gidsetsize;
1181 if (ngrp < 0 || ngrp >= ngroups_max + 1)
1183 linux_gidset = malloc(ngrp * sizeof(*linux_gidset), M_TEMP, M_WAITOK);
1184 error = copyin(args->grouplist, linux_gidset, ngrp * sizeof(l_gid_t));
1190 oldcred = crcopysafe(p, newcred);
1193 * cr_groups[0] holds egid. Setting the whole set from
1194 * the supplied set will cause egid to be changed too.
1195 * Keep cr_groups[0] unchanged to prevent that.
1198 if ((error = priv_check_cred(oldcred, PRIV_CRED_SETGROUPS, 0)) != 0) {
1205 newcred->cr_ngroups = ngrp + 1;
1207 bsd_gidset = newcred->cr_groups;
1210 bsd_gidset[ngrp + 1] = linux_gidset[ngrp];
1214 newcred->cr_ngroups = 1;
1217 p->p_ucred = newcred;
1222 free(linux_gidset, M_TEMP);
1227 linux_getgroups(struct thread *td, struct linux_getgroups_args *args)
1230 l_gid_t *linux_gidset;
1232 int bsd_gidsetsz, ngrp, error;
1234 cred = td->td_ucred;
1235 bsd_gidset = cred->cr_groups;
1236 bsd_gidsetsz = cred->cr_ngroups - 1;
1239 * cr_groups[0] holds egid. Returning the whole set
1240 * here will cause a duplicate. Exclude cr_groups[0]
1244 if ((ngrp = args->gidsetsize) == 0) {
1245 td->td_retval[0] = bsd_gidsetsz;
1249 if (ngrp < bsd_gidsetsz)
1253 linux_gidset = malloc(bsd_gidsetsz * sizeof(*linux_gidset),
1255 while (ngrp < bsd_gidsetsz) {
1256 linux_gidset[ngrp] = bsd_gidset[ngrp + 1];
1260 error = copyout(linux_gidset, args->grouplist, ngrp * sizeof(l_gid_t));
1261 free(linux_gidset, M_TEMP);
1265 td->td_retval[0] = ngrp;
1270 linux_setrlimit(struct thread *td, struct linux_setrlimit_args *args)
1272 struct rlimit bsd_rlim;
1273 struct l_rlimit rlim;
1278 if (ldebug(setrlimit))
1279 printf(ARGS(setrlimit, "%d, %p"),
1280 args->resource, (void *)args->rlim);
1283 if (args->resource >= LINUX_RLIM_NLIMITS)
1286 which = linux_to_bsd_resource[args->resource];
1290 error = copyin(args->rlim, &rlim, sizeof(rlim));
1294 bsd_rlim.rlim_cur = (rlim_t)rlim.rlim_cur;
1295 bsd_rlim.rlim_max = (rlim_t)rlim.rlim_max;
1296 return (kern_setrlimit(td, which, &bsd_rlim));
1300 linux_old_getrlimit(struct thread *td, struct linux_old_getrlimit_args *args)
1302 struct l_rlimit rlim;
1303 struct proc *p = td->td_proc;
1304 struct rlimit bsd_rlim;
1308 if (ldebug(old_getrlimit))
1309 printf(ARGS(old_getrlimit, "%d, %p"),
1310 args->resource, (void *)args->rlim);
1313 if (args->resource >= LINUX_RLIM_NLIMITS)
1316 which = linux_to_bsd_resource[args->resource];
1321 lim_rlimit(p, which, &bsd_rlim);
1324 #ifdef COMPAT_LINUX32
1325 rlim.rlim_cur = (unsigned int)bsd_rlim.rlim_cur;
1326 if (rlim.rlim_cur == UINT_MAX)
1327 rlim.rlim_cur = INT_MAX;
1328 rlim.rlim_max = (unsigned int)bsd_rlim.rlim_max;
1329 if (rlim.rlim_max == UINT_MAX)
1330 rlim.rlim_max = INT_MAX;
1332 rlim.rlim_cur = (unsigned long)bsd_rlim.rlim_cur;
1333 if (rlim.rlim_cur == ULONG_MAX)
1334 rlim.rlim_cur = LONG_MAX;
1335 rlim.rlim_max = (unsigned long)bsd_rlim.rlim_max;
1336 if (rlim.rlim_max == ULONG_MAX)
1337 rlim.rlim_max = LONG_MAX;
1339 return (copyout(&rlim, args->rlim, sizeof(rlim)));
1343 linux_getrlimit(struct thread *td, struct linux_getrlimit_args *args)
1345 struct l_rlimit rlim;
1346 struct proc *p = td->td_proc;
1347 struct rlimit bsd_rlim;
1351 if (ldebug(getrlimit))
1352 printf(ARGS(getrlimit, "%d, %p"),
1353 args->resource, (void *)args->rlim);
1356 if (args->resource >= LINUX_RLIM_NLIMITS)
1359 which = linux_to_bsd_resource[args->resource];
1364 lim_rlimit(p, which, &bsd_rlim);
1367 rlim.rlim_cur = (l_ulong)bsd_rlim.rlim_cur;
1368 rlim.rlim_max = (l_ulong)bsd_rlim.rlim_max;
1369 return (copyout(&rlim, args->rlim, sizeof(rlim)));
1373 linux_sched_setscheduler(struct thread *td,
1374 struct linux_sched_setscheduler_args *args)
1376 struct sched_param sched_param;
1381 if (ldebug(sched_setscheduler))
1382 printf(ARGS(sched_setscheduler, "%d, %d, %p"),
1383 args->pid, args->policy, (const void *)args->param);
1386 switch (args->policy) {
1387 case LINUX_SCHED_OTHER:
1388 policy = SCHED_OTHER;
1390 case LINUX_SCHED_FIFO:
1391 policy = SCHED_FIFO;
1393 case LINUX_SCHED_RR:
1400 error = copyin(args->param, &sched_param, sizeof(sched_param));
1404 tdt = linux_tdfind(td, args->pid, -1);
1408 error = kern_sched_setscheduler(td, tdt, policy, &sched_param);
1409 PROC_UNLOCK(tdt->td_proc);
1414 linux_sched_getscheduler(struct thread *td,
1415 struct linux_sched_getscheduler_args *args)
1421 if (ldebug(sched_getscheduler))
1422 printf(ARGS(sched_getscheduler, "%d"), args->pid);
1425 tdt = linux_tdfind(td, args->pid, -1);
1429 error = kern_sched_getscheduler(td, tdt, &policy);
1430 PROC_UNLOCK(tdt->td_proc);
1434 td->td_retval[0] = LINUX_SCHED_OTHER;
1437 td->td_retval[0] = LINUX_SCHED_FIFO;
1440 td->td_retval[0] = LINUX_SCHED_RR;
1447 linux_sched_get_priority_max(struct thread *td,
1448 struct linux_sched_get_priority_max_args *args)
1450 struct sched_get_priority_max_args bsd;
1453 if (ldebug(sched_get_priority_max))
1454 printf(ARGS(sched_get_priority_max, "%d"), args->policy);
1457 switch (args->policy) {
1458 case LINUX_SCHED_OTHER:
1459 bsd.policy = SCHED_OTHER;
1461 case LINUX_SCHED_FIFO:
1462 bsd.policy = SCHED_FIFO;
1464 case LINUX_SCHED_RR:
1465 bsd.policy = SCHED_RR;
1470 return (sys_sched_get_priority_max(td, &bsd));
1474 linux_sched_get_priority_min(struct thread *td,
1475 struct linux_sched_get_priority_min_args *args)
1477 struct sched_get_priority_min_args bsd;
1480 if (ldebug(sched_get_priority_min))
1481 printf(ARGS(sched_get_priority_min, "%d"), args->policy);
1484 switch (args->policy) {
1485 case LINUX_SCHED_OTHER:
1486 bsd.policy = SCHED_OTHER;
1488 case LINUX_SCHED_FIFO:
1489 bsd.policy = SCHED_FIFO;
1491 case LINUX_SCHED_RR:
1492 bsd.policy = SCHED_RR;
1497 return (sys_sched_get_priority_min(td, &bsd));
1500 #define REBOOT_CAD_ON 0x89abcdef
1501 #define REBOOT_CAD_OFF 0
1502 #define REBOOT_HALT 0xcdef0123
1503 #define REBOOT_RESTART 0x01234567
1504 #define REBOOT_RESTART2 0xA1B2C3D4
1505 #define REBOOT_POWEROFF 0x4321FEDC
1506 #define REBOOT_MAGIC1 0xfee1dead
1507 #define REBOOT_MAGIC2 0x28121969
1508 #define REBOOT_MAGIC2A 0x05121996
1509 #define REBOOT_MAGIC2B 0x16041998
1512 linux_reboot(struct thread *td, struct linux_reboot_args *args)
1514 struct reboot_args bsd_args;
1518 printf(ARGS(reboot, "0x%x"), args->cmd);
1521 if (args->magic1 != REBOOT_MAGIC1)
1524 switch (args->magic2) {
1526 case REBOOT_MAGIC2A:
1527 case REBOOT_MAGIC2B:
1533 switch (args->cmd) {
1535 case REBOOT_CAD_OFF:
1536 return (priv_check(td, PRIV_REBOOT));
1538 bsd_args.opt = RB_HALT;
1540 case REBOOT_RESTART:
1541 case REBOOT_RESTART2:
1544 case REBOOT_POWEROFF:
1545 bsd_args.opt = RB_POWEROFF;
1550 return (sys_reboot(td, &bsd_args));
1555 * The FreeBSD native getpid(2), getgid(2) and getuid(2) also modify
1556 * td->td_retval[1] when COMPAT_43 is defined. This clobbers registers that
1557 * are assumed to be preserved. The following lightweight syscalls fixes
1558 * this. See also linux_getgid16() and linux_getuid16() in linux_uid16.c
1560 * linux_getpid() - MP SAFE
1561 * linux_getgid() - MP SAFE
1562 * linux_getuid() - MP SAFE
1566 linux_getpid(struct thread *td, struct linux_getpid_args *args)
1571 printf(ARGS(getpid, ""));
1573 td->td_retval[0] = td->td_proc->p_pid;
1579 linux_gettid(struct thread *td, struct linux_gettid_args *args)
1581 struct linux_emuldata *em;
1585 printf(ARGS(gettid, ""));
1589 KASSERT(em != NULL, ("gettid: emuldata not found.\n"));
1591 td->td_retval[0] = em->em_tid;
1598 linux_getppid(struct thread *td, struct linux_getppid_args *args)
1602 if (ldebug(getppid))
1603 printf(ARGS(getppid, ""));
1606 PROC_LOCK(td->td_proc);
1607 td->td_retval[0] = td->td_proc->p_pptr->p_pid;
1608 PROC_UNLOCK(td->td_proc);
1613 linux_getgid(struct thread *td, struct linux_getgid_args *args)
1618 printf(ARGS(getgid, ""));
1621 td->td_retval[0] = td->td_ucred->cr_rgid;
1626 linux_getuid(struct thread *td, struct linux_getuid_args *args)
1631 printf(ARGS(getuid, ""));
1634 td->td_retval[0] = td->td_ucred->cr_ruid;
1640 linux_getsid(struct thread *td, struct linux_getsid_args *args)
1642 struct getsid_args bsd;
1646 printf(ARGS(getsid, "%i"), args->pid);
1649 bsd.pid = args->pid;
1650 return (sys_getsid(td, &bsd));
1654 linux_nosys(struct thread *td, struct nosys_args *ignore)
1661 linux_getpriority(struct thread *td, struct linux_getpriority_args *args)
1663 struct getpriority_args bsd_args;
1667 if (ldebug(getpriority))
1668 printf(ARGS(getpriority, "%i, %i"), args->which, args->who);
1671 bsd_args.which = args->which;
1672 bsd_args.who = args->who;
1673 error = sys_getpriority(td, &bsd_args);
1674 td->td_retval[0] = 20 - td->td_retval[0];
1679 linux_sethostname(struct thread *td, struct linux_sethostname_args *args)
1684 if (ldebug(sethostname))
1685 printf(ARGS(sethostname, "*, %i"), args->len);
1689 name[1] = KERN_HOSTNAME;
1690 return (userland_sysctl(td, name, 2, 0, 0, 0, args->hostname,
1695 linux_setdomainname(struct thread *td, struct linux_setdomainname_args *args)
1700 if (ldebug(setdomainname))
1701 printf(ARGS(setdomainname, "*, %i"), args->len);
1705 name[1] = KERN_NISDOMAINNAME;
1706 return (userland_sysctl(td, name, 2, 0, 0, 0, args->name,
1711 linux_exit_group(struct thread *td, struct linux_exit_group_args *args)
1715 if (ldebug(exit_group))
1716 printf(ARGS(exit_group, "%i"), args->error_code);
1719 LINUX_CTR2(exit_group, "thread(%d) (%d)", td->td_tid,
1723 * XXX: we should send a signal to the parent if
1724 * SIGNAL_EXIT_GROUP is set. We ignore that (temporarily?)
1725 * as it doesnt occur often.
1727 exit1(td, W_EXITCODE(args->error_code, 0));
1731 #define _LINUX_CAPABILITY_VERSION 0x19980330
1733 struct l_user_cap_header {
1738 struct l_user_cap_data {
1745 linux_capget(struct thread *td, struct linux_capget_args *args)
1747 struct l_user_cap_header luch;
1748 struct l_user_cap_data lucd;
1751 if (args->hdrp == NULL)
1754 error = copyin(args->hdrp, &luch, sizeof(luch));
1758 if (luch.version != _LINUX_CAPABILITY_VERSION) {
1759 luch.version = _LINUX_CAPABILITY_VERSION;
1760 error = copyout(&luch, args->hdrp, sizeof(luch));
1771 * The current implementation doesn't support setting
1772 * a capability (it's essentially a stub) so indicate
1773 * that no capabilities are currently set or available
1776 bzero (&lucd, sizeof(lucd));
1777 error = copyout(&lucd, args->datap, sizeof(lucd));
1784 linux_capset(struct thread *td, struct linux_capset_args *args)
1786 struct l_user_cap_header luch;
1787 struct l_user_cap_data lucd;
1790 if (args->hdrp == NULL || args->datap == NULL)
1793 error = copyin(args->hdrp, &luch, sizeof(luch));
1797 if (luch.version != _LINUX_CAPABILITY_VERSION) {
1798 luch.version = _LINUX_CAPABILITY_VERSION;
1799 error = copyout(&luch, args->hdrp, sizeof(luch));
1808 error = copyin(args->datap, &lucd, sizeof(lucd));
1812 /* We currently don't support setting any capabilities. */
1813 if (lucd.effective || lucd.permitted || lucd.inheritable) {
1815 "capset effective=0x%x, permitted=0x%x, "
1816 "inheritable=0x%x is not implemented",
1817 (int)lucd.effective, (int)lucd.permitted,
1818 (int)lucd.inheritable);
1826 linux_prctl(struct thread *td, struct linux_prctl_args *args)
1828 int error = 0, max_size;
1829 struct proc *p = td->td_proc;
1830 char comm[LINUX_MAX_COMM_LEN];
1831 struct linux_emuldata *em;
1836 printf(ARGS(prctl, "%d, %d, %d, %d, %d"), args->option,
1837 args->arg2, args->arg3, args->arg4, args->arg5);
1840 switch (args->option) {
1841 case LINUX_PR_SET_PDEATHSIG:
1842 if (!LINUX_SIG_VALID(args->arg2))
1845 KASSERT(em != NULL, ("prctl: emuldata not found.\n"));
1846 em->pdeath_signal = args->arg2;
1848 case LINUX_PR_GET_PDEATHSIG:
1850 KASSERT(em != NULL, ("prctl: emuldata not found.\n"));
1851 pdeath_signal = em->pdeath_signal;
1852 error = copyout(&pdeath_signal,
1853 (void *)(register_t)args->arg2,
1854 sizeof(pdeath_signal));
1856 case LINUX_PR_GET_KEEPCAPS:
1858 * Indicate that we always clear the effective and
1859 * permitted capability sets when the user id becomes
1860 * non-zero (actually the capability sets are simply
1861 * always zero in the current implementation).
1863 td->td_retval[0] = 0;
1865 case LINUX_PR_SET_KEEPCAPS:
1867 * Ignore requests to keep the effective and permitted
1868 * capability sets when the user id becomes non-zero.
1871 case LINUX_PR_SET_NAME:
1873 * To be on the safe side we need to make sure to not
1874 * overflow the size a linux program expects. We already
1875 * do this here in the copyin, so that we don't need to
1878 max_size = MIN(sizeof(comm), sizeof(p->p_comm));
1879 error = copyinstr((void *)(register_t)args->arg2, comm,
1882 /* Linux silently truncates the name if it is too long. */
1883 if (error == ENAMETOOLONG) {
1885 * XXX: copyinstr() isn't documented to populate the
1886 * array completely, so do a copyin() to be on the
1887 * safe side. This should be changed in case
1888 * copyinstr() is changed to guarantee this.
1890 error = copyin((void *)(register_t)args->arg2, comm,
1892 comm[max_size - 1] = '\0';
1898 strlcpy(p->p_comm, comm, sizeof(p->p_comm));
1901 case LINUX_PR_GET_NAME:
1903 strlcpy(comm, p->p_comm, sizeof(comm));
1905 error = copyout(comm, (void *)(register_t)args->arg2,
1917 linux_sched_setparam(struct thread *td,
1918 struct linux_sched_setparam_args *uap)
1920 struct sched_param sched_param;
1925 if (ldebug(sched_setparam))
1926 printf(ARGS(sched_setparam, "%d, *"), uap->pid);
1929 error = copyin(uap->param, &sched_param, sizeof(sched_param));
1933 tdt = linux_tdfind(td, uap->pid, -1);
1937 error = kern_sched_setparam(td, tdt, &sched_param);
1938 PROC_UNLOCK(tdt->td_proc);
1943 linux_sched_getparam(struct thread *td,
1944 struct linux_sched_getparam_args *uap)
1946 struct sched_param sched_param;
1951 if (ldebug(sched_getparam))
1952 printf(ARGS(sched_getparam, "%d, *"), uap->pid);
1955 tdt = linux_tdfind(td, uap->pid, -1);
1959 error = kern_sched_getparam(td, tdt, &sched_param);
1960 PROC_UNLOCK(tdt->td_proc);
1962 error = copyout(&sched_param, uap->param,
1963 sizeof(sched_param));
1968 * Get affinity of a process.
1971 linux_sched_getaffinity(struct thread *td,
1972 struct linux_sched_getaffinity_args *args)
1976 struct cpuset_getaffinity_args cga;
1979 if (ldebug(sched_getaffinity))
1980 printf(ARGS(sched_getaffinity, "%d, %d, *"), args->pid,
1983 if (args->len < sizeof(cpuset_t))
1986 tdt = linux_tdfind(td, args->pid, -1);
1990 PROC_UNLOCK(tdt->td_proc);
1991 cga.level = CPU_LEVEL_WHICH;
1992 cga.which = CPU_WHICH_TID;
1993 cga.id = tdt->td_tid;
1994 cga.cpusetsize = sizeof(cpuset_t);
1995 cga.mask = (cpuset_t *) args->user_mask_ptr;
1997 if ((error = sys_cpuset_getaffinity(td, &cga)) == 0)
1998 td->td_retval[0] = sizeof(cpuset_t);
2004 * Set affinity of a process.
2007 linux_sched_setaffinity(struct thread *td,
2008 struct linux_sched_setaffinity_args *args)
2010 struct cpuset_setaffinity_args csa;
2014 if (ldebug(sched_setaffinity))
2015 printf(ARGS(sched_setaffinity, "%d, %d, *"), args->pid,
2018 if (args->len < sizeof(cpuset_t))
2021 tdt = linux_tdfind(td, args->pid, -1);
2025 PROC_UNLOCK(tdt->td_proc);
2026 csa.level = CPU_LEVEL_WHICH;
2027 csa.which = CPU_WHICH_TID;
2028 csa.id = tdt->td_tid;
2029 csa.cpusetsize = sizeof(cpuset_t);
2030 csa.mask = (cpuset_t *) args->user_mask_ptr;
2032 return (sys_cpuset_setaffinity(td, &csa));
2036 linux_sched_rr_get_interval(struct thread *td,
2037 struct linux_sched_rr_get_interval_args *uap)
2040 struct l_timespec lts;
2044 tdt = linux_tdfind(td, uap->pid, -1);
2048 error = kern_sched_rr_get_interval_td(td, tdt, &ts);
2049 PROC_UNLOCK(tdt->td_proc);
2052 lts.tv_sec = ts.tv_sec;
2053 lts.tv_nsec = ts.tv_nsec;
2054 return (copyout(<s, uap->interval, sizeof(lts)));
2058 * In case when the Linux thread is the initial thread in
2059 * the thread group thread id is equal to the process id.
2060 * Glibc depends on this magic (assert in pthread_getattr_np.c).
2063 linux_tdfind(struct thread *td, lwpid_t tid, pid_t pid)
2065 struct linux_emuldata *em;
2070 if (tid == 0 || tid == td->td_tid) {
2072 PROC_LOCK(tdt->td_proc);
2073 } else if (tid > PID_MAX)
2074 tdt = tdfind(tid, pid);
2077 * Initial thread where the tid equal to the pid.
2081 if (SV_PROC_ABI(p) != SV_ABI_LINUX) {
2083 * p is not a Linuxulator process.
2088 FOREACH_THREAD_IN_PROC(p, tdt) {
2090 if (tid == em->em_tid)
2102 linux_to_bsd_waitopts(int options, int *bsdopts)
2105 if (options & LINUX_WNOHANG)
2106 *bsdopts |= WNOHANG;
2107 if (options & LINUX_WUNTRACED)
2108 *bsdopts |= WUNTRACED;
2109 if (options & LINUX_WEXITED)
2110 *bsdopts |= WEXITED;
2111 if (options & LINUX_WCONTINUED)
2112 *bsdopts |= WCONTINUED;
2113 if (options & LINUX_WNOWAIT)
2114 *bsdopts |= WNOWAIT;
2116 if (options & __WCLONE)
2117 *bsdopts |= WLINUXCLONE;