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>
35 #include <sys/fcntl.h>
36 #include <sys/imgact.h>
38 #include <sys/malloc.h>
40 #include <sys/mutex.h>
44 #include <sys/queue.h>
45 #include <sys/resource.h>
46 #include <sys/resourcevar.h>
47 #include <sys/signalvar.h>
48 #include <sys/syscallsubr.h>
49 #include <sys/sysproto.h>
50 #include <sys/unistd.h>
52 #include <sys/sched.h>
54 #include <machine/frame.h>
55 #include <machine/psl.h>
56 #include <machine/segments.h>
57 #include <machine/sysarch.h>
61 #include <vm/vm_map.h>
63 #include <i386/linux/linux.h>
64 #include <i386/linux/linux_proto.h>
65 #include <compat/linux/linux_ipc.h>
66 #include <compat/linux/linux_misc.h>
67 #include <compat/linux/linux_signal.h>
68 #include <compat/linux/linux_util.h>
69 #include <compat/linux/linux_emul.h>
71 #include <i386/include/pcb.h> /* needed for pcb definition in linux_set_thread_area */
73 #include "opt_posix.h"
75 extern struct sysentvec elf32_freebsd_sysvec; /* defined in i386/i386/elf_machdep.c */
83 l_uint read_exec_only:1;
84 l_uint limit_in_pages:1;
85 l_uint seg_not_present:1;
89 struct l_old_select_argv {
94 struct l_timeval *timeout;
97 static int linux_mmap_common(struct thread *td, l_uintptr_t addr,
98 l_size_t len, l_int prot, l_int flags, l_int fd,
102 linux_to_bsd_sigaltstack(int lsa)
106 if (lsa & LINUX_SS_DISABLE)
108 if (lsa & LINUX_SS_ONSTACK)
114 bsd_to_linux_sigaltstack(int bsa)
118 if (bsa & SS_DISABLE)
119 lsa |= LINUX_SS_DISABLE;
120 if (bsa & SS_ONSTACK)
121 lsa |= LINUX_SS_ONSTACK;
126 linux_execve(struct thread *td, struct linux_execve_args *args)
130 struct image_args eargs;
132 LCONVPATHEXIST(td, args->path, &newpath);
136 printf(ARGS(execve, "%s"), newpath);
139 error = exec_copyin_args(&eargs, newpath, UIO_SYSSPACE,
140 args->argp, args->envp);
141 free(newpath, M_TEMP);
143 error = kern_execve(td, &eargs, NULL);
145 /* linux process can exec fbsd one, dont attempt
146 * to create emuldata for such process using
147 * linux_proc_init, this leads to a panic on KASSERT
148 * because such process has p->p_emuldata == NULL
150 if (SV_PROC_ABI(td->td_proc) == SV_ABI_LINUX)
151 error = linux_proc_init(td, 0, 0);
155 struct l_ipc_kludge {
156 struct l_msgbuf *msgp;
161 linux_ipc(struct thread *td, struct linux_ipc_args *args)
164 switch (args->what & 0xFFFF) {
166 struct linux_semop_args a;
168 a.semid = args->arg1;
170 a.nsops = args->arg2;
171 return (linux_semop(td, &a));
174 struct linux_semget_args a;
177 a.nsems = args->arg2;
178 a.semflg = args->arg3;
179 return (linux_semget(td, &a));
182 struct linux_semctl_args a;
185 a.semid = args->arg1;
186 a.semnum = args->arg2;
188 error = copyin(args->ptr, &a.arg, sizeof(a.arg));
191 return (linux_semctl(td, &a));
194 struct linux_msgsnd_args a;
196 a.msqid = args->arg1;
198 a.msgsz = args->arg2;
199 a.msgflg = args->arg3;
200 return (linux_msgsnd(td, &a));
203 struct linux_msgrcv_args a;
205 a.msqid = args->arg1;
206 a.msgsz = args->arg2;
207 a.msgflg = args->arg3;
208 if ((args->what >> 16) == 0) {
209 struct l_ipc_kludge tmp;
212 if (args->ptr == NULL)
214 error = copyin(args->ptr, &tmp, sizeof(tmp));
218 a.msgtyp = tmp.msgtyp;
221 a.msgtyp = args->arg5;
223 return (linux_msgrcv(td, &a));
226 struct linux_msgget_args a;
229 a.msgflg = args->arg2;
230 return (linux_msgget(td, &a));
233 struct linux_msgctl_args a;
235 a.msqid = args->arg1;
238 return (linux_msgctl(td, &a));
241 struct linux_shmat_args a;
243 a.shmid = args->arg1;
244 a.shmaddr = args->ptr;
245 a.shmflg = args->arg2;
246 a.raddr = (l_ulong *)args->arg3;
247 return (linux_shmat(td, &a));
250 struct linux_shmdt_args a;
252 a.shmaddr = args->ptr;
253 return (linux_shmdt(td, &a));
256 struct linux_shmget_args a;
260 a.shmflg = args->arg3;
261 return (linux_shmget(td, &a));
264 struct linux_shmctl_args a;
266 a.shmid = args->arg1;
269 return (linux_shmctl(td, &a));
279 linux_old_select(struct thread *td, struct linux_old_select_args *args)
281 struct l_old_select_argv linux_args;
282 struct linux_select_args newsel;
286 if (ldebug(old_select))
287 printf(ARGS(old_select, "%p"), args->ptr);
290 error = copyin(args->ptr, &linux_args, sizeof(linux_args));
294 newsel.nfds = linux_args.nfds;
295 newsel.readfds = linux_args.readfds;
296 newsel.writefds = linux_args.writefds;
297 newsel.exceptfds = linux_args.exceptfds;
298 newsel.timeout = linux_args.timeout;
299 return (linux_select(td, &newsel));
303 linux_set_cloned_tls(struct thread *td, void *desc)
305 struct segment_descriptor sd;
306 struct l_user_desc info;
310 error = copyin(desc, &info, sizeof(struct l_user_desc));
312 printf(LMSG("copyin failed!"));
314 idx = info.entry_number;
317 * looks like we're getting the idx we returned
318 * in the set_thread_area() syscall
320 if (idx != 6 && idx != 3) {
321 printf(LMSG("resetting idx!"));
325 /* this doesnt happen in practice */
327 /* we might copy out the entry_number as 3 */
328 info.entry_number = 3;
329 error = copyout(&info, desc, sizeof(struct l_user_desc));
331 printf(LMSG("copyout failed!"));
334 a[0] = LINUX_LDT_entry_a(&info);
335 a[1] = LINUX_LDT_entry_b(&info);
337 memcpy(&sd, &a, sizeof(a));
340 printf("Segment created in clone with "
341 "CLONE_SETTLS: lobase: %x, hibase: %x, "
342 "lolimit: %x, hilimit: %x, type: %i, "
343 "dpl: %i, p: %i, xx: %i, def32: %i, "
344 "gran: %i\n", sd.sd_lobase, sd.sd_hibase,
345 sd.sd_lolimit, sd.sd_hilimit, sd.sd_type,
346 sd.sd_dpl, sd.sd_p, sd.sd_xx,
347 sd.sd_def32, sd.sd_gran);
351 td->td_pcb->pcb_gsd = sd;
352 td->td_pcb->pcb_gs = GSEL(GUGS_SEL, SEL_UPL);
359 linux_set_upcall_kse(struct thread *td, register_t stack)
362 td->td_frame->tf_esp = stack;
367 #define STACK_SIZE (2 * 1024 * 1024)
368 #define GUARD_SIZE (4 * PAGE_SIZE)
371 linux_mmap2(struct thread *td, struct linux_mmap2_args *args)
376 printf(ARGS(mmap2, "%p, %d, %d, 0x%08x, %d, %d"),
377 (void *)args->addr, args->len, args->prot,
378 args->flags, args->fd, args->pgoff);
381 return (linux_mmap_common(td, args->addr, args->len, args->prot,
382 args->flags, args->fd, (uint64_t)(uint32_t)args->pgoff *
387 linux_mmap(struct thread *td, struct linux_mmap_args *args)
390 struct l_mmap_argv linux_args;
392 error = copyin(args->ptr, &linux_args, sizeof(linux_args));
398 printf(ARGS(mmap, "%p, %d, %d, 0x%08x, %d, %d"),
399 (void *)linux_args.addr, linux_args.len, linux_args.prot,
400 linux_args.flags, linux_args.fd, linux_args.pgoff);
403 return (linux_mmap_common(td, linux_args.addr, linux_args.len,
404 linux_args.prot, linux_args.flags, linux_args.fd,
405 (uint32_t)linux_args.pgoff));
409 linux_mmap_common(struct thread *td, l_uintptr_t addr, l_size_t len, l_int prot,
410 l_int flags, l_int fd, l_loff_t pos)
412 struct proc *p = td->td_proc;
413 struct mmap_args /* {
431 * You must specify exactly one of MAP_SHARED and MAP_PRIVATE
433 if (!((flags & LINUX_MAP_SHARED) ^ (flags & LINUX_MAP_PRIVATE)))
436 if (flags & LINUX_MAP_SHARED)
437 bsd_args.flags |= MAP_SHARED;
438 if (flags & LINUX_MAP_PRIVATE)
439 bsd_args.flags |= MAP_PRIVATE;
440 if (flags & LINUX_MAP_FIXED)
441 bsd_args.flags |= MAP_FIXED;
442 if (flags & LINUX_MAP_ANON) {
443 /* Enforce pos to be on page boundary, then ignore. */
444 if ((pos & PAGE_MASK) != 0)
447 bsd_args.flags |= MAP_ANON;
449 bsd_args.flags |= MAP_NOSYNC;
450 if (flags & LINUX_MAP_GROWSDOWN)
451 bsd_args.flags |= MAP_STACK;
454 * PROT_READ, PROT_WRITE, or PROT_EXEC implies PROT_READ and PROT_EXEC
455 * on Linux/i386. We do this to ensure maximum compatibility.
456 * Linux/ia64 does the same in i386 emulation mode.
458 bsd_args.prot = prot;
459 if (bsd_args.prot & (PROT_READ | PROT_WRITE | PROT_EXEC))
460 bsd_args.prot |= PROT_READ | PROT_EXEC;
462 /* Linux does not check file descriptor when MAP_ANONYMOUS is set. */
463 bsd_args.fd = (bsd_args.flags & MAP_ANON) ? -1 : fd;
464 if (bsd_args.fd != -1) {
466 * Linux follows Solaris mmap(2) description:
467 * The file descriptor fildes is opened with
468 * read permission, regardless of the
469 * protection options specified.
472 if ((error = fget(td, bsd_args.fd, &fp)) != 0)
474 if (fp->f_type != DTYPE_VNODE) {
479 /* Linux mmap() just fails for O_WRONLY files */
480 if (!(fp->f_flag & FREAD)) {
488 if (flags & LINUX_MAP_GROWSDOWN) {
490 * The Linux MAP_GROWSDOWN option does not limit auto
491 * growth of the region. Linux mmap with this option
492 * takes as addr the inital BOS, and as len, the initial
493 * region size. It can then grow down from addr without
494 * limit. However, linux threads has an implicit internal
495 * limit to stack size of STACK_SIZE. Its just not
496 * enforced explicitly in linux. But, here we impose
497 * a limit of (STACK_SIZE - GUARD_SIZE) on the stack
498 * region, since we can do this with our mmap.
500 * Our mmap with MAP_STACK takes addr as the maximum
501 * downsize limit on BOS, and as len the max size of
502 * the region. It them maps the top SGROWSIZ bytes,
503 * and auto grows the region down, up to the limit
506 * If we don't use the MAP_STACK option, the effect
507 * of this code is to allocate a stack region of a
508 * fixed size of (STACK_SIZE - GUARD_SIZE).
511 if ((caddr_t)PTRIN(addr) + len > p->p_vmspace->vm_maxsaddr) {
513 * Some linux apps will attempt to mmap
514 * thread stacks near the top of their
515 * address space. If their TOS is greater
516 * than vm_maxsaddr, vm_map_growstack()
517 * will confuse the thread stack with the
518 * process stack and deliver a SEGV if they
519 * attempt to grow the thread stack past their
520 * current stacksize rlimit. To avoid this,
521 * adjust vm_maxsaddr upwards to reflect
522 * the current stacksize rlimit rather
523 * than the maximum possible stacksize.
524 * It would be better to adjust the
525 * mmap'ed region, but some apps do not check
526 * mmap's return value.
529 p->p_vmspace->vm_maxsaddr = (char *)USRSTACK -
530 lim_cur(p, RLIMIT_STACK);
535 * This gives us our maximum stack size and a new BOS.
536 * If we're using VM_STACK, then mmap will just map
537 * the top SGROWSIZ bytes, and let the stack grow down
538 * to the limit at BOS. If we're not using VM_STACK
539 * we map the full stack, since we don't have a way
542 if (len > STACK_SIZE - GUARD_SIZE) {
543 bsd_args.addr = (caddr_t)PTRIN(addr);
546 bsd_args.addr = (caddr_t)PTRIN(addr) -
547 (STACK_SIZE - GUARD_SIZE - len);
548 bsd_args.len = STACK_SIZE - GUARD_SIZE;
551 bsd_args.addr = (caddr_t)PTRIN(addr);
558 printf("-> %s(%p, %d, %d, 0x%08x, %d, 0x%x)\n",
560 (void *)bsd_args.addr, bsd_args.len, bsd_args.prot,
561 bsd_args.flags, bsd_args.fd, (int)bsd_args.pos);
563 error = mmap(td, &bsd_args);
566 printf("-> %s() return: 0x%x (0x%08x)\n",
567 __func__, error, (u_int)td->td_retval[0]);
573 linux_mprotect(struct thread *td, struct linux_mprotect_args *uap)
575 struct mprotect_args bsd_args;
577 bsd_args.addr = uap->addr;
578 bsd_args.len = uap->len;
579 bsd_args.prot = uap->prot;
580 if (bsd_args.prot & (PROT_READ | PROT_WRITE | PROT_EXEC))
581 bsd_args.prot |= PROT_READ | PROT_EXEC;
582 return (mprotect(td, &bsd_args));
586 linux_pipe(struct thread *td, struct linux_pipe_args *args)
593 printf(ARGS(pipe, "*"));
596 error = kern_pipe(td, fildes);
600 /* XXX: Close descriptors on error. */
601 return (copyout(fildes, args->pipefds, sizeof fildes));
605 linux_ioperm(struct thread *td, struct linux_ioperm_args *args)
608 struct i386_ioperm_args iia;
610 iia.start = args->start;
611 iia.length = args->length;
612 iia.enable = args->enable;
613 error = i386_set_ioperm(td, &iia);
618 linux_iopl(struct thread *td, struct linux_iopl_args *args)
622 if (args->level < 0 || args->level > 3)
624 if ((error = priv_check(td, PRIV_IO)) != 0)
626 if ((error = securelevel_gt(td->td_ucred, 0)) != 0)
628 td->td_frame->tf_eflags = (td->td_frame->tf_eflags & ~PSL_IOPL) |
629 (args->level * (PSL_IOPL / 3));
634 linux_modify_ldt(struct thread *td, struct linux_modify_ldt_args *uap)
637 struct i386_ldt_args ldt;
638 struct l_descriptor ld;
639 union descriptor desc;
643 case 0x00: /* read_ldt */
645 ldt.descs = uap->ptr;
646 ldt.num = uap->bytecount / sizeof(union descriptor);
647 error = i386_get_ldt(td, &ldt);
648 td->td_retval[0] *= sizeof(union descriptor);
650 case 0x02: /* read_default_ldt = 0 */
651 size = 5*sizeof(struct l_desc_struct);
652 if (size > uap->bytecount)
653 size = uap->bytecount;
654 for (written = error = 0; written < size && error == 0; written++)
655 error = subyte((char *)uap->ptr + written, 0);
656 td->td_retval[0] = written;
658 case 0x01: /* write_ldt */
659 case 0x11: /* write_ldt */
660 if (uap->bytecount != sizeof(ld))
663 error = copyin(uap->ptr, &ld, sizeof(ld));
667 ldt.start = ld.entry_number;
670 desc.sd.sd_lolimit = (ld.limit & 0x0000ffff);
671 desc.sd.sd_hilimit = (ld.limit & 0x000f0000) >> 16;
672 desc.sd.sd_lobase = (ld.base_addr & 0x00ffffff);
673 desc.sd.sd_hibase = (ld.base_addr & 0xff000000) >> 24;
674 desc.sd.sd_type = SDT_MEMRO | ((ld.read_exec_only ^ 1) << 1) |
677 desc.sd.sd_p = (ld.seg_not_present ^ 1);
679 desc.sd.sd_def32 = ld.seg_32bit;
680 desc.sd.sd_gran = ld.limit_in_pages;
681 error = i386_set_ldt(td, &ldt, &desc);
688 if (error == EOPNOTSUPP) {
689 printf("linux: modify_ldt needs kernel option USER_LDT\n");
697 linux_sigaction(struct thread *td, struct linux_sigaction_args *args)
700 l_sigaction_t act, oact;
704 if (ldebug(sigaction))
705 printf(ARGS(sigaction, "%d, %p, %p"),
706 args->sig, (void *)args->nsa, (void *)args->osa);
709 if (args->nsa != NULL) {
710 error = copyin(args->nsa, &osa, sizeof(l_osigaction_t));
713 act.lsa_handler = osa.lsa_handler;
714 act.lsa_flags = osa.lsa_flags;
715 act.lsa_restorer = osa.lsa_restorer;
716 LINUX_SIGEMPTYSET(act.lsa_mask);
717 act.lsa_mask.__bits[0] = osa.lsa_mask;
720 error = linux_do_sigaction(td, args->sig, args->nsa ? &act : NULL,
721 args->osa ? &oact : NULL);
723 if (args->osa != NULL && !error) {
724 osa.lsa_handler = oact.lsa_handler;
725 osa.lsa_flags = oact.lsa_flags;
726 osa.lsa_restorer = oact.lsa_restorer;
727 osa.lsa_mask = oact.lsa_mask.__bits[0];
728 error = copyout(&osa, args->osa, sizeof(l_osigaction_t));
735 * Linux has two extra args, restart and oldmask. We dont use these,
736 * but it seems that "restart" is actually a context pointer that
737 * enables the signal to happen with a different register set.
740 linux_sigsuspend(struct thread *td, struct linux_sigsuspend_args *args)
746 if (ldebug(sigsuspend))
747 printf(ARGS(sigsuspend, "%08lx"), (unsigned long)args->mask);
750 LINUX_SIGEMPTYSET(mask);
751 mask.__bits[0] = args->mask;
752 linux_to_bsd_sigset(&mask, &sigmask);
753 return (kern_sigsuspend(td, sigmask));
757 linux_rt_sigsuspend(struct thread *td, struct linux_rt_sigsuspend_args *uap)
764 if (ldebug(rt_sigsuspend))
765 printf(ARGS(rt_sigsuspend, "%p, %d"),
766 (void *)uap->newset, uap->sigsetsize);
769 if (uap->sigsetsize != sizeof(l_sigset_t))
772 error = copyin(uap->newset, &lmask, sizeof(l_sigset_t));
776 linux_to_bsd_sigset(&lmask, &sigmask);
777 return (kern_sigsuspend(td, sigmask));
781 linux_pause(struct thread *td, struct linux_pause_args *args)
783 struct proc *p = td->td_proc;
788 printf(ARGS(pause, ""));
792 sigmask = td->td_sigmask;
794 return (kern_sigsuspend(td, sigmask));
798 linux_sigaltstack(struct thread *td, struct linux_sigaltstack_args *uap)
805 if (ldebug(sigaltstack))
806 printf(ARGS(sigaltstack, "%p, %p"), uap->uss, uap->uoss);
809 if (uap->uss != NULL) {
810 error = copyin(uap->uss, &lss, sizeof(l_stack_t));
814 ss.ss_sp = lss.ss_sp;
815 ss.ss_size = lss.ss_size;
816 ss.ss_flags = linux_to_bsd_sigaltstack(lss.ss_flags);
818 error = kern_sigaltstack(td, (uap->uss != NULL) ? &ss : NULL,
819 (uap->uoss != NULL) ? &oss : NULL);
820 if (!error && uap->uoss != NULL) {
821 lss.ss_sp = oss.ss_sp;
822 lss.ss_size = oss.ss_size;
823 lss.ss_flags = bsd_to_linux_sigaltstack(oss.ss_flags);
824 error = copyout(&lss, uap->uoss, sizeof(l_stack_t));
831 linux_ftruncate64(struct thread *td, struct linux_ftruncate64_args *args)
833 struct ftruncate_args sa;
836 if (ldebug(ftruncate64))
837 printf(ARGS(ftruncate64, "%u, %jd"), args->fd,
838 (intmax_t)args->length);
842 sa.length = args->length;
843 return ftruncate(td, &sa);
847 linux_set_thread_area(struct thread *td, struct linux_set_thread_area_args *args)
849 struct l_user_desc info;
853 struct segment_descriptor sd;
855 error = copyin(args->desc, &info, sizeof(struct l_user_desc));
860 if (ldebug(set_thread_area))
861 printf(ARGS(set_thread_area, "%i, %x, %x, %i, %i, %i, %i, %i, %i\n"),
869 info.seg_not_present,
873 idx = info.entry_number;
875 * Semantics of linux version: every thread in the system has array of
876 * 3 tls descriptors. 1st is GLIBC TLS, 2nd is WINE, 3rd unknown. This
877 * syscall loads one of the selected tls decriptors with a value and
878 * also loads GDT descriptors 6, 7 and 8 with the content of the
879 * per-thread descriptors.
881 * Semantics of fbsd version: I think we can ignore that linux has 3
882 * per-thread descriptors and use just the 1st one. The tls_array[]
883 * is used only in set/get-thread_area() syscalls and for loading the
884 * GDT descriptors. In fbsd we use just one GDT descriptor for TLS so
885 * we will load just one.
887 * XXX: this doesn't work when a user space process tries to use more
888 * than 1 TLS segment. Comment in the linux sources says wine might do
893 * we support just GLIBC TLS now
894 * we should let 3 proceed as well because we use this segment so
895 * if code does two subsequent calls it should succeed
897 if (idx != 6 && idx != -1 && idx != 3)
901 * we have to copy out the GDT entry we use
902 * FreeBSD uses GDT entry #3 for storing %gs so load that
904 * XXX: what if a user space program doesn't check this value and tries
907 idx = info.entry_number = 3;
908 error = copyout(&info, args->desc, sizeof(struct l_user_desc));
912 if (LINUX_LDT_empty(&info)) {
916 a[0] = LINUX_LDT_entry_a(&info);
917 a[1] = LINUX_LDT_entry_b(&info);
920 memcpy(&sd, &a, sizeof(a));
922 if (ldebug(set_thread_area))
923 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,
935 /* this is taken from i386 version of cpu_set_user_tls() */
938 td->td_pcb->pcb_gsd = sd;
939 PCPU_GET(fsgs_gdt)[1] = sd;
940 load_gs(GSEL(GUGS_SEL, SEL_UPL));
947 linux_get_thread_area(struct thread *td, struct linux_get_thread_area_args *args)
950 struct l_user_desc info;
953 struct l_desc_struct desc;
954 struct segment_descriptor sd;
957 if (ldebug(get_thread_area))
958 printf(ARGS(get_thread_area, "%p"), args->desc);
961 error = copyin(args->desc, &info, sizeof(struct l_user_desc));
965 idx = info.entry_number;
966 /* XXX: I am not sure if we want 3 to be allowed too. */
967 if (idx != 6 && idx != 3)
972 memset(&info, 0, sizeof(info));
974 sd = PCPU_GET(fsgs_gdt)[1];
976 memcpy(&desc, &sd, sizeof(desc));
978 info.entry_number = idx;
979 info.base_addr = LINUX_GET_BASE(&desc);
980 info.limit = LINUX_GET_LIMIT(&desc);
981 info.seg_32bit = LINUX_GET_32BIT(&desc);
982 info.contents = LINUX_GET_CONTENTS(&desc);
983 info.read_exec_only = !LINUX_GET_WRITABLE(&desc);
984 info.limit_in_pages = LINUX_GET_LIMIT_PAGES(&desc);
985 info.seg_not_present = !LINUX_GET_PRESENT(&desc);
986 info.useable = LINUX_GET_USEABLE(&desc);
988 error = copyout(&info, args->desc, sizeof(struct l_user_desc));
995 /* copied from kern/kern_time.c */
997 linux_timer_create(struct thread *td, struct linux_timer_create_args *args)
999 return ktimer_create(td, (struct ktimer_create_args *) args);
1003 linux_timer_settime(struct thread *td, struct linux_timer_settime_args *args)
1005 return ktimer_settime(td, (struct ktimer_settime_args *) args);
1009 linux_timer_gettime(struct thread *td, struct linux_timer_gettime_args *args)
1011 return ktimer_gettime(td, (struct ktimer_gettime_args *) args);
1015 linux_timer_getoverrun(struct thread *td, struct linux_timer_getoverrun_args *args)
1017 return ktimer_getoverrun(td, (struct ktimer_getoverrun_args *) args);
1021 linux_timer_delete(struct thread *td, struct linux_timer_delete_args *args)
1023 return ktimer_delete(td, (struct ktimer_delete_args *) args);
1026 /* XXX: this wont work with module - convert it */
1028 linux_mq_open(struct thread *td, struct linux_mq_open_args *args)
1030 #ifdef P1003_1B_MQUEUE
1031 return kmq_open(td, (struct kmq_open_args *) args);
1038 linux_mq_unlink(struct thread *td, struct linux_mq_unlink_args *args)
1040 #ifdef P1003_1B_MQUEUE
1041 return kmq_unlink(td, (struct kmq_unlink_args *) args);
1048 linux_mq_timedsend(struct thread *td, struct linux_mq_timedsend_args *args)
1050 #ifdef P1003_1B_MQUEUE
1051 return kmq_timedsend(td, (struct kmq_timedsend_args *) args);
1058 linux_mq_timedreceive(struct thread *td, struct linux_mq_timedreceive_args *args)
1060 #ifdef P1003_1B_MQUEUE
1061 return kmq_timedreceive(td, (struct kmq_timedreceive_args *) args);
1068 linux_mq_notify(struct thread *td, struct linux_mq_notify_args *args)
1070 #ifdef P1003_1B_MQUEUE
1071 return kmq_notify(td, (struct kmq_notify_args *) args);
1078 linux_mq_getsetattr(struct thread *td, struct linux_mq_getsetattr_args *args)
1080 #ifdef P1003_1B_MQUEUE
1081 return kmq_setattr(td, (struct kmq_setattr_args *) args);
1088 linux_wait4(struct thread *td, struct linux_wait4_args *args)
1091 struct rusage ru, *rup;
1095 printf(ARGS(wait4, "%d, %p, %d, %p"),
1096 args->pid, (void *)args->status, args->options,
1097 (void *)args->rusage);
1100 options = (args->options & (WNOHANG | WUNTRACED));
1101 /* WLINUXCLONE should be equal to __WCLONE, but we make sure */
1102 if (args->options & __WCLONE)
1103 options |= WLINUXCLONE;
1105 if (args->rusage != NULL)
1109 error = linux_common_wait(td, args->pid, args->status, options, rup);
1112 if (args->rusage != NULL)
1113 error = copyout(&ru, args->rusage, sizeof(ru));