2 * Copyright (c) 2004 Tim J. Robbins
3 * Copyright (c) 2002 Doug Rabson
4 * Copyright (c) 2000 Marcel Moolenaar
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer
12 * in this position and unchanged.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
35 #include <sys/kernel.h>
36 #include <sys/systm.h>
38 #include <sys/fcntl.h>
39 #include <sys/clock.h>
40 #include <sys/imgact.h>
41 #include <sys/limits.h>
43 #include <sys/malloc.h>
45 #include <sys/mutex.h>
48 #include <sys/resource.h>
49 #include <sys/resourcevar.h>
50 #include <sys/sched.h>
51 #include <sys/syscallsubr.h>
52 #include <sys/sysproto.h>
53 #include <sys/unistd.h>
56 #include <machine/frame.h>
57 #include <machine/pcb.h>
58 #include <machine/psl.h>
59 #include <machine/segments.h>
60 #include <machine/specialreg.h>
64 #include <vm/vm_map.h>
66 #include <compat/freebsd32/freebsd32_util.h>
67 #include <amd64/linux32/linux.h>
68 #include <amd64/linux32/linux32_proto.h>
69 #include <compat/linux/linux_ipc.h>
70 #include <compat/linux/linux_misc.h>
71 #include <compat/linux/linux_signal.h>
72 #include <compat/linux/linux_util.h>
73 #include <compat/linux/linux_emul.h>
75 struct l_old_select_argv {
79 l_uintptr_t exceptfds;
84 linux_to_bsd_sigaltstack(int lsa)
88 if (lsa & LINUX_SS_DISABLE)
90 if (lsa & LINUX_SS_ONSTACK)
95 static int linux_mmap_common(struct thread *td, l_uintptr_t addr,
96 l_size_t len, l_int prot, l_int flags, l_int fd,
100 bsd_to_linux_sigaltstack(int bsa)
104 if (bsa & SS_DISABLE)
105 lsa |= LINUX_SS_DISABLE;
106 if (bsa & SS_ONSTACK)
107 lsa |= LINUX_SS_ONSTACK;
112 bsd_to_linux_rusage(struct rusage *ru, struct l_rusage *lru)
115 lru->ru_utime.tv_sec = ru->ru_utime.tv_sec;
116 lru->ru_utime.tv_usec = ru->ru_utime.tv_usec;
117 lru->ru_stime.tv_sec = ru->ru_stime.tv_sec;
118 lru->ru_stime.tv_usec = ru->ru_stime.tv_usec;
119 lru->ru_maxrss = ru->ru_maxrss;
120 lru->ru_ixrss = ru->ru_ixrss;
121 lru->ru_idrss = ru->ru_idrss;
122 lru->ru_isrss = ru->ru_isrss;
123 lru->ru_minflt = ru->ru_minflt;
124 lru->ru_majflt = ru->ru_majflt;
125 lru->ru_nswap = ru->ru_nswap;
126 lru->ru_inblock = ru->ru_inblock;
127 lru->ru_oublock = ru->ru_oublock;
128 lru->ru_msgsnd = ru->ru_msgsnd;
129 lru->ru_msgrcv = ru->ru_msgrcv;
130 lru->ru_nsignals = ru->ru_nsignals;
131 lru->ru_nvcsw = ru->ru_nvcsw;
132 lru->ru_nivcsw = ru->ru_nivcsw;
136 linux_execve(struct thread *td, struct linux_execve_args *args)
138 struct image_args eargs;
142 LCONVPATHEXIST(td, args->path, &path);
146 printf(ARGS(execve, "%s"), path);
149 error = freebsd32_exec_copyin_args(&eargs, path, UIO_SYSSPACE,
150 args->argp, args->envp);
153 error = kern_execve(td, &eargs, NULL);
155 /* Linux process can execute FreeBSD one, do not attempt
156 * to create emuldata for such process using
157 * linux_proc_init, this leads to a panic on KASSERT
158 * because such process has p->p_emuldata == NULL.
160 if (SV_PROC_ABI(td->td_proc) == SV_ABI_LINUX)
161 error = linux_proc_init(td, 0, 0);
165 CTASSERT(sizeof(struct l_iovec32) == 8);
168 linux32_copyinuio(struct l_iovec32 *iovp, l_ulong iovcnt, struct uio **uiop)
170 struct l_iovec32 iov32;
177 if (iovcnt > UIO_MAXIOV)
179 iovlen = iovcnt * sizeof(struct iovec);
180 uio = malloc(iovlen + sizeof(*uio), M_IOV, M_WAITOK);
181 iov = (struct iovec *)(uio + 1);
182 for (i = 0; i < iovcnt; i++) {
183 error = copyin(&iovp[i], &iov32, sizeof(struct l_iovec32));
188 iov[i].iov_base = PTRIN(iov32.iov_base);
189 iov[i].iov_len = iov32.iov_len;
192 uio->uio_iovcnt = iovcnt;
193 uio->uio_segflg = UIO_USERSPACE;
194 uio->uio_offset = -1;
196 for (i = 0; i < iovcnt; i++) {
197 if (iov->iov_len > INT_MAX - uio->uio_resid) {
201 uio->uio_resid += iov->iov_len;
209 linux32_copyiniov(struct l_iovec32 *iovp32, l_ulong iovcnt, struct iovec **iovp,
212 struct l_iovec32 iov32;
218 if (iovcnt > UIO_MAXIOV)
220 iovlen = iovcnt * sizeof(struct iovec);
221 iov = malloc(iovlen, M_IOV, M_WAITOK);
222 for (i = 0; i < iovcnt; i++) {
223 error = copyin(&iovp32[i], &iov32, sizeof(struct l_iovec32));
228 iov[i].iov_base = PTRIN(iov32.iov_base);
229 iov[i].iov_len = iov32.iov_len;
237 linux_readv(struct thread *td, struct linux_readv_args *uap)
242 error = linux32_copyinuio(uap->iovp, uap->iovcnt, &auio);
245 error = kern_readv(td, uap->fd, auio);
251 linux_writev(struct thread *td, struct linux_writev_args *uap)
256 error = linux32_copyinuio(uap->iovp, uap->iovcnt, &auio);
259 error = kern_writev(td, uap->fd, auio);
264 struct l_ipc_kludge {
270 linux_ipc(struct thread *td, struct linux_ipc_args *args)
273 switch (args->what & 0xFFFF) {
275 struct linux_semop_args a;
277 a.semid = args->arg1;
279 a.nsops = args->arg2;
280 return (linux_semop(td, &a));
283 struct linux_semget_args a;
286 a.nsems = args->arg2;
287 a.semflg = args->arg3;
288 return (linux_semget(td, &a));
291 struct linux_semctl_args a;
294 a.semid = args->arg1;
295 a.semnum = args->arg2;
297 error = copyin(args->ptr, &a.arg, sizeof(a.arg));
300 return (linux_semctl(td, &a));
303 struct linux_msgsnd_args a;
305 a.msqid = args->arg1;
307 a.msgsz = args->arg2;
308 a.msgflg = args->arg3;
309 return (linux_msgsnd(td, &a));
312 struct linux_msgrcv_args a;
314 a.msqid = args->arg1;
315 a.msgsz = args->arg2;
316 a.msgflg = args->arg3;
317 if ((args->what >> 16) == 0) {
318 struct l_ipc_kludge tmp;
323 error = copyin(args->ptr, &tmp, sizeof(tmp));
326 a.msgp = PTRIN(tmp.msgp);
327 a.msgtyp = tmp.msgtyp;
330 a.msgtyp = args->arg5;
332 return (linux_msgrcv(td, &a));
335 struct linux_msgget_args a;
338 a.msgflg = args->arg2;
339 return (linux_msgget(td, &a));
342 struct linux_msgctl_args a;
344 a.msqid = args->arg1;
347 return (linux_msgctl(td, &a));
350 struct linux_shmat_args a;
352 a.shmid = args->arg1;
353 a.shmaddr = args->ptr;
354 a.shmflg = args->arg2;
355 a.raddr = PTRIN((l_uint)args->arg3);
356 return (linux_shmat(td, &a));
359 struct linux_shmdt_args a;
361 a.shmaddr = args->ptr;
362 return (linux_shmdt(td, &a));
365 struct linux_shmget_args a;
369 a.shmflg = args->arg3;
370 return (linux_shmget(td, &a));
373 struct linux_shmctl_args a;
375 a.shmid = args->arg1;
378 return (linux_shmctl(td, &a));
388 linux_old_select(struct thread *td, struct linux_old_select_args *args)
390 struct l_old_select_argv linux_args;
391 struct linux_select_args newsel;
395 if (ldebug(old_select))
396 printf(ARGS(old_select, "%p"), args->ptr);
399 error = copyin(args->ptr, &linux_args, sizeof(linux_args));
403 newsel.nfds = linux_args.nfds;
404 newsel.readfds = PTRIN(linux_args.readfds);
405 newsel.writefds = PTRIN(linux_args.writefds);
406 newsel.exceptfds = PTRIN(linux_args.exceptfds);
407 newsel.timeout = PTRIN(linux_args.timeout);
408 return (linux_select(td, &newsel));
412 linux_set_cloned_tls(struct thread *td, void *desc)
414 struct user_segment_descriptor sd;
415 struct l_user_desc info;
420 error = copyin(desc, &info, sizeof(struct l_user_desc));
422 printf(LMSG("copyin failed!"));
424 /* We might copy out the entry_number as GUGS32_SEL. */
425 info.entry_number = GUGS32_SEL;
426 error = copyout(&info, desc, sizeof(struct l_user_desc));
428 printf(LMSG("copyout failed!"));
430 a[0] = LINUX_LDT_entry_a(&info);
431 a[1] = LINUX_LDT_entry_b(&info);
433 memcpy(&sd, &a, sizeof(a));
436 printf("Segment created in clone with "
437 "CLONE_SETTLS: lobase: %x, hibase: %x, "
438 "lolimit: %x, hilimit: %x, type: %i, "
439 "dpl: %i, p: %i, xx: %i, long: %i, "
440 "def32: %i, gran: %i\n", sd.sd_lobase,
441 sd.sd_hibase, sd.sd_lolimit, sd.sd_hilimit,
442 sd.sd_type, sd.sd_dpl, sd.sd_p, sd.sd_xx,
443 sd.sd_long, sd.sd_def32, sd.sd_gran);
446 pcb->pcb_gsbase = (register_t)info.base_addr;
447 /* XXXKIB pcb->pcb_gs32sd = sd; */
448 td->td_frame->tf_gs = GSEL(GUGS32_SEL, SEL_UPL);
449 set_pcb_flags(pcb, PCB_GS32BIT | PCB_32BIT);
456 linux_set_upcall_kse(struct thread *td, register_t stack)
459 td->td_frame->tf_rsp = stack;
464 #define STACK_SIZE (2 * 1024 * 1024)
465 #define GUARD_SIZE (4 * PAGE_SIZE)
468 linux_mmap2(struct thread *td, struct linux_mmap2_args *args)
473 printf(ARGS(mmap2, "0x%08x, %d, %d, 0x%08x, %d, %d"),
474 args->addr, args->len, args->prot,
475 args->flags, args->fd, args->pgoff);
478 return (linux_mmap_common(td, PTROUT(args->addr), args->len, args->prot,
479 args->flags, args->fd, (uint64_t)(uint32_t)args->pgoff *
484 linux_mmap(struct thread *td, struct linux_mmap_args *args)
487 struct l_mmap_argv linux_args;
489 error = copyin(args->ptr, &linux_args, sizeof(linux_args));
495 printf(ARGS(mmap, "0x%08x, %d, %d, 0x%08x, %d, %d"),
496 linux_args.addr, linux_args.len, linux_args.prot,
497 linux_args.flags, linux_args.fd, linux_args.pgoff);
500 return (linux_mmap_common(td, linux_args.addr, linux_args.len,
501 linux_args.prot, linux_args.flags, linux_args.fd,
502 (uint32_t)linux_args.pgoff));
506 linux_mmap_common(struct thread *td, l_uintptr_t addr, l_size_t len, l_int prot,
507 l_int flags, l_int fd, l_loff_t pos)
509 struct proc *p = td->td_proc;
510 struct mmap_args /* {
528 * You must specify exactly one of MAP_SHARED and MAP_PRIVATE
530 if (!((flags & LINUX_MAP_SHARED) ^ (flags & LINUX_MAP_PRIVATE)))
533 if (flags & LINUX_MAP_SHARED)
534 bsd_args.flags |= MAP_SHARED;
535 if (flags & LINUX_MAP_PRIVATE)
536 bsd_args.flags |= MAP_PRIVATE;
537 if (flags & LINUX_MAP_FIXED)
538 bsd_args.flags |= MAP_FIXED;
539 if (flags & LINUX_MAP_ANON) {
540 /* Enforce pos to be on page boundary, then ignore. */
541 if ((pos & PAGE_MASK) != 0)
544 bsd_args.flags |= MAP_ANON;
546 bsd_args.flags |= MAP_NOSYNC;
547 if (flags & LINUX_MAP_GROWSDOWN)
548 bsd_args.flags |= MAP_STACK;
551 * PROT_READ, PROT_WRITE, or PROT_EXEC implies PROT_READ and PROT_EXEC
552 * on Linux/i386. We do this to ensure maximum compatibility.
553 * Linux/ia64 does the same in i386 emulation mode.
555 bsd_args.prot = prot;
556 if (bsd_args.prot & (PROT_READ | PROT_WRITE | PROT_EXEC))
557 bsd_args.prot |= PROT_READ | PROT_EXEC;
559 /* Linux does not check file descriptor when MAP_ANONYMOUS is set. */
560 bsd_args.fd = (bsd_args.flags & MAP_ANON) ? -1 : fd;
561 if (bsd_args.fd != -1) {
563 * Linux follows Solaris mmap(2) description:
564 * The file descriptor fildes is opened with
565 * read permission, regardless of the
566 * protection options specified.
569 if ((error = fget(td, bsd_args.fd, &fp)) != 0)
571 if (fp->f_type != DTYPE_VNODE) {
576 /* Linux mmap() just fails for O_WRONLY files */
577 if (!(fp->f_flag & FREAD)) {
585 if (flags & LINUX_MAP_GROWSDOWN) {
587 * The Linux MAP_GROWSDOWN option does not limit auto
588 * growth of the region. Linux mmap with this option
589 * takes as addr the inital BOS, and as len, the initial
590 * region size. It can then grow down from addr without
591 * limit. However, Linux threads has an implicit internal
592 * limit to stack size of STACK_SIZE. Its just not
593 * enforced explicitly in Linux. But, here we impose
594 * a limit of (STACK_SIZE - GUARD_SIZE) on the stack
595 * region, since we can do this with our mmap.
597 * Our mmap with MAP_STACK takes addr as the maximum
598 * downsize limit on BOS, and as len the max size of
599 * the region. It then maps the top SGROWSIZ bytes,
600 * and auto grows the region down, up to the limit
603 * If we don't use the MAP_STACK option, the effect
604 * of this code is to allocate a stack region of a
605 * fixed size of (STACK_SIZE - GUARD_SIZE).
608 if ((caddr_t)PTRIN(addr) + len > p->p_vmspace->vm_maxsaddr) {
610 * Some Linux apps will attempt to mmap
611 * thread stacks near the top of their
612 * address space. If their TOS is greater
613 * than vm_maxsaddr, vm_map_growstack()
614 * will confuse the thread stack with the
615 * process stack and deliver a SEGV if they
616 * attempt to grow the thread stack past their
617 * current stacksize rlimit. To avoid this,
618 * adjust vm_maxsaddr upwards to reflect
619 * the current stacksize rlimit rather
620 * than the maximum possible stacksize.
621 * It would be better to adjust the
622 * mmap'ed region, but some apps do not check
623 * mmap's return value.
626 p->p_vmspace->vm_maxsaddr = (char *)LINUX32_USRSTACK -
627 lim_cur(p, RLIMIT_STACK);
632 * This gives us our maximum stack size and a new BOS.
633 * If we're using VM_STACK, then mmap will just map
634 * the top SGROWSIZ bytes, and let the stack grow down
635 * to the limit at BOS. If we're not using VM_STACK
636 * we map the full stack, since we don't have a way
639 if (len > STACK_SIZE - GUARD_SIZE) {
640 bsd_args.addr = (caddr_t)PTRIN(addr);
643 bsd_args.addr = (caddr_t)PTRIN(addr) -
644 (STACK_SIZE - GUARD_SIZE - len);
645 bsd_args.len = STACK_SIZE - GUARD_SIZE;
648 bsd_args.addr = (caddr_t)PTRIN(addr);
655 printf("-> %s(%p, %d, %d, 0x%08x, %d, 0x%x)\n",
657 (void *)bsd_args.addr, (int)bsd_args.len, bsd_args.prot,
658 bsd_args.flags, bsd_args.fd, (int)bsd_args.pos);
660 error = mmap(td, &bsd_args);
663 printf("-> %s() return: 0x%x (0x%08x)\n",
664 __func__, error, (u_int)td->td_retval[0]);
670 linux_mprotect(struct thread *td, struct linux_mprotect_args *uap)
672 struct mprotect_args bsd_args;
674 bsd_args.addr = uap->addr;
675 bsd_args.len = uap->len;
676 bsd_args.prot = uap->prot;
677 if (bsd_args.prot & (PROT_READ | PROT_WRITE | PROT_EXEC))
678 bsd_args.prot |= PROT_READ | PROT_EXEC;
679 return (mprotect(td, &bsd_args));
683 linux_iopl(struct thread *td, struct linux_iopl_args *args)
687 if (args->level < 0 || args->level > 3)
689 if ((error = priv_check(td, PRIV_IO)) != 0)
691 if ((error = securelevel_gt(td->td_ucred, 0)) != 0)
693 td->td_frame->tf_rflags = (td->td_frame->tf_rflags & ~PSL_IOPL) |
694 (args->level * (PSL_IOPL / 3));
700 linux_pipe(struct thread *td, struct linux_pipe_args *args)
707 printf(ARGS(pipe, "*"));
710 error = kern_pipe(td, fildes);
714 /* XXX: Close descriptors on error. */
715 return (copyout(fildes, args->pipefds, sizeof fildes));
719 linux_sigaction(struct thread *td, struct linux_sigaction_args *args)
722 l_sigaction_t act, oact;
726 if (ldebug(sigaction))
727 printf(ARGS(sigaction, "%d, %p, %p"),
728 args->sig, (void *)args->nsa, (void *)args->osa);
731 if (args->nsa != NULL) {
732 error = copyin(args->nsa, &osa, sizeof(l_osigaction_t));
735 act.lsa_handler = osa.lsa_handler;
736 act.lsa_flags = osa.lsa_flags;
737 act.lsa_restorer = osa.lsa_restorer;
738 LINUX_SIGEMPTYSET(act.lsa_mask);
739 act.lsa_mask.__bits[0] = osa.lsa_mask;
742 error = linux_do_sigaction(td, args->sig, args->nsa ? &act : NULL,
743 args->osa ? &oact : NULL);
745 if (args->osa != NULL && !error) {
746 osa.lsa_handler = oact.lsa_handler;
747 osa.lsa_flags = oact.lsa_flags;
748 osa.lsa_restorer = oact.lsa_restorer;
749 osa.lsa_mask = oact.lsa_mask.__bits[0];
750 error = copyout(&osa, args->osa, sizeof(l_osigaction_t));
757 * Linux has two extra args, restart and oldmask. We don't use these,
758 * but it seems that "restart" is actually a context pointer that
759 * enables the signal to happen with a different register set.
762 linux_sigsuspend(struct thread *td, struct linux_sigsuspend_args *args)
768 if (ldebug(sigsuspend))
769 printf(ARGS(sigsuspend, "%08lx"), (unsigned long)args->mask);
772 LINUX_SIGEMPTYSET(mask);
773 mask.__bits[0] = args->mask;
774 linux_to_bsd_sigset(&mask, &sigmask);
775 return (kern_sigsuspend(td, sigmask));
779 linux_rt_sigsuspend(struct thread *td, struct linux_rt_sigsuspend_args *uap)
786 if (ldebug(rt_sigsuspend))
787 printf(ARGS(rt_sigsuspend, "%p, %d"),
788 (void *)uap->newset, uap->sigsetsize);
791 if (uap->sigsetsize != sizeof(l_sigset_t))
794 error = copyin(uap->newset, &lmask, sizeof(l_sigset_t));
798 linux_to_bsd_sigset(&lmask, &sigmask);
799 return (kern_sigsuspend(td, sigmask));
803 linux_pause(struct thread *td, struct linux_pause_args *args)
805 struct proc *p = td->td_proc;
810 printf(ARGS(pause, ""));
814 sigmask = td->td_sigmask;
816 return (kern_sigsuspend(td, sigmask));
820 linux_sigaltstack(struct thread *td, struct linux_sigaltstack_args *uap)
827 if (ldebug(sigaltstack))
828 printf(ARGS(sigaltstack, "%p, %p"), uap->uss, uap->uoss);
831 if (uap->uss != NULL) {
832 error = copyin(uap->uss, &lss, sizeof(l_stack_t));
836 ss.ss_sp = PTRIN(lss.ss_sp);
837 ss.ss_size = lss.ss_size;
838 ss.ss_flags = linux_to_bsd_sigaltstack(lss.ss_flags);
840 error = kern_sigaltstack(td, (uap->uss != NULL) ? &ss : NULL,
841 (uap->uoss != NULL) ? &oss : NULL);
842 if (!error && uap->uoss != NULL) {
843 lss.ss_sp = PTROUT(oss.ss_sp);
844 lss.ss_size = oss.ss_size;
845 lss.ss_flags = bsd_to_linux_sigaltstack(oss.ss_flags);
846 error = copyout(&lss, uap->uoss, sizeof(l_stack_t));
853 linux_ftruncate64(struct thread *td, struct linux_ftruncate64_args *args)
855 struct ftruncate_args sa;
858 if (ldebug(ftruncate64))
859 printf(ARGS(ftruncate64, "%u, %jd"), args->fd,
860 (intmax_t)args->length);
864 sa.length = args->length;
865 return ftruncate(td, &sa);
869 linux_gettimeofday(struct thread *td, struct linux_gettimeofday_args *uap)
878 atv32.tv_sec = atv.tv_sec;
879 atv32.tv_usec = atv.tv_usec;
880 error = copyout(&atv32, uap->tp, sizeof(atv32));
882 if (error == 0 && uap->tzp != NULL) {
883 rtz.tz_minuteswest = tz_minuteswest;
884 rtz.tz_dsttime = tz_dsttime;
885 error = copyout(&rtz, uap->tzp, sizeof(rtz));
891 linux_settimeofday(struct thread *td, struct linux_settimeofday_args *uap)
894 struct timeval atv, *tvp;
895 struct timezone atz, *tzp;
899 error = copyin(uap->tp, &atv32, sizeof(atv32));
902 atv.tv_sec = atv32.tv_sec;
903 atv.tv_usec = atv32.tv_usec;
908 error = copyin(uap->tzp, &atz, sizeof(atz));
914 return (kern_settimeofday(td, tvp, tzp));
918 linux_getrusage(struct thread *td, struct linux_getrusage_args *uap)
924 error = kern_getrusage(td, uap->who, &s);
927 if (uap->rusage != NULL) {
928 bsd_to_linux_rusage(&s, &s32);
929 error = copyout(&s32, uap->rusage, sizeof(s32));
935 linux_sched_rr_get_interval(struct thread *td,
936 struct linux_sched_rr_get_interval_args *uap)
939 struct l_timespec ts32;
942 error = kern_sched_rr_get_interval(td, uap->pid, &ts);
945 ts32.tv_sec = ts.tv_sec;
946 ts32.tv_nsec = ts.tv_nsec;
947 return (copyout(&ts32, uap->interval, sizeof(ts32)));
951 linux_set_thread_area(struct thread *td,
952 struct linux_set_thread_area_args *args)
954 struct l_user_desc info;
955 struct user_segment_descriptor sd;
960 error = copyin(args->desc, &info, sizeof(struct l_user_desc));
965 if (ldebug(set_thread_area))
966 printf(ARGS(set_thread_area, "%i, %x, %x, %i, %i, %i, "
967 "%i, %i, %i"), info.entry_number, info.base_addr,
968 info.limit, info.seg_32bit, info.contents,
969 info.read_exec_only, info.limit_in_pages,
970 info.seg_not_present, info.useable);
974 * Semantics of Linux version: every thread in the system has array
975 * of three TLS descriptors. 1st is GLIBC TLS, 2nd is WINE, 3rd unknown.
976 * This syscall loads one of the selected TLS decriptors with a value
977 * and also loads GDT descriptors 6, 7 and 8 with the content of
978 * the per-thread descriptors.
980 * Semantics of FreeBSD version: I think we can ignore that Linux has
981 * three per-thread descriptors and use just the first one.
982 * The tls_array[] is used only in [gs]et_thread_area() syscalls and
983 * for loading the GDT descriptors. We use just one GDT descriptor
984 * for TLS, so we will load just one.
986 * XXX: This doesn't work when a user space process tries to use more
987 * than one TLS segment. Comment in the Linux source says wine might
992 * GLIBC reads current %gs and call set_thread_area() with it.
993 * We should let GUDATA_SEL and GUGS32_SEL proceed as well because
994 * we use these segments.
996 switch (info.entry_number) {
1001 info.entry_number = GUGS32_SEL;
1008 * We have to copy out the GDT entry we use.
1010 * XXX: What if a user space program does not check the return value
1011 * and tries to use 6, 7 or 8?
1013 error = copyout(&info, args->desc, sizeof(struct l_user_desc));
1017 if (LINUX_LDT_empty(&info)) {
1021 a[0] = LINUX_LDT_entry_a(&info);
1022 a[1] = LINUX_LDT_entry_b(&info);
1025 memcpy(&sd, &a, sizeof(a));
1027 if (ldebug(set_thread_area))
1028 printf("Segment created in set_thread_area: "
1029 "lobase: %x, hibase: %x, lolimit: %x, hilimit: %x, "
1030 "type: %i, dpl: %i, p: %i, xx: %i, long: %i, "
1031 "def32: %i, gran: %i\n",
1046 pcb->pcb_gsbase = (register_t)info.base_addr;
1047 set_pcb_flags(pcb, PCB_32BIT | PCB_GS32BIT);
1048 update_gdt_gsbase(td, info.base_addr);
1054 linux_wait4(struct thread *td, struct linux_wait4_args *args)
1057 struct rusage ru, *rup;
1058 struct l_rusage lru;
1062 printf(ARGS(wait4, "%d, %p, %d, %p"),
1063 args->pid, (void *)args->status, args->options,
1064 (void *)args->rusage);
1067 options = (args->options & (WNOHANG | WUNTRACED));
1068 /* WLINUXCLONE should be equal to __WCLONE, but we make sure */
1069 if (args->options & __WCLONE)
1070 options |= WLINUXCLONE;
1072 if (args->rusage != NULL)
1076 error = linux_common_wait(td, args->pid, args->status, options, rup);
1079 if (args->rusage != NULL) {
1080 bsd_to_linux_rusage(rup, &lru);
1081 error = copyout(&lru, args->rusage, sizeof(lru));