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)
131 struct image_args eargs;
133 LCONVPATHEXIST(td, args->path, &newpath);
137 printf(ARGS(execve, "%s"), newpath);
140 error = exec_copyin_args(&eargs, newpath, UIO_SYSSPACE,
141 args->argp, args->envp);
142 free(newpath, M_TEMP);
144 error = kern_execve(td, &eargs, NULL);
146 /* linux process can exec fbsd one, dont attempt
147 * to create emuldata for such process using
148 * linux_proc_init, this leads to a panic on KASSERT
149 * because such process has p->p_emuldata == NULL
151 if (SV_PROC_ABI(td->td_proc) == SV_ABI_LINUX)
152 error = linux_proc_init(td, 0, 0);
156 struct l_ipc_kludge {
157 struct l_msgbuf *msgp;
162 linux_ipc(struct thread *td, struct linux_ipc_args *args)
165 switch (args->what & 0xFFFF) {
167 struct linux_semop_args a;
169 a.semid = args->arg1;
171 a.nsops = args->arg2;
172 return (linux_semop(td, &a));
175 struct linux_semget_args a;
178 a.nsems = args->arg2;
179 a.semflg = args->arg3;
180 return (linux_semget(td, &a));
183 struct linux_semctl_args a;
186 a.semid = args->arg1;
187 a.semnum = args->arg2;
189 error = copyin(args->ptr, &a.arg, sizeof(a.arg));
192 return (linux_semctl(td, &a));
195 struct linux_msgsnd_args a;
197 a.msqid = args->arg1;
199 a.msgsz = args->arg2;
200 a.msgflg = args->arg3;
201 return (linux_msgsnd(td, &a));
204 struct linux_msgrcv_args a;
206 a.msqid = args->arg1;
207 a.msgsz = args->arg2;
208 a.msgflg = args->arg3;
209 if ((args->what >> 16) == 0) {
210 struct l_ipc_kludge tmp;
213 if (args->ptr == NULL)
215 error = copyin(args->ptr, &tmp, sizeof(tmp));
219 a.msgtyp = tmp.msgtyp;
222 a.msgtyp = args->arg5;
224 return (linux_msgrcv(td, &a));
227 struct linux_msgget_args a;
230 a.msgflg = args->arg2;
231 return (linux_msgget(td, &a));
234 struct linux_msgctl_args a;
236 a.msqid = args->arg1;
239 return (linux_msgctl(td, &a));
242 struct linux_shmat_args a;
244 a.shmid = args->arg1;
245 a.shmaddr = args->ptr;
246 a.shmflg = args->arg2;
247 a.raddr = (l_ulong *)args->arg3;
248 return (linux_shmat(td, &a));
251 struct linux_shmdt_args a;
253 a.shmaddr = args->ptr;
254 return (linux_shmdt(td, &a));
257 struct linux_shmget_args a;
261 a.shmflg = args->arg3;
262 return (linux_shmget(td, &a));
265 struct linux_shmctl_args a;
267 a.shmid = args->arg1;
270 return (linux_shmctl(td, &a));
280 linux_old_select(struct thread *td, struct linux_old_select_args *args)
282 struct l_old_select_argv linux_args;
283 struct linux_select_args newsel;
287 if (ldebug(old_select))
288 printf(ARGS(old_select, "%p"), args->ptr);
291 error = copyin(args->ptr, &linux_args, sizeof(linux_args));
295 newsel.nfds = linux_args.nfds;
296 newsel.readfds = linux_args.readfds;
297 newsel.writefds = linux_args.writefds;
298 newsel.exceptfds = linux_args.exceptfds;
299 newsel.timeout = linux_args.timeout;
300 return (linux_select(td, &newsel));
304 linux_set_cloned_tls(struct thread *td, void *desc)
306 struct segment_descriptor sd;
307 struct l_user_desc info;
311 error = copyin(desc, &info, sizeof(struct l_user_desc));
313 printf(LMSG("copyin failed!"));
315 idx = info.entry_number;
318 * looks like we're getting the idx we returned
319 * in the set_thread_area() syscall
321 if (idx != 6 && idx != 3) {
322 printf(LMSG("resetting idx!"));
326 /* this doesnt happen in practice */
328 /* we might copy out the entry_number as 3 */
329 info.entry_number = 3;
330 error = copyout(&info, desc, sizeof(struct l_user_desc));
332 printf(LMSG("copyout failed!"));
335 a[0] = LINUX_LDT_entry_a(&info);
336 a[1] = LINUX_LDT_entry_b(&info);
338 memcpy(&sd, &a, sizeof(a));
341 printf("Segment created in clone with "
342 "CLONE_SETTLS: lobase: %x, hibase: %x, "
343 "lolimit: %x, hilimit: %x, type: %i, "
344 "dpl: %i, p: %i, xx: %i, def32: %i, "
345 "gran: %i\n", sd.sd_lobase, sd.sd_hibase,
346 sd.sd_lolimit, sd.sd_hilimit, sd.sd_type,
347 sd.sd_dpl, sd.sd_p, sd.sd_xx,
348 sd.sd_def32, sd.sd_gran);
352 td->td_pcb->pcb_gsd = sd;
353 td->td_pcb->pcb_gs = GSEL(GUGS_SEL, SEL_UPL);
360 linux_set_upcall_kse(struct thread *td, register_t stack)
363 td->td_frame->tf_esp = stack;
368 #define STACK_SIZE (2 * 1024 * 1024)
369 #define GUARD_SIZE (4 * PAGE_SIZE)
372 linux_mmap2(struct thread *td, struct linux_mmap2_args *args)
377 printf(ARGS(mmap2, "%p, %d, %d, 0x%08x, %d, %d"),
378 (void *)args->addr, args->len, args->prot,
379 args->flags, args->fd, args->pgoff);
382 return (linux_mmap_common(td, args->addr, args->len, args->prot,
383 args->flags, args->fd, (uint64_t)(uint32_t)args->pgoff *
388 linux_mmap(struct thread *td, struct linux_mmap_args *args)
391 struct l_mmap_argv linux_args;
393 error = copyin(args->ptr, &linux_args, sizeof(linux_args));
399 printf(ARGS(mmap, "%p, %d, %d, 0x%08x, %d, %d"),
400 (void *)linux_args.addr, linux_args.len, linux_args.prot,
401 linux_args.flags, linux_args.fd, linux_args.pgoff);
404 return (linux_mmap_common(td, linux_args.addr, linux_args.len,
405 linux_args.prot, linux_args.flags, linux_args.fd,
406 (uint32_t)linux_args.pgoff));
410 linux_mmap_common(struct thread *td, l_uintptr_t addr, l_size_t len, l_int prot,
411 l_int flags, l_int fd, l_loff_t pos)
413 struct proc *p = td->td_proc;
414 struct mmap_args /* {
433 * You must specify exactly one of MAP_SHARED and MAP_PRIVATE
435 if (!((flags & LINUX_MAP_SHARED) ^ (flags & LINUX_MAP_PRIVATE)))
438 if (flags & LINUX_MAP_SHARED)
439 bsd_args.flags |= MAP_SHARED;
440 if (flags & LINUX_MAP_PRIVATE)
441 bsd_args.flags |= MAP_PRIVATE;
442 if (flags & LINUX_MAP_FIXED)
443 bsd_args.flags |= MAP_FIXED;
444 if (flags & LINUX_MAP_ANON) {
445 /* Enforce pos to be on page boundary, then ignore. */
446 if ((pos & PAGE_MASK) != 0)
449 bsd_args.flags |= MAP_ANON;
451 bsd_args.flags |= MAP_NOSYNC;
452 if (flags & LINUX_MAP_GROWSDOWN)
453 bsd_args.flags |= MAP_STACK;
456 * PROT_READ, PROT_WRITE, or PROT_EXEC implies PROT_READ and PROT_EXEC
457 * on Linux/i386. We do this to ensure maximum compatibility.
458 * Linux/ia64 does the same in i386 emulation mode.
460 bsd_args.prot = prot;
461 if (bsd_args.prot & (PROT_READ | PROT_WRITE | PROT_EXEC))
462 bsd_args.prot |= PROT_READ | PROT_EXEC;
464 /* Linux does not check file descriptor when MAP_ANONYMOUS is set. */
465 bsd_args.fd = (bsd_args.flags & MAP_ANON) ? -1 : fd;
466 if (bsd_args.fd != -1) {
468 * Linux follows Solaris mmap(2) description:
469 * The file descriptor fildes is opened with
470 * read permission, regardless of the
471 * protection options specified.
473 * Checking just CAP_MMAP is fine here, since the real work
474 * is done in the FreeBSD mmap().
477 error = fget(td, bsd_args.fd,
478 cap_rights_init(&rights, CAP_MMAP), &fp);
481 if (fp->f_type != DTYPE_VNODE) {
486 /* Linux mmap() just fails for O_WRONLY files */
487 if (!(fp->f_flag & FREAD)) {
495 if (flags & LINUX_MAP_GROWSDOWN) {
497 * The Linux MAP_GROWSDOWN option does not limit auto
498 * growth of the region. Linux mmap with this option
499 * takes as addr the inital BOS, and as len, the initial
500 * region size. It can then grow down from addr without
501 * limit. However, linux threads has an implicit internal
502 * limit to stack size of STACK_SIZE. Its just not
503 * enforced explicitly in linux. But, here we impose
504 * a limit of (STACK_SIZE - GUARD_SIZE) on the stack
505 * region, since we can do this with our mmap.
507 * Our mmap with MAP_STACK takes addr as the maximum
508 * downsize limit on BOS, and as len the max size of
509 * the region. It them maps the top SGROWSIZ bytes,
510 * and auto grows the region down, up to the limit
513 * If we don't use the MAP_STACK option, the effect
514 * of this code is to allocate a stack region of a
515 * fixed size of (STACK_SIZE - GUARD_SIZE).
518 if ((caddr_t)PTRIN(addr) + len > p->p_vmspace->vm_maxsaddr) {
520 * Some linux apps will attempt to mmap
521 * thread stacks near the top of their
522 * address space. If their TOS is greater
523 * than vm_maxsaddr, vm_map_growstack()
524 * will confuse the thread stack with the
525 * process stack and deliver a SEGV if they
526 * attempt to grow the thread stack past their
527 * current stacksize rlimit. To avoid this,
528 * adjust vm_maxsaddr upwards to reflect
529 * the current stacksize rlimit rather
530 * than the maximum possible stacksize.
531 * It would be better to adjust the
532 * mmap'ed region, but some apps do not check
533 * mmap's return value.
536 p->p_vmspace->vm_maxsaddr = (char *)USRSTACK -
537 lim_cur(p, RLIMIT_STACK);
542 * This gives us our maximum stack size and a new BOS.
543 * If we're using VM_STACK, then mmap will just map
544 * the top SGROWSIZ bytes, and let the stack grow down
545 * to the limit at BOS. If we're not using VM_STACK
546 * we map the full stack, since we don't have a way
549 if (len > STACK_SIZE - GUARD_SIZE) {
550 bsd_args.addr = (caddr_t)PTRIN(addr);
553 bsd_args.addr = (caddr_t)PTRIN(addr) -
554 (STACK_SIZE - GUARD_SIZE - len);
555 bsd_args.len = STACK_SIZE - GUARD_SIZE;
558 bsd_args.addr = (caddr_t)PTRIN(addr);
565 printf("-> %s(%p, %d, %d, 0x%08x, %d, 0x%x)\n",
567 (void *)bsd_args.addr, bsd_args.len, bsd_args.prot,
568 bsd_args.flags, bsd_args.fd, (int)bsd_args.pos);
570 error = sys_mmap(td, &bsd_args);
573 printf("-> %s() return: 0x%x (0x%08x)\n",
574 __func__, error, (u_int)td->td_retval[0]);
580 linux_mprotect(struct thread *td, struct linux_mprotect_args *uap)
582 struct mprotect_args bsd_args;
584 bsd_args.addr = uap->addr;
585 bsd_args.len = uap->len;
586 bsd_args.prot = uap->prot;
587 if (bsd_args.prot & (PROT_READ | PROT_WRITE | PROT_EXEC))
588 bsd_args.prot |= PROT_READ | PROT_EXEC;
589 return (sys_mprotect(td, &bsd_args));
593 linux_ioperm(struct thread *td, struct linux_ioperm_args *args)
596 struct i386_ioperm_args iia;
598 iia.start = args->start;
599 iia.length = args->length;
600 iia.enable = args->enable;
601 error = i386_set_ioperm(td, &iia);
606 linux_iopl(struct thread *td, struct linux_iopl_args *args)
610 if (args->level < 0 || args->level > 3)
612 if ((error = priv_check(td, PRIV_IO)) != 0)
614 if ((error = securelevel_gt(td->td_ucred, 0)) != 0)
616 td->td_frame->tf_eflags = (td->td_frame->tf_eflags & ~PSL_IOPL) |
617 (args->level * (PSL_IOPL / 3));
622 linux_modify_ldt(struct thread *td, struct linux_modify_ldt_args *uap)
625 struct i386_ldt_args ldt;
626 struct l_descriptor ld;
627 union descriptor desc;
631 case 0x00: /* read_ldt */
633 ldt.descs = uap->ptr;
634 ldt.num = uap->bytecount / sizeof(union descriptor);
635 error = i386_get_ldt(td, &ldt);
636 td->td_retval[0] *= sizeof(union descriptor);
638 case 0x02: /* read_default_ldt = 0 */
639 size = 5*sizeof(struct l_desc_struct);
640 if (size > uap->bytecount)
641 size = uap->bytecount;
642 for (written = error = 0; written < size && error == 0; written++)
643 error = subyte((char *)uap->ptr + written, 0);
644 td->td_retval[0] = written;
646 case 0x01: /* write_ldt */
647 case 0x11: /* write_ldt */
648 if (uap->bytecount != sizeof(ld))
651 error = copyin(uap->ptr, &ld, sizeof(ld));
655 ldt.start = ld.entry_number;
658 desc.sd.sd_lolimit = (ld.limit & 0x0000ffff);
659 desc.sd.sd_hilimit = (ld.limit & 0x000f0000) >> 16;
660 desc.sd.sd_lobase = (ld.base_addr & 0x00ffffff);
661 desc.sd.sd_hibase = (ld.base_addr & 0xff000000) >> 24;
662 desc.sd.sd_type = SDT_MEMRO | ((ld.read_exec_only ^ 1) << 1) |
665 desc.sd.sd_p = (ld.seg_not_present ^ 1);
667 desc.sd.sd_def32 = ld.seg_32bit;
668 desc.sd.sd_gran = ld.limit_in_pages;
669 error = i386_set_ldt(td, &ldt, &desc);
676 if (error == EOPNOTSUPP) {
677 printf("linux: modify_ldt needs kernel option USER_LDT\n");
685 linux_sigaction(struct thread *td, struct linux_sigaction_args *args)
688 l_sigaction_t act, oact;
692 if (ldebug(sigaction))
693 printf(ARGS(sigaction, "%d, %p, %p"),
694 args->sig, (void *)args->nsa, (void *)args->osa);
697 if (args->nsa != NULL) {
698 error = copyin(args->nsa, &osa, sizeof(l_osigaction_t));
701 act.lsa_handler = osa.lsa_handler;
702 act.lsa_flags = osa.lsa_flags;
703 act.lsa_restorer = osa.lsa_restorer;
704 LINUX_SIGEMPTYSET(act.lsa_mask);
705 act.lsa_mask.__bits[0] = osa.lsa_mask;
708 error = linux_do_sigaction(td, args->sig, args->nsa ? &act : NULL,
709 args->osa ? &oact : NULL);
711 if (args->osa != NULL && !error) {
712 osa.lsa_handler = oact.lsa_handler;
713 osa.lsa_flags = oact.lsa_flags;
714 osa.lsa_restorer = oact.lsa_restorer;
715 osa.lsa_mask = oact.lsa_mask.__bits[0];
716 error = copyout(&osa, args->osa, sizeof(l_osigaction_t));
723 * Linux has two extra args, restart and oldmask. We dont use these,
724 * but it seems that "restart" is actually a context pointer that
725 * enables the signal to happen with a different register set.
728 linux_sigsuspend(struct thread *td, struct linux_sigsuspend_args *args)
734 if (ldebug(sigsuspend))
735 printf(ARGS(sigsuspend, "%08lx"), (unsigned long)args->mask);
738 LINUX_SIGEMPTYSET(mask);
739 mask.__bits[0] = args->mask;
740 linux_to_bsd_sigset(&mask, &sigmask);
741 return (kern_sigsuspend(td, sigmask));
745 linux_rt_sigsuspend(struct thread *td, struct linux_rt_sigsuspend_args *uap)
752 if (ldebug(rt_sigsuspend))
753 printf(ARGS(rt_sigsuspend, "%p, %d"),
754 (void *)uap->newset, uap->sigsetsize);
757 if (uap->sigsetsize != sizeof(l_sigset_t))
760 error = copyin(uap->newset, &lmask, sizeof(l_sigset_t));
764 linux_to_bsd_sigset(&lmask, &sigmask);
765 return (kern_sigsuspend(td, sigmask));
769 linux_pause(struct thread *td, struct linux_pause_args *args)
771 struct proc *p = td->td_proc;
776 printf(ARGS(pause, ""));
780 sigmask = td->td_sigmask;
782 return (kern_sigsuspend(td, sigmask));
786 linux_sigaltstack(struct thread *td, struct linux_sigaltstack_args *uap)
793 if (ldebug(sigaltstack))
794 printf(ARGS(sigaltstack, "%p, %p"), uap->uss, uap->uoss);
797 if (uap->uss != NULL) {
798 error = copyin(uap->uss, &lss, sizeof(l_stack_t));
802 ss.ss_sp = lss.ss_sp;
803 ss.ss_size = lss.ss_size;
804 ss.ss_flags = linux_to_bsd_sigaltstack(lss.ss_flags);
806 error = kern_sigaltstack(td, (uap->uss != NULL) ? &ss : NULL,
807 (uap->uoss != NULL) ? &oss : NULL);
808 if (!error && uap->uoss != NULL) {
809 lss.ss_sp = oss.ss_sp;
810 lss.ss_size = oss.ss_size;
811 lss.ss_flags = bsd_to_linux_sigaltstack(oss.ss_flags);
812 error = copyout(&lss, uap->uoss, sizeof(l_stack_t));
819 linux_ftruncate64(struct thread *td, struct linux_ftruncate64_args *args)
821 struct ftruncate_args sa;
824 if (ldebug(ftruncate64))
825 printf(ARGS(ftruncate64, "%u, %jd"), args->fd,
826 (intmax_t)args->length);
830 sa.length = args->length;
831 return sys_ftruncate(td, &sa);
835 linux_set_thread_area(struct thread *td, struct linux_set_thread_area_args *args)
837 struct l_user_desc info;
841 struct segment_descriptor sd;
843 error = copyin(args->desc, &info, sizeof(struct l_user_desc));
848 if (ldebug(set_thread_area))
849 printf(ARGS(set_thread_area, "%i, %x, %x, %i, %i, %i, %i, %i, %i\n"),
857 info.seg_not_present,
861 idx = info.entry_number;
863 * Semantics of linux version: every thread in the system has array of
864 * 3 tls descriptors. 1st is GLIBC TLS, 2nd is WINE, 3rd unknown. This
865 * syscall loads one of the selected tls decriptors with a value and
866 * also loads GDT descriptors 6, 7 and 8 with the content of the
867 * per-thread descriptors.
869 * Semantics of fbsd version: I think we can ignore that linux has 3
870 * per-thread descriptors and use just the 1st one. The tls_array[]
871 * is used only in set/get-thread_area() syscalls and for loading the
872 * GDT descriptors. In fbsd we use just one GDT descriptor for TLS so
873 * we will load just one.
875 * XXX: this doesn't work when a user space process tries to use more
876 * than 1 TLS segment. Comment in the linux sources says wine might do
881 * we support just GLIBC TLS now
882 * we should let 3 proceed as well because we use this segment so
883 * if code does two subsequent calls it should succeed
885 if (idx != 6 && idx != -1 && idx != 3)
889 * we have to copy out the GDT entry we use
890 * FreeBSD uses GDT entry #3 for storing %gs so load that
892 * XXX: what if a user space program doesn't check this value and tries
895 idx = info.entry_number = 3;
896 error = copyout(&info, args->desc, sizeof(struct l_user_desc));
900 if (LINUX_LDT_empty(&info)) {
904 a[0] = LINUX_LDT_entry_a(&info);
905 a[1] = LINUX_LDT_entry_b(&info);
908 memcpy(&sd, &a, sizeof(a));
910 if (ldebug(set_thread_area))
911 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,
923 /* this is taken from i386 version of cpu_set_user_tls() */
926 td->td_pcb->pcb_gsd = sd;
927 PCPU_GET(fsgs_gdt)[1] = sd;
928 load_gs(GSEL(GUGS_SEL, SEL_UPL));
935 linux_get_thread_area(struct thread *td, struct linux_get_thread_area_args *args)
938 struct l_user_desc info;
941 struct l_desc_struct desc;
942 struct segment_descriptor sd;
945 if (ldebug(get_thread_area))
946 printf(ARGS(get_thread_area, "%p"), args->desc);
949 error = copyin(args->desc, &info, sizeof(struct l_user_desc));
953 idx = info.entry_number;
954 /* XXX: I am not sure if we want 3 to be allowed too. */
955 if (idx != 6 && idx != 3)
960 memset(&info, 0, sizeof(info));
962 sd = PCPU_GET(fsgs_gdt)[1];
964 memcpy(&desc, &sd, sizeof(desc));
966 info.entry_number = idx;
967 info.base_addr = LINUX_GET_BASE(&desc);
968 info.limit = LINUX_GET_LIMIT(&desc);
969 info.seg_32bit = LINUX_GET_32BIT(&desc);
970 info.contents = LINUX_GET_CONTENTS(&desc);
971 info.read_exec_only = !LINUX_GET_WRITABLE(&desc);
972 info.limit_in_pages = LINUX_GET_LIMIT_PAGES(&desc);
973 info.seg_not_present = !LINUX_GET_PRESENT(&desc);
974 info.useable = LINUX_GET_USEABLE(&desc);
976 error = copyout(&info, args->desc, sizeof(struct l_user_desc));
983 /* XXX: this wont work with module - convert it */
985 linux_mq_open(struct thread *td, struct linux_mq_open_args *args)
987 #ifdef P1003_1B_MQUEUE
988 return sys_kmq_open(td, (struct kmq_open_args *) args);
995 linux_mq_unlink(struct thread *td, struct linux_mq_unlink_args *args)
997 #ifdef P1003_1B_MQUEUE
998 return sys_kmq_unlink(td, (struct kmq_unlink_args *) args);
1005 linux_mq_timedsend(struct thread *td, struct linux_mq_timedsend_args *args)
1007 #ifdef P1003_1B_MQUEUE
1008 return sys_kmq_timedsend(td, (struct kmq_timedsend_args *) args);
1015 linux_mq_timedreceive(struct thread *td, struct linux_mq_timedreceive_args *args)
1017 #ifdef P1003_1B_MQUEUE
1018 return sys_kmq_timedreceive(td, (struct kmq_timedreceive_args *) args);
1025 linux_mq_notify(struct thread *td, struct linux_mq_notify_args *args)
1027 #ifdef P1003_1B_MQUEUE
1028 return sys_kmq_notify(td, (struct kmq_notify_args *) args);
1035 linux_mq_getsetattr(struct thread *td, struct linux_mq_getsetattr_args *args)
1037 #ifdef P1003_1B_MQUEUE
1038 return sys_kmq_setattr(td, (struct kmq_setattr_args *) args);
1045 linux_wait4(struct thread *td, struct linux_wait4_args *args)
1048 struct rusage ru, *rup;
1052 printf(ARGS(wait4, "%d, %p, %d, %p"),
1053 args->pid, (void *)args->status, args->options,
1054 (void *)args->rusage);
1057 options = (args->options & (WNOHANG | WUNTRACED));
1058 /* WLINUXCLONE should be equal to __WCLONE, but we make sure */
1059 if (args->options & __WCLONE)
1060 options |= WLINUXCLONE;
1062 if (args->rusage != NULL)
1066 error = linux_common_wait(td, args->pid, args->status, options, rup);
1069 if (args->rusage != NULL)
1070 error = copyout(&ru, args->rusage, sizeof(ru));