2 * Copyright (c) 2000 Marcel Moolenaar
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/capsicum.h>
36 #include <sys/fcntl.h>
37 #include <sys/imgact.h>
39 #include <sys/malloc.h>
41 #include <sys/mutex.h>
45 #include <sys/queue.h>
46 #include <sys/resource.h>
47 #include <sys/resourcevar.h>
48 #include <sys/signalvar.h>
49 #include <sys/syscallsubr.h>
50 #include <sys/sysproto.h>
51 #include <sys/unistd.h>
53 #include <sys/sched.h>
55 #include <machine/frame.h>
56 #include <machine/psl.h>
57 #include <machine/segments.h>
58 #include <machine/sysarch.h>
62 #include <vm/vm_map.h>
64 #include <i386/linux/linux.h>
65 #include <i386/linux/linux_proto.h>
66 #include <compat/linux/linux_ipc.h>
67 #include <compat/linux/linux_misc.h>
68 #include <compat/linux/linux_signal.h>
69 #include <compat/linux/linux_util.h>
70 #include <compat/linux/linux_emul.h>
72 #include <i386/include/pcb.h> /* needed for pcb definition in linux_set_thread_area */
74 #include "opt_posix.h"
76 extern struct sysentvec elf32_freebsd_sysvec; /* defined in i386/i386/elf_machdep.c */
84 l_uint read_exec_only:1;
85 l_uint limit_in_pages:1;
86 l_uint seg_not_present:1;
90 struct l_old_select_argv {
95 struct l_timeval *timeout;
98 static int linux_mmap_common(struct thread *td, l_uintptr_t addr,
99 l_size_t len, l_int prot, l_int flags, l_int fd,
103 linux_to_bsd_sigaltstack(int lsa)
107 if (lsa & LINUX_SS_DISABLE)
109 if (lsa & LINUX_SS_ONSTACK)
115 bsd_to_linux_sigaltstack(int bsa)
119 if (bsa & SS_DISABLE)
120 lsa |= LINUX_SS_DISABLE;
121 if (bsa & SS_ONSTACK)
122 lsa |= LINUX_SS_ONSTACK;
127 linux_execve(struct thread *td, struct linux_execve_args *args)
129 struct image_args eargs;
130 struct vmspace *oldvmspace;
134 LCONVPATHEXIST(td, args->path, &newpath);
138 printf(ARGS(execve, "%s"), newpath);
141 error = pre_execve(td, &oldvmspace);
143 free(newpath, M_TEMP);
146 error = exec_copyin_args(&eargs, newpath, UIO_SYSSPACE,
147 args->argp, args->envp);
148 free(newpath, M_TEMP);
150 error = kern_execve(td, &eargs, NULL);
152 error = linux_common_execve(td, &eargs);
153 post_execve(td, error, oldvmspace);
157 struct l_ipc_kludge {
158 struct l_msgbuf *msgp;
163 linux_ipc(struct thread *td, struct linux_ipc_args *args)
166 switch (args->what & 0xFFFF) {
168 struct linux_semop_args a;
170 a.semid = args->arg1;
172 a.nsops = args->arg2;
173 return (linux_semop(td, &a));
176 struct linux_semget_args a;
179 a.nsems = args->arg2;
180 a.semflg = args->arg3;
181 return (linux_semget(td, &a));
184 struct linux_semctl_args a;
187 a.semid = args->arg1;
188 a.semnum = args->arg2;
190 error = copyin(args->ptr, &a.arg, sizeof(a.arg));
193 return (linux_semctl(td, &a));
196 struct linux_msgsnd_args a;
198 a.msqid = args->arg1;
200 a.msgsz = args->arg2;
201 a.msgflg = args->arg3;
202 return (linux_msgsnd(td, &a));
205 struct linux_msgrcv_args a;
207 a.msqid = args->arg1;
208 a.msgsz = args->arg2;
209 a.msgflg = args->arg3;
210 if ((args->what >> 16) == 0) {
211 struct l_ipc_kludge tmp;
214 if (args->ptr == NULL)
216 error = copyin(args->ptr, &tmp, sizeof(tmp));
220 a.msgtyp = tmp.msgtyp;
223 a.msgtyp = args->arg5;
225 return (linux_msgrcv(td, &a));
228 struct linux_msgget_args a;
231 a.msgflg = args->arg2;
232 return (linux_msgget(td, &a));
235 struct linux_msgctl_args a;
237 a.msqid = args->arg1;
240 return (linux_msgctl(td, &a));
243 struct linux_shmat_args a;
245 a.shmid = args->arg1;
246 a.shmaddr = args->ptr;
247 a.shmflg = args->arg2;
248 a.raddr = (l_ulong *)args->arg3;
249 return (linux_shmat(td, &a));
252 struct linux_shmdt_args a;
254 a.shmaddr = args->ptr;
255 return (linux_shmdt(td, &a));
258 struct linux_shmget_args a;
262 a.shmflg = args->arg3;
263 return (linux_shmget(td, &a));
266 struct linux_shmctl_args a;
268 a.shmid = args->arg1;
271 return (linux_shmctl(td, &a));
281 linux_old_select(struct thread *td, struct linux_old_select_args *args)
283 struct l_old_select_argv linux_args;
284 struct linux_select_args newsel;
288 if (ldebug(old_select))
289 printf(ARGS(old_select, "%p"), args->ptr);
292 error = copyin(args->ptr, &linux_args, sizeof(linux_args));
296 newsel.nfds = linux_args.nfds;
297 newsel.readfds = linux_args.readfds;
298 newsel.writefds = linux_args.writefds;
299 newsel.exceptfds = linux_args.exceptfds;
300 newsel.timeout = linux_args.timeout;
301 return (linux_select(td, &newsel));
305 linux_set_cloned_tls(struct thread *td, void *desc)
307 struct segment_descriptor sd;
308 struct l_user_desc info;
312 error = copyin(desc, &info, sizeof(struct l_user_desc));
314 printf(LMSG("copyin failed!"));
316 idx = info.entry_number;
319 * looks like we're getting the idx we returned
320 * in the set_thread_area() syscall
322 if (idx != 6 && idx != 3) {
323 printf(LMSG("resetting idx!"));
327 /* this doesnt happen in practice */
329 /* we might copy out the entry_number as 3 */
330 info.entry_number = 3;
331 error = copyout(&info, desc, sizeof(struct l_user_desc));
333 printf(LMSG("copyout failed!"));
336 a[0] = LINUX_LDT_entry_a(&info);
337 a[1] = LINUX_LDT_entry_b(&info);
339 memcpy(&sd, &a, sizeof(a));
342 printf("Segment created in clone with "
343 "CLONE_SETTLS: lobase: %x, hibase: %x, "
344 "lolimit: %x, hilimit: %x, type: %i, "
345 "dpl: %i, p: %i, xx: %i, def32: %i, "
346 "gran: %i\n", sd.sd_lobase, sd.sd_hibase,
347 sd.sd_lolimit, sd.sd_hilimit, sd.sd_type,
348 sd.sd_dpl, sd.sd_p, sd.sd_xx,
349 sd.sd_def32, sd.sd_gran);
353 td->td_pcb->pcb_gsd = sd;
354 td->td_pcb->pcb_gs = GSEL(GUGS_SEL, SEL_UPL);
361 linux_set_upcall_kse(struct thread *td, register_t stack)
365 td->td_frame->tf_esp = stack;
368 * The newly created Linux thread returns
369 * to the user space by the same path that a parent do.
371 td->td_frame->tf_eax = 0;
375 #define STACK_SIZE (2 * 1024 * 1024)
376 #define GUARD_SIZE (4 * PAGE_SIZE)
379 linux_mmap2(struct thread *td, struct linux_mmap2_args *args)
384 printf(ARGS(mmap2, "%p, %d, %d, 0x%08x, %d, %d"),
385 (void *)args->addr, args->len, args->prot,
386 args->flags, args->fd, args->pgoff);
389 return (linux_mmap_common(td, args->addr, args->len, args->prot,
390 args->flags, args->fd, (uint64_t)(uint32_t)args->pgoff *
395 linux_mmap(struct thread *td, struct linux_mmap_args *args)
398 struct l_mmap_argv linux_args;
400 error = copyin(args->ptr, &linux_args, sizeof(linux_args));
406 printf(ARGS(mmap, "%p, %d, %d, 0x%08x, %d, %d"),
407 (void *)linux_args.addr, linux_args.len, linux_args.prot,
408 linux_args.flags, linux_args.fd, linux_args.pgoff);
411 return (linux_mmap_common(td, linux_args.addr, linux_args.len,
412 linux_args.prot, linux_args.flags, linux_args.fd,
413 (uint32_t)linux_args.pgoff));
417 linux_mmap_common(struct thread *td, l_uintptr_t addr, l_size_t len, l_int prot,
418 l_int flags, l_int fd, l_loff_t pos)
420 struct proc *p = td->td_proc;
421 struct mmap_args /* {
440 * You must specify exactly one of MAP_SHARED and MAP_PRIVATE
442 if (!((flags & LINUX_MAP_SHARED) ^ (flags & LINUX_MAP_PRIVATE)))
445 if (flags & LINUX_MAP_SHARED)
446 bsd_args.flags |= MAP_SHARED;
447 if (flags & LINUX_MAP_PRIVATE)
448 bsd_args.flags |= MAP_PRIVATE;
449 if (flags & LINUX_MAP_FIXED)
450 bsd_args.flags |= MAP_FIXED;
451 if (flags & LINUX_MAP_ANON) {
452 /* Enforce pos to be on page boundary, then ignore. */
453 if ((pos & PAGE_MASK) != 0)
456 bsd_args.flags |= MAP_ANON;
458 bsd_args.flags |= MAP_NOSYNC;
459 if (flags & LINUX_MAP_GROWSDOWN)
460 bsd_args.flags |= MAP_STACK;
463 * PROT_READ, PROT_WRITE, or PROT_EXEC implies PROT_READ and PROT_EXEC
464 * on Linux/i386. We do this to ensure maximum compatibility.
465 * Linux/ia64 does the same in i386 emulation mode.
467 bsd_args.prot = prot;
468 if (bsd_args.prot & (PROT_READ | PROT_WRITE | PROT_EXEC))
469 bsd_args.prot |= PROT_READ | PROT_EXEC;
471 /* Linux does not check file descriptor when MAP_ANONYMOUS is set. */
472 bsd_args.fd = (bsd_args.flags & MAP_ANON) ? -1 : fd;
473 if (bsd_args.fd != -1) {
475 * Linux follows Solaris mmap(2) description:
476 * The file descriptor fildes is opened with
477 * read permission, regardless of the
478 * protection options specified.
480 * Checking just CAP_MMAP is fine here, since the real work
481 * is done in the FreeBSD mmap().
484 error = fget(td, bsd_args.fd,
485 cap_rights_init(&rights, CAP_MMAP), &fp);
488 if (fp->f_type != DTYPE_VNODE) {
493 /* Linux mmap() just fails for O_WRONLY files */
494 if (!(fp->f_flag & FREAD)) {
502 if (flags & LINUX_MAP_GROWSDOWN) {
504 * The Linux MAP_GROWSDOWN option does not limit auto
505 * growth of the region. Linux mmap with this option
506 * takes as addr the inital BOS, and as len, the initial
507 * region size. It can then grow down from addr without
508 * limit. However, linux threads has an implicit internal
509 * limit to stack size of STACK_SIZE. Its just not
510 * enforced explicitly in linux. But, here we impose
511 * a limit of (STACK_SIZE - GUARD_SIZE) on the stack
512 * region, since we can do this with our mmap.
514 * Our mmap with MAP_STACK takes addr as the maximum
515 * downsize limit on BOS, and as len the max size of
516 * the region. It them maps the top SGROWSIZ bytes,
517 * and auto grows the region down, up to the limit
520 * If we don't use the MAP_STACK option, the effect
521 * of this code is to allocate a stack region of a
522 * fixed size of (STACK_SIZE - GUARD_SIZE).
525 if ((caddr_t)PTRIN(addr) + len > p->p_vmspace->vm_maxsaddr) {
527 * Some linux apps will attempt to mmap
528 * thread stacks near the top of their
529 * address space. If their TOS is greater
530 * than vm_maxsaddr, vm_map_growstack()
531 * will confuse the thread stack with the
532 * process stack and deliver a SEGV if they
533 * attempt to grow the thread stack past their
534 * current stacksize rlimit. To avoid this,
535 * adjust vm_maxsaddr upwards to reflect
536 * the current stacksize rlimit rather
537 * than the maximum possible stacksize.
538 * It would be better to adjust the
539 * mmap'ed region, but some apps do not check
540 * mmap's return value.
543 p->p_vmspace->vm_maxsaddr = (char *)USRSTACK -
544 lim_cur(p, RLIMIT_STACK);
549 * This gives us our maximum stack size and a new BOS.
550 * If we're using VM_STACK, then mmap will just map
551 * the top SGROWSIZ bytes, and let the stack grow down
552 * to the limit at BOS. If we're not using VM_STACK
553 * we map the full stack, since we don't have a way
556 if (len > STACK_SIZE - GUARD_SIZE) {
557 bsd_args.addr = (caddr_t)PTRIN(addr);
560 bsd_args.addr = (caddr_t)PTRIN(addr) -
561 (STACK_SIZE - GUARD_SIZE - len);
562 bsd_args.len = STACK_SIZE - GUARD_SIZE;
565 bsd_args.addr = (caddr_t)PTRIN(addr);
572 printf("-> %s(%p, %d, %d, 0x%08x, %d, 0x%x)\n",
574 (void *)bsd_args.addr, bsd_args.len, bsd_args.prot,
575 bsd_args.flags, bsd_args.fd, (int)bsd_args.pos);
577 error = sys_mmap(td, &bsd_args);
580 printf("-> %s() return: 0x%x (0x%08x)\n",
581 __func__, error, (u_int)td->td_retval[0]);
587 linux_mprotect(struct thread *td, struct linux_mprotect_args *uap)
589 struct mprotect_args bsd_args;
591 bsd_args.addr = uap->addr;
592 bsd_args.len = uap->len;
593 bsd_args.prot = uap->prot;
594 if (bsd_args.prot & (PROT_READ | PROT_WRITE | PROT_EXEC))
595 bsd_args.prot |= PROT_READ | PROT_EXEC;
596 return (sys_mprotect(td, &bsd_args));
600 linux_ioperm(struct thread *td, struct linux_ioperm_args *args)
603 struct i386_ioperm_args iia;
605 iia.start = args->start;
606 iia.length = args->length;
607 iia.enable = args->enable;
608 error = i386_set_ioperm(td, &iia);
613 linux_iopl(struct thread *td, struct linux_iopl_args *args)
617 if (args->level < 0 || args->level > 3)
619 if ((error = priv_check(td, PRIV_IO)) != 0)
621 if ((error = securelevel_gt(td->td_ucred, 0)) != 0)
623 td->td_frame->tf_eflags = (td->td_frame->tf_eflags & ~PSL_IOPL) |
624 (args->level * (PSL_IOPL / 3));
629 linux_modify_ldt(struct thread *td, struct linux_modify_ldt_args *uap)
632 struct i386_ldt_args ldt;
633 struct l_descriptor ld;
634 union descriptor desc;
638 case 0x00: /* read_ldt */
640 ldt.descs = uap->ptr;
641 ldt.num = uap->bytecount / sizeof(union descriptor);
642 error = i386_get_ldt(td, &ldt);
643 td->td_retval[0] *= sizeof(union descriptor);
645 case 0x02: /* read_default_ldt = 0 */
646 size = 5*sizeof(struct l_desc_struct);
647 if (size > uap->bytecount)
648 size = uap->bytecount;
649 for (written = error = 0; written < size && error == 0; written++)
650 error = subyte((char *)uap->ptr + written, 0);
651 td->td_retval[0] = written;
653 case 0x01: /* write_ldt */
654 case 0x11: /* write_ldt */
655 if (uap->bytecount != sizeof(ld))
658 error = copyin(uap->ptr, &ld, sizeof(ld));
662 ldt.start = ld.entry_number;
665 desc.sd.sd_lolimit = (ld.limit & 0x0000ffff);
666 desc.sd.sd_hilimit = (ld.limit & 0x000f0000) >> 16;
667 desc.sd.sd_lobase = (ld.base_addr & 0x00ffffff);
668 desc.sd.sd_hibase = (ld.base_addr & 0xff000000) >> 24;
669 desc.sd.sd_type = SDT_MEMRO | ((ld.read_exec_only ^ 1) << 1) |
672 desc.sd.sd_p = (ld.seg_not_present ^ 1);
674 desc.sd.sd_def32 = ld.seg_32bit;
675 desc.sd.sd_gran = ld.limit_in_pages;
676 error = i386_set_ldt(td, &ldt, &desc);
683 if (error == EOPNOTSUPP) {
684 printf("linux: modify_ldt needs kernel option USER_LDT\n");
692 linux_sigaction(struct thread *td, struct linux_sigaction_args *args)
695 l_sigaction_t act, oact;
699 if (ldebug(sigaction))
700 printf(ARGS(sigaction, "%d, %p, %p"),
701 args->sig, (void *)args->nsa, (void *)args->osa);
704 if (args->nsa != NULL) {
705 error = copyin(args->nsa, &osa, sizeof(l_osigaction_t));
708 act.lsa_handler = osa.lsa_handler;
709 act.lsa_flags = osa.lsa_flags;
710 act.lsa_restorer = osa.lsa_restorer;
711 LINUX_SIGEMPTYSET(act.lsa_mask);
712 act.lsa_mask.__bits[0] = osa.lsa_mask;
715 error = linux_do_sigaction(td, args->sig, args->nsa ? &act : NULL,
716 args->osa ? &oact : NULL);
718 if (args->osa != NULL && !error) {
719 osa.lsa_handler = oact.lsa_handler;
720 osa.lsa_flags = oact.lsa_flags;
721 osa.lsa_restorer = oact.lsa_restorer;
722 osa.lsa_mask = oact.lsa_mask.__bits[0];
723 error = copyout(&osa, args->osa, sizeof(l_osigaction_t));
730 * Linux has two extra args, restart and oldmask. We dont use these,
731 * but it seems that "restart" is actually a context pointer that
732 * enables the signal to happen with a different register set.
735 linux_sigsuspend(struct thread *td, struct linux_sigsuspend_args *args)
741 if (ldebug(sigsuspend))
742 printf(ARGS(sigsuspend, "%08lx"), (unsigned long)args->mask);
745 LINUX_SIGEMPTYSET(mask);
746 mask.__bits[0] = args->mask;
747 linux_to_bsd_sigset(&mask, &sigmask);
748 return (kern_sigsuspend(td, sigmask));
752 linux_rt_sigsuspend(struct thread *td, struct linux_rt_sigsuspend_args *uap)
759 if (ldebug(rt_sigsuspend))
760 printf(ARGS(rt_sigsuspend, "%p, %d"),
761 (void *)uap->newset, uap->sigsetsize);
764 if (uap->sigsetsize != sizeof(l_sigset_t))
767 error = copyin(uap->newset, &lmask, sizeof(l_sigset_t));
771 linux_to_bsd_sigset(&lmask, &sigmask);
772 return (kern_sigsuspend(td, sigmask));
776 linux_pause(struct thread *td, struct linux_pause_args *args)
778 struct proc *p = td->td_proc;
783 printf(ARGS(pause, ""));
787 sigmask = td->td_sigmask;
789 return (kern_sigsuspend(td, sigmask));
793 linux_sigaltstack(struct thread *td, struct linux_sigaltstack_args *uap)
800 if (ldebug(sigaltstack))
801 printf(ARGS(sigaltstack, "%p, %p"), uap->uss, uap->uoss);
804 if (uap->uss != NULL) {
805 error = copyin(uap->uss, &lss, sizeof(l_stack_t));
809 ss.ss_sp = lss.ss_sp;
810 ss.ss_size = lss.ss_size;
811 ss.ss_flags = linux_to_bsd_sigaltstack(lss.ss_flags);
813 error = kern_sigaltstack(td, (uap->uss != NULL) ? &ss : NULL,
814 (uap->uoss != NULL) ? &oss : NULL);
815 if (!error && uap->uoss != NULL) {
816 lss.ss_sp = oss.ss_sp;
817 lss.ss_size = oss.ss_size;
818 lss.ss_flags = bsd_to_linux_sigaltstack(oss.ss_flags);
819 error = copyout(&lss, uap->uoss, sizeof(l_stack_t));
826 linux_ftruncate64(struct thread *td, struct linux_ftruncate64_args *args)
828 struct ftruncate_args sa;
831 if (ldebug(ftruncate64))
832 printf(ARGS(ftruncate64, "%u, %jd"), args->fd,
833 (intmax_t)args->length);
837 sa.length = args->length;
838 return sys_ftruncate(td, &sa);
842 linux_set_thread_area(struct thread *td, struct linux_set_thread_area_args *args)
844 struct l_user_desc info;
848 struct segment_descriptor sd;
850 error = copyin(args->desc, &info, sizeof(struct l_user_desc));
855 if (ldebug(set_thread_area))
856 printf(ARGS(set_thread_area, "%i, %x, %x, %i, %i, %i, %i, %i, %i\n"),
864 info.seg_not_present,
868 idx = info.entry_number;
870 * Semantics of linux version: every thread in the system has array of
871 * 3 tls descriptors. 1st is GLIBC TLS, 2nd is WINE, 3rd unknown. This
872 * syscall loads one of the selected tls decriptors with a value and
873 * also loads GDT descriptors 6, 7 and 8 with the content of the
874 * per-thread descriptors.
876 * Semantics of fbsd version: I think we can ignore that linux has 3
877 * per-thread descriptors and use just the 1st one. The tls_array[]
878 * is used only in set/get-thread_area() syscalls and for loading the
879 * GDT descriptors. In fbsd we use just one GDT descriptor for TLS so
880 * we will load just one.
882 * XXX: this doesn't work when a user space process tries to use more
883 * than 1 TLS segment. Comment in the linux sources says wine might do
888 * we support just GLIBC TLS now
889 * we should let 3 proceed as well because we use this segment so
890 * if code does two subsequent calls it should succeed
892 if (idx != 6 && idx != -1 && idx != 3)
896 * we have to copy out the GDT entry we use
897 * FreeBSD uses GDT entry #3 for storing %gs so load that
899 * XXX: what if a user space program doesn't check this value and tries
902 idx = info.entry_number = 3;
903 error = copyout(&info, args->desc, sizeof(struct l_user_desc));
907 if (LINUX_LDT_empty(&info)) {
911 a[0] = LINUX_LDT_entry_a(&info);
912 a[1] = LINUX_LDT_entry_b(&info);
915 memcpy(&sd, &a, sizeof(a));
917 if (ldebug(set_thread_area))
918 printf("Segment created in set_thread_area: lobase: %x, hibase: %x, lolimit: %x, hilimit: %x, type: %i, dpl: %i, p: %i, xx: %i, def32: %i, gran: %i\n", sd.sd_lobase,
930 /* this is taken from i386 version of cpu_set_user_tls() */
933 td->td_pcb->pcb_gsd = sd;
934 PCPU_GET(fsgs_gdt)[1] = sd;
935 load_gs(GSEL(GUGS_SEL, SEL_UPL));
942 linux_get_thread_area(struct thread *td, struct linux_get_thread_area_args *args)
945 struct l_user_desc info;
948 struct l_desc_struct desc;
949 struct segment_descriptor sd;
952 if (ldebug(get_thread_area))
953 printf(ARGS(get_thread_area, "%p"), args->desc);
956 error = copyin(args->desc, &info, sizeof(struct l_user_desc));
960 idx = info.entry_number;
961 /* XXX: I am not sure if we want 3 to be allowed too. */
962 if (idx != 6 && idx != 3)
967 memset(&info, 0, sizeof(info));
969 sd = PCPU_GET(fsgs_gdt)[1];
971 memcpy(&desc, &sd, sizeof(desc));
973 info.entry_number = idx;
974 info.base_addr = LINUX_GET_BASE(&desc);
975 info.limit = LINUX_GET_LIMIT(&desc);
976 info.seg_32bit = LINUX_GET_32BIT(&desc);
977 info.contents = LINUX_GET_CONTENTS(&desc);
978 info.read_exec_only = !LINUX_GET_WRITABLE(&desc);
979 info.limit_in_pages = LINUX_GET_LIMIT_PAGES(&desc);
980 info.seg_not_present = !LINUX_GET_PRESENT(&desc);
981 info.useable = LINUX_GET_USEABLE(&desc);
983 error = copyout(&info, args->desc, sizeof(struct l_user_desc));
990 /* XXX: this wont work with module - convert it */
992 linux_mq_open(struct thread *td, struct linux_mq_open_args *args)
994 #ifdef P1003_1B_MQUEUE
995 return sys_kmq_open(td, (struct kmq_open_args *) args);
1002 linux_mq_unlink(struct thread *td, struct linux_mq_unlink_args *args)
1004 #ifdef P1003_1B_MQUEUE
1005 return sys_kmq_unlink(td, (struct kmq_unlink_args *) args);
1012 linux_mq_timedsend(struct thread *td, struct linux_mq_timedsend_args *args)
1014 #ifdef P1003_1B_MQUEUE
1015 return sys_kmq_timedsend(td, (struct kmq_timedsend_args *) args);
1022 linux_mq_timedreceive(struct thread *td, struct linux_mq_timedreceive_args *args)
1024 #ifdef P1003_1B_MQUEUE
1025 return sys_kmq_timedreceive(td, (struct kmq_timedreceive_args *) args);
1032 linux_mq_notify(struct thread *td, struct linux_mq_notify_args *args)
1034 #ifdef P1003_1B_MQUEUE
1035 return sys_kmq_notify(td, (struct kmq_notify_args *) args);
1042 linux_mq_getsetattr(struct thread *td, struct linux_mq_getsetattr_args *args)
1044 #ifdef P1003_1B_MQUEUE
1045 return sys_kmq_setattr(td, (struct kmq_setattr_args *) args);
1052 linux_wait4(struct thread *td, struct linux_wait4_args *args)
1055 struct rusage ru, *rup;
1059 printf(ARGS(wait4, "%d, %p, %d, %p"),
1060 args->pid, (void *)args->status, args->options,
1061 (void *)args->rusage);
1064 options = (args->options & (WNOHANG | WUNTRACED));
1065 /* WLINUXCLONE should be equal to __WCLONE, but we make sure */
1066 if (args->options & __WCLONE)
1067 options |= WLINUXCLONE;
1069 if (args->rusage != NULL)
1073 error = linux_common_wait(td, args->pid, args->status, options, rup);
1076 if (args->rusage != NULL)
1077 error = copyout(&ru, args->rusage, sizeof(ru));