From 1910949b03c5c3613c98fd9d25f1c680ec929f71 Mon Sep 17 00:00:00 2001 From: Yonghong Yan Date: Thu, 27 Sep 2007 21:18:23 -0500 Subject: [PATCH] merged in amd64 linux emulation from freebsd, but the building infra is not ready. so it would build --- sys/emulation/linux/amd64/Makefile | 16 + sys/emulation/linux/amd64/linux.h | 873 +++++++++++++++++ sys/emulation/linux/amd64/linux32_dummy.c | 135 +++ sys/emulation/linux/amd64/linux32_genassym.c | 19 + sys/emulation/linux/amd64/linux32_ipc64.h | 146 +++ sys/emulation/linux/amd64/linux32_locore.s | 44 + sys/emulation/linux/amd64/linux32_machdep.c | 1362 ++++++++++++++++++++++++++ sys/emulation/linux/amd64/linux32_support.s | 125 +++ sys/emulation/linux/amd64/linux32_sysvec.c | 1133 +++++++++++++++++++++ sys/emulation/linux/amd64/syscalls.conf | 12 + sys/emulation/linux/amd64/syscalls.master | 483 +++++++++ 11 files changed, 4348 insertions(+) create mode 100644 sys/emulation/linux/amd64/Makefile create mode 100644 sys/emulation/linux/amd64/linux.h create mode 100644 sys/emulation/linux/amd64/linux32_dummy.c create mode 100644 sys/emulation/linux/amd64/linux32_genassym.c create mode 100644 sys/emulation/linux/amd64/linux32_ipc64.h create mode 100644 sys/emulation/linux/amd64/linux32_locore.s create mode 100644 sys/emulation/linux/amd64/linux32_machdep.c create mode 100644 sys/emulation/linux/amd64/linux32_support.s create mode 100644 sys/emulation/linux/amd64/linux32_sysvec.c create mode 100644 sys/emulation/linux/amd64/syscalls.conf create mode 100644 sys/emulation/linux/amd64/syscalls.master diff --git a/sys/emulation/linux/amd64/Makefile b/sys/emulation/linux/amd64/Makefile new file mode 100644 index 0000000000..0fe8feffc2 --- /dev/null +++ b/sys/emulation/linux/amd64/Makefile @@ -0,0 +1,16 @@ +# Makefile for syscall tables +# +# $FreeBSD: src/sys/amd64/linux32/Makefile,v 1.1 2004/08/16 07:55:06 tjr Exp $ +# $DragonFly$ + +all: + @echo "make sysent only" + +sysent: linux32_sysent.c linux32_syscall.h linux32_proto.h + +linux32_sysent.c linux32_syscall.h linux32_proto.h: ../../kern/makesyscalls.sh \ + syscalls.master syscalls.conf + -mv -f linux32_sysent.c linux32_sysent.c.bak + -mv -f linux32_syscall.h linux32_syscall.h.bak + -mv -f linux32_proto.h linux32_proto.h.bak + sh ../../kern/makesyscalls.sh syscalls.master syscalls.conf diff --git a/sys/emulation/linux/amd64/linux.h b/sys/emulation/linux/amd64/linux.h new file mode 100644 index 0000000000..500f739e71 --- /dev/null +++ b/sys/emulation/linux/amd64/linux.h @@ -0,0 +1,873 @@ +/*- + * Copyright (c) 2004 Tim J. Robbins + * Copyright (c) 2001 Doug Rabson + * Copyright (c) 1994-1996 Søren Schmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: src/sys/amd64/linux32/linux.h,v 1.15 2007/03/29 02:11:46 julian Exp $ + * $DragonFly$ + */ + +#ifndef _AMD64_LINUX_H_ +#define _AMD64_LINUX_H_ + +#include + +/* + * debugging support + */ +extern u_char linux_debug_map[]; +#define ldebug(name) isclr(linux_debug_map, LINUX_SYS_linux_ ## name) +#define ARGS(nm, fmt) "linux(%ld): "#nm"("fmt")\n", (long)td->td_proc->p_pid +#define LMSG(fmt) "linux(%ld): "fmt"\n", (long)td->td_proc->p_pid + +#ifdef MALLOC_DECLARE +MALLOC_DECLARE(M_LINUX); +#endif + +#define LINUX32_USRSTACK ((1ul << 32) - PAGE_SIZE) +/* XXX 16 = sizeof(linux32_ps_strings) */ +#define LINUX32_PS_STRINGS (LINUX32_USRSTACK - 16) +#define LINUX32_MAXDSIZ (512 * 1024 * 1024) /* 512MB */ +#define LINUX32_MAXSSIZ (64 * 1024 * 1024) /* 64MB */ +#define LINUX32_MAXVMEM 0 /* Unlimited */ + +#define PTRIN(v) (void *)(uintptr_t)(v) +#define PTROUT(v) (l_uintptr_t)(uintptr_t)(v) + +/* + * Provide a separate set of types for the Linux types. + */ +typedef int l_int; +typedef int32_t l_long; +typedef int64_t l_longlong; +typedef short l_short; +typedef unsigned int l_uint; +typedef uint32_t l_ulong; +typedef uint64_t l_ulonglong; +typedef unsigned short l_ushort; + +typedef l_ulong l_uintptr_t; +typedef l_long l_clock_t; +typedef l_int l_daddr_t; +typedef l_ushort l_dev_t; +typedef l_uint l_gid_t; +typedef l_ushort l_gid16_t; +typedef l_ulong l_ino_t; +typedef l_int l_key_t; +typedef l_longlong l_loff_t; +typedef l_ushort l_mode_t; +typedef l_long l_off_t; +typedef l_int l_pid_t; +typedef l_uint l_size_t; +typedef l_long l_suseconds_t; +typedef l_long l_time_t; +typedef l_uint l_uid_t; +typedef l_ushort l_uid16_t; + +typedef struct { + l_int val[2]; +} __packed l_fsid_t; + +typedef struct { + l_time_t tv_sec; + l_suseconds_t tv_usec; +} __packed l_timeval; + +#define l_fd_set fd_set + +/* + * Miscellaneous + */ +#define LINUX_NAME_MAX 255 +#define LINUX_MAX_UTSNAME 65 + +#define LINUX_CTL_MAXNAME 10 + +struct l___sysctl_args +{ + l_uintptr_t name; + l_int nlen; + l_uintptr_t oldval; + l_uintptr_t oldlenp; + l_uintptr_t newval; + l_size_t newlen; + l_ulong __spare[4]; +} __packed; + +/* Scheduling policies */ +#define LINUX_SCHED_OTHER 0 +#define LINUX_SCHED_FIFO 1 +#define LINUX_SCHED_RR 2 + +/* Resource limits */ +#define LINUX_RLIMIT_CPU 0 +#define LINUX_RLIMIT_FSIZE 1 +#define LINUX_RLIMIT_DATA 2 +#define LINUX_RLIMIT_STACK 3 +#define LINUX_RLIMIT_CORE 4 +#define LINUX_RLIMIT_RSS 5 +#define LINUX_RLIMIT_NPROC 6 +#define LINUX_RLIMIT_NOFILE 7 +#define LINUX_RLIMIT_MEMLOCK 8 +#define LINUX_RLIMIT_AS 9 /* Address space limit */ + +#define LINUX_RLIM_NLIMITS 10 + +struct l_rlimit { + l_ulong rlim_cur; + l_ulong rlim_max; +} __packed; + +struct l_rusage { + l_timeval ru_utime; + l_timeval ru_stime; + l_long ru_maxrss; + l_long ru_ixrss; + l_long ru_idrss; + l_long ru_isrss; + l_long ru_minflt; + l_long ru_majflt; + l_long ru_nswap; + l_long ru_inblock; + l_long ru_oublock; + l_long ru_msgsnd; + l_long ru_msgrcv; + l_long ru_nsignals; + l_long ru_nvcsw; + l_long ru_nivcsw; +} __packed; + +/* mmap options */ +#define LINUX_MAP_SHARED 0x0001 +#define LINUX_MAP_PRIVATE 0x0002 +#define LINUX_MAP_FIXED 0x0010 +#define LINUX_MAP_ANON 0x0020 +#define LINUX_MAP_GROWSDOWN 0x0100 + +struct l_mmap_argv { + l_uintptr_t addr; + l_size_t len; + l_int prot; + l_int flags; + l_int fd; + l_off_t pgoff; +} __packed; + +/* + * stat family of syscalls + */ +struct l_timespec { + l_time_t tv_sec; + l_long tv_nsec; +} __packed; + +struct l_newstat { + l_ushort st_dev; + l_ushort __pad1; + l_ulong st_ino; + l_ushort st_mode; + l_ushort st_nlink; + l_ushort st_uid; + l_ushort st_gid; + l_ushort st_rdev; + l_ushort __pad2; + l_ulong st_size; + l_ulong st_blksize; + l_ulong st_blocks; + struct l_timespec st_atimespec; + struct l_timespec st_mtimespec; + struct l_timespec st_ctimespec; + l_ulong __unused4; + l_ulong __unused5; +} __packed; + +struct l_stat { + l_ushort st_dev; + l_ulong st_ino; + l_ushort st_mode; + l_ushort st_nlink; + l_ushort st_uid; + l_ushort st_gid; + l_ushort st_rdev; + l_long st_size; + struct l_timespec st_atimespec; + struct l_timespec st_mtimespec; + struct l_timespec st_ctimespec; + l_long st_blksize; + l_long st_blocks; + l_ulong st_flags; + l_ulong st_gen; +}; + +struct l_stat64 { + l_ushort st_dev; + u_char __pad0[10]; + l_ulong __st_ino; + l_uint st_mode; + l_uint st_nlink; + l_ulong st_uid; + l_ulong st_gid; + l_ushort st_rdev; + u_char __pad3[10]; + l_longlong st_size; + l_ulong st_blksize; + l_ulong st_blocks; + l_ulong __pad4; + struct l_timespec st_atimespec; + struct l_timespec st_mtimespec; + struct l_timespec st_ctimespec; + l_ulonglong st_ino; +} __packed; + +struct l_new_utsname { + char sysname[LINUX_MAX_UTSNAME]; + char nodename[LINUX_MAX_UTSNAME]; + char release[LINUX_MAX_UTSNAME]; + char version[LINUX_MAX_UTSNAME]; + char machine[LINUX_MAX_UTSNAME]; + char domainname[LINUX_MAX_UTSNAME]; +} __packed; + +/* + * Signalling + */ +#define LINUX_SIGHUP 1 +#define LINUX_SIGINT 2 +#define LINUX_SIGQUIT 3 +#define LINUX_SIGILL 4 +#define LINUX_SIGTRAP 5 +#define LINUX_SIGABRT 6 +#define LINUX_SIGIOT LINUX_SIGABRT +#define LINUX_SIGBUS 7 +#define LINUX_SIGFPE 8 +#define LINUX_SIGKILL 9 +#define LINUX_SIGUSR1 10 +#define LINUX_SIGSEGV 11 +#define LINUX_SIGUSR2 12 +#define LINUX_SIGPIPE 13 +#define LINUX_SIGALRM 14 +#define LINUX_SIGTERM 15 +#define LINUX_SIGSTKFLT 16 +#define LINUX_SIGCHLD 17 +#define LINUX_SIGCONT 18 +#define LINUX_SIGSTOP 19 +#define LINUX_SIGTSTP 20 +#define LINUX_SIGTTIN 21 +#define LINUX_SIGTTOU 22 +#define LINUX_SIGURG 23 +#define LINUX_SIGXCPU 24 +#define LINUX_SIGXFSZ 25 +#define LINUX_SIGVTALRM 26 +#define LINUX_SIGPROF 27 +#define LINUX_SIGWINCH 28 +#define LINUX_SIGIO 29 +#define LINUX_SIGPOLL LINUX_SIGIO +#define LINUX_SIGPWR 30 +#define LINUX_SIGSYS 31 + +#define LINUX_SIGTBLSZ 31 +#define LINUX_NSIG_WORDS 2 +#define LINUX_NBPW 32 +#define LINUX_NSIG (LINUX_NBPW * LINUX_NSIG_WORDS) + +/* sigaction flags */ +#define LINUX_SA_NOCLDSTOP 0x00000001 +#define LINUX_SA_NOCLDWAIT 0x00000002 +#define LINUX_SA_SIGINFO 0x00000004 +#define LINUX_SA_RESTORER 0x04000000 +#define LINUX_SA_ONSTACK 0x08000000 +#define LINUX_SA_RESTART 0x10000000 +#define LINUX_SA_INTERRUPT 0x20000000 +#define LINUX_SA_NOMASK 0x40000000 +#define LINUX_SA_ONESHOT 0x80000000 + +/* sigprocmask actions */ +#define LINUX_SIG_BLOCK 0 +#define LINUX_SIG_UNBLOCK 1 +#define LINUX_SIG_SETMASK 2 + +/* sigset_t macros */ +#define LINUX_SIGEMPTYSET(set) (set).__bits[0] = (set).__bits[1] = 0 +#define LINUX_SIGISMEMBER(set, sig) SIGISMEMBER(set, sig) +#define LINUX_SIGADDSET(set, sig) SIGADDSET(set, sig) + +/* sigaltstack */ +#define LINUX_MINSIGSTKSZ 2048 +#define LINUX_SS_ONSTACK 1 +#define LINUX_SS_DISABLE 2 + +int linux_to_bsd_sigaltstack(int lsa); +int bsd_to_linux_sigaltstack(int bsa); + +typedef l_uintptr_t l_handler_t; +typedef l_ulong l_osigset_t; + +typedef struct { + l_uint __bits[LINUX_NSIG_WORDS]; +} __packed l_sigset_t; + +typedef struct { + l_handler_t lsa_handler; + l_osigset_t lsa_mask; + l_ulong lsa_flags; + l_uintptr_t lsa_restorer; +} __packed l_osigaction_t; + +typedef struct { + l_handler_t lsa_handler; + l_ulong lsa_flags; + l_uintptr_t lsa_restorer; + l_sigset_t lsa_mask; +} __packed l_sigaction_t; + +typedef struct { + l_uintptr_t ss_sp; + l_int ss_flags; + l_size_t ss_size; +} __packed l_stack_t; + +/* The Linux sigcontext, pretty much a standard 386 trapframe. */ +struct l_sigcontext { + l_int sc_gs; + l_int sc_fs; + l_int sc_es; + l_int sc_ds; + l_int sc_edi; + l_int sc_esi; + l_int sc_ebp; + l_int sc_esp; + l_int sc_ebx; + l_int sc_edx; + l_int sc_ecx; + l_int sc_eax; + l_int sc_trapno; + l_int sc_err; + l_int sc_eip; + l_int sc_cs; + l_int sc_eflags; + l_int sc_esp_at_signal; + l_int sc_ss; + l_int sc_387; + l_int sc_mask; + l_int sc_cr2; +} __packed; + +struct l_ucontext { + l_ulong uc_flags; + l_uintptr_t uc_link; + l_stack_t uc_stack; + struct l_sigcontext uc_mcontext; + l_sigset_t uc_sigmask; +} __packed; + +#define LINUX_SI_MAX_SIZE 128 +#define LINUX_SI_PAD_SIZE ((LINUX_SI_MAX_SIZE/sizeof(l_int)) - 3) + +union l_sigval { + l_int sival_int; + l_uintptr_t sival_ptr; +}; + +typedef struct l_siginfo { + l_int lsi_signo; + l_int lsi_errno; + l_int lsi_code; + union { + l_int _pad[LINUX_SI_PAD_SIZE]; + + struct { + l_pid_t _pid; + l_uid16_t _uid; + } __packed _kill; + + struct { + l_uint _timer1; + l_uint _timer2; + } __packed _timer; + + struct { + l_pid_t _pid; /* sender's pid */ + l_uid16_t _uid; /* sender's uid */ + union l_sigval _sigval; + } __packed _rt; + + struct { + l_pid_t _pid; /* which child */ + l_uid16_t _uid; /* sender's uid */ + l_int _status; /* exit code */ + l_clock_t _utime; + l_clock_t _stime; + } __packed _sigchld; + + struct { + l_uintptr_t _addr; /* Faulting insn/memory ref. */ + } __packed _sigfault; + + struct { + l_int _band; /* POLL_IN,POLL_OUT,POLL_MSG */ + l_int _fd; + } __packed _sigpoll; + } _sifields; +} __packed l_siginfo_t; + +#define lsi_pid _sifields._kill._pid +#define lsi_uid _sifields._kill._uid +#define lsi_status _sifields._sigchld._status +#define lsi_utime _sifields._sigchld._utime +#define lsi_stime _sifields._sigchld._stime +#define lsi_value _sifields._rt._sigval +#define lsi_int _sifields._rt._sigval.sival_int +#define lsi_ptr _sifields._rt._sigval.sival_ptr +#define lsi_addr _sifields._sigfault._addr +#define lsi_band _sifields._sigpoll._band +#define lsi_fd _sifields._sigpoll._fd + +struct l_fpreg { + u_int16_t significand[4]; + u_int16_t exponent; +} __packed; + +struct l_fpxreg { + u_int16_t significand[4]; + u_int16_t exponent; + u_int16_t padding[3]; +} __packed; + +struct l_xmmreg { + u_int32_t element[4]; +} __packed; + +struct l_fpstate { + /* Regular FPU environment */ + u_int32_t cw; + u_int32_t sw; + u_int32_t tag; + u_int32_t ipoff; + u_int32_t cssel; + u_int32_t dataoff; + u_int32_t datasel; + struct l_fpreg _st[8]; + u_int16_t status; + u_int16_t magic; /* 0xffff = regular FPU data */ + + /* FXSR FPU environment */ + u_int32_t _fxsr_env[6]; /* env is ignored. */ + u_int32_t mxcsr; + u_int32_t reserved; + struct l_fpxreg _fxsr_st[8]; /* reg data is ignored. */ + struct l_xmmreg _xmm[8]; + u_int32_t padding[56]; +} __packed; + +/* + * We make the stack look like Linux expects it when calling a signal + * handler, but use the BSD way of calling the handler and sigreturn(). + * This means that we need to pass the pointer to the handler too. + * It is appended to the frame to not interfere with the rest of it. + */ +struct l_sigframe { + l_int sf_sig; + struct l_sigcontext sf_sc; + struct l_fpstate sf_fpstate; + l_uint sf_extramask[LINUX_NSIG_WORDS-1]; + l_handler_t sf_handler; +} __packed; + +struct l_rt_sigframe { + l_int sf_sig; + l_uintptr_t sf_siginfo; + l_uintptr_t sf_ucontext; + l_siginfo_t sf_si; + struct l_ucontext sf_sc; + l_handler_t sf_handler; +} __packed; + +extern int bsd_to_linux_signal[]; +extern int linux_to_bsd_signal[]; +extern struct sysentvec elf_linux_sysvec; + +/* + * Pluggable ioctl handlers + */ +struct linux_ioctl_args; +struct thread; + +typedef int linux_ioctl_function_t(struct thread *, struct linux_ioctl_args *); + +struct linux_ioctl_handler { + linux_ioctl_function_t *func; + int low, high; +}; + +int linux_ioctl_register_handler(struct linux_ioctl_handler *h); +int linux_ioctl_unregister_handler(struct linux_ioctl_handler *h); + +/* + * open/fcntl flags + */ +#define LINUX_O_RDONLY 00000000 +#define LINUX_O_WRONLY 00000001 +#define LINUX_O_RDWR 00000002 +#define LINUX_O_ACCMODE 00000003 +#define LINUX_O_CREAT 00000100 +#define LINUX_O_EXCL 00000200 +#define LINUX_O_NOCTTY 00000400 +#define LINUX_O_TRUNC 00001000 +#define LINUX_O_APPEND 00002000 +#define LINUX_O_NONBLOCK 00004000 +#define LINUX_O_NDELAY LINUX_O_NONBLOCK +#define LINUX_O_SYNC 00010000 +#define LINUX_FASYNC 00020000 +#define LINUX_O_DIRECT 00040000 /* Direct disk access hint */ +#define LINUX_O_LARGEFILE 00100000 +#define LINUX_O_DIRECTORY 00200000 /* Must be a directory */ +#define LINUX_O_NOFOLLOW 00400000 /* Do not follow links */ +#define LINUX_O_NOATIME 01000000 + +#define LINUX_F_DUPFD 0 +#define LINUX_F_GETFD 1 +#define LINUX_F_SETFD 2 +#define LINUX_F_GETFL 3 +#define LINUX_F_SETFL 4 +#define LINUX_F_GETLK 5 +#define LINUX_F_SETLK 6 +#define LINUX_F_SETLKW 7 +#define LINUX_F_SETOWN 8 +#define LINUX_F_GETOWN 9 + +#define LINUX_F_GETLK64 12 +#define LINUX_F_SETLK64 13 +#define LINUX_F_SETLKW64 14 + +#define LINUX_F_RDLCK 0 +#define LINUX_F_WRLCK 1 +#define LINUX_F_UNLCK 2 + +#define LINUX_AT_FDCWD -100 + +/* + * mount flags + */ +#define LINUX_MS_RDONLY 0x0001 +#define LINUX_MS_NOSUID 0x0002 +#define LINUX_MS_NODEV 0x0004 +#define LINUX_MS_NOEXEC 0x0008 +#define LINUX_MS_REMOUNT 0x0020 + +/* + * SystemV IPC defines + */ +#define LINUX_SEMOP 1 +#define LINUX_SEMGET 2 +#define LINUX_SEMCTL 3 +#define LINUX_MSGSND 11 +#define LINUX_MSGRCV 12 +#define LINUX_MSGGET 13 +#define LINUX_MSGCTL 14 +#define LINUX_SHMAT 21 +#define LINUX_SHMDT 22 +#define LINUX_SHMGET 23 +#define LINUX_SHMCTL 24 + +#define LINUX_IPC_RMID 0 +#define LINUX_IPC_SET 1 +#define LINUX_IPC_STAT 2 +#define LINUX_IPC_INFO 3 + +#define LINUX_SHM_LOCK 11 +#define LINUX_SHM_UNLOCK 12 +#define LINUX_SHM_STAT 13 +#define LINUX_SHM_INFO 14 + +#define LINUX_SHM_RDONLY 0x1000 +#define LINUX_SHM_RND 0x2000 +#define LINUX_SHM_REMAP 0x4000 + +/* semctl commands */ +#define LINUX_GETPID 11 +#define LINUX_GETVAL 12 +#define LINUX_GETALL 13 +#define LINUX_GETNCNT 14 +#define LINUX_GETZCNT 15 +#define LINUX_SETVAL 16 +#define LINUX_SETALL 17 +#define LINUX_SEM_STAT 18 +#define LINUX_SEM_INFO 19 + +union l_semun { + l_int val; + l_uintptr_t buf; + l_uintptr_t array; + l_uintptr_t __buf; + l_uintptr_t __pad; +} __packed; + +/* + * Socket defines + */ +#define LINUX_SOCKET 1 +#define LINUX_BIND 2 +#define LINUX_CONNECT 3 +#define LINUX_LISTEN 4 +#define LINUX_ACCEPT 5 +#define LINUX_GETSOCKNAME 6 +#define LINUX_GETPEERNAME 7 +#define LINUX_SOCKETPAIR 8 +#define LINUX_SEND 9 +#define LINUX_RECV 10 +#define LINUX_SENDTO 11 +#define LINUX_RECVFROM 12 +#define LINUX_SHUTDOWN 13 +#define LINUX_SETSOCKOPT 14 +#define LINUX_GETSOCKOPT 15 +#define LINUX_SENDMSG 16 +#define LINUX_RECVMSG 17 + +#define LINUX_AF_UNSPEC 0 +#define LINUX_AF_UNIX 1 +#define LINUX_AF_INET 2 +#define LINUX_AF_AX25 3 +#define LINUX_AF_IPX 4 +#define LINUX_AF_APPLETALK 5 +#define LINUX_AF_INET6 10 + +#define LINUX_SOL_SOCKET 1 +#define LINUX_SOL_IP 0 +#define LINUX_SOL_IPX 256 +#define LINUX_SOL_AX25 257 +#define LINUX_SOL_TCP 6 +#define LINUX_SOL_UDP 17 + +#define LINUX_SO_DEBUG 1 +#define LINUX_SO_REUSEADDR 2 +#define LINUX_SO_TYPE 3 +#define LINUX_SO_ERROR 4 +#define LINUX_SO_DONTROUTE 5 +#define LINUX_SO_BROADCAST 6 +#define LINUX_SO_SNDBUF 7 +#define LINUX_SO_RCVBUF 8 +#define LINUX_SO_KEEPALIVE 9 +#define LINUX_SO_OOBINLINE 10 +#define LINUX_SO_NO_CHECK 11 +#define LINUX_SO_PRIORITY 12 +#define LINUX_SO_LINGER 13 +#define LINUX_SO_PEERCRED 17 +#define LINUX_SO_RCVLOWAT 18 +#define LINUX_SO_SNDLOWAT 19 +#define LINUX_SO_RCVTIMEO 20 +#define LINUX_SO_SNDTIMEO 21 +#define LINUX_SO_TIMESTAMP 29 +#define LINUX_SO_ACCEPTCONN 30 + +#define LINUX_IP_TOS 1 +#define LINUX_IP_TTL 2 +#define LINUX_IP_HDRINCL 3 +#define LINUX_IP_OPTIONS 4 + +#define LINUX_IP_MULTICAST_IF 32 +#define LINUX_IP_MULTICAST_TTL 33 +#define LINUX_IP_MULTICAST_LOOP 34 +#define LINUX_IP_ADD_MEMBERSHIP 35 +#define LINUX_IP_DROP_MEMBERSHIP 36 + +struct l_sockaddr { + l_ushort sa_family; + char sa_data[14]; +} __packed; + +struct l_ifmap { + l_ulong mem_start; + l_ulong mem_end; + l_ushort base_addr; + u_char irq; + u_char dma; + u_char port; +} __packed; + +#define LINUX_IFHWADDRLEN 6 +#define LINUX_IFNAMSIZ 16 + +struct l_ifreq { + union { + char ifrn_name[LINUX_IFNAMSIZ]; + } ifr_ifrn; + + union { + struct l_sockaddr ifru_addr; + struct l_sockaddr ifru_dstaddr; + struct l_sockaddr ifru_broadaddr; + struct l_sockaddr ifru_netmask; + struct l_sockaddr ifru_hwaddr; + l_short ifru_flags[1]; + l_int ifru_metric; + l_int ifru_mtu; + struct l_ifmap ifru_map; + char ifru_slave[LINUX_IFNAMSIZ]; + l_uintptr_t ifru_data; + } ifr_ifru; +} __packed; + +#define ifr_name ifr_ifrn.ifrn_name /* Interface name */ +#define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */ + +struct l_ifconf { + int ifc_len; + union { + l_uintptr_t ifcu_buf; + l_uintptr_t ifcu_req; + } ifc_ifcu; +} __packed; + +#define ifc_buf ifc_ifcu.ifcu_buf +#define ifc_req ifc_ifcu.ifcu_req + +/* + * poll() + */ +#define LINUX_POLLIN 0x0001 +#define LINUX_POLLPRI 0x0002 +#define LINUX_POLLOUT 0x0004 +#define LINUX_POLLERR 0x0008 +#define LINUX_POLLHUP 0x0010 +#define LINUX_POLLNVAL 0x0020 +#define LINUX_POLLRDNORM 0x0040 +#define LINUX_POLLRDBAND 0x0080 +#define LINUX_POLLWRNORM 0x0100 +#define LINUX_POLLWRBAND 0x0200 +#define LINUX_POLLMSG 0x0400 + +struct l_pollfd { + l_int fd; + l_short events; + l_short revents; +} __packed; + +struct l_user_desc { + l_uint entry_number; + l_uint base_addr; + l_uint limit; + l_uint seg_32bit:1; + l_uint contents:2; + l_uint read_exec_only:1; + l_uint limit_in_pages:1; + l_uint seg_not_present:1; + l_uint useable:1; +}; + +#define LINUX_LOWERWORD 0x0000ffff + +/* + * Macros which does the same thing as those in Linux include/asm-um/ldt-i386.h. + * These convert Linux user space descriptor to machine one. + */ +#define LINUX_LDT_entry_a(info) \ + ((((info)->base_addr & LINUX_LOWERWORD) << 16) | \ + ((info)->limit & LINUX_LOWERWORD)) + +#define LINUX_ENTRY_B_READ_EXEC_ONLY 9 +#define LINUX_ENTRY_B_CONTENTS 10 +#define LINUX_ENTRY_B_SEG_NOT_PRESENT 15 +#define LINUX_ENTRY_B_BASE_ADDR 16 +#define LINUX_ENTRY_B_USEABLE 20 +#define LINUX_ENTRY_B_SEG32BIT 22 +#define LINUX_ENTRY_B_LIMIT 23 + +#define LINUX_LDT_entry_b(info) \ + (((info)->base_addr & 0xff000000) | \ + ((info)->limit & 0xf0000) | \ + ((info)->contents << LINUX_ENTRY_B_CONTENTS) | \ + (((info)->seg_not_present == 0) << LINUX_ENTRY_B_SEG_NOT_PRESENT) | \ + (((info)->base_addr & 0x00ff0000) >> LINUX_ENTRY_B_BASE_ADDR) | \ + (((info)->read_exec_only == 0) << LINUX_ENTRY_B_READ_EXEC_ONLY) | \ + ((info)->seg_32bit << LINUX_ENTRY_B_SEG32BIT) | \ + ((info)->useable << LINUX_ENTRY_B_USEABLE) | \ + ((info)->limit_in_pages << LINUX_ENTRY_B_LIMIT) | 0x7000) + +#define LINUX_LDT_empty(info) \ + ((info)->base_addr == 0 && \ + (info)->limit == 0 && \ + (info)->contents == 0 && \ + (info)->seg_not_present == 1 && \ + (info)->read_exec_only == 1 && \ + (info)->seg_32bit == 0 && \ + (info)->limit_in_pages == 0 && \ + (info)->useable == 0) + +/* + * Macros for converting segments. + * They do the same as those in arch/i386/kernel/process.c in Linux. + */ +#define LINUX_GET_BASE(desc) \ + ((((desc)->a >> 16) & LINUX_LOWERWORD) | \ + (((desc)->b << 16) & 0x00ff0000) | \ + ((desc)->b & 0xff000000)) + +#define LINUX_GET_LIMIT(desc) \ + (((desc)->a & LINUX_LOWERWORD) | \ + ((desc)->b & 0xf0000)) + +#define LINUX_GET_32BIT(desc) \ + (((desc)->b >> LINUX_ENTRY_B_SEG32BIT) & 1) +#define LINUX_GET_CONTENTS(desc) \ + (((desc)->b >> LINUX_ENTRY_B_CONTENTS) & 3) +#define LINUX_GET_WRITABLE(desc) \ + (((desc)->b >> LINUX_ENTRY_B_READ_EXEC_ONLY) & 1) +#define LINUX_GET_LIMIT_PAGES(desc) \ + (((desc)->b >> LINUX_ENTRY_B_LIMIT) & 1) +#define LINUX_GET_PRESENT(desc) \ + (((desc)->b >> LINUX_ENTRY_B_SEG_NOT_PRESENT) & 1) +#define LINUX_GET_USEABLE(desc) \ + (((desc)->b >> LINUX_ENTRY_B_USEABLE) & 1) + +#define LINUX_CLOCK_REALTIME 0 +#define LINUX_CLOCK_MONOTONIC 1 +#define LINUX_CLOCK_PROCESS_CPUTIME_ID 2 +#define LINUX_CLOCK_THREAD_CPUTIME_ID 3 +#define LINUX_CLOCK_REALTIME_HR 4 +#define LINUX_CLOCK_MONOTONIC_HR 5 + +typedef int l_timer_t; +typedef int l_mqd_t; + +#define LINUX_CLONE_VM 0x00000100 +#define LINUX_CLONE_FS 0x00000200 +#define LINUX_CLONE_FILES 0x00000400 +#define LINUX_CLONE_SIGHAND 0x00000800 +#define LINUX_CLONE_PID 0x00001000 /* No longer exist in Linux */ +#define LINUX_CLONE_VFORK 0x00004000 +#define LINUX_CLONE_PARENT 0x00008000 +#define LINUX_CLONE_THREAD 0x00010000 +#define LINUX_CLONE_SETTLS 0x00080000 +#define LINUX_CLONE_PARENT_SETTID 0x00100000 +#define LINUX_CLONE_CHILD_CLEARTID 0x00200000 +#define LINUX_CLONE_CHILD_SETTID 0x01000000 + +#define LINUX_THREADING_FLAGS \ + (LINUX_CLONE_VM | LINUX_CLONE_FS | LINUX_CLONE_FILES | \ + LINUX_CLONE_SIGHAND | LINUX_CLONE_THREAD) + +#endif /* !_AMD64_LINUX_H_ */ diff --git a/sys/emulation/linux/amd64/linux32_dummy.c b/sys/emulation/linux/amd64/linux32_dummy.c new file mode 100644 index 0000000000..06df96d3a5 --- /dev/null +++ b/sys/emulation/linux/amd64/linux32_dummy.c @@ -0,0 +1,135 @@ +/*- + * Copyright (c) 1994-1995 Søren Schmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: src/sys/amd64/linux32/linux32_dummy.c,v 1.9 2007/04/18 18:08:12 jkim Exp $ + * $DragonFly$ + */ + + +#include +#include +#include + +#include +#include +#include + +DUMMY(stime); +DUMMY(olduname); +DUMMY(syslog); +DUMMY(uname); +DUMMY(vhangup); +DUMMY(swapoff); +DUMMY(adjtimex); +DUMMY(create_module); +DUMMY(init_module); +DUMMY(delete_module); +DUMMY(get_kernel_syms); +DUMMY(quotactl); +DUMMY(bdflush); +DUMMY(sysfs); +DUMMY(query_module); +DUMMY(nfsservctl); +DUMMY(rt_sigqueueinfo); +DUMMY(capget); +DUMMY(capset); +DUMMY(sendfile); +DUMMY(truncate64); +DUMMY(setfsuid); +DUMMY(setfsgid); +DUMMY(pivot_root); +DUMMY(mincore); +DUMMY(fadvise64); +DUMMY(ptrace); +DUMMY(lookup_dcookie); +DUMMY(epoll_create); +DUMMY(epoll_ctl); +DUMMY(epoll_wait); +DUMMY(remap_file_pages); +DUMMY(timer_create); +DUMMY(timer_settime); +DUMMY(timer_gettime); +DUMMY(timer_getoverrun); +DUMMY(timer_delete); +DUMMY(fstatfs64); +DUMMY(fadvise64_64); +DUMMY(mbind); +DUMMY(get_mempolicy); +DUMMY(set_mempolicy); +DUMMY(mq_open); +DUMMY(mq_unlink); +DUMMY(mq_timedsend); +DUMMY(mq_timedreceive); +DUMMY(mq_notify); +DUMMY(mq_getsetattr); +DUMMY(kexec_load); +DUMMY(waitid); +DUMMY(add_key); +DUMMY(request_key); +DUMMY(keyctl); +DUMMY(ioprio_set); +DUMMY(ioprio_get); +DUMMY(inotify_init); +DUMMY(inotify_add_watch); +DUMMY(inotify_rm_watch); +DUMMY(migrate_pages); +DUMMY(mkdirat); +DUMMY(mknodat); +DUMMY(fchownat); +DUMMY(futimesat); +DUMMY(fstatat64); +DUMMY(unlinkat); +DUMMY(renameat); +DUMMY(linkat); +DUMMY(symlinkat); +DUMMY(readlinkat); +DUMMY(fchmodat); +DUMMY(faccessat); +DUMMY(pselect6); +DUMMY(ppoll); +DUMMY(unshare); + +#define DUMMY_XATTR(s) \ +int \ +linux_ ## s ## xattr( \ + struct thread *td, struct linux_ ## s ## xattr_args *arg) \ +{ \ + \ + return (ENOATTR); \ +} +DUMMY_XATTR(set); +DUMMY_XATTR(lset); +DUMMY_XATTR(fset); +DUMMY_XATTR(get); +DUMMY_XATTR(lget); +DUMMY_XATTR(fget); +DUMMY_XATTR(list); +DUMMY_XATTR(llist); +DUMMY_XATTR(flist); +DUMMY_XATTR(remove); +DUMMY_XATTR(lremove); +DUMMY_XATTR(fremove); diff --git a/sys/emulation/linux/amd64/linux32_genassym.c b/sys/emulation/linux/amd64/linux32_genassym.c new file mode 100644 index 0000000000..5faa78c655 --- /dev/null +++ b/sys/emulation/linux/amd64/linux32_genassym.c @@ -0,0 +1,19 @@ +/* + * $FreeBSD: src/sys/amd64/linux32/linux32_genassym.c,v 1.1 2004/08/16 07:55:06 tjr Exp $ + * $DragonFly$ + */ + +#include +#include +#include + +#include + +ASSYM(LINUX_SIGF_HANDLER, offsetof(struct l_sigframe, sf_handler)); +ASSYM(LINUX_SIGF_SC, offsetof(struct l_sigframe, sf_sc)); +ASSYM(LINUX_SC_GS, offsetof(struct l_sigcontext, sc_gs)); +ASSYM(LINUX_SC_FS, offsetof(struct l_sigcontext, sc_fs)); +ASSYM(LINUX_SC_ES, offsetof(struct l_sigcontext, sc_es)); +ASSYM(LINUX_SC_DS, offsetof(struct l_sigcontext, sc_ds)); +ASSYM(LINUX_RT_SIGF_HANDLER, offsetof(struct l_rt_sigframe, sf_handler)); +ASSYM(LINUX_RT_SIGF_UC, offsetof(struct l_rt_sigframe, sf_sc)); diff --git a/sys/emulation/linux/amd64/linux32_ipc64.h b/sys/emulation/linux/amd64/linux32_ipc64.h new file mode 100644 index 0000000000..2b4f6d39dc --- /dev/null +++ b/sys/emulation/linux/amd64/linux32_ipc64.h @@ -0,0 +1,146 @@ +/*- + * Copyright (c) 2002 Maxim Sobolev + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: src/sys/amd64/linux32/linux32_ipc64.h,v 1.1 2004/08/16 07:55:06 tjr Exp $ + * $DragonFly$ + */ + +#ifndef _AMD64_LINUX_LINUX_IPC64_H_ +#define _AMD64_LINUX_LINUX_IPC64_H_ + +/* + * The ipc64_perm structure for i386 architecture. + * Note extra padding because this structure is passed back and forth + * between kernel and user space. + * + * Pad space is left for: + * - 32-bit mode_t and seq + * - 2 miscellaneous 32-bit values + */ + +struct l_ipc64_perm +{ + l_key_t key; + l_uid_t uid; + l_gid_t gid; + l_uid_t cuid; + l_gid_t cgid; + l_mode_t mode; + l_ushort __pad1; + l_ushort seq; + l_ushort __pad2; + l_ulong __unused1; + l_ulong __unused2; +} __packed; + +/* + * The msqid64_ds structure for i386 architecture. + * Note extra padding because this structure is passed back and forth + * between kernel and user space. + * + * Pad space is left for: + * - 64-bit time_t to solve y2038 problem + * - 2 miscellaneous 32-bit values + */ + +struct l_msqid64_ds { + struct l_ipc64_perm msg_perm; + l_time_t msg_stime; /* last msgsnd time */ + l_ulong __unused1; + l_time_t msg_rtime; /* last msgrcv time */ + l_ulong __unused2; + l_time_t msg_ctime; /* last change time */ + l_ulong __unused3; + l_ulong msg_cbytes; /* current number of bytes on queue */ + l_ulong msg_qnum; /* number of messages in queue */ + l_ulong msg_qbytes; /* max number of bytes on queue */ + l_pid_t msg_lspid; /* pid of last msgsnd */ + l_pid_t msg_lrpid; /* last receive pid */ + l_ulong __unused4; + l_ulong __unused5; +} __packed; + +/* + * The semid64_ds structure for i386 architecture. + * Note extra padding because this structure is passed back and forth + * between kernel and user space. + * + * Pad space is left for: + * - 64-bit time_t to solve y2038 problem + * - 2 miscellaneous 32-bit values + */ + +struct l_semid64_ds { + struct l_ipc64_perm sem_perm; /* permissions */ + l_time_t sem_otime; /* last semop time */ + l_ulong __unused1; + l_time_t sem_ctime; /* last change time */ + l_ulong __unused2; + l_ulong sem_nsems; /* no. of semaphores in array */ + l_ulong __unused3; + l_ulong __unused4; +} __packed; + +/* + * The shmid64_ds structure for i386 architecture. + * Note extra padding because this structure is passed back and forth + * between kernel and user space. + * + * Pad space is left for: + * - 64-bit time_t to solve y2038 problem + * - 2 miscellaneous 32-bit values + */ + +struct l_shmid64_ds { + struct l_ipc64_perm shm_perm; /* operation perms */ + l_size_t shm_segsz; /* size of segment (bytes) */ + l_time_t shm_atime; /* last attach time */ + l_ulong __unused1; + l_time_t shm_dtime; /* last detach time */ + l_ulong __unused2; + l_time_t shm_ctime; /* last change time */ + l_ulong __unused3; + l_pid_t shm_cpid; /* pid of creator */ + l_pid_t shm_lpid; /* pid of last operator */ + l_ulong shm_nattch; /* no. of current attaches */ + l_ulong __unused4; + l_ulong __unused5; +} __packed; + +struct l_shminfo64 { + l_ulong shmmax; + l_ulong shmmin; + l_ulong shmmni; + l_ulong shmseg; + l_ulong shmall; + l_ulong __unused1; + l_ulong __unused2; + l_ulong __unused3; + l_ulong __unused4; +} __packed; + +#endif /* !_AMD64_LINUX_LINUX_IPC64_H_ */ diff --git a/sys/emulation/linux/amd64/linux32_locore.s b/sys/emulation/linux/amd64/linux32_locore.s new file mode 100644 index 0000000000..8426f670af --- /dev/null +++ b/sys/emulation/linux/amd64/linux32_locore.s @@ -0,0 +1,44 @@ +/* + * $FreeBSD: src/sys/amd64/linux32/linux32_locore.s,v 1.2 2007/03/30 00:06:21 jkim Exp $ + * $DragonFly$ + */ + +#include "linux32_assym.h" /* system definitions */ +#include /* miscellaneous asm macros */ + +#include /* system call numbers */ + +.text +.code32 + +NON_GPROF_ENTRY(linux_sigcode) + call *LINUX_SIGF_HANDLER(%esp) + leal LINUX_SIGF_SC(%esp),%ebx /* linux scp */ + movl LINUX_SC_ES(%ebx),%es + movl LINUX_SC_DS(%ebx),%ds + movl %esp, %ebx /* pass sigframe */ + push %eax /* fake ret addr */ + movl $LINUX_SYS_linux_sigreturn,%eax /* linux_sigreturn() */ + int $0x80 /* enter kernel with args */ +0: jmp 0b + ALIGN_TEXT +/* XXXXX */ +linux_rt_sigcode: + call *LINUX_RT_SIGF_HANDLER(%esp) + leal LINUX_RT_SIGF_UC(%esp),%ebx /* linux ucp */ + movl LINUX_SC_ES(%ebx),%es + movl LINUX_SC_DS(%ebx),%ds + push %eax /* fake ret addr */ + movl $LINUX_SYS_linux_rt_sigreturn,%eax /* linux_rt_sigreturn() */ + int $0x80 /* enter kernel with args */ +0: jmp 0b + ALIGN_TEXT +/* XXXXX */ +linux_esigcode: + + .data + .globl linux_szsigcode, linux_sznonrtsigcode +linux_szsigcode: + .long linux_esigcode-linux_sigcode +linux_sznonrtsigcode: + .long linux_rt_sigcode-linux_sigcode diff --git a/sys/emulation/linux/amd64/linux32_machdep.c b/sys/emulation/linux/amd64/linux32_machdep.c new file mode 100644 index 0000000000..3d8ae7a617 --- /dev/null +++ b/sys/emulation/linux/amd64/linux32_machdep.c @@ -0,0 +1,1362 @@ +/*- + * Copyright (c) 2004 Tim J. Robbins + * Copyright (c) 2002 Doug Rabson + * Copyright (c) 2000 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: src/sys/amd64/linux32/linux32_machdep.c,v 1.45 2007/07/04 23:06:43 peter Exp $ + * $DragonFly$ + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +struct l_old_select_argv { + l_int nfds; + l_uintptr_t readfds; + l_uintptr_t writefds; + l_uintptr_t exceptfds; + l_uintptr_t timeout; +} __packed; + +int +linux_to_bsd_sigaltstack(int lsa) +{ + int bsa = 0; + + if (lsa & LINUX_SS_DISABLE) + bsa |= SS_DISABLE; + if (lsa & LINUX_SS_ONSTACK) + bsa |= SS_ONSTACK; + return (bsa); +} + +int +bsd_to_linux_sigaltstack(int bsa) +{ + int lsa = 0; + + if (bsa & SS_DISABLE) + lsa |= LINUX_SS_DISABLE; + if (bsa & SS_ONSTACK) + lsa |= LINUX_SS_ONSTACK; + return (lsa); +} + +/* + * Custom version of exec_copyin_args() so that we can translate + * the pointers. + */ +static int +linux_exec_copyin_args(struct image_args *args, char *fname, + enum uio_seg segflg, char **argv, char **envv) +{ + char *argp, *envp; + u_int32_t *p32, arg; + size_t length; + int error; + + bzero(args, sizeof(*args)); + if (argv == NULL) + return (EFAULT); + + /* + * Allocate temporary demand zeroed space for argument and + * environment strings + */ + args->buf = (char *)kmem_alloc_wait(exec_map, + PATH_MAX + ARG_MAX + MAXSHELLCMDLEN); + if (args->buf == NULL) + return (ENOMEM); + args->begin_argv = args->buf; + args->endp = args->begin_argv; + args->stringspace = ARG_MAX; + + args->fname = args->buf + ARG_MAX; + + /* + * Copy the file name. + */ + error = (segflg == UIO_SYSSPACE) ? + copystr(fname, args->fname, PATH_MAX, &length) : + copyinstr(fname, args->fname, PATH_MAX, &length); + if (error != 0) + goto err_exit; + + /* + * extract arguments first + */ + p32 = (u_int32_t *)argv; + for (;;) { + error = copyin(p32++, &arg, sizeof(arg)); + if (error) + goto err_exit; + if (arg == 0) + break; + argp = PTRIN(arg); + error = copyinstr(argp, args->endp, args->stringspace, &length); + if (error) { + if (error == ENAMETOOLONG) + error = E2BIG; + + goto err_exit; + } + args->stringspace -= length; + args->endp += length; + args->argc++; + } + + args->begin_envv = args->endp; + + /* + * extract environment strings + */ + if (envv) { + p32 = (u_int32_t *)envv; + for (;;) { + error = copyin(p32++, &arg, sizeof(arg)); + if (error) + goto err_exit; + if (arg == 0) + break; + envp = PTRIN(arg); + error = copyinstr(envp, args->endp, args->stringspace, + &length); + if (error) { + if (error == ENAMETOOLONG) + error = E2BIG; + goto err_exit; + } + args->stringspace -= length; + args->endp += length; + args->envc++; + } + } + + return (0); + +err_exit: + kmem_free_wakeup(exec_map, (vm_offset_t)args->buf, + PATH_MAX + ARG_MAX + MAXSHELLCMDLEN); + args->buf = NULL; + return (error); +} + +int +linux_execve(struct thread *td, struct linux_execve_args *args) +{ + struct image_args eargs; + char *path; + int error; + + LCONVPATHEXIST(td, args->path, &path); + +#ifdef DEBUG + if (ldebug(execve)) + printf(ARGS(execve, "%s"), path); +#endif + + error = linux_exec_copyin_args(&eargs, path, UIO_SYSSPACE, args->argp, + args->envp); + free(path, M_TEMP); + if (error == 0) + error = kern_execve(td, &eargs, NULL); + if (error == 0) + /* Linux process can execute FreeBSD one, do not attempt + * to create emuldata for such process using + * linux_proc_init, this leads to a panic on KASSERT + * because such process has p->p_emuldata == NULL. + */ + if (td->td_proc->p_sysent == &elf_linux_sysvec) + error = linux_proc_init(td, 0, 0); + return (error); +} + +struct iovec32 { + u_int32_t iov_base; + int iov_len; +}; + +CTASSERT(sizeof(struct iovec32) == 8); + +static int +linux32_copyinuio(struct iovec32 *iovp, u_int iovcnt, struct uio **uiop) +{ + struct iovec32 iov32; + struct iovec *iov; + struct uio *uio; + u_int iovlen; + int error, i; + + *uiop = NULL; + if (iovcnt > UIO_MAXIOV) + return (EINVAL); + iovlen = iovcnt * sizeof(struct iovec); + uio = malloc(iovlen + sizeof(*uio), M_IOV, M_WAITOK); + iov = (struct iovec *)(uio + 1); + for (i = 0; i < iovcnt; i++) { + error = copyin(&iovp[i], &iov32, sizeof(struct iovec32)); + if (error) { + free(uio, M_IOV); + return (error); + } + iov[i].iov_base = PTRIN(iov32.iov_base); + iov[i].iov_len = iov32.iov_len; + } + uio->uio_iov = iov; + uio->uio_iovcnt = iovcnt; + uio->uio_segflg = UIO_USERSPACE; + uio->uio_offset = -1; + uio->uio_resid = 0; + for (i = 0; i < iovcnt; i++) { + if (iov->iov_len > INT_MAX - uio->uio_resid) { + free(uio, M_IOV); + return (EINVAL); + } + uio->uio_resid += iov->iov_len; + iov++; + } + *uiop = uio; + return (0); +} + +int +linux_readv(struct thread *td, struct linux_readv_args *uap) +{ + struct uio *auio; + int error; + + error = linux32_copyinuio(uap->iovp, uap->iovcnt, &auio); + if (error) + return (error); + error = kern_readv(td, uap->fd, auio); + free(auio, M_IOV); + return (error); +} + +int +linux_writev(struct thread *td, struct linux_writev_args *uap) +{ + struct uio *auio; + int error; + + error = linux32_copyinuio(uap->iovp, uap->iovcnt, &auio); + if (error) + return (error); + error = kern_writev(td, uap->fd, auio); + free(auio, M_IOV); + return (error); +} + +struct l_ipc_kludge { + l_uintptr_t msgp; + l_long msgtyp; +} __packed; + +int +linux_ipc(struct thread *td, struct linux_ipc_args *args) +{ + + switch (args->what & 0xFFFF) { + case LINUX_SEMOP: { + struct linux_semop_args a; + + a.semid = args->arg1; + a.tsops = args->ptr; + a.nsops = args->arg2; + return (linux_semop(td, &a)); + } + case LINUX_SEMGET: { + struct linux_semget_args a; + + a.key = args->arg1; + a.nsems = args->arg2; + a.semflg = args->arg3; + return (linux_semget(td, &a)); + } + case LINUX_SEMCTL: { + struct linux_semctl_args a; + int error; + + a.semid = args->arg1; + a.semnum = args->arg2; + a.cmd = args->arg3; + error = copyin(args->ptr, &a.arg, sizeof(a.arg)); + if (error) + return (error); + return (linux_semctl(td, &a)); + } + case LINUX_MSGSND: { + struct linux_msgsnd_args a; + + a.msqid = args->arg1; + a.msgp = args->ptr; + a.msgsz = args->arg2; + a.msgflg = args->arg3; + return (linux_msgsnd(td, &a)); + } + case LINUX_MSGRCV: { + struct linux_msgrcv_args a; + + a.msqid = args->arg1; + a.msgsz = args->arg2; + a.msgflg = args->arg3; + if ((args->what >> 16) == 0) { + struct l_ipc_kludge tmp; + int error; + + if (args->ptr == 0) + return (EINVAL); + error = copyin(args->ptr, &tmp, sizeof(tmp)); + if (error) + return (error); + a.msgp = PTRIN(tmp.msgp); + a.msgtyp = tmp.msgtyp; + } else { + a.msgp = args->ptr; + a.msgtyp = args->arg5; + } + return (linux_msgrcv(td, &a)); + } + case LINUX_MSGGET: { + struct linux_msgget_args a; + + a.key = args->arg1; + a.msgflg = args->arg2; + return (linux_msgget(td, &a)); + } + case LINUX_MSGCTL: { + struct linux_msgctl_args a; + + a.msqid = args->arg1; + a.cmd = args->arg2; + a.buf = args->ptr; + return (linux_msgctl(td, &a)); + } + case LINUX_SHMAT: { + struct linux_shmat_args a; + + a.shmid = args->arg1; + a.shmaddr = args->ptr; + a.shmflg = args->arg2; + a.raddr = PTRIN((l_uint)args->arg3); + return (linux_shmat(td, &a)); + } + case LINUX_SHMDT: { + struct linux_shmdt_args a; + + a.shmaddr = args->ptr; + return (linux_shmdt(td, &a)); + } + case LINUX_SHMGET: { + struct linux_shmget_args a; + + a.key = args->arg1; + a.size = args->arg2; + a.shmflg = args->arg3; + return (linux_shmget(td, &a)); + } + case LINUX_SHMCTL: { + struct linux_shmctl_args a; + + a.shmid = args->arg1; + a.cmd = args->arg2; + a.buf = args->ptr; + return (linux_shmctl(td, &a)); + } + default: + break; + } + + return (EINVAL); +} + +int +linux_old_select(struct thread *td, struct linux_old_select_args *args) +{ + struct l_old_select_argv linux_args; + struct linux_select_args newsel; + int error; + +#ifdef DEBUG + if (ldebug(old_select)) + printf(ARGS(old_select, "%p"), args->ptr); +#endif + + error = copyin(args->ptr, &linux_args, sizeof(linux_args)); + if (error) + return (error); + + newsel.nfds = linux_args.nfds; + newsel.readfds = PTRIN(linux_args.readfds); + newsel.writefds = PTRIN(linux_args.writefds); + newsel.exceptfds = PTRIN(linux_args.exceptfds); + newsel.timeout = PTRIN(linux_args.timeout); + return (linux_select(td, &newsel)); +} + +int +linux_fork(struct thread *td, struct linux_fork_args *args) +{ + int error; + struct proc *p2; + struct thread *td2; + +#ifdef DEBUG + if (ldebug(fork)) + printf(ARGS(fork, "")); +#endif + + if ((error = fork1(td, RFFDG | RFPROC | RFSTOPPED, 0, &p2)) != 0) + return (error); + + if (error == 0) { + td->td_retval[0] = p2->p_pid; + td->td_retval[1] = 0; + } + + if (td->td_retval[1] == 1) + td->td_retval[0] = 0; + error = linux_proc_init(td, td->td_retval[0], 0); + if (error) + return (error); + + td2 = FIRST_THREAD_IN_PROC(p2); + + /* + * Make this runnable after we are finished with it. + */ + thread_lock(td2); + TD_SET_CAN_RUN(td2); + sched_add(td2, SRQ_BORING); + thread_unlock(td2); + + return (0); +} + +int +linux_vfork(struct thread *td, struct linux_vfork_args *args) +{ + int error; + struct proc *p2; + struct thread *td2; + +#ifdef DEBUG + if (ldebug(vfork)) + printf(ARGS(vfork, "")); +#endif + + /* Exclude RFPPWAIT */ + if ((error = fork1(td, RFFDG | RFPROC | RFMEM | RFSTOPPED, 0, &p2)) != 0) + return (error); + if (error == 0) { + td->td_retval[0] = p2->p_pid; + td->td_retval[1] = 0; + } + /* Are we the child? */ + if (td->td_retval[1] == 1) + td->td_retval[0] = 0; + error = linux_proc_init(td, td->td_retval[0], 0); + if (error) + return (error); + + PROC_LOCK(p2); + p2->p_flag |= P_PPWAIT; + PROC_UNLOCK(p2); + + td2 = FIRST_THREAD_IN_PROC(p2); + + /* + * Make this runnable after we are finished with it. + */ + thread_lock(td2); + TD_SET_CAN_RUN(td2); + sched_add(td2, SRQ_BORING); + thread_unlock(td2); + + /* wait for the children to exit, ie. emulate vfork */ + PROC_LOCK(p2); + while (p2->p_flag & P_PPWAIT) + msleep(td->td_proc, &p2->p_mtx, PWAIT, "ppwait", 0); + PROC_UNLOCK(p2); + + return (0); +} + +int +linux_clone(struct thread *td, struct linux_clone_args *args) +{ + int error, ff = RFPROC | RFSTOPPED; + struct proc *p2; + struct thread *td2; + int exit_signal; + struct linux_emuldata *em; + +#ifdef DEBUG + if (ldebug(clone)) { + printf(ARGS(clone, "flags %x, stack %p, parent tid: %p, " + "child tid: %p"), (unsigned)args->flags, + args->stack, args->parent_tidptr, args->child_tidptr); + } +#endif + + exit_signal = args->flags & 0x000000ff; + if (LINUX_SIG_VALID(exit_signal)) { + if (exit_signal <= LINUX_SIGTBLSZ) + exit_signal = + linux_to_bsd_signal[_SIG_IDX(exit_signal)]; + } else if (exit_signal != 0) + return (EINVAL); + + if (args->flags & LINUX_CLONE_VM) + ff |= RFMEM; + if (args->flags & LINUX_CLONE_SIGHAND) + ff |= RFSIGSHARE; + /* + * XXX: In Linux, sharing of fs info (chroot/cwd/umask) + * and open files is independant. In FreeBSD, its in one + * structure but in reality it does not cause any problems + * because both of these flags are usually set together. + */ + if (!(args->flags & (LINUX_CLONE_FILES | LINUX_CLONE_FS))) + ff |= RFFDG; + + /* + * Attempt to detect when linux_clone(2) is used for creating + * kernel threads. Unfortunately despite the existence of the + * CLONE_THREAD flag, version of linuxthreads package used in + * most popular distros as of beginning of 2005 doesn't make + * any use of it. Therefore, this detection relies on + * empirical observation that linuxthreads sets certain + * combination of flags, so that we can make more or less + * precise detection and notify the FreeBSD kernel that several + * processes are in fact part of the same threading group, so + * that special treatment is necessary for signal delivery + * between those processes and fd locking. + */ + if ((args->flags & 0xffffff00) == LINUX_THREADING_FLAGS) + ff |= RFTHREAD; + + if (args->flags & LINUX_CLONE_PARENT_SETTID) + if (args->parent_tidptr == NULL) + return (EINVAL); + + error = fork1(td, ff, 0, &p2); + if (error) + return (error); + + if (args->flags & (LINUX_CLONE_PARENT | LINUX_CLONE_THREAD)) { + sx_xlock(&proctree_lock); + PROC_LOCK(p2); + proc_reparent(p2, td->td_proc->p_pptr); + PROC_UNLOCK(p2); + sx_xunlock(&proctree_lock); + } + + /* create the emuldata */ + error = linux_proc_init(td, p2->p_pid, args->flags); + /* reference it - no need to check this */ + em = em_find(p2, EMUL_DOLOCK); + KASSERT(em != NULL, ("clone: emuldata not found.\n")); + /* and adjust it */ + + if (args->flags & LINUX_CLONE_THREAD) { +#ifdef notyet + PROC_LOCK(p2); + p2->p_pgrp = td->td_proc->p_pgrp; + PROC_UNLOCK(p2); +#endif + exit_signal = 0; + } + + if (args->flags & LINUX_CLONE_CHILD_SETTID) + em->child_set_tid = args->child_tidptr; + else + em->child_set_tid = NULL; + + if (args->flags & LINUX_CLONE_CHILD_CLEARTID) + em->child_clear_tid = args->child_tidptr; + else + em->child_clear_tid = NULL; + + EMUL_UNLOCK(&emul_lock); + + if (args->flags & LINUX_CLONE_PARENT_SETTID) { + error = copyout(&p2->p_pid, args->parent_tidptr, + sizeof(p2->p_pid)); + if (error) + printf(LMSG("copyout failed!")); + } + + PROC_LOCK(p2); + p2->p_sigparent = exit_signal; + PROC_UNLOCK(p2); + td2 = FIRST_THREAD_IN_PROC(p2); + /* + * In a case of stack = NULL, we are supposed to COW calling process + * stack. This is what normal fork() does, so we just keep tf_rsp arg + * intact. + */ + if (args->stack) + td2->td_frame->tf_rsp = PTROUT(args->stack); + + if (args->flags & LINUX_CLONE_SETTLS) { + struct user_segment_descriptor sd; + struct l_user_desc info; + int a[2]; + + error = copyin((void *)td->td_frame->tf_rsi, &info, + sizeof(struct l_user_desc)); + if (error) { + printf(LMSG("copyin failed!")); + } else { + /* We might copy out the entry_number as GUGS32_SEL. */ + info.entry_number = GUGS32_SEL; + error = copyout(&info, (void *)td->td_frame->tf_rsi, + sizeof(struct l_user_desc)); + if (error) + printf(LMSG("copyout failed!")); + + a[0] = LINUX_LDT_entry_a(&info); + a[1] = LINUX_LDT_entry_b(&info); + + memcpy(&sd, &a, sizeof(a)); +#ifdef DEBUG + if (ldebug(clone)) + printf("Segment created in clone with " + "CLONE_SETTLS: lobase: %x, hibase: %x, " + "lolimit: %x, hilimit: %x, type: %i, " + "dpl: %i, p: %i, xx: %i, long: %i, " + "def32: %i, gran: %i\n", sd.sd_lobase, + sd.sd_hibase, sd.sd_lolimit, sd.sd_hilimit, + sd.sd_type, sd.sd_dpl, sd.sd_p, sd.sd_xx, + sd.sd_long, sd.sd_def32, sd.sd_gran); +#endif + td2->td_pcb->pcb_gsbase = (register_t)info.base_addr; + td2->td_pcb->pcb_gs32sd = sd; + td2->td_pcb->pcb_gs32p = &gdt[GUGS32_SEL]; + td2->td_pcb->pcb_gs = GSEL(GUGS32_SEL, SEL_UPL); + td2->td_pcb->pcb_flags |= PCB_32BIT; + } + } + +#ifdef DEBUG + if (ldebug(clone)) + printf(LMSG("clone: successful rfork to %d, " + "stack %p sig = %d"), (int)p2->p_pid, args->stack, + exit_signal); +#endif + if (args->flags & LINUX_CLONE_VFORK) { + PROC_LOCK(p2); + p2->p_flag |= P_PPWAIT; + PROC_UNLOCK(p2); + } + + /* + * Make this runnable after we are finished with it. + */ + thread_lock(td2); + TD_SET_CAN_RUN(td2); + sched_add(td2, SRQ_BORING); + thread_unlock(td2); + + td->td_retval[0] = p2->p_pid; + td->td_retval[1] = 0; + + if (args->flags & LINUX_CLONE_VFORK) { + /* wait for the children to exit, ie. emulate vfork */ + PROC_LOCK(p2); + while (p2->p_flag & P_PPWAIT) + msleep(td->td_proc, &p2->p_mtx, PWAIT, "ppwait", 0); + PROC_UNLOCK(p2); + } + + return (0); +} + +#define STACK_SIZE (2 * 1024 * 1024) +#define GUARD_SIZE (4 * PAGE_SIZE) + +static int linux_mmap_common(struct thread *, struct l_mmap_argv *); + +int +linux_mmap2(struct thread *td, struct linux_mmap2_args *args) +{ + struct l_mmap_argv linux_args; + +#ifdef DEBUG + if (ldebug(mmap2)) + printf(ARGS(mmap2, "0x%08x, %d, %d, 0x%08x, %d, %d"), + args->addr, args->len, args->prot, + args->flags, args->fd, args->pgoff); +#endif + + linux_args.addr = PTROUT(args->addr); + linux_args.len = args->len; + linux_args.prot = args->prot; + linux_args.flags = args->flags; + linux_args.fd = args->fd; + linux_args.pgoff = args->pgoff; + + return (linux_mmap_common(td, &linux_args)); +} + +int +linux_mmap(struct thread *td, struct linux_mmap_args *args) +{ + int error; + struct l_mmap_argv linux_args; + + error = copyin(args->ptr, &linux_args, sizeof(linux_args)); + if (error) + return (error); + +#ifdef DEBUG + if (ldebug(mmap)) + printf(ARGS(mmap, "0x%08x, %d, %d, 0x%08x, %d, %d"), + linux_args.addr, linux_args.len, linux_args.prot, + linux_args.flags, linux_args.fd, linux_args.pgoff); +#endif + if ((linux_args.pgoff % PAGE_SIZE) != 0) + return (EINVAL); + linux_args.pgoff /= PAGE_SIZE; + + return (linux_mmap_common(td, &linux_args)); +} + +static int +linux_mmap_common(struct thread *td, struct l_mmap_argv *linux_args) +{ + struct proc *p = td->td_proc; + struct mmap_args /* { + caddr_t addr; + size_t len; + int prot; + int flags; + int fd; + long pad; + off_t pos; + } */ bsd_args; + int error; + struct file *fp; + + error = 0; + bsd_args.flags = 0; + fp = NULL; + + /* + * Linux mmap(2): + * You must specify exactly one of MAP_SHARED and MAP_PRIVATE + */ + if (! ((linux_args->flags & LINUX_MAP_SHARED) ^ + (linux_args->flags & LINUX_MAP_PRIVATE))) + return (EINVAL); + + if (linux_args->flags & LINUX_MAP_SHARED) + bsd_args.flags |= MAP_SHARED; + if (linux_args->flags & LINUX_MAP_PRIVATE) + bsd_args.flags |= MAP_PRIVATE; + if (linux_args->flags & LINUX_MAP_FIXED) + bsd_args.flags |= MAP_FIXED; + if (linux_args->flags & LINUX_MAP_ANON) + bsd_args.flags |= MAP_ANON; + else + bsd_args.flags |= MAP_NOSYNC; + if (linux_args->flags & LINUX_MAP_GROWSDOWN) + bsd_args.flags |= MAP_STACK; + + /* + * PROT_READ, PROT_WRITE, or PROT_EXEC implies PROT_READ and PROT_EXEC + * on Linux/i386. We do this to ensure maximum compatibility. + * Linux/ia64 does the same in i386 emulation mode. + */ + bsd_args.prot = linux_args->prot; + if (bsd_args.prot & (PROT_READ | PROT_WRITE | PROT_EXEC)) + bsd_args.prot |= PROT_READ | PROT_EXEC; + + /* Linux does not check file descriptor when MAP_ANONYMOUS is set. */ + bsd_args.fd = (bsd_args.flags & MAP_ANON) ? -1 : linux_args->fd; + if (bsd_args.fd != -1) { + /* + * Linux follows Solaris mmap(2) description: + * The file descriptor fildes is opened with + * read permission, regardless of the + * protection options specified. + */ + + if ((error = fget(td, bsd_args.fd, &fp)) != 0) + return (error); + if (fp->f_type != DTYPE_VNODE) { + fdrop(fp, td); + return (EINVAL); + } + + /* Linux mmap() just fails for O_WRONLY files */ + if (!(fp->f_flag & FREAD)) { + fdrop(fp, td); + return (EACCES); + } + + fdrop(fp, td); + } + + if (linux_args->flags & LINUX_MAP_GROWSDOWN) { + /* + * The Linux MAP_GROWSDOWN option does not limit auto + * growth of the region. Linux mmap with this option + * takes as addr the inital BOS, and as len, the initial + * region size. It can then grow down from addr without + * limit. However, Linux threads has an implicit internal + * limit to stack size of STACK_SIZE. Its just not + * enforced explicitly in Linux. But, here we impose + * a limit of (STACK_SIZE - GUARD_SIZE) on the stack + * region, since we can do this with our mmap. + * + * Our mmap with MAP_STACK takes addr as the maximum + * downsize limit on BOS, and as len the max size of + * the region. It then maps the top SGROWSIZ bytes, + * and auto grows the region down, up to the limit + * in addr. + * + * If we don't use the MAP_STACK option, the effect + * of this code is to allocate a stack region of a + * fixed size of (STACK_SIZE - GUARD_SIZE). + */ + + if ((caddr_t)PTRIN(linux_args->addr) + linux_args->len > + p->p_vmspace->vm_maxsaddr) { + /* + * Some Linux apps will attempt to mmap + * thread stacks near the top of their + * address space. If their TOS is greater + * than vm_maxsaddr, vm_map_growstack() + * will confuse the thread stack with the + * process stack and deliver a SEGV if they + * attempt to grow the thread stack past their + * current stacksize rlimit. To avoid this, + * adjust vm_maxsaddr upwards to reflect + * the current stacksize rlimit rather + * than the maximum possible stacksize. + * It would be better to adjust the + * mmap'ed region, but some apps do not check + * mmap's return value. + */ + PROC_LOCK(p); + p->p_vmspace->vm_maxsaddr = (char *)LINUX32_USRSTACK - + lim_cur(p, RLIMIT_STACK); + PROC_UNLOCK(p); + } + + /* This gives us our maximum stack size */ + if (linux_args->len > STACK_SIZE - GUARD_SIZE) + bsd_args.len = linux_args->len; + else + bsd_args.len = STACK_SIZE - GUARD_SIZE; + + /* + * This gives us a new BOS. If we're using VM_STACK, then + * mmap will just map the top SGROWSIZ bytes, and let + * the stack grow down to the limit at BOS. If we're + * not using VM_STACK we map the full stack, since we + * don't have a way to autogrow it. + */ + bsd_args.addr = (caddr_t)PTRIN(linux_args->addr) - + bsd_args.len; + } else { + bsd_args.addr = (caddr_t)PTRIN(linux_args->addr); + bsd_args.len = linux_args->len; + } + bsd_args.pos = (off_t)linux_args->pgoff * PAGE_SIZE; + +#ifdef DEBUG + if (ldebug(mmap)) + printf("-> %s(%p, %d, %d, 0x%08x, %d, 0x%x)\n", + __func__, + (void *)bsd_args.addr, (int)bsd_args.len, bsd_args.prot, + bsd_args.flags, bsd_args.fd, (int)bsd_args.pos); +#endif + error = mmap(td, &bsd_args); +#ifdef DEBUG + if (ldebug(mmap)) + printf("-> %s() return: 0x%x (0x%08x)\n", + __func__, error, (u_int)td->td_retval[0]); +#endif + return (error); +} + +int +linux_mprotect(struct thread *td, struct linux_mprotect_args *uap) +{ + struct mprotect_args bsd_args; + + bsd_args.addr = uap->addr; + bsd_args.len = uap->len; + bsd_args.prot = uap->prot; + if (bsd_args.prot & (PROT_READ | PROT_WRITE | PROT_EXEC)) + bsd_args.prot |= PROT_READ | PROT_EXEC; + return (mprotect(td, &bsd_args)); +} + +int +linux_iopl(struct thread *td, struct linux_iopl_args *args) +{ + int error; + + if (args->level < 0 || args->level > 3) + return (EINVAL); + if ((error = priv_check(td, PRIV_IO)) != 0) + return (error); + if ((error = securelevel_gt(td->td_ucred, 0)) != 0) + return (error); + td->td_frame->tf_rflags = (td->td_frame->tf_rflags & ~PSL_IOPL) | + (args->level * (PSL_IOPL / 3)); + + return (0); +} + +int +linux_pipe(struct thread *td, struct linux_pipe_args *args) +{ + int pip[2]; + int error; + register_t reg_rdx; + +#ifdef DEBUG + if (ldebug(pipe)) + printf(ARGS(pipe, "*")); +#endif + + reg_rdx = td->td_retval[1]; + error = pipe(td, 0); + if (error) { + td->td_retval[1] = reg_rdx; + return (error); + } + + pip[0] = td->td_retval[0]; + pip[1] = td->td_retval[1]; + error = copyout(pip, args->pipefds, 2 * sizeof(int)); + if (error) { + td->td_retval[1] = reg_rdx; + return (error); + } + + td->td_retval[1] = reg_rdx; + td->td_retval[0] = 0; + return (0); +} + +int +linux_sigaction(struct thread *td, struct linux_sigaction_args *args) +{ + l_osigaction_t osa; + l_sigaction_t act, oact; + int error; + +#ifdef DEBUG + if (ldebug(sigaction)) + printf(ARGS(sigaction, "%d, %p, %p"), + args->sig, (void *)args->nsa, (void *)args->osa); +#endif + + if (args->nsa != NULL) { + error = copyin(args->nsa, &osa, sizeof(l_osigaction_t)); + if (error) + return (error); + act.lsa_handler = osa.lsa_handler; + act.lsa_flags = osa.lsa_flags; + act.lsa_restorer = osa.lsa_restorer; + LINUX_SIGEMPTYSET(act.lsa_mask); + act.lsa_mask.__bits[0] = osa.lsa_mask; + } + + error = linux_do_sigaction(td, args->sig, args->nsa ? &act : NULL, + args->osa ? &oact : NULL); + + if (args->osa != NULL && !error) { + osa.lsa_handler = oact.lsa_handler; + osa.lsa_flags = oact.lsa_flags; + osa.lsa_restorer = oact.lsa_restorer; + osa.lsa_mask = oact.lsa_mask.__bits[0]; + error = copyout(&osa, args->osa, sizeof(l_osigaction_t)); + } + + return (error); +} + +/* + * Linux has two extra args, restart and oldmask. We don't use these, + * but it seems that "restart" is actually a context pointer that + * enables the signal to happen with a different register set. + */ +int +linux_sigsuspend(struct thread *td, struct linux_sigsuspend_args *args) +{ + sigset_t sigmask; + l_sigset_t mask; + +#ifdef DEBUG + if (ldebug(sigsuspend)) + printf(ARGS(sigsuspend, "%08lx"), (unsigned long)args->mask); +#endif + + LINUX_SIGEMPTYSET(mask); + mask.__bits[0] = args->mask; + linux_to_bsd_sigset(&mask, &sigmask); + return (kern_sigsuspend(td, sigmask)); +} + +int +linux_rt_sigsuspend(struct thread *td, struct linux_rt_sigsuspend_args *uap) +{ + l_sigset_t lmask; + sigset_t sigmask; + int error; + +#ifdef DEBUG + if (ldebug(rt_sigsuspend)) + printf(ARGS(rt_sigsuspend, "%p, %d"), + (void *)uap->newset, uap->sigsetsize); +#endif + + if (uap->sigsetsize != sizeof(l_sigset_t)) + return (EINVAL); + + error = copyin(uap->newset, &lmask, sizeof(l_sigset_t)); + if (error) + return (error); + + linux_to_bsd_sigset(&lmask, &sigmask); + return (kern_sigsuspend(td, sigmask)); +} + +int +linux_pause(struct thread *td, struct linux_pause_args *args) +{ + struct proc *p = td->td_proc; + sigset_t sigmask; + +#ifdef DEBUG + if (ldebug(pause)) + printf(ARGS(pause, "")); +#endif + + PROC_LOCK(p); + sigmask = td->td_sigmask; + PROC_UNLOCK(p); + return (kern_sigsuspend(td, sigmask)); +} + +int +linux_sigaltstack(struct thread *td, struct linux_sigaltstack_args *uap) +{ + stack_t ss, oss; + l_stack_t lss; + int error; + +#ifdef DEBUG + if (ldebug(sigaltstack)) + printf(ARGS(sigaltstack, "%p, %p"), uap->uss, uap->uoss); +#endif + + if (uap->uss != NULL) { + error = copyin(uap->uss, &lss, sizeof(l_stack_t)); + if (error) + return (error); + + ss.ss_sp = PTRIN(lss.ss_sp); + ss.ss_size = lss.ss_size; + ss.ss_flags = linux_to_bsd_sigaltstack(lss.ss_flags); + } + error = kern_sigaltstack(td, (uap->uss != NULL) ? &ss : NULL, + (uap->uoss != NULL) ? &oss : NULL); + if (!error && uap->uoss != NULL) { + lss.ss_sp = PTROUT(oss.ss_sp); + lss.ss_size = oss.ss_size; + lss.ss_flags = bsd_to_linux_sigaltstack(oss.ss_flags); + error = copyout(&lss, uap->uoss, sizeof(l_stack_t)); + } + + return (error); +} + +int +linux_ftruncate64(struct thread *td, struct linux_ftruncate64_args *args) +{ + struct ftruncate_args sa; + +#ifdef DEBUG + if (ldebug(ftruncate64)) + printf(ARGS(ftruncate64, "%u, %jd"), args->fd, + (intmax_t)args->length); +#endif + + sa.fd = args->fd; + sa.length = args->length; + return ftruncate(td, &sa); +} + +int +linux_gettimeofday(struct thread *td, struct linux_gettimeofday_args *uap) +{ + struct timeval atv; + l_timeval atv32; + struct timezone rtz; + int error = 0; + + if (uap->tp) { + microtime(&atv); + atv32.tv_sec = atv.tv_sec; + atv32.tv_usec = atv.tv_usec; + error = copyout(&atv32, uap->tp, sizeof(atv32)); + } + if (error == 0 && uap->tzp != NULL) { + rtz.tz_minuteswest = tz_minuteswest; + rtz.tz_dsttime = tz_dsttime; + error = copyout(&rtz, uap->tzp, sizeof(rtz)); + } + return (error); +} + +int +linux_settimeofday(struct thread *td, struct linux_settimeofday_args *uap) +{ + l_timeval atv32; + struct timeval atv, *tvp; + struct timezone atz, *tzp; + int error; + + if (uap->tp) { + error = copyin(uap->tp, &atv32, sizeof(atv32)); + if (error) + return (error); + atv.tv_sec = atv32.tv_sec; + atv.tv_usec = atv32.tv_usec; + tvp = &atv; + } else + tvp = NULL; + if (uap->tzp) { + error = copyin(uap->tzp, &atz, sizeof(atz)); + if (error) + return (error); + tzp = &atz; + } else + tzp = NULL; + return (kern_settimeofday(td, tvp, tzp)); +} + +int +linux_getrusage(struct thread *td, struct linux_getrusage_args *uap) +{ + struct l_rusage s32; + struct rusage s; + int error; + + error = kern_getrusage(td, uap->who, &s); + if (error != 0) + return (error); + if (uap->rusage != NULL) { + s32.ru_utime.tv_sec = s.ru_utime.tv_sec; + s32.ru_utime.tv_usec = s.ru_utime.tv_usec; + s32.ru_stime.tv_sec = s.ru_stime.tv_sec; + s32.ru_stime.tv_usec = s.ru_stime.tv_usec; + s32.ru_maxrss = s.ru_maxrss; + s32.ru_ixrss = s.ru_ixrss; + s32.ru_idrss = s.ru_idrss; + s32.ru_isrss = s.ru_isrss; + s32.ru_minflt = s.ru_minflt; + s32.ru_majflt = s.ru_majflt; + s32.ru_nswap = s.ru_nswap; + s32.ru_inblock = s.ru_inblock; + s32.ru_oublock = s.ru_oublock; + s32.ru_msgsnd = s.ru_msgsnd; + s32.ru_msgrcv = s.ru_msgrcv; + s32.ru_nsignals = s.ru_nsignals; + s32.ru_nvcsw = s.ru_nvcsw; + s32.ru_nivcsw = s.ru_nivcsw; + error = copyout(&s32, uap->rusage, sizeof(s32)); + } + return (error); +} + +int +linux_sched_rr_get_interval(struct thread *td, + struct linux_sched_rr_get_interval_args *uap) +{ + struct timespec ts; + struct l_timespec ts32; + int error; + + error = kern_sched_rr_get_interval(td, uap->pid, &ts); + if (error != 0) + return (error); + ts32.tv_sec = ts.tv_sec; + ts32.tv_nsec = ts.tv_nsec; + return (copyout(&ts32, uap->interval, sizeof(ts32))); +} + +int +linux_set_thread_area(struct thread *td, + struct linux_set_thread_area_args *args) +{ + struct l_user_desc info; + struct user_segment_descriptor sd; + int a[2]; + int error; + + error = copyin(args->desc, &info, sizeof(struct l_user_desc)); + if (error) + return (error); + +#ifdef DEBUG + if (ldebug(set_thread_area)) + printf(ARGS(set_thread_area, "%i, %x, %x, %i, %i, %i, " + "%i, %i, %i"), info.entry_number, info.base_addr, + info.limit, info.seg_32bit, info.contents, + info.read_exec_only, info.limit_in_pages, + info.seg_not_present, info.useable); +#endif + + /* + * Semantics of Linux version: every thread in the system has array + * of three TLS descriptors. 1st is GLIBC TLS, 2nd is WINE, 3rd unknown. + * This syscall loads one of the selected TLS decriptors with a value + * and also loads GDT descriptors 6, 7 and 8 with the content of + * the per-thread descriptors. + * + * Semantics of FreeBSD version: I think we can ignore that Linux has + * three per-thread descriptors and use just the first one. + * The tls_array[] is used only in [gs]et_thread_area() syscalls and + * for loading the GDT descriptors. We use just one GDT descriptor + * for TLS, so we will load just one. + * + * XXX: This doesn't work when a user space process tries to use more + * than one TLS segment. Comment in the Linux source says wine might + * do this. + */ + + /* + * GLIBC reads current %gs and call set_thread_area() with it. + * We should let GUDATA_SEL and GUGS32_SEL proceed as well because + * we use these segments. + */ + switch (info.entry_number) { + case GUGS32_SEL: + case GUDATA_SEL: + case 6: + case -1: + info.entry_number = GUGS32_SEL; + break; + default: + return (EINVAL); + } + + /* + * We have to copy out the GDT entry we use. + * + * XXX: What if a user space program does not check the return value + * and tries to use 6, 7 or 8? + */ + error = copyout(&info, args->desc, sizeof(struct l_user_desc)); + if (error) + return (error); + + if (LINUX_LDT_empty(&info)) { + a[0] = 0; + a[1] = 0; + } else { + a[0] = LINUX_LDT_entry_a(&info); + a[1] = LINUX_LDT_entry_b(&info); + } + + memcpy(&sd, &a, sizeof(a)); +#ifdef DEBUG + if (ldebug(set_thread_area)) + printf("Segment created in set_thread_area: " + "lobase: %x, hibase: %x, lolimit: %x, hilimit: %x, " + "type: %i, dpl: %i, p: %i, xx: %i, long: %i, " + "def32: %i, gran: %i\n", + sd.sd_lobase, + sd.sd_hibase, + sd.sd_lolimit, + sd.sd_hilimit, + sd.sd_type, + sd.sd_dpl, + sd.sd_p, + sd.sd_xx, + sd.sd_long, + sd.sd_def32, + sd.sd_gran); +#endif + + critical_enter(); + td->td_pcb->pcb_gsbase = (register_t)info.base_addr; + td->td_pcb->pcb_gs32sd = gdt[GUGS32_SEL] = sd; + td->td_pcb->pcb_gs32p = &gdt[GUGS32_SEL]; + td->td_pcb->pcb_flags |= PCB_32BIT; + wrmsr(MSR_KGSBASE, td->td_pcb->pcb_gsbase); + critical_exit(); + + return (0); +} diff --git a/sys/emulation/linux/amd64/linux32_support.s b/sys/emulation/linux/amd64/linux32_support.s new file mode 100644 index 0000000000..34b91be3c1 --- /dev/null +++ b/sys/emulation/linux/amd64/linux32_support.s @@ -0,0 +1,125 @@ +/*- + * Copyright (c) 2007 Konstantin Belousov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/sys/amd64/linux32/linux32_support.s,v 1.1 2007/05/23 08:33:05 kib Exp $ + * $DragonFly$ + */ + +#include "linux32_assym.h" /* system definitions */ +#include /* miscellaneous asm macros */ + +#include "assym.s" + +futex_fault: + movq $0,PCB_ONFAULT(%r8) + movl $-EFAULT,%eax + ret + +ENTRY(futex_xchgl) + movq PCPU(CURPCB),%r8 + movq $futex_fault,PCB_ONFAULT(%r8) + movq $VM_MAXUSER_ADDRESS-4,%rax + cmpq %rax,%rsi + ja futex_fault + xchgl %edi,(%rsi) + movl %edi,(%rdx) + xorl %eax,%eax + movq %rax,PCB_ONFAULT(%r8) + ret + +ENTRY(futex_addl) + movq PCPU(CURPCB),%r8 + movq $futex_fault,PCB_ONFAULT(%r8) + movq $VM_MAXUSER_ADDRESS-4,%rax + cmpq %rax,%rsi + ja futex_fault +#ifdef SMP + lock +#endif + xaddl %edi,(%rsi) + movl %edi,(%rdx) + xorl %eax,%eax + movq %rax,PCB_ONFAULT(%r8) + ret + +ENTRY(futex_orl) + movq PCPU(CURPCB),%r8 + movq $futex_fault,PCB_ONFAULT(%r8) + movq $VM_MAXUSER_ADDRESS-4,%rax + cmpq %rax,%rsi + ja futex_fault + movl (%rsi),%eax +1: movl %eax,%ecx + orl %edi,%ecx +#ifdef SMP + lock +#endif + cmpxchgl %ecx,(%rsi) + jnz 1b + movl %eax,(%rdx) + xorl %eax,%eax + movq %rax,PCB_ONFAULT(%r8) + ret + +ENTRY(futex_andl) + movq PCPU(CURPCB),%r8 + movq $futex_fault,PCB_ONFAULT(%r8) + movq $VM_MAXUSER_ADDRESS-4,%rax + cmpq %rax,%rsi + ja futex_fault + movl (%rsi),%eax +1: movl %eax,%ecx + andl %edi,%ecx +#ifdef SMP + lock +#endif + cmpxchgl %ecx,(%rsi) + jnz 1b + movl %eax,(%rdx) + xorl %eax,%eax + movq %rax,PCB_ONFAULT(%r8) + ret + +ENTRY(futex_xorl) + movq PCPU(CURPCB),%r8 + movq $futex_fault,PCB_ONFAULT(%r8) + movq $VM_MAXUSER_ADDRESS-4,%rax + cmpq %rax,%rsi + ja futex_fault + movl (%rsi),%eax +1: movl %eax,%ecx + xorl %edi,%ecx +#ifdef SMP + lock +#endif + cmpxchgl %ecx,(%rsi) + jnz 1b + movl %eax,(%rdx) + xorl %eax,%eax + movq %rax,PCB_ONFAULT(%r8) + ret diff --git a/sys/emulation/linux/amd64/linux32_sysvec.c b/sys/emulation/linux/amd64/linux32_sysvec.c new file mode 100644 index 0000000000..2a7ae5398b --- /dev/null +++ b/sys/emulation/linux/amd64/linux32_sysvec.c @@ -0,0 +1,1133 @@ +/*- + * Copyright (c) 2004 Tim J. Robbins + * Copyright (c) 2003 Peter Wemm + * Copyright (c) 2002 Doug Rabson + * Copyright (c) 1998-1999 Andrew Gallatin + * Copyright (c) 1994-1996 Søren Schmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: src/sys/amd64/linux32/linux32_sysvec.c,v 1.29 2007/05/14 22:40:04 jhb Exp $ + * $DragonFly$ + */ + +#include "opt_compat.h" + +#ifndef COMPAT_IA32 +#error "Unable to compile Linux-emulator due to missing COMPAT_IA32 option!" +#endif + +#define __ELF_WORD_SIZE 32 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +MODULE_VERSION(linux, 1); + +MALLOC_DEFINE(M_LINUX, "linux", "Linux mode structures"); + +#define AUXARGS_ENTRY_32(pos, id, val) \ + do { \ + suword32(pos++, id); \ + suword32(pos++, val); \ + } while (0) + +#if BYTE_ORDER == LITTLE_ENDIAN +#define SHELLMAGIC 0x2123 /* #! */ +#else +#define SHELLMAGIC 0x2321 +#endif + +/* + * Allow the sendsig functions to use the ldebug() facility + * even though they are not syscalls themselves. Map them + * to syscall 0. This is slightly less bogus than using + * ldebug(sigreturn). + */ +#define LINUX_SYS_linux_rt_sendsig 0 +#define LINUX_SYS_linux_sendsig 0 + +extern char linux_sigcode[]; +extern int linux_szsigcode; + +extern struct sysent linux_sysent[LINUX_SYS_MAXSYSCALL]; + +SET_DECLARE(linux_ioctl_handler_set, struct linux_ioctl_handler); +SET_DECLARE(linux_device_handler_set, struct linux_device_handler); + +static int elf_linux_fixup(register_t **stack_base, + struct image_params *iparams); +static register_t *linux_copyout_strings(struct image_params *imgp); +static void linux_prepsyscall(struct trapframe *tf, int *args, u_int *code, + caddr_t *params); +static void linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask); +static void exec_linux_setregs(struct thread *td, u_long entry, + u_long stack, u_long ps_strings); +static void linux32_fixlimit(struct rlimit *rl, int which); + +extern LIST_HEAD(futex_list, futex) futex_list; +extern struct sx futex_sx; + +static eventhandler_tag linux_exit_tag; +static eventhandler_tag linux_schedtail_tag; +static eventhandler_tag linux_exec_tag; + +/* + * Linux syscalls return negative errno's, we do positive and map them + * Reference: + * FreeBSD: src/sys/sys/errno.h + * Linux: linux-2.6.17.8/include/asm-generic/errno-base.h + * linux-2.6.17.8/include/asm-generic/errno.h + */ +static int bsd_to_linux_errno[ELAST + 1] = { + -0, -1, -2, -3, -4, -5, -6, -7, -8, -9, + -10, -35, -12, -13, -14, -15, -16, -17, -18, -19, + -20, -21, -22, -23, -24, -25, -26, -27, -28, -29, + -30, -31, -32, -33, -34, -11,-115,-114, -88, -89, + -90, -91, -92, -93, -94, -95, -96, -97, -98, -99, + -100,-101,-102,-103,-104,-105,-106,-107,-108,-109, + -110,-111, -40, -36,-112,-113, -39, -11, -87,-122, + -116, -66, -6, -6, -6, -6, -6, -37, -38, -9, + -6, -6, -43, -42, -75,-125, -84, -95, -16, -74, + -72, -67, -71 +}; + +int bsd_to_linux_signal[LINUX_SIGTBLSZ] = { + LINUX_SIGHUP, LINUX_SIGINT, LINUX_SIGQUIT, LINUX_SIGILL, + LINUX_SIGTRAP, LINUX_SIGABRT, 0, LINUX_SIGFPE, + LINUX_SIGKILL, LINUX_SIGBUS, LINUX_SIGSEGV, LINUX_SIGSYS, + LINUX_SIGPIPE, LINUX_SIGALRM, LINUX_SIGTERM, LINUX_SIGURG, + LINUX_SIGSTOP, LINUX_SIGTSTP, LINUX_SIGCONT, LINUX_SIGCHLD, + LINUX_SIGTTIN, LINUX_SIGTTOU, LINUX_SIGIO, LINUX_SIGXCPU, + LINUX_SIGXFSZ, LINUX_SIGVTALRM, LINUX_SIGPROF, LINUX_SIGWINCH, + 0, LINUX_SIGUSR1, LINUX_SIGUSR2 +}; + +int linux_to_bsd_signal[LINUX_SIGTBLSZ] = { + SIGHUP, SIGINT, SIGQUIT, SIGILL, + SIGTRAP, SIGABRT, SIGBUS, SIGFPE, + SIGKILL, SIGUSR1, SIGSEGV, SIGUSR2, + SIGPIPE, SIGALRM, SIGTERM, SIGBUS, + SIGCHLD, SIGCONT, SIGSTOP, SIGTSTP, + SIGTTIN, SIGTTOU, SIGURG, SIGXCPU, + SIGXFSZ, SIGVTALRM, SIGPROF, SIGWINCH, + SIGIO, SIGURG, SIGSYS +}; + +#define LINUX_T_UNKNOWN 255 +static int _bsd_to_linux_trapcode[] = { + LINUX_T_UNKNOWN, /* 0 */ + 6, /* 1 T_PRIVINFLT */ + LINUX_T_UNKNOWN, /* 2 */ + 3, /* 3 T_BPTFLT */ + LINUX_T_UNKNOWN, /* 4 */ + LINUX_T_UNKNOWN, /* 5 */ + 16, /* 6 T_ARITHTRAP */ + 254, /* 7 T_ASTFLT */ + LINUX_T_UNKNOWN, /* 8 */ + 13, /* 9 T_PROTFLT */ + 1, /* 10 T_TRCTRAP */ + LINUX_T_UNKNOWN, /* 11 */ + 14, /* 12 T_PAGEFLT */ + LINUX_T_UNKNOWN, /* 13 */ + 17, /* 14 T_ALIGNFLT */ + LINUX_T_UNKNOWN, /* 15 */ + LINUX_T_UNKNOWN, /* 16 */ + LINUX_T_UNKNOWN, /* 17 */ + 0, /* 18 T_DIVIDE */ + 2, /* 19 T_NMI */ + 4, /* 20 T_OFLOW */ + 5, /* 21 T_BOUND */ + 7, /* 22 T_DNA */ + 8, /* 23 T_DOUBLEFLT */ + 9, /* 24 T_FPOPFLT */ + 10, /* 25 T_TSSFLT */ + 11, /* 26 T_SEGNPFLT */ + 12, /* 27 T_STKFLT */ + 18, /* 28 T_MCHK */ + 19, /* 29 T_XMMFLT */ + 15 /* 30 T_RESERVED */ +}; +#define bsd_to_linux_trapcode(code) \ + ((code)td_proc == imgp->proc && + (curthread->td_proc->p_flag & P_SA) == 0, + ("unsafe elf_linux_fixup(), should be curproc")); + base = (Elf32_Addr *)*stack_base; + args = (Elf32_Auxargs *)imgp->auxargs; + pos = base + (imgp->args->argc + imgp->args->envc + 2); + + if (args->trace) + AUXARGS_ENTRY_32(pos, AT_DEBUG, 1); + if (args->execfd != -1) + AUXARGS_ENTRY_32(pos, AT_EXECFD, args->execfd); + AUXARGS_ENTRY_32(pos, AT_PHDR, args->phdr); + AUXARGS_ENTRY_32(pos, AT_PHENT, args->phent); + AUXARGS_ENTRY_32(pos, AT_PHNUM, args->phnum); + AUXARGS_ENTRY_32(pos, AT_PAGESZ, args->pagesz); + AUXARGS_ENTRY_32(pos, AT_FLAGS, args->flags); + AUXARGS_ENTRY_32(pos, AT_ENTRY, args->entry); + AUXARGS_ENTRY_32(pos, AT_BASE, args->base); + AUXARGS_ENTRY_32(pos, AT_UID, imgp->proc->p_ucred->cr_ruid); + AUXARGS_ENTRY_32(pos, AT_EUID, imgp->proc->p_ucred->cr_svuid); + AUXARGS_ENTRY_32(pos, AT_GID, imgp->proc->p_ucred->cr_rgid); + AUXARGS_ENTRY_32(pos, AT_EGID, imgp->proc->p_ucred->cr_svgid); + AUXARGS_ENTRY_32(pos, AT_NULL, 0); + + free(imgp->auxargs, M_TEMP); + imgp->auxargs = NULL; + + base--; + suword32(base, (uint32_t)imgp->args->argc); + *stack_base = (register_t *)base; + return 0; +} + +extern int _ucodesel, _ucode32sel, _udatasel; +extern unsigned long linux_sznonrtsigcode; + +static void +linux_rt_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask) +{ + struct thread *td = curthread; + struct proc *p = td->td_proc; + struct sigacts *psp; + struct trapframe *regs; + struct l_rt_sigframe *fp, frame; + int oonstack; + int sig; + int code; + + sig = ksi->ksi_signo; + code = ksi->ksi_code; + PROC_LOCK_ASSERT(p, MA_OWNED); + psp = p->p_sigacts; + mtx_assert(&psp->ps_mtx, MA_OWNED); + regs = td->td_frame; + oonstack = sigonstack(regs->tf_rsp); + +#ifdef DEBUG + if (ldebug(rt_sendsig)) + printf(ARGS(rt_sendsig, "%p, %d, %p, %u"), + catcher, sig, (void*)mask, code); +#endif + /* + * Allocate space for the signal handler context. + */ + if ((td->td_pflags & TDP_ALTSTACK) && !oonstack && + SIGISMEMBER(psp->ps_sigonstack, sig)) { + fp = (struct l_rt_sigframe *)(td->td_sigstk.ss_sp + + td->td_sigstk.ss_size - sizeof(struct l_rt_sigframe)); + } else + fp = (struct l_rt_sigframe *)regs->tf_rsp - 1; + mtx_unlock(&psp->ps_mtx); + + /* + * Build the argument list for the signal handler. + */ + if (p->p_sysent->sv_sigtbl) + if (sig <= p->p_sysent->sv_sigsize) + sig = p->p_sysent->sv_sigtbl[_SIG_IDX(sig)]; + + bzero(&frame, sizeof(frame)); + + frame.sf_handler = PTROUT(catcher); + frame.sf_sig = sig; + frame.sf_siginfo = PTROUT(&fp->sf_si); + frame.sf_ucontext = PTROUT(&fp->sf_sc); + + /* Fill in POSIX parts */ + frame.sf_si.lsi_signo = sig; + frame.sf_si.lsi_code = code; + frame.sf_si.lsi_addr = PTROUT(ksi->ksi_addr); + + /* + * Build the signal context to be used by sigreturn. + */ + frame.sf_sc.uc_flags = 0; /* XXX ??? */ + frame.sf_sc.uc_link = 0; /* XXX ??? */ + + frame.sf_sc.uc_stack.ss_sp = PTROUT(td->td_sigstk.ss_sp); + frame.sf_sc.uc_stack.ss_size = td->td_sigstk.ss_size; + frame.sf_sc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK) + ? ((oonstack) ? LINUX_SS_ONSTACK : 0) : LINUX_SS_DISABLE; + PROC_UNLOCK(p); + + bsd_to_linux_sigset(mask, &frame.sf_sc.uc_sigmask); + + frame.sf_sc.uc_mcontext.sc_mask = frame.sf_sc.uc_sigmask.__bits[0]; + frame.sf_sc.uc_mcontext.sc_gs = rgs(); + frame.sf_sc.uc_mcontext.sc_fs = rfs(); + __asm __volatile("movl %%es,%0" : + "=rm" (frame.sf_sc.uc_mcontext.sc_es)); + __asm __volatile("movl %%ds,%0" : + "=rm" (frame.sf_sc.uc_mcontext.sc_ds)); + frame.sf_sc.uc_mcontext.sc_edi = regs->tf_rdi; + frame.sf_sc.uc_mcontext.sc_esi = regs->tf_rsi; + frame.sf_sc.uc_mcontext.sc_ebp = regs->tf_rbp; + frame.sf_sc.uc_mcontext.sc_ebx = regs->tf_rbx; + frame.sf_sc.uc_mcontext.sc_edx = regs->tf_rdx; + frame.sf_sc.uc_mcontext.sc_ecx = regs->tf_rcx; + frame.sf_sc.uc_mcontext.sc_eax = regs->tf_rax; + frame.sf_sc.uc_mcontext.sc_eip = regs->tf_rip; + frame.sf_sc.uc_mcontext.sc_cs = regs->tf_cs; + frame.sf_sc.uc_mcontext.sc_eflags = regs->tf_rflags; + frame.sf_sc.uc_mcontext.sc_esp_at_signal = regs->tf_rsp; + frame.sf_sc.uc_mcontext.sc_ss = regs->tf_ss; + frame.sf_sc.uc_mcontext.sc_err = regs->tf_err; + frame.sf_sc.uc_mcontext.sc_trapno = bsd_to_linux_trapcode(code); + +#ifdef DEBUG + if (ldebug(rt_sendsig)) + printf(LMSG("rt_sendsig flags: 0x%x, sp: %p, ss: 0x%lx, mask: 0x%x"), + frame.sf_sc.uc_stack.ss_flags, td->td_sigstk.ss_sp, + td->td_sigstk.ss_size, frame.sf_sc.uc_mcontext.sc_mask); +#endif + + if (copyout(&frame, fp, sizeof(frame)) != 0) { + /* + * Process has trashed its stack; give it an illegal + * instruction to halt it in its tracks. + */ +#ifdef DEBUG + if (ldebug(rt_sendsig)) + printf(LMSG("rt_sendsig: bad stack %p, oonstack=%x"), + fp, oonstack); +#endif + PROC_LOCK(p); + sigexit(td, SIGILL); + } + + /* + * Build context to run handler in. + */ + regs->tf_rsp = PTROUT(fp); + regs->tf_rip = LINUX32_PS_STRINGS - *(p->p_sysent->sv_szsigcode) + + linux_sznonrtsigcode; + regs->tf_rflags &= ~PSL_T; + regs->tf_cs = _ucode32sel; + regs->tf_ss = _udatasel; + load_ds(_udatasel); + td->td_pcb->pcb_ds = _udatasel; + load_es(_udatasel); + td->td_pcb->pcb_es = _udatasel; + /* leave user %fs and %gs untouched */ + PROC_LOCK(p); + mtx_lock(&psp->ps_mtx); +} + + +/* + * Send an interrupt to process. + * + * Stack is set up to allow sigcode stored + * in u. to call routine, followed by kcall + * to sigreturn routine below. After sigreturn + * resets the signal mask, the stack, and the + * frame pointer, it returns to the user + * specified pc, psl. + */ +static void +linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask) +{ + struct thread *td = curthread; + struct proc *p = td->td_proc; + struct sigacts *psp; + struct trapframe *regs; + struct l_sigframe *fp, frame; + l_sigset_t lmask; + int oonstack, i; + int sig, code; + + sig = ksi->ksi_signo; + code = ksi->ksi_code; + PROC_LOCK_ASSERT(p, MA_OWNED); + psp = p->p_sigacts; + mtx_assert(&psp->ps_mtx, MA_OWNED); + if (SIGISMEMBER(psp->ps_siginfo, sig)) { + /* Signal handler installed with SA_SIGINFO. */ + linux_rt_sendsig(catcher, ksi, mask); + return; + } + + regs = td->td_frame; + oonstack = sigonstack(regs->tf_rsp); + +#ifdef DEBUG + if (ldebug(sendsig)) + printf(ARGS(sendsig, "%p, %d, %p, %u"), + catcher, sig, (void*)mask, code); +#endif + + /* + * Allocate space for the signal handler context. + */ + if ((td->td_pflags & TDP_ALTSTACK) && !oonstack && + SIGISMEMBER(psp->ps_sigonstack, sig)) { + fp = (struct l_sigframe *)(td->td_sigstk.ss_sp + + td->td_sigstk.ss_size - sizeof(struct l_sigframe)); + } else + fp = (struct l_sigframe *)regs->tf_rsp - 1; + mtx_unlock(&psp->ps_mtx); + PROC_UNLOCK(p); + + /* + * Build the argument list for the signal handler. + */ + if (p->p_sysent->sv_sigtbl) + if (sig <= p->p_sysent->sv_sigsize) + sig = p->p_sysent->sv_sigtbl[_SIG_IDX(sig)]; + + bzero(&frame, sizeof(frame)); + + frame.sf_handler = PTROUT(catcher); + frame.sf_sig = sig; + + bsd_to_linux_sigset(mask, &lmask); + + /* + * Build the signal context to be used by sigreturn. + */ + frame.sf_sc.sc_mask = lmask.__bits[0]; + frame.sf_sc.sc_gs = rgs(); + frame.sf_sc.sc_fs = rfs(); + __asm __volatile("movl %%es,%0" : "=rm" (frame.sf_sc.sc_es)); + __asm __volatile("movl %%ds,%0" : "=rm" (frame.sf_sc.sc_ds)); + frame.sf_sc.sc_edi = regs->tf_rdi; + frame.sf_sc.sc_esi = regs->tf_rsi; + frame.sf_sc.sc_ebp = regs->tf_rbp; + frame.sf_sc.sc_ebx = regs->tf_rbx; + frame.sf_sc.sc_edx = regs->tf_rdx; + frame.sf_sc.sc_ecx = regs->tf_rcx; + frame.sf_sc.sc_eax = regs->tf_rax; + frame.sf_sc.sc_eip = regs->tf_rip; + frame.sf_sc.sc_cs = regs->tf_cs; + frame.sf_sc.sc_eflags = regs->tf_rflags; + frame.sf_sc.sc_esp_at_signal = regs->tf_rsp; + frame.sf_sc.sc_ss = regs->tf_ss; + frame.sf_sc.sc_err = regs->tf_err; + frame.sf_sc.sc_trapno = bsd_to_linux_trapcode(code); + + for (i = 0; i < (LINUX_NSIG_WORDS-1); i++) + frame.sf_extramask[i] = lmask.__bits[i+1]; + + if (copyout(&frame, fp, sizeof(frame)) != 0) { + /* + * Process has trashed its stack; give it an illegal + * instruction to halt it in its tracks. + */ + PROC_LOCK(p); + sigexit(td, SIGILL); + } + + /* + * Build context to run handler in. + */ + regs->tf_rsp = PTROUT(fp); + regs->tf_rip = LINUX32_PS_STRINGS - *(p->p_sysent->sv_szsigcode); + regs->tf_rflags &= ~PSL_T; + regs->tf_cs = _ucode32sel; + regs->tf_ss = _udatasel; + load_ds(_udatasel); + td->td_pcb->pcb_ds = _udatasel; + load_es(_udatasel); + td->td_pcb->pcb_es = _udatasel; + /* leave user %fs and %gs untouched */ + PROC_LOCK(p); + mtx_lock(&psp->ps_mtx); +} + +/* + * System call to cleanup state after a signal + * has been taken. Reset signal mask and + * stack state from context left by sendsig (above). + * Return to previous pc and psl as specified by + * context left by sendsig. Check carefully to + * make sure that the user has not modified the + * psl to gain improper privileges or to cause + * a machine fault. + */ +int +linux_sigreturn(struct thread *td, struct linux_sigreturn_args *args) +{ + struct proc *p = td->td_proc; + struct l_sigframe frame; + struct trapframe *regs; + l_sigset_t lmask; + int eflags, i; + ksiginfo_t ksi; + + regs = td->td_frame; + +#ifdef DEBUG + if (ldebug(sigreturn)) + printf(ARGS(sigreturn, "%p"), (void *)args->sfp); +#endif + /* + * The trampoline code hands us the sigframe. + * It is unsafe to keep track of it ourselves, in the event that a + * program jumps out of a signal handler. + */ + if (copyin(args->sfp, &frame, sizeof(frame)) != 0) + return (EFAULT); + + /* + * Check for security violations. + */ +#define EFLAGS_SECURE(ef, oef) ((((ef) ^ (oef)) & ~PSL_USERCHANGE) == 0) + eflags = frame.sf_sc.sc_eflags; + /* + * XXX do allow users to change the privileged flag PSL_RF. The + * cpu sets PSL_RF in tf_eflags for faults. Debuggers should + * sometimes set it there too. tf_eflags is kept in the signal + * context during signal handling and there is no other place + * to remember it, so the PSL_RF bit may be corrupted by the + * signal handler without us knowing. Corruption of the PSL_RF + * bit at worst causes one more or one less debugger trap, so + * allowing it is fairly harmless. + */ + if (!EFLAGS_SECURE(eflags & ~PSL_RF, regs->tf_rflags & ~PSL_RF)) + return(EINVAL); + + /* + * Don't allow users to load a valid privileged %cs. Let the + * hardware check for invalid selectors, excess privilege in + * other selectors, invalid %eip's and invalid %esp's. + */ +#define CS_SECURE(cs) (ISPL(cs) == SEL_UPL) + if (!CS_SECURE(frame.sf_sc.sc_cs)) { + ksiginfo_init_trap(&ksi); + ksi.ksi_signo = SIGBUS; + ksi.ksi_code = BUS_OBJERR; + ksi.ksi_trapno = T_PROTFLT; + ksi.ksi_addr = (void *)regs->tf_rip; + trapsignal(td, &ksi); + return(EINVAL); + } + + lmask.__bits[0] = frame.sf_sc.sc_mask; + for (i = 0; i < (LINUX_NSIG_WORDS-1); i++) + lmask.__bits[i+1] = frame.sf_extramask[i]; + PROC_LOCK(p); + linux_to_bsd_sigset(&lmask, &td->td_sigmask); + SIG_CANTMASK(td->td_sigmask); + signotify(td); + PROC_UNLOCK(p); + + /* + * Restore signal context. + */ + /* Selectors were restored by the trampoline. */ + regs->tf_rdi = frame.sf_sc.sc_edi; + regs->tf_rsi = frame.sf_sc.sc_esi; + regs->tf_rbp = frame.sf_sc.sc_ebp; + regs->tf_rbx = frame.sf_sc.sc_ebx; + regs->tf_rdx = frame.sf_sc.sc_edx; + regs->tf_rcx = frame.sf_sc.sc_ecx; + regs->tf_rax = frame.sf_sc.sc_eax; + regs->tf_rip = frame.sf_sc.sc_eip; + regs->tf_cs = frame.sf_sc.sc_cs; + regs->tf_rflags = eflags; + regs->tf_rsp = frame.sf_sc.sc_esp_at_signal; + regs->tf_ss = frame.sf_sc.sc_ss; + + return (EJUSTRETURN); +} + +/* + * System call to cleanup state after a signal + * has been taken. Reset signal mask and + * stack state from context left by rt_sendsig (above). + * Return to previous pc and psl as specified by + * context left by sendsig. Check carefully to + * make sure that the user has not modified the + * psl to gain improper privileges or to cause + * a machine fault. + */ +int +linux_rt_sigreturn(struct thread *td, struct linux_rt_sigreturn_args *args) +{ + struct proc *p = td->td_proc; + struct l_ucontext uc; + struct l_sigcontext *context; + l_stack_t *lss; + stack_t ss; + struct trapframe *regs; + int eflags; + ksiginfo_t ksi; + + regs = td->td_frame; + +#ifdef DEBUG + if (ldebug(rt_sigreturn)) + printf(ARGS(rt_sigreturn, "%p"), (void *)args->ucp); +#endif + /* + * The trampoline code hands us the ucontext. + * It is unsafe to keep track of it ourselves, in the event that a + * program jumps out of a signal handler. + */ + if (copyin(args->ucp, &uc, sizeof(uc)) != 0) + return (EFAULT); + + context = &uc.uc_mcontext; + + /* + * Check for security violations. + */ +#define EFLAGS_SECURE(ef, oef) ((((ef) ^ (oef)) & ~PSL_USERCHANGE) == 0) + eflags = context->sc_eflags; + /* + * XXX do allow users to change the privileged flag PSL_RF. The + * cpu sets PSL_RF in tf_eflags for faults. Debuggers should + * sometimes set it there too. tf_eflags is kept in the signal + * context during signal handling and there is no other place + * to remember it, so the PSL_RF bit may be corrupted by the + * signal handler without us knowing. Corruption of the PSL_RF + * bit at worst causes one more or one less debugger trap, so + * allowing it is fairly harmless. + */ + if (!EFLAGS_SECURE(eflags & ~PSL_RF, regs->tf_rflags & ~PSL_RF)) + return(EINVAL); + + /* + * Don't allow users to load a valid privileged %cs. Let the + * hardware check for invalid selectors, excess privilege in + * other selectors, invalid %eip's and invalid %esp's. + */ +#define CS_SECURE(cs) (ISPL(cs) == SEL_UPL) + if (!CS_SECURE(context->sc_cs)) { + ksiginfo_init_trap(&ksi); + ksi.ksi_signo = SIGBUS; + ksi.ksi_code = BUS_OBJERR; + ksi.ksi_trapno = T_PROTFLT; + ksi.ksi_addr = (void *)regs->tf_rip; + trapsignal(td, &ksi); + return(EINVAL); + } + + PROC_LOCK(p); + linux_to_bsd_sigset(&uc.uc_sigmask, &td->td_sigmask); + SIG_CANTMASK(td->td_sigmask); + signotify(td); + PROC_UNLOCK(p); + + /* + * Restore signal context + */ + /* Selectors were restored by the trampoline. */ + regs->tf_rdi = context->sc_edi; + regs->tf_rsi = context->sc_esi; + regs->tf_rbp = context->sc_ebp; + regs->tf_rbx = context->sc_ebx; + regs->tf_rdx = context->sc_edx; + regs->tf_rcx = context->sc_ecx; + regs->tf_rax = context->sc_eax; + regs->tf_rip = context->sc_eip; + regs->tf_cs = context->sc_cs; + regs->tf_rflags = eflags; + regs->tf_rsp = context->sc_esp_at_signal; + regs->tf_ss = context->sc_ss; + + /* + * call sigaltstack & ignore results.. + */ + lss = &uc.uc_stack; + ss.ss_sp = PTRIN(lss->ss_sp); + ss.ss_size = lss->ss_size; + ss.ss_flags = linux_to_bsd_sigaltstack(lss->ss_flags); + +#ifdef DEBUG + if (ldebug(rt_sigreturn)) + printf(LMSG("rt_sigret flags: 0x%x, sp: %p, ss: 0x%lx, mask: 0x%x"), + ss.ss_flags, ss.ss_sp, ss.ss_size, context->sc_mask); +#endif + (void)kern_sigaltstack(td, &ss, NULL); + + return (EJUSTRETURN); +} + +/* + * MPSAFE + */ +static void +linux_prepsyscall(struct trapframe *tf, int *args, u_int *code, caddr_t *params) +{ + args[0] = tf->tf_rbx; + args[1] = tf->tf_rcx; + args[2] = tf->tf_rdx; + args[3] = tf->tf_rsi; + args[4] = tf->tf_rdi; + args[5] = tf->tf_rbp; /* Unconfirmed */ + *params = NULL; /* no copyin */ +} + +/* + * If a linux binary is exec'ing something, try this image activator + * first. We override standard shell script execution in order to + * be able to modify the interpreter path. We only do this if a linux + * binary is doing the exec, so we do not create an EXEC module for it. + */ +static int exec_linux_imgact_try(struct image_params *iparams); + +static int +exec_linux_imgact_try(struct image_params *imgp) +{ + const char *head = (const char *)imgp->image_header; + char *rpath; + int error = -1, len; + + /* + * The interpreter for shell scripts run from a linux binary needs + * to be located in /compat/linux if possible in order to recursively + * maintain linux path emulation. + */ + if (((const short *)head)[0] == SHELLMAGIC) { + /* + * Run our normal shell image activator. If it succeeds attempt + * to use the alternate path for the interpreter. If an alternate + * path is found, use our stringspace to store it. + */ + if ((error = exec_shell_imgact(imgp)) == 0) { + linux_emul_convpath(FIRST_THREAD_IN_PROC(imgp->proc), + imgp->interpreter_name, UIO_SYSSPACE, &rpath, 0); + if (rpath != NULL) { + len = strlen(rpath) + 1; + + if (len <= MAXSHELLCMDLEN) { + memcpy(imgp->interpreter_name, rpath, len); + } + free(rpath, M_TEMP); + } + } + } + return(error); +} + +/* + * Clear registers on exec + * XXX copied from ia32_signal.c. + */ +static void +exec_linux_setregs(td, entry, stack, ps_strings) + struct thread *td; + u_long entry; + u_long stack; + u_long ps_strings; +{ + struct trapframe *regs = td->td_frame; + struct pcb *pcb = td->td_pcb; + + critical_enter(); + wrmsr(MSR_FSBASE, 0); + wrmsr(MSR_KGSBASE, 0); /* User value while we're in the kernel */ + pcb->pcb_fsbase = 0; + pcb->pcb_gsbase = 0; + critical_exit(); + load_ds(_udatasel); + load_es(_udatasel); + load_fs(_udatasel); + load_gs(_udatasel); + pcb->pcb_ds = _udatasel; + pcb->pcb_es = _udatasel; + pcb->pcb_fs = _udatasel; + pcb->pcb_gs = _udatasel; + + bzero((char *)regs, sizeof(struct trapframe)); + regs->tf_rip = entry; + regs->tf_rsp = stack; + regs->tf_rflags = PSL_USER | (regs->tf_rflags & PSL_T); + regs->tf_ss = _udatasel; + regs->tf_cs = _ucode32sel; + regs->tf_rbx = ps_strings; + load_cr0(rcr0() | CR0_MP | CR0_TS); + fpstate_drop(td); + + /* Return via doreti so that we can change to a different %cs */ + pcb->pcb_flags |= PCB_FULLCTX; + td->td_retval[1] = 0; +} + +/* + * XXX copied from ia32_sysvec.c. + */ +static register_t * +linux_copyout_strings(struct image_params *imgp) +{ + int argc, envc; + u_int32_t *vectp; + char *stringp, *destp; + u_int32_t *stack_base; + struct linux32_ps_strings *arginfo; + int sigcodesz; + + /* + * Calculate string base and vector table pointers. + * Also deal with signal trampoline code for this exec type. + */ + arginfo = (struct linux32_ps_strings *)LINUX32_PS_STRINGS; + sigcodesz = *(imgp->proc->p_sysent->sv_szsigcode); + destp = (caddr_t)arginfo - sigcodesz - SPARE_USRSPACE - + roundup((ARG_MAX - imgp->args->stringspace), sizeof(char *)); + + /* + * install sigcode + */ + if (sigcodesz) + copyout(imgp->proc->p_sysent->sv_sigcode, + ((caddr_t)arginfo - sigcodesz), sigcodesz); + + /* + * If we have a valid auxargs ptr, prepare some room + * on the stack. + */ + if (imgp->auxargs) { + /* + * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for + * lower compatibility. + */ + imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size + : (AT_COUNT * 2); + /* + * The '+ 2' is for the null pointers at the end of each of + * the arg and env vector sets,and imgp->auxarg_size is room + * for argument of Runtime loader. + */ + vectp = (u_int32_t *) (destp - (imgp->args->argc + imgp->args->envc + 2 + + imgp->auxarg_size) * sizeof(u_int32_t)); + + } else + /* + * The '+ 2' is for the null pointers at the end of each of + * the arg and env vector sets + */ + vectp = (u_int32_t *) + (destp - (imgp->args->argc + imgp->args->envc + 2) * sizeof(u_int32_t)); + + /* + * vectp also becomes our initial stack base + */ + stack_base = vectp; + + stringp = imgp->args->begin_argv; + argc = imgp->args->argc; + envc = imgp->args->envc; + /* + * Copy out strings - arguments and environment. + */ + copyout(stringp, destp, ARG_MAX - imgp->args->stringspace); + + /* + * Fill in "ps_strings" struct for ps, w, etc. + */ + suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp); + suword32(&arginfo->ps_nargvstr, argc); + + /* + * Fill in argument portion of vector table. + */ + for (; argc > 0; --argc) { + suword32(vectp++, (u_int32_t)(intptr_t)destp); + while (*stringp++ != 0) + destp++; + destp++; + } + + /* a null vector table pointer separates the argp's from the envp's */ + suword32(vectp++, 0); + + suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp); + suword32(&arginfo->ps_nenvstr, envc); + + /* + * Fill in environment portion of vector table. + */ + for (; envc > 0; --envc) { + suword32(vectp++, (u_int32_t)(intptr_t)destp); + while (*stringp++ != 0) + destp++; + destp++; + } + + /* end of vector table is a null pointer */ + suword32(vectp, 0); + + return ((register_t *)stack_base); +} + +SYSCTL_NODE(_compat, OID_AUTO, linux32, CTLFLAG_RW, 0, + "32-bit Linux emulation"); + +static u_long linux32_maxdsiz = LINUX32_MAXDSIZ; +SYSCTL_ULONG(_compat_linux32, OID_AUTO, maxdsiz, CTLFLAG_RW, + &linux32_maxdsiz, 0, ""); +static u_long linux32_maxssiz = LINUX32_MAXSSIZ; +SYSCTL_ULONG(_compat_linux32, OID_AUTO, maxssiz, CTLFLAG_RW, + &linux32_maxssiz, 0, ""); +static u_long linux32_maxvmem = LINUX32_MAXVMEM; +SYSCTL_ULONG(_compat_linux32, OID_AUTO, maxvmem, CTLFLAG_RW, + &linux32_maxvmem, 0, ""); + +static void +linux32_fixlimit(struct rlimit *rl, int which) +{ + + switch (which) { + case RLIMIT_DATA: + if (linux32_maxdsiz != 0) { + if (rl->rlim_cur > linux32_maxdsiz) + rl->rlim_cur = linux32_maxdsiz; + if (rl->rlim_max > linux32_maxdsiz) + rl->rlim_max = linux32_maxdsiz; + } + break; + case RLIMIT_STACK: + if (linux32_maxssiz != 0) { + if (rl->rlim_cur > linux32_maxssiz) + rl->rlim_cur = linux32_maxssiz; + if (rl->rlim_max > linux32_maxssiz) + rl->rlim_max = linux32_maxssiz; + } + break; + case RLIMIT_VMEM: + if (linux32_maxvmem != 0) { + if (rl->rlim_cur > linux32_maxvmem) + rl->rlim_cur = linux32_maxvmem; + if (rl->rlim_max > linux32_maxvmem) + rl->rlim_max = linux32_maxvmem; + } + break; + } +} + +struct sysentvec elf_linux_sysvec = { + LINUX_SYS_MAXSYSCALL, + linux_sysent, + 0, + LINUX_SIGTBLSZ, + bsd_to_linux_signal, + ELAST + 1, + bsd_to_linux_errno, + translate_traps, + elf_linux_fixup, + linux_sendsig, + linux_sigcode, + &linux_szsigcode, + linux_prepsyscall, + "Linux ELF32", + elf32_coredump, + exec_linux_imgact_try, + LINUX_MINSIGSTKSZ, + PAGE_SIZE, + VM_MIN_ADDRESS, + LINUX32_USRSTACK, + LINUX32_USRSTACK, + LINUX32_PS_STRINGS, + VM_PROT_ALL, + linux_copyout_strings, + exec_linux_setregs, + linux32_fixlimit +}; + +static Elf32_Brandinfo linux_brand = { + ELFOSABI_LINUX, + EM_386, + "Linux", + "/compat/linux", + "/lib/ld-linux.so.1", + &elf_linux_sysvec, + NULL, + BI_CAN_EXEC_DYN, + }; + +static Elf32_Brandinfo linux_glibc2brand = { + ELFOSABI_LINUX, + EM_386, + "Linux", + "/compat/linux", + "/lib/ld-linux.so.2", + &elf_linux_sysvec, + NULL, + BI_CAN_EXEC_DYN, + }; + +Elf32_Brandinfo *linux_brandlist[] = { + &linux_brand, + &linux_glibc2brand, + NULL + }; + +static int +linux_elf_modevent(module_t mod, int type, void *data) +{ + Elf32_Brandinfo **brandinfo; + int error; + struct linux_ioctl_handler **lihp; + struct linux_device_handler **ldhp; + + error = 0; + + switch(type) { + case MOD_LOAD: + for (brandinfo = &linux_brandlist[0]; *brandinfo != NULL; + ++brandinfo) + if (elf32_insert_brand_entry(*brandinfo) < 0) + error = EINVAL; + if (error == 0) { + SET_FOREACH(lihp, linux_ioctl_handler_set) + linux_ioctl_register_handler(*lihp); + SET_FOREACH(ldhp, linux_device_handler_set) + linux_device_register_handler(*ldhp); + mtx_init(&emul_lock, "emuldata lock", NULL, MTX_DEF); + sx_init(&emul_shared_lock, "emuldata->shared lock"); + LIST_INIT(&futex_list); + sx_init(&futex_sx, "futex protection lock"); + linux_exit_tag = EVENTHANDLER_REGISTER(process_exit, linux_proc_exit, + NULL, 1000); + linux_schedtail_tag = EVENTHANDLER_REGISTER(schedtail, linux_schedtail, + NULL, 1000); + linux_exec_tag = EVENTHANDLER_REGISTER(process_exec, linux_proc_exec, + NULL, 1000); + if (bootverbose) + printf("Linux ELF exec handler installed\n"); + } else + printf("cannot insert Linux ELF brand handler\n"); + break; + case MOD_UNLOAD: + for (brandinfo = &linux_brandlist[0]; *brandinfo != NULL; + ++brandinfo) + if (elf32_brand_inuse(*brandinfo)) + error = EBUSY; + if (error == 0) { + for (brandinfo = &linux_brandlist[0]; + *brandinfo != NULL; ++brandinfo) + if (elf32_remove_brand_entry(*brandinfo) < 0) + error = EINVAL; + } + if (error == 0) { + SET_FOREACH(lihp, linux_ioctl_handler_set) + linux_ioctl_unregister_handler(*lihp); + SET_FOREACH(ldhp, linux_device_handler_set) + linux_device_unregister_handler(*ldhp); + mtx_destroy(&emul_lock); + sx_destroy(&emul_shared_lock); + sx_destroy(&futex_sx); + EVENTHANDLER_DEREGISTER(process_exit, linux_exit_tag); + EVENTHANDLER_DEREGISTER(schedtail, linux_schedtail_tag); + EVENTHANDLER_DEREGISTER(process_exec, linux_exec_tag); + if (bootverbose) + printf("Linux ELF exec handler removed\n"); + } else + printf("Could not deinstall ELF interpreter entry\n"); + break; + default: + return EOPNOTSUPP; + } + return error; +} + +static moduledata_t linux_elf_mod = { + "linuxelf", + linux_elf_modevent, + 0 +}; + +DECLARE_MODULE(linuxelf, linux_elf_mod, SI_SUB_EXEC, SI_ORDER_ANY); diff --git a/sys/emulation/linux/amd64/syscalls.conf b/sys/emulation/linux/amd64/syscalls.conf new file mode 100644 index 0000000000..cbd2e4c419 --- /dev/null +++ b/sys/emulation/linux/amd64/syscalls.conf @@ -0,0 +1,12 @@ +# $FreeBSD: src/sys/amd64/linux32/syscalls.conf,v 1.2 2006/08/15 17:25:54 jhb Exp $ +# $DragonFly$ +sysnames="/dev/null" +sysproto="linux32_proto.h" +sysproto_h=_LINUX_SYSPROTO_H_ +syshdr="linux32_syscall.h" +syssw="linux32_sysent.c" +sysmk="/dev/null" +syscallprefix="LINUX_SYS_" +switchname="linux_sysent" +namesname="linux_syscallnames" +systrace="/dev/null" diff --git a/sys/emulation/linux/amd64/syscalls.master b/sys/emulation/linux/amd64/syscalls.master new file mode 100644 index 0000000000..d5c99a3538 --- /dev/null +++ b/sys/emulation/linux/amd64/syscalls.master @@ -0,0 +1,483 @@ + $FreeBSD: src/sys/amd64/linux32/syscalls.master,v 1.28 2007/03/30 00:06:21 jkim Exp $ + $DragonFly$ + +; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 +; System call name/number master file (or rather, slave, from LINUX). +; Processed to create linux_sysent.c, linux_proto.h and linux_syscall.h. + +; Columns: number audit type nargs name alt{name,tag,rtyp}/comments +; number system call number, must be in order +; audit the audit event associated with the system call +; A value of AUE_NULL means no auditing, but it also means that +; there is no audit event for the call at this time. For the +; case where the event exists, but we don't want auditing, the +; event should be #defined to AUE_NULL in audit_kevents.h. +; type one of STD, OBSOL, UNIMPL +; name psuedo-prototype of syscall routine +; If one of the following alts is different, then all appear: +; altname name of system call if different +; alttag name of args struct tag if different from [o]`name'"_args" +; altrtyp return type if not int (bogus - syscalls always return int) +; for UNIMPL/OBSOL, name continues with comments + +; types: +; STD always included +; OBSOL obsolete, not included in system, only specifies name +; UNIMPL not implemented, placeholder only + +#include "opt_compat.h" +#include +#include +#include +#include +#include +#include + +; Isn't pretty, but there seems to be no other way to trap nosys +#define nosys linux_nosys + +; #ifdef's, etc. may be included, and are copied to the output files. + +0 AUE_NULL UNIMPL setup +1 AUE_EXIT NOPROTO { void sys_exit(int rval); } exit \ + sys_exit_args void +2 AUE_FORK STD { int linux_fork(void); } +3 AUE_NULL NOPROTO { int read(int fd, char *buf, \ + u_int nbyte); } +4 AUE_NULL NOPROTO { int write(int fd, char *buf, \ + u_int nbyte); } +5 AUE_OPEN_RWTC STD { int linux_open(char *path, l_int flags, \ + l_int mode); } +6 AUE_CLOSE NOPROTO { int close(int fd); } +7 AUE_WAIT4 STD { int linux_waitpid(l_pid_t pid, \ + l_int *status, l_int options); } +8 AUE_CREAT STD { int linux_creat(char *path, \ + l_int mode); } +9 AUE_LINK STD { int linux_link(char *path, char *to); } +10 AUE_UNLINK STD { int linux_unlink(char *path); } +11 AUE_EXECVE STD { int linux_execve(char *path, char **argp, \ + char **envp); } +12 AUE_CHDIR STD { int linux_chdir(char *path); } +13 AUE_NULL STD { int linux_time(l_time_t *tm); } +14 AUE_MKNOD STD { int linux_mknod(char *path, l_int mode, \ + l_dev_t dev); } +15 AUE_CHMOD STD { int linux_chmod(char *path, \ + l_mode_t mode); } +16 AUE_LCHOWN STD { int linux_lchown16(char *path, \ + l_uid16_t uid, l_gid16_t gid); } +17 AUE_NULL UNIMPL break +18 AUE_STAT STD { int linux_stat(char *path, \ + struct linux_stat *up); } +19 AUE_LSEEK STD { int linux_lseek(l_uint fdes, l_off_t off, \ + l_int whence); } +20 AUE_GETPID STD { int linux_getpid(void); } +21 AUE_MOUNT STD { int linux_mount(char *specialfile, \ + char *dir, char *filesystemtype, \ + l_ulong rwflag, void *data); } +22 AUE_UMOUNT STD { int linux_oldumount(char *path); } +23 AUE_SETUID STD { int linux_setuid16(l_uid16_t uid); } +24 AUE_GETUID STD { int linux_getuid16(void); } +25 AUE_SETTIMEOFDAY STD { int linux_stime(void); } +26 AUE_PTRACE STD { int linux_ptrace(l_long req, l_long pid, \ + l_long addr, l_long data); } +27 AUE_NULL STD { int linux_alarm(l_uint secs); } +28 AUE_FSTAT UNIMPL fstat +29 AUE_NULL STD { int linux_pause(void); } +30 AUE_UTIME STD { int linux_utime(char *fname, \ + struct l_utimbuf *times); } +31 AUE_NULL UNIMPL stty +32 AUE_NULL UNIMPL gtty +33 AUE_ACCESS STD { int linux_access(char *path, l_int flags); } +34 AUE_NICE STD { int linux_nice(l_int inc); } +35 AUE_NULL UNIMPL ftime +36 AUE_SYNC NOPROTO { int sync(void); } +37 AUE_KILL STD { int linux_kill(l_int pid, l_int signum); } +38 AUE_RENAME STD { int linux_rename(char *from, char *to); } +39 AUE_MKDIR STD { int linux_mkdir(char *path, l_int mode); } +40 AUE_RMDIR STD { int linux_rmdir(char *path); } +41 AUE_DUP NOPROTO { int dup(u_int fd); } +42 AUE_PIPE STD { int linux_pipe(l_ulong *pipefds); } +43 AUE_NULL STD { int linux_times(struct l_times_argv *buf); } +44 AUE_NULL UNIMPL prof +45 AUE_NULL STD { int linux_brk(l_ulong dsend); } +46 AUE_SETGID STD { int linux_setgid16(l_gid16_t gid); } +47 AUE_GETGID STD { int linux_getgid16(void); } +48 AUE_NULL STD { int linux_signal(l_int sig, \ + l_handler_t handler); } +49 AUE_GETEUID STD { int linux_geteuid16(void); } +50 AUE_GETEGID STD { int linux_getegid16(void); } +51 AUE_ACCT NOPROTO { int acct(char *path); } +52 AUE_UMOUNT STD { int linux_umount(char *path, l_int flags); } +53 AUE_NULL UNIMPL lock +54 AUE_IOCTL STD { int linux_ioctl(l_uint fd, l_uint cmd, \ + uintptr_t arg); } +55 AUE_FCNTL STD { int linux_fcntl(l_uint fd, l_uint cmd, \ + uintptr_t arg); } +56 AUE_NULL UNIMPL mpx +57 AUE_SETPGRP NOPROTO { int setpgid(int pid, int pgid); } +58 AUE_NULL UNIMPL ulimit +59 AUE_NULL STD { int linux_olduname(void); } +60 AUE_UMASK NOPROTO { int umask(int newmask); } +61 AUE_CHROOT NOPROTO { int chroot(char *path); } +62 AUE_NULL STD { int linux_ustat(l_dev_t dev, \ + struct l_ustat *ubuf); } +63 AUE_DUP2 NOPROTO { int dup2(u_int from, u_int to); } +64 AUE_GETPPID STD { int linux_getppid(void); } +65 AUE_GETPGRP NOPROTO { int getpgrp(void); } +66 AUE_SETSID NOPROTO { int setsid(void); } +67 AUE_NULL STD { int linux_sigaction(l_int sig, \ + l_osigaction_t *nsa, \ + l_osigaction_t *osa); } +68 AUE_NULL STD { int linux_sgetmask(void); } +69 AUE_NULL STD { int linux_ssetmask(l_osigset_t mask); } +70 AUE_SETREUID STD { int linux_setreuid16(l_uid16_t ruid, \ + l_uid16_t euid); } +71 AUE_SETREGID STD { int linux_setregid16(l_gid16_t rgid, \ + l_gid16_t egid); } +72 AUE_NULL STD { int linux_sigsuspend(l_int hist0, \ + l_int hist1, l_osigset_t mask); } +73 AUE_NULL STD { int linux_sigpending(l_osigset_t *mask); } +74 AUE_SYSCTL STD { int linux_sethostname(char *hostname, \ + u_int len); } +75 AUE_SETRLIMIT STD { int linux_setrlimit(l_uint resource, \ + struct l_rlimit *rlim); } +76 AUE_GETRLIMIT STD { int linux_old_getrlimit(l_uint resource, \ + struct l_rlimit *rlim); } +77 AUE_GETRUSAGE STD { int linux_getrusage(int who, \ + struct l_rusage *rusage); } +78 AUE_NULL STD { int linux_gettimeofday( \ + struct l_timeval *tp, \ + struct timezone *tzp); } +79 AUE_SETTIMEOFDAY STD { int linux_settimeofday( \ + struct l_timeval *tp, \ + struct timezone *tzp); } +80 AUE_GETGROUPS STD { int linux_getgroups16(l_uint gidsetsize, \ + l_gid16_t *gidset); } +81 AUE_SETGROUPS STD { int linux_setgroups16(l_uint gidsetsize, \ + l_gid16_t *gidset); } +82 AUE_SELECT STD { int linux_old_select( \ + struct l_old_select_argv *ptr); } +83 AUE_SYMLINK STD { int linux_symlink(char *path, char *to); } +84 AUE_LSTAT STD { int linux_lstat(char *path, struct linux_lstat *up); } +85 AUE_READLINK STD { int linux_readlink(char *name, char *buf, \ + l_int count); } +86 AUE_USELIB UNIMPL linux_uselib +87 AUE_SWAPON NOPROTO { int swapon(char *name); } +88 AUE_REBOOT STD { int linux_reboot(l_int magic1, \ + l_int magic2, l_uint cmd, void *arg); } +89 AUE_GETDIRENTRIES STD { int linux_readdir(l_uint fd, \ + struct l_dirent *dent, l_uint count); } +90 AUE_MMAP STD { int linux_mmap(struct l_mmap_argv *ptr); } +91 AUE_MUNMAP NOPROTO { int munmap(caddr_t addr, int len); } +92 AUE_TRUNCATE STD { int linux_truncate(char *path, \ + l_ulong length); } +93 AUE_FTRUNCATE STD { int linux_ftruncate(int fd, long length); } +94 AUE_FCHMOD NOPROTO { int fchmod(int fd, int mode); } +95 AUE_FCHOWN NOPROTO { int fchown(int fd, int uid, int gid); } +96 AUE_GETPRIORITY STD { int linux_getpriority(int which, int who); } +97 AUE_SETPRIORITY NOPROTO { int setpriority(int which, int who, \ + int prio); } +98 AUE_PROFILE UNIMPL profil +99 AUE_STATFS STD { int linux_statfs(char *path, \ + struct l_statfs_buf *buf); } +100 AUE_FSTATFS STD { int linux_fstatfs(l_uint fd, \ + struct l_statfs_buf *buf); } +101 AUE_NULL UNIMPL ioperm +102 AUE_NULL STD { int linux_socketcall(l_int what, \ + l_ulong args); } +103 AUE_NULL STD { int linux_syslog(l_int type, char *buf, \ + l_int len); } +104 AUE_SETITIMER STD { int linux_setitimer(l_int which, \ + struct l_itimerval *itv, \ + struct l_itimerval *oitv); } +105 AUE_GETITIMER STD { int linux_getitimer(l_int which, \ + struct l_itimerval *itv); } +106 AUE_STAT STD { int linux_newstat(char *path, \ + struct l_newstat *buf); } +107 AUE_LSTAT STD { int linux_newlstat(char *path, \ + struct l_newstat *buf); } +108 AUE_FSTAT STD { int linux_newfstat(l_uint fd, \ + struct l_newstat *buf); } +109 AUE_NULL STD { int linux_uname(void); } +110 AUE_NULL STD { int linux_iopl(l_ulong level); } +111 AUE_NULL STD { int linux_vhangup(void); } +112 AUE_NULL UNIMPL idle +113 AUE_NULL UNIMPL vm86old +114 AUE_WAIT4 STD { int linux_wait4(l_pid_t pid, \ + l_uint *status, l_int options, \ + struct l_rusage *rusage); } +115 AUE_SWAPOFF STD { int linux_swapoff(void); } +116 AUE_NULL STD { int linux_sysinfo(struct l_sysinfo *info); } +117 AUE_NULL STD { int linux_ipc(l_uint what, l_int arg1, \ + l_int arg2, l_int arg3, void *ptr, \ + l_long arg5); } +118 AUE_FSYNC NOPROTO { int fsync(int fd); } +119 AUE_SIGRETURN STD { int linux_sigreturn( \ + struct l_sigframe *sfp); } +; linux uses some strange calling convention here so we have to use the dummy arg +120 AUE_RFORK STD { int linux_clone(l_int flags, void *stack, \ + void *parent_tidptr, int dummy, void * child_tidptr); } +121 AUE_SYSCTL NOPROTO { int setdomainname(char *name, \ + int len); } +122 AUE_NULL STD { int linux_newuname( \ + struct l_new_utsname *buf); } +123 AUE_NULL UNIMPL modify_ldt +124 AUE_ADJTIME STD { int linux_adjtimex(void); } +125 AUE_MPROTECT STD { int linux_mprotect(caddr_t addr, int len, \ + int prot); } +126 AUE_SIGPROCMASK STD { int linux_sigprocmask(l_int how, \ + l_osigset_t *mask, l_osigset_t *omask); } +127 AUE_NULL STD { int linux_create_module(void); } +128 AUE_NULL STD { int linux_init_module(void); } +129 AUE_NULL STD { int linux_delete_module(void); } +130 AUE_NULL STD { int linux_get_kernel_syms(void); } +131 AUE_QUOTACTL STD { int linux_quotactl(void); } +132 AUE_GETPGID NOPROTO { int getpgid(int pid); } +133 AUE_FCHDIR NOPROTO { int fchdir(int fd); } +134 AUE_BDFLUSH STD { int linux_bdflush(void); } +135 AUE_NULL STD { int linux_sysfs(l_int option, \ + l_ulong arg1, l_ulong arg2); } +136 AUE_PERSONALITY STD { int linux_personality(l_ulong per); } +137 AUE_NULL UNIMPL afs_syscall +138 AUE_SETFSUID STD { int linux_setfsuid16(l_uid16_t uid); } +139 AUE_SETFSGID STD { int linux_setfsgid16(l_gid16_t gid); } +140 AUE_LSEEK STD { int linux_llseek(l_int fd, l_ulong ohigh, \ + l_ulong olow, l_loff_t *res, \ + l_uint whence); } +141 AUE_GETDIRENTRIES STD { int linux_getdents(l_uint fd, void *dent, \ + l_uint count); } +142 AUE_SELECT STD { int linux_select(l_int nfds, \ + l_fd_set *readfds, l_fd_set *writefds, \ + l_fd_set *exceptfds, \ + struct l_timeval *timeout); } +143 AUE_FLOCK NOPROTO { int flock(int fd, int how); } +144 AUE_MSYNC STD { int linux_msync(l_ulong addr, \ + l_size_t len, l_int fl); } +145 AUE_READV STD { int linux_readv(int fd, struct iovec32 *iovp, \ + u_int iovcnt); } +146 AUE_WRITEV STD { int linux_writev(int fd, struct iovec32 *iovp, \ + u_int iovcnt); } +147 AUE_GETSID STD { int linux_getsid(l_pid_t pid); } +148 AUE_NULL STD { int linux_fdatasync(l_uint fd); } +149 AUE_SYSCTL STD { int linux_sysctl( \ + struct l___sysctl_args *args); } +150 AUE_MLOCK NOPROTO { int mlock(const void *addr, size_t len); } +151 AUE_MUNLOCK NOPROTO { int munlock(const void *addr, size_t len); } +152 AUE_MLOCKALL NOPROTO { int mlockall(int how); } +153 AUE_MUNLOCKALL NOPROTO { int munlockall(void); } +154 AUE_SCHED_SETPARAM NOPROTO { int sched_setparam(pid_t pid, \ + const struct sched_param *param); } +155 AUE_SCHED_GETPARAM NOPROTO { int sched_getparam(pid_t pid, \ + struct sched_param *param); } +156 AUE_SCHED_SETSCHEDULER STD { int linux_sched_setscheduler( \ + l_pid_t pid, l_int policy, \ + struct l_sched_param *param); } +157 AUE_SCHED_GETSCHEDULER STD { int linux_sched_getscheduler( \ + l_pid_t pid); } +158 AUE_NULL NOPROTO { int sched_yield(void); } +159 AUE_SCHED_GET_PRIORITY_MAX STD { int linux_sched_get_priority_max( \ + l_int policy); } +160 AUE_SCHED_GET_PRIORITY_MIN STD { int linux_sched_get_priority_min( \ + l_int policy); } +161 AUE_SCHED_RR_GET_INTERVAL STD { int linux_sched_rr_get_interval(l_pid_t pid, \ + struct l_timespec *interval); } +162 AUE_NULL STD { int linux_nanosleep( \ + const struct l_timespec *rqtp, \ + struct l_timespec *rmtp); } +163 AUE_NULL STD { int linux_mremap(l_ulong addr, \ + l_ulong old_len, l_ulong new_len, \ + l_ulong flags, l_ulong new_addr); } +164 AUE_SETRESUID STD { int linux_setresuid16(l_uid16_t ruid, \ + l_uid16_t euid, l_uid16_t suid); } +165 AUE_GETRESUID STD { int linux_getresuid16(l_uid16_t *ruid, \ + l_uid16_t *euid, l_uid16_t *suid); } +166 AUE_NULL UNIMPL vm86 +167 AUE_NULL STD { int linux_query_module(void); } +168 AUE_POLL NOPROTO { int poll(struct pollfd*, \ + unsigned int nfds, int timeout); } +169 AUE_NULL STD { int linux_nfsservctl(void); } +170 AUE_SETRESGID STD { int linux_setresgid16(l_gid16_t rgid, \ + l_gid16_t egid, l_gid16_t sgid); } +171 AUE_GETRESGID STD { int linux_getresgid16(l_gid16_t *rgid, \ + l_gid16_t *egid, l_gid16_t *sgid); } +172 AUE_PRCTL STD { int linux_prctl(l_int option, l_int arg2, l_int arg3, \ + l_int arg4, l_int arg5); } +173 AUE_NULL STD { int linux_rt_sigreturn( \ + struct l_ucontext *ucp); } +174 AUE_NULL STD { int linux_rt_sigaction(l_int sig, \ + l_sigaction_t *act, l_sigaction_t *oact, \ + l_size_t sigsetsize); } +175 AUE_NULL STD { int linux_rt_sigprocmask(l_int how, \ + l_sigset_t *mask, l_sigset_t *omask, \ + l_size_t sigsetsize); } +176 AUE_NULL STD { int linux_rt_sigpending(l_sigset_t *set, \ + l_size_t sigsetsize); } +177 AUE_NULL STD { int linux_rt_sigtimedwait(l_sigset_t *mask, \ + l_siginfo_t *ptr, \ + struct l_timeval *timeout, \ + l_size_t sigsetsize); } +178 AUE_NULL STD { int linux_rt_sigqueueinfo(void); } +179 AUE_NULL STD { int linux_rt_sigsuspend( \ + l_sigset_t *newset, \ + l_size_t sigsetsize); } +180 AUE_PREAD STD { int linux_pread(l_uint fd, char *buf, \ + l_size_t nbyte, l_loff_t offset); } +181 AUE_PWRITE STD { int linux_pwrite(l_uint fd, char *buf, \ + l_size_t nbyte, l_loff_t offset); } +182 AUE_CHOWN STD { int linux_chown16(char *path, \ + l_uid16_t uid, l_gid16_t gid); } +183 AUE_GETCWD STD { int linux_getcwd(char *buf, \ + l_ulong bufsize); } +184 AUE_CAPGET STD { int linux_capget(void); } +185 AUE_CAPSET STD { int linux_capset(void); } +186 AUE_NULL STD { int linux_sigaltstack(l_stack_t *uss, \ + l_stack_t *uoss); } +187 AUE_SENDFILE STD { int linux_sendfile(void); } +188 AUE_GETPMSG UNIMPL getpmsg +189 AUE_PUTPMSG UNIMPL putpmsg +190 AUE_VFORK STD { int linux_vfork(void); } +191 AUE_GETRLIMIT STD { int linux_getrlimit(l_uint resource, \ + struct l_rlimit *rlim); } +192 AUE_MMAP STD { int linux_mmap2(l_ulong addr, l_ulong len, \ + l_ulong prot, l_ulong flags, l_ulong fd, \ + l_ulong pgoff); } +193 AUE_TRUNCATE STD { int linux_truncate64(char *path, \ + l_loff_t length); } +194 AUE_FTRUNCATE STD { int linux_ftruncate64(l_uint fd, \ + l_loff_t length); } +195 AUE_STAT STD { int linux_stat64(char *filename, \ + struct l_stat64 *statbuf, l_long flags); } +196 AUE_LSTAT STD { int linux_lstat64(char *filename, \ + struct l_stat64 *statbuf, l_long flags); } +197 AUE_FSTAT STD { int linux_fstat64(l_ulong fd, \ + struct l_stat64 *statbuf, l_long flags); } +198 AUE_LCHOWN STD { int linux_lchown(char *path, l_uid_t uid, \ + l_gid_t gid); } +199 AUE_GETUID STD { int linux_getuid(void); } +200 AUE_GETGID STD { int linux_getgid(void); } +201 AUE_GETEUID NOPROTO { int geteuid(void); } +202 AUE_GETEGID NOPROTO { int getegid(void); } +203 AUE_SETREUID NOPROTO { int setreuid(uid_t ruid, uid_t euid); } +204 AUE_SETREGID NOPROTO { int setregid(gid_t rgid, gid_t egid); } +205 AUE_GETGROUPS STD { int linux_getgroups(l_int gidsetsize, \ + l_gid_t *grouplist); } +206 AUE_SETGROUPS STD { int linux_setgroups(l_int gidsetsize, \ + l_gid_t *grouplist); } +207 AUE_FCHOWN NODEF fchown fchown fchown_args int +208 AUE_SETRESUID NOPROTO { int setresuid(uid_t ruid, uid_t euid, \ + uid_t suid); } +209 AUE_GETRESUID NOPROTO { int getresuid(uid_t *ruid, uid_t *euid, \ + uid_t *suid); } +210 AUE_SETRESGID NOPROTO { int setresgid(gid_t rgid, gid_t egid, \ + gid_t sgid); } +211 AUE_GETRESGID NOPROTO { int getresgid(gid_t *rgid, gid_t *egid, \ + gid_t *sgid); } +212 AUE_CHOWN STD { int linux_chown(char *path, l_uid_t uid, \ + l_gid_t gid); } +213 AUE_SETUID NOPROTO { int setuid(uid_t uid); } +214 AUE_SETGID NOPROTO { int setgid(gid_t gid); } +215 AUE_SETFSUID STD { int linux_setfsuid(l_uid_t uid); } +216 AUE_SETFSGID STD { int linux_setfsgid(l_gid_t gid); } +217 AUE_PIVOT_ROOT STD { int linux_pivot_root(char *new_root, \ + char *put_old); } +218 AUE_MINCORE STD { int linux_mincore(l_ulong start, \ + l_size_t len, u_char *vec); } +219 AUE_MADVISE NOPROTO { int madvise(void *addr, size_t len, \ + int behav); } +220 AUE_GETDIRENTRIES STD { int linux_getdents64(l_uint fd, \ + void *dirent, l_uint count); } +221 AUE_FCNTL STD { int linux_fcntl64(l_uint fd, l_uint cmd, \ + uintptr_t arg); } +222 AUE_NULL UNIMPL +223 AUE_NULL UNIMPL +224 AUE_NULL STD { long linux_gettid(void); } +225 AUE_NULL UNIMPL linux_readahead +226 AUE_NULL STD { int linux_setxattr(void); } +227 AUE_NULL STD { int linux_lsetxattr(void); } +228 AUE_NULL STD { int linux_fsetxattr(void); } +229 AUE_NULL STD { int linux_getxattr(void); } +230 AUE_NULL STD { int linux_lgetxattr(void); } +231 AUE_NULL STD { int linux_fgetxattr(void); } +232 AUE_NULL STD { int linux_listxattr(void); } +233 AUE_NULL STD { int linux_llistxattr(void); } +234 AUE_NULL STD { int linux_flistxattr(void); } +235 AUE_NULL STD { int linux_removexattr(void); } +236 AUE_NULL STD { int linux_lremovexattr(void); } +237 AUE_NULL STD { int linux_fremovexattr(void); } +238 AUE_NULL STD { int linux_tkill(int tid, int sig); } +239 AUE_SENDFILE UNIMPL linux_sendfile64 +240 AUE_NULL STD { int linux_sys_futex(void *uaddr, int op, int val, \ + struct l_timespec *timeout, void *uaddr2, int val3); } +241 AUE_NULL UNIMPL linux_sched_setaffinity +242 AUE_NULL UNIMPL linux_sched_getaffinity +243 AUE_NULL STD { int linux_set_thread_area(struct l_user_desc *desc); } +244 AUE_NULL UNIMPL linux_get_thread_area +245 AUE_NULL UNIMPL linux_io_setup +246 AUE_NULL UNIMPL linux_io_destroy +247 AUE_NULL UNIMPL linux_io_getevents +248 AUE_NULL UNIMPL inux_io_submit +249 AUE_NULL UNIMPL linux_io_cancel +250 AUE_NULL STD { int linux_fadvise64(void); } +251 AUE_NULL UNIMPL +252 AUE_EXIT STD { int linux_exit_group(int error_code); } +253 AUE_NULL STD { int linux_lookup_dcookie(void); } +254 AUE_NULL STD { int linux_epoll_create(void); } +255 AUE_NULL STD { int linux_epoll_ctl(void); } +256 AUE_NULL STD { int linux_epoll_wait(void); } +257 AUE_NULL STD { int linux_remap_file_pages(void); } +258 AUE_NULL STD { int linux_set_tid_address(int *tidptr); } +259 AUE_NULL STD { int linux_timer_create(void); } +260 AUE_NULL STD { int linux_timer_settime(void); } +261 AUE_NULL STD { int linux_timer_gettime(void); } +262 AUE_NULL STD { int linux_timer_getoverrun(void); } +263 AUE_NULL STD { int linux_timer_delete(void); } +264 AUE_CLOCK_SETTIME STD { int linux_clock_settime(clockid_t which, struct l_timespec *tp); } +265 AUE_NULL STD { int linux_clock_gettime(clockid_t which, struct l_timespec *tp); } +266 AUE_NULL STD { int linux_clock_getres(clockid_t which, struct l_timespec *tp); } +267 AUE_NULL STD { int linux_clock_nanosleep(clockid_t which, int flags, \ + struct l_timespec *rqtp, struct l_timespec *rmtp); } +268 AUE_STATFS STD { int linux_statfs64(char *path, struct l_statfs64_buf *buf); } +269 AUE_FSTATFS STD { int linux_fstatfs64(void); } +270 AUE_NULL STD { int linux_tgkill(int tgid, int pid, int sig); } +271 AUE_UTIMES STD { int linux_utimes(char *fname, \ + struct l_timeval *tptr); } +272 AUE_NULL STD { int linux_fadvise64_64(void); } +273 AUE_NULL UNIMPL +274 AUE_NULL STD { int linux_mbind(void); } +275 AUE_NULL STD { int linux_get_mempolicy(void); } +276 AUE_NULL STD { int linux_set_mempolicy(void); } +277 AUE_NULL STD { int linux_mq_open(void); } +278 AUE_NULL STD { int linux_mq_unlink(void); } +279 AUE_NULL STD { int linux_mq_timedsend(void); } +280 AUE_NULL STD { int linux_mq_timedreceive(void); } +281 AUE_NULL STD { int linux_mq_notify(void); } +282 AUE_NULL STD { int linux_mq_getsetattr(void); } +283 AUE_NULL STD { int linux_kexec_load(void); } +284 AUE_NULL STD { int linux_waitid(void); } +285 AUE_NULL UNIMPL +286 AUE_NULL STD { int linux_add_key(void); } +287 AUE_NULL STD { int linux_request_key(void); } +288 AUE_NULL STD { int linux_keyctl(void); } +289 AUE_NULL STD { int linux_ioprio_set(void); } +290 AUE_NULL STD { int linux_ioprio_get(void); } +291 AUE_NULL STD { int linux_inotify_init(void); } +292 AUE_NULL STD { int linux_inotify_add_watch(void); } +293 AUE_NULL STD { int linux_inotify_rm_watch(void); } +294 AUE_NULL STD { int linux_migrate_pages(void); } +295 AUE_OPEN_RWTC STD { int linux_openat(l_int dfd, char *filename, \ + l_int flags, l_int mode); } +296 AUE_NULL STD { int linux_mkdirat(void); } +297 AUE_NULL STD { int linux_mknodat(void); } +298 AUE_NULL STD { int linux_fchownat(void); } +299 AUE_NULL STD { int linux_futimesat(void); } +300 AUE_NULL STD { int linux_fstatat64(void); } +301 AUE_NULL STD { int linux_unlinkat(void); } +302 AUE_NULL STD { int linux_renameat(void); } +303 AUE_NULL STD { int linux_linkat(void); } +304 AUE_NULL STD { int linux_symlinkat(void); } +305 AUE_NULL STD { int linux_readlinkat(void); } +306 AUE_NULL STD { int linux_fchmodat(void); } +307 AUE_NULL STD { int linux_faccessat(void); } +308 AUE_NULL STD { int linux_pselect6(void); } +309 AUE_NULL STD { int linux_ppoll(void); } +310 AUE_NULL STD { int linux_unshare(void); } -- 2.11.4.GIT