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 /* linux process can exec fbsd one, dont attempt
153 * to create emuldata for such process using
154 * linux_proc_init, this leads to a panic on KASSERT
155 * because such process has p->p_emuldata == NULL
157 if (SV_PROC_ABI(td->td_proc) == SV_ABI_LINUX)
158 error = linux_proc_init(td, 0, 0);
160 post_execve(td, error, oldvmspace);
164 struct l_ipc_kludge {
165 struct l_msgbuf *msgp;
170 linux_ipc(struct thread *td, struct linux_ipc_args *args)
173 switch (args->what & 0xFFFF) {
175 struct linux_semop_args a;
177 a.semid = args->arg1;
179 a.nsops = args->arg2;
180 return (linux_semop(td, &a));
183 struct linux_semget_args a;
186 a.nsems = args->arg2;
187 a.semflg = args->arg3;
188 return (linux_semget(td, &a));
191 struct linux_semctl_args a;
194 a.semid = args->arg1;
195 a.semnum = args->arg2;
197 error = copyin(args->ptr, &a.arg, sizeof(a.arg));
200 return (linux_semctl(td, &a));
203 struct linux_msgsnd_args a;
205 a.msqid = args->arg1;
207 a.msgsz = args->arg2;
208 a.msgflg = args->arg3;
209 return (linux_msgsnd(td, &a));
212 struct linux_msgrcv_args a;
214 a.msqid = args->arg1;
215 a.msgsz = args->arg2;
216 a.msgflg = args->arg3;
217 if ((args->what >> 16) == 0) {
218 struct l_ipc_kludge tmp;
221 if (args->ptr == NULL)
223 error = copyin(args->ptr, &tmp, sizeof(tmp));
227 a.msgtyp = tmp.msgtyp;
230 a.msgtyp = args->arg5;
232 return (linux_msgrcv(td, &a));
235 struct linux_msgget_args a;
238 a.msgflg = args->arg2;
239 return (linux_msgget(td, &a));
242 struct linux_msgctl_args a;
244 a.msqid = args->arg1;
247 return (linux_msgctl(td, &a));
250 struct linux_shmat_args a;
252 a.shmid = args->arg1;
253 a.shmaddr = args->ptr;
254 a.shmflg = args->arg2;
255 a.raddr = (l_ulong *)args->arg3;
256 return (linux_shmat(td, &a));
259 struct linux_shmdt_args a;
261 a.shmaddr = args->ptr;
262 return (linux_shmdt(td, &a));
265 struct linux_shmget_args a;
269 a.shmflg = args->arg3;
270 return (linux_shmget(td, &a));
273 struct linux_shmctl_args a;
275 a.shmid = args->arg1;
278 return (linux_shmctl(td, &a));
288 linux_old_select(struct thread *td, struct linux_old_select_args *args)
290 struct l_old_select_argv linux_args;
291 struct linux_select_args newsel;
295 if (ldebug(old_select))
296 printf(ARGS(old_select, "%p"), args->ptr);
299 error = copyin(args->ptr, &linux_args, sizeof(linux_args));
303 newsel.nfds = linux_args.nfds;
304 newsel.readfds = linux_args.readfds;
305 newsel.writefds = linux_args.writefds;
306 newsel.exceptfds = linux_args.exceptfds;
307 newsel.timeout = linux_args.timeout;
308 return (linux_select(td, &newsel));
312 linux_set_cloned_tls(struct thread *td, void *desc)
314 struct segment_descriptor sd;
315 struct l_user_desc info;
319 error = copyin(desc, &info, sizeof(struct l_user_desc));
321 printf(LMSG("copyin failed!"));
323 idx = info.entry_number;
326 * looks like we're getting the idx we returned
327 * in the set_thread_area() syscall
329 if (idx != 6 && idx != 3) {
330 printf(LMSG("resetting idx!"));
334 /* this doesnt happen in practice */
336 /* we might copy out the entry_number as 3 */
337 info.entry_number = 3;
338 error = copyout(&info, desc, sizeof(struct l_user_desc));
340 printf(LMSG("copyout failed!"));
343 a[0] = LINUX_LDT_entry_a(&info);
344 a[1] = LINUX_LDT_entry_b(&info);
346 memcpy(&sd, &a, sizeof(a));
349 printf("Segment created in clone with "
350 "CLONE_SETTLS: lobase: %x, hibase: %x, "
351 "lolimit: %x, hilimit: %x, type: %i, "
352 "dpl: %i, p: %i, xx: %i, def32: %i, "
353 "gran: %i\n", sd.sd_lobase, sd.sd_hibase,
354 sd.sd_lolimit, sd.sd_hilimit, sd.sd_type,
355 sd.sd_dpl, sd.sd_p, sd.sd_xx,
356 sd.sd_def32, sd.sd_gran);
360 td->td_pcb->pcb_gsd = sd;
361 td->td_pcb->pcb_gs = GSEL(GUGS_SEL, SEL_UPL);
368 linux_set_upcall_kse(struct thread *td, register_t stack)
371 td->td_frame->tf_esp = stack;
376 #define STACK_SIZE (2 * 1024 * 1024)
377 #define GUARD_SIZE (4 * PAGE_SIZE)
380 linux_mmap2(struct thread *td, struct linux_mmap2_args *args)
385 printf(ARGS(mmap2, "%p, %d, %d, 0x%08x, %d, %d"),
386 (void *)args->addr, args->len, args->prot,
387 args->flags, args->fd, args->pgoff);
390 return (linux_mmap_common(td, args->addr, args->len, args->prot,
391 args->flags, args->fd, (uint64_t)(uint32_t)args->pgoff *
396 linux_mmap(struct thread *td, struct linux_mmap_args *args)
399 struct l_mmap_argv linux_args;
401 error = copyin(args->ptr, &linux_args, sizeof(linux_args));
407 printf(ARGS(mmap, "%p, %d, %d, 0x%08x, %d, %d"),
408 (void *)linux_args.addr, linux_args.len, linux_args.prot,
409 linux_args.flags, linux_args.fd, linux_args.pgoff);
412 return (linux_mmap_common(td, linux_args.addr, linux_args.len,
413 linux_args.prot, linux_args.flags, linux_args.fd,
414 (uint32_t)linux_args.pgoff));
418 linux_mmap_common(struct thread *td, l_uintptr_t addr, l_size_t len, l_int prot,
419 l_int flags, l_int fd, l_loff_t pos)
421 struct proc *p = td->td_proc;
422 struct mmap_args /* {
441 * You must specify exactly one of MAP_SHARED and MAP_PRIVATE
443 if (!((flags & LINUX_MAP_SHARED) ^ (flags & LINUX_MAP_PRIVATE)))
446 if (flags & LINUX_MAP_SHARED)
447 bsd_args.flags |= MAP_SHARED;
448 if (flags & LINUX_MAP_PRIVATE)
449 bsd_args.flags |= MAP_PRIVATE;
450 if (flags & LINUX_MAP_FIXED)
451 bsd_args.flags |= MAP_FIXED;
452 if (flags & LINUX_MAP_ANON) {
453 /* Enforce pos to be on page boundary, then ignore. */
454 if ((pos & PAGE_MASK) != 0)
457 bsd_args.flags |= MAP_ANON;
459 bsd_args.flags |= MAP_NOSYNC;
460 if (flags & LINUX_MAP_GROWSDOWN)
461 bsd_args.flags |= MAP_STACK;
464 * PROT_READ, PROT_WRITE, or PROT_EXEC implies PROT_READ and PROT_EXEC
465 * on Linux/i386. We do this to ensure maximum compatibility.
466 * Linux/ia64 does the same in i386 emulation mode.
468 bsd_args.prot = prot;
469 if (bsd_args.prot & (PROT_READ | PROT_WRITE | PROT_EXEC))
470 bsd_args.prot |= PROT_READ | PROT_EXEC;
472 /* Linux does not check file descriptor when MAP_ANONYMOUS is set. */
473 bsd_args.fd = (bsd_args.flags & MAP_ANON) ? -1 : fd;
474 if (bsd_args.fd != -1) {
476 * Linux follows Solaris mmap(2) description:
477 * The file descriptor fildes is opened with
478 * read permission, regardless of the
479 * protection options specified.
481 * Checking just CAP_MMAP is fine here, since the real work
482 * is done in the FreeBSD mmap().
485 error = fget(td, bsd_args.fd,
486 cap_rights_init(&rights, CAP_MMAP), &fp);
489 if (fp->f_type != DTYPE_VNODE) {
494 /* Linux mmap() just fails for O_WRONLY files */
495 if (!(fp->f_flag & FREAD)) {
503 if (flags & LINUX_MAP_GROWSDOWN) {
505 * The Linux MAP_GROWSDOWN option does not limit auto
506 * growth of the region. Linux mmap with this option
507 * takes as addr the inital BOS, and as len, the initial
508 * region size. It can then grow down from addr without
509 * limit. However, linux threads has an implicit internal
510 * limit to stack size of STACK_SIZE. Its just not
511 * enforced explicitly in linux. But, here we impose
512 * a limit of (STACK_SIZE - GUARD_SIZE) on the stack
513 * region, since we can do this with our mmap.
515 * Our mmap with MAP_STACK takes addr as the maximum
516 * downsize limit on BOS, and as len the max size of
517 * the region. It them maps the top SGROWSIZ bytes,
518 * and auto grows the region down, up to the limit
521 * If we don't use the MAP_STACK option, the effect
522 * of this code is to allocate a stack region of a
523 * fixed size of (STACK_SIZE - GUARD_SIZE).
526 if ((caddr_t)PTRIN(addr) + len > p->p_vmspace->vm_maxsaddr) {
528 * Some linux apps will attempt to mmap
529 * thread stacks near the top of their
530 * address space. If their TOS is greater
531 * than vm_maxsaddr, vm_map_growstack()
532 * will confuse the thread stack with the
533 * process stack and deliver a SEGV if they
534 * attempt to grow the thread stack past their
535 * current stacksize rlimit. To avoid this,
536 * adjust vm_maxsaddr upwards to reflect
537 * the current stacksize rlimit rather
538 * than the maximum possible stacksize.
539 * It would be better to adjust the
540 * mmap'ed region, but some apps do not check
541 * mmap's return value.
544 p->p_vmspace->vm_maxsaddr = (char *)USRSTACK -
545 lim_cur(p, RLIMIT_STACK);
550 * This gives us our maximum stack size and a new BOS.
551 * If we're using VM_STACK, then mmap will just map
552 * the top SGROWSIZ bytes, and let the stack grow down
553 * to the limit at BOS. If we're not using VM_STACK
554 * we map the full stack, since we don't have a way
557 if (len > STACK_SIZE - GUARD_SIZE) {
558 bsd_args.addr = (caddr_t)PTRIN(addr);
561 bsd_args.addr = (caddr_t)PTRIN(addr) -
562 (STACK_SIZE - GUARD_SIZE - len);
563 bsd_args.len = STACK_SIZE - GUARD_SIZE;
566 bsd_args.addr = (caddr_t)PTRIN(addr);
573 printf("-> %s(%p, %d, %d, 0x%08x, %d, 0x%x)\n",
575 (void *)bsd_args.addr, bsd_args.len, bsd_args.prot,
576 bsd_args.flags, bsd_args.fd, (int)bsd_args.pos);
578 error = sys_mmap(td, &bsd_args);
581 printf("-> %s() return: 0x%x (0x%08x)\n",
582 __func__, error, (u_int)td->td_retval[0]);
588 linux_mprotect(struct thread *td, struct linux_mprotect_args *uap)
590 struct mprotect_args bsd_args;
592 bsd_args.addr = uap->addr;
593 bsd_args.len = uap->len;
594 bsd_args.prot = uap->prot;
595 if (bsd_args.prot & (PROT_READ | PROT_WRITE | PROT_EXEC))
596 bsd_args.prot |= PROT_READ | PROT_EXEC;
597 return (sys_mprotect(td, &bsd_args));
601 linux_ioperm(struct thread *td, struct linux_ioperm_args *args)
604 struct i386_ioperm_args iia;
606 iia.start = args->start;
607 iia.length = args->length;
608 iia.enable = args->enable;
609 error = i386_set_ioperm(td, &iia);
614 linux_iopl(struct thread *td, struct linux_iopl_args *args)
618 if (args->level < 0 || args->level > 3)
620 if ((error = priv_check(td, PRIV_IO)) != 0)
622 if ((error = securelevel_gt(td->td_ucred, 0)) != 0)
624 td->td_frame->tf_eflags = (td->td_frame->tf_eflags & ~PSL_IOPL) |
625 (args->level * (PSL_IOPL / 3));
630 linux_modify_ldt(struct thread *td, struct linux_modify_ldt_args *uap)
633 struct i386_ldt_args ldt;
634 struct l_descriptor ld;
635 union descriptor desc;
639 case 0x00: /* read_ldt */
641 ldt.descs = uap->ptr;
642 ldt.num = uap->bytecount / sizeof(union descriptor);
643 error = i386_get_ldt(td, &ldt);
644 td->td_retval[0] *= sizeof(union descriptor);
646 case 0x02: /* read_default_ldt = 0 */
647 size = 5*sizeof(struct l_desc_struct);
648 if (size > uap->bytecount)
649 size = uap->bytecount;
650 for (written = error = 0; written < size && error == 0; written++)
651 error = subyte((char *)uap->ptr + written, 0);
652 td->td_retval[0] = written;
654 case 0x01: /* write_ldt */
655 case 0x11: /* write_ldt */
656 if (uap->bytecount != sizeof(ld))
659 error = copyin(uap->ptr, &ld, sizeof(ld));
663 ldt.start = ld.entry_number;
666 desc.sd.sd_lolimit = (ld.limit & 0x0000ffff);
667 desc.sd.sd_hilimit = (ld.limit & 0x000f0000) >> 16;
668 desc.sd.sd_lobase = (ld.base_addr & 0x00ffffff);
669 desc.sd.sd_hibase = (ld.base_addr & 0xff000000) >> 24;
670 desc.sd.sd_type = SDT_MEMRO | ((ld.read_exec_only ^ 1) << 1) |
673 desc.sd.sd_p = (ld.seg_not_present ^ 1);
675 desc.sd.sd_def32 = ld.seg_32bit;
676 desc.sd.sd_gran = ld.limit_in_pages;
677 error = i386_set_ldt(td, &ldt, &desc);
684 if (error == EOPNOTSUPP) {
685 printf("linux: modify_ldt needs kernel option USER_LDT\n");
693 linux_sigaction(struct thread *td, struct linux_sigaction_args *args)
696 l_sigaction_t act, oact;
700 if (ldebug(sigaction))
701 printf(ARGS(sigaction, "%d, %p, %p"),
702 args->sig, (void *)args->nsa, (void *)args->osa);
705 if (args->nsa != NULL) {
706 error = copyin(args->nsa, &osa, sizeof(l_osigaction_t));
709 act.lsa_handler = osa.lsa_handler;
710 act.lsa_flags = osa.lsa_flags;
711 act.lsa_restorer = osa.lsa_restorer;
712 LINUX_SIGEMPTYSET(act.lsa_mask);
713 act.lsa_mask.__bits[0] = osa.lsa_mask;
716 error = linux_do_sigaction(td, args->sig, args->nsa ? &act : NULL,
717 args->osa ? &oact : NULL);
719 if (args->osa != NULL && !error) {
720 osa.lsa_handler = oact.lsa_handler;
721 osa.lsa_flags = oact.lsa_flags;
722 osa.lsa_restorer = oact.lsa_restorer;
723 osa.lsa_mask = oact.lsa_mask.__bits[0];
724 error = copyout(&osa, args->osa, sizeof(l_osigaction_t));
731 * Linux has two extra args, restart and oldmask. We dont use these,
732 * but it seems that "restart" is actually a context pointer that
733 * enables the signal to happen with a different register set.
736 linux_sigsuspend(struct thread *td, struct linux_sigsuspend_args *args)
742 if (ldebug(sigsuspend))
743 printf(ARGS(sigsuspend, "%08lx"), (unsigned long)args->mask);
746 LINUX_SIGEMPTYSET(mask);
747 mask.__bits[0] = args->mask;
748 linux_to_bsd_sigset(&mask, &sigmask);
749 return (kern_sigsuspend(td, sigmask));
753 linux_rt_sigsuspend(struct thread *td, struct linux_rt_sigsuspend_args *uap)
760 if (ldebug(rt_sigsuspend))
761 printf(ARGS(rt_sigsuspend, "%p, %d"),
762 (void *)uap->newset, uap->sigsetsize);
765 if (uap->sigsetsize != sizeof(l_sigset_t))
768 error = copyin(uap->newset, &lmask, sizeof(l_sigset_t));
772 linux_to_bsd_sigset(&lmask, &sigmask);
773 return (kern_sigsuspend(td, sigmask));
777 linux_pause(struct thread *td, struct linux_pause_args *args)
779 struct proc *p = td->td_proc;
784 printf(ARGS(pause, ""));
788 sigmask = td->td_sigmask;
790 return (kern_sigsuspend(td, sigmask));
794 linux_sigaltstack(struct thread *td, struct linux_sigaltstack_args *uap)
801 if (ldebug(sigaltstack))
802 printf(ARGS(sigaltstack, "%p, %p"), uap->uss, uap->uoss);
805 if (uap->uss != NULL) {
806 error = copyin(uap->uss, &lss, sizeof(l_stack_t));
810 ss.ss_sp = lss.ss_sp;
811 ss.ss_size = lss.ss_size;
812 ss.ss_flags = linux_to_bsd_sigaltstack(lss.ss_flags);
814 error = kern_sigaltstack(td, (uap->uss != NULL) ? &ss : NULL,
815 (uap->uoss != NULL) ? &oss : NULL);
816 if (!error && uap->uoss != NULL) {
817 lss.ss_sp = oss.ss_sp;
818 lss.ss_size = oss.ss_size;
819 lss.ss_flags = bsd_to_linux_sigaltstack(oss.ss_flags);
820 error = copyout(&lss, uap->uoss, sizeof(l_stack_t));
827 linux_ftruncate64(struct thread *td, struct linux_ftruncate64_args *args)
829 struct ftruncate_args sa;
832 if (ldebug(ftruncate64))
833 printf(ARGS(ftruncate64, "%u, %jd"), args->fd,
834 (intmax_t)args->length);
838 sa.length = args->length;
839 return sys_ftruncate(td, &sa);
843 linux_set_thread_area(struct thread *td, struct linux_set_thread_area_args *args)
845 struct l_user_desc info;
849 struct segment_descriptor sd;
851 error = copyin(args->desc, &info, sizeof(struct l_user_desc));
856 if (ldebug(set_thread_area))
857 printf(ARGS(set_thread_area, "%i, %x, %x, %i, %i, %i, %i, %i, %i\n"),
865 info.seg_not_present,
869 idx = info.entry_number;
871 * Semantics of linux version: every thread in the system has array of
872 * 3 tls descriptors. 1st is GLIBC TLS, 2nd is WINE, 3rd unknown. This
873 * syscall loads one of the selected tls decriptors with a value and
874 * also loads GDT descriptors 6, 7 and 8 with the content of the
875 * per-thread descriptors.
877 * Semantics of fbsd version: I think we can ignore that linux has 3
878 * per-thread descriptors and use just the 1st one. The tls_array[]
879 * is used only in set/get-thread_area() syscalls and for loading the
880 * GDT descriptors. In fbsd we use just one GDT descriptor for TLS so
881 * we will load just one.
883 * XXX: this doesn't work when a user space process tries to use more
884 * than 1 TLS segment. Comment in the linux sources says wine might do
889 * we support just GLIBC TLS now
890 * we should let 3 proceed as well because we use this segment so
891 * if code does two subsequent calls it should succeed
893 if (idx != 6 && idx != -1 && idx != 3)
897 * we have to copy out the GDT entry we use
898 * FreeBSD uses GDT entry #3 for storing %gs so load that
900 * XXX: what if a user space program doesn't check this value and tries
903 idx = info.entry_number = 3;
904 error = copyout(&info, args->desc, sizeof(struct l_user_desc));
908 if (LINUX_LDT_empty(&info)) {
912 a[0] = LINUX_LDT_entry_a(&info);
913 a[1] = LINUX_LDT_entry_b(&info);
916 memcpy(&sd, &a, sizeof(a));
918 if (ldebug(set_thread_area))
919 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,
931 /* this is taken from i386 version of cpu_set_user_tls() */
934 td->td_pcb->pcb_gsd = sd;
935 PCPU_GET(fsgs_gdt)[1] = sd;
936 load_gs(GSEL(GUGS_SEL, SEL_UPL));
943 linux_get_thread_area(struct thread *td, struct linux_get_thread_area_args *args)
946 struct l_user_desc info;
949 struct l_desc_struct desc;
950 struct segment_descriptor sd;
953 if (ldebug(get_thread_area))
954 printf(ARGS(get_thread_area, "%p"), args->desc);
957 error = copyin(args->desc, &info, sizeof(struct l_user_desc));
961 idx = info.entry_number;
962 /* XXX: I am not sure if we want 3 to be allowed too. */
963 if (idx != 6 && idx != 3)
968 memset(&info, 0, sizeof(info));
970 sd = PCPU_GET(fsgs_gdt)[1];
972 memcpy(&desc, &sd, sizeof(desc));
974 info.entry_number = idx;
975 info.base_addr = LINUX_GET_BASE(&desc);
976 info.limit = LINUX_GET_LIMIT(&desc);
977 info.seg_32bit = LINUX_GET_32BIT(&desc);
978 info.contents = LINUX_GET_CONTENTS(&desc);
979 info.read_exec_only = !LINUX_GET_WRITABLE(&desc);
980 info.limit_in_pages = LINUX_GET_LIMIT_PAGES(&desc);
981 info.seg_not_present = !LINUX_GET_PRESENT(&desc);
982 info.useable = LINUX_GET_USEABLE(&desc);
984 error = copyout(&info, args->desc, sizeof(struct l_user_desc));
991 /* XXX: this wont work with module - convert it */
993 linux_mq_open(struct thread *td, struct linux_mq_open_args *args)
995 #ifdef P1003_1B_MQUEUE
996 return sys_kmq_open(td, (struct kmq_open_args *) args);
1003 linux_mq_unlink(struct thread *td, struct linux_mq_unlink_args *args)
1005 #ifdef P1003_1B_MQUEUE
1006 return sys_kmq_unlink(td, (struct kmq_unlink_args *) args);
1013 linux_mq_timedsend(struct thread *td, struct linux_mq_timedsend_args *args)
1015 #ifdef P1003_1B_MQUEUE
1016 return sys_kmq_timedsend(td, (struct kmq_timedsend_args *) args);
1023 linux_mq_timedreceive(struct thread *td, struct linux_mq_timedreceive_args *args)
1025 #ifdef P1003_1B_MQUEUE
1026 return sys_kmq_timedreceive(td, (struct kmq_timedreceive_args *) args);
1033 linux_mq_notify(struct thread *td, struct linux_mq_notify_args *args)
1035 #ifdef P1003_1B_MQUEUE
1036 return sys_kmq_notify(td, (struct kmq_notify_args *) args);
1043 linux_mq_getsetattr(struct thread *td, struct linux_mq_getsetattr_args *args)
1045 #ifdef P1003_1B_MQUEUE
1046 return sys_kmq_setattr(td, (struct kmq_setattr_args *) args);
1053 linux_wait4(struct thread *td, struct linux_wait4_args *args)
1056 struct rusage ru, *rup;
1060 printf(ARGS(wait4, "%d, %p, %d, %p"),
1061 args->pid, (void *)args->status, args->options,
1062 (void *)args->rusage);
1065 options = (args->options & (WNOHANG | WUNTRACED));
1066 /* WLINUXCLONE should be equal to __WCLONE, but we make sure */
1067 if (args->options & __WCLONE)
1068 options |= WLINUXCLONE;
1070 if (args->rusage != NULL)
1074 error = linux_common_wait(td, args->pid, args->status, options, rup);
1077 if (args->rusage != NULL)
1078 error = copyout(&ru, args->rusage, sizeof(ru));