summaryrefslogtreecommitdiffstats
path: root/sys/alpha/linux
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1996-03-02 19:38:20 +0000
committerpeter <peter@FreeBSD.org>1996-03-02 19:38:20 +0000
commit8465726bdae0892d85c26b32cd01d2f6936303ef (patch)
tree83b4d342a731e2a76c19f214d574f24753abe420 /sys/alpha/linux
parent8283a18c8bf4ad6c988d73b3290e9d4b4a743ae3 (diff)
downloadFreeBSD-src-8465726bdae0892d85c26b32cd01d2f6936303ef.zip
FreeBSD-src-8465726bdae0892d85c26b32cd01d2f6936303ef.tar.gz
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now working, at least on my machine. (whew! :-) I'm uncomfortable with the size of this commit, but it's too inter-dependant to easily seperate out. The main changes: COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386 machine dependent section into the linux emulator itself. The int 0x80 syscall code was almost identical to the lcall 7,0 code and a minor tweak allows them to both be used with the same C code. All kernels can now just modload the lkm and it'll DTRT without having to rebuild the kernel first. Like IBCS2, you can statically compile it in with "options LINUX". A pile of new syscalls implemented, including getdents(), llseek(), readv(), writev(), msync(), personality(). The Linux-ELF libraries want to use some of these. linux_select() now obeys Linux semantics, ie: returns the time remaining of the timeout value rather than leaving it the original value. Quite a few bugs removed, including incorrect arguments being used in syscalls.. eg: mixups between passing the sigset as an int, vs passing it as a pointer and doing a copyin(), missing return values, unhandled cases, SIOC* ioctls, etc. The build for the code has changed. i386/conf/files now knows how to build linux_genassym and generate linux_assym.h on the fly. Supporting changes elsewhere in the kernel: The user-mode signal trampoline has moved from the U area to immediately below the top of the stack (below PS_STRINGS). This allows the different binary emulations to have their own signal trampoline code (which gets rid of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so that the emulator can provide the exact "struct sigcontext *" argument to the program's signal handlers. The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which have the same values as the re-used SA_DISABLE and SA_ONSTACK which are intended for sigaction only. This enables the support of a SA_RESETHAND flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal semantics where the signal handler is reset when it's triggered. makesyscalls.sh no longer appends the struct sysentvec on the end of the generated init_sysent.c code. It's a lot saner to have it in a seperate file rather than trying to update the structure inside the awk script. :-) At exec time, the dozen bytes or so of signal trampoline code are copied to the top of the user's stack, rather than obtaining the trampoline code the old way by getting a clone of the parent's user area. This allows Linux and native binaries to freely exec each other without getting trampolines mixed up.
Diffstat (limited to 'sys/alpha/linux')
-rw-r--r--sys/alpha/linux/linux.h62
-rw-r--r--sys/alpha/linux/linux_dummy.c105
-rw-r--r--sys/alpha/linux/linux_genassym.c22
-rw-r--r--sys/alpha/linux/linux_sysvec.c358
4 files changed, 480 insertions, 67 deletions
diff --git a/sys/alpha/linux/linux.h b/sys/alpha/linux/linux.h
index c0fbc0a..f6bab97 100644
--- a/sys/alpha/linux/linux.h
+++ b/sys/alpha/linux/linux.h
@@ -25,7 +25,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: linux.h,v 1.3 1995/12/29 22:12:10 sos Exp $
+ * $Id: linux.h,v 1.4 1996/01/30 22:56:29 mpp Exp $
*/
#ifndef _I386_LINUX_LINUX_H_
@@ -55,9 +55,56 @@ typedef struct {
} linux_sigaction_t;
typedef int linux_key_t;
+/*
+ * The Linux sigcontext, pretty much a standard 386 trapframe.
+ */
+
+struct linux_sigcontext {
+ int sc_gs;
+ int sc_fs;
+ int sc_es;
+ int sc_ds;
+ int sc_edi;
+ int sc_esi;
+ int sc_ebp;
+ int sc_esp;
+ int sc_ebx;
+ int sc_edx;
+ int sc_ecx;
+ int sc_eax;
+ int sc_trapno;
+ int sc_err;
+ int sc_eip;
+ int sc_cs;
+ int sc_eflags;
+ int sc_esp_at_signal;
+ int sc_ss;
+ int sc_387;
+ int sc_mask;
+ int sc_cr2;
+};
+
+/*
+ * 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 linux_sigframe {
+ int sf_sig;
+ struct linux_sigcontext sf_sc;
+ sig_t sf_handler;
+};
+
extern int bsd_to_linux_signal[];
extern int linux_to_bsd_signal[];
+extern struct sysentvec linux_sysvec;
+
+struct image_params;
+int linux_fixup __P((int **stack_base, struct image_params *iparams));
+
/* misc defines */
#define LINUX_NAME_MAX 255
@@ -421,9 +468,14 @@ extern int linux_to_bsd_signal[];
#define LINUX_SNDCTL_DSP_GETISPACE 0x500D
#define LINUX_SNDCTL_DSP_NONBLOCK 0x500E
-#ifdef KERNEL
-caddr_t ua_alloc_init __P((int len));
-caddr_t ua_alloc __P((int len));
-#endif
+/* Socket system defines */
+#define LINUX_SIOCGIFCONF 0x8912
+#define LINUX_SIOCGIFFLAGS 0x8913
+#define LINUX_SIOCGIFADDR 0x8915
+#define LINUX_SIOCGIFDSTADDR 0x8917
+#define LINUX_SIOCGIFBRDADDR 0x8919
+#define LINUX_SIOCGIFNETMASK 0x891b
+#define LINUX_SIOCADDMULTI 0x8931
+#define LINUX_SIOCDELMULTI 0x8932
#endif /* !_I386_LINUX_LINUX_H_ */
diff --git a/sys/alpha/linux/linux_dummy.c b/sys/alpha/linux/linux_dummy.c
index 6c55613..2fcab46 100644
--- a/sys/alpha/linux/linux_dummy.c
+++ b/sys/alpha/linux/linux_dummy.c
@@ -25,7 +25,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: linux_dummy.c,v 1.1 1995/06/25 17:32:33 sos Exp $
+ * $Id: linux_dummy.c,v 1.2 1995/11/22 07:43:44 bde Exp $
*/
#include <sys/param.h>
@@ -34,283 +34,264 @@
#include <sys/proc.h>
#include <sys/resourcevar.h>
-#include <i386/linux/sysproto.h>
+#include <i386/linux/linux.h>
+#include <i386/linux/linux_proto.h>
int
-linux_setup(struct proc *p, void *args, int *retval)
+linux_setup(struct proc *p, struct linux_setup_args *args, int *retval)
{
printf("Linux-emul(%d): setup() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_break(struct proc *p, void *args, int *retval)
+linux_break(struct proc *p, struct linux_break_args *args, int *retval)
{
printf("Linux-emul(%d): break() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_stat(struct proc *p, void *args, int *retval)
+linux_stat(struct proc *p, struct linux_stat_args *args, int *retval)
{
printf("Linux-emul(%d): stat() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_fstat(struct proc *p, void *args, int *retval)
+linux_fstat(struct proc *p, struct linux_fstat_args *args, int *retval)
{
printf("Linux-emul(%d): fstat() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_mount(struct proc *p, void *args, int *retval)
+linux_mount(struct proc *p, struct linux_mount_args *args, int *retval)
{
printf("Linux-emul(%d): mount() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_umount(struct proc *p, void *args, int *retval)
+linux_umount(struct proc *p, struct linux_umount_args *args, int *retval)
{
printf("Linux-emul(%d): umount() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_stime(struct proc *p, void *args, int *retval)
+linux_stime(struct proc *p, struct linux_stime_args *args, int *retval)
{
printf("Linux-emul(%d): stime() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_ptrace(struct proc *p, void *args, int *retval)
+linux_ptrace(struct proc *p, struct linux_ptrace_args *args, int *retval)
{
printf("Linux-emul(%d): ptrace() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_pause(struct proc *p, void *args, int *retval)
-{
- printf("Linux-emul(%d): pause() not supported\n", p->p_pid);
- return ENOSYS;
-}
-
-int
-linux_stty(struct proc *p, void *args, int *retval)
+linux_stty(struct proc *p, struct linux_stty_args *args, int *retval)
{
printf("Linux-emul(%d): stty() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_gtty(struct proc *p, void *args, int *retval)
+linux_gtty(struct proc *p, struct linux_gtty_args *args, int *retval)
{
printf("Linux-emul(%d): gtty() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_nice(struct proc *p, void *args, int *retval)
+linux_nice(struct proc *p, struct linux_nice_args *args, int *retval)
{
printf("Linux-emul(%d): nice() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_ftime(struct proc *p, void *args, int *retval)
+linux_ftime(struct proc *p, struct linux_ftime_args *args, int *retval)
{
printf("Linux-emul(%d): ftime() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_prof(struct proc *p, void *args, int *retval)
+linux_prof(struct proc *p, struct linux_prof_args *args, int *retval)
{
printf("Linux-emul(%d): prof() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_signal(struct proc *p, void *args, int *retval)
-{
- printf("Linux-emul(%d): signal() not supported\n", p->p_pid);
- return ENOSYS;
-}
-
-int
-linux_phys(struct proc *p, void *args, int *retval)
+linux_phys(struct proc *p, struct linux_phys_args *args, int *retval)
{
printf("Linux-emul(%d): phys() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_lock(struct proc *p, void *args, int *retval)
+linux_lock(struct proc *p, struct linux_lock_args *args, int *retval)
{
printf("Linux-emul(%d): lock() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_mpx(struct proc *p, void *args, int *retval)
+linux_mpx(struct proc *p, struct linux_mpx_args *args, int *retval)
{
printf("Linux-emul(%d): mpx() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_ulimit(struct proc *p, void *args, int *retval)
+linux_ulimit(struct proc *p, struct linux_ulimit_args *args, int *retval)
{
printf("Linux-emul(%d): ulimit() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_olduname(struct proc *p, void *args, int *retval)
+linux_olduname(struct proc *p, struct linux_olduname_args *args, int *retval)
{
printf("Linux-emul(%d): olduname() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_ustat(struct proc *p, void *args, int *retval)
+linux_ustat(struct proc *p, struct linux_ustat_args *args, int *retval)
{
printf("Linux-emul(%d): ustat() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_ioperm(struct proc *p, void *args, int *retval)
+linux_ioperm(struct proc *p, struct linux_ioperm_args *args, int *retval)
{
printf("Linux-emul(%d): ioperm() not supported\n", p->p_pid);
return 0; /* EINVAL SOS XXX */
}
int
-linux_syslog(struct proc *p, void *args, int *retval)
+linux_ksyslog(struct proc *p, struct linux_ksyslog_args *args, int *retval)
{
- printf("Linux-emul(%d): syslog() not supported (BSD sigreturn)\n",p->p_pid);
- return sigreturn(p, args, retval);
+ printf("Linux-emul(%d): ksyslog(%x) not supported\n",
+ p->p_pid, args->what);
+ return ENOSYS; /* EPERM - Peter - it's a root-only thing */
}
int
-linux_iopl(struct proc *p, void *args, int *retval)
+linux_iopl(struct proc *p, struct linux_iopl_args *args, int *retval)
{
printf("Linux-emul(%d): iopl() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_vhangup(struct proc *p, void *args, int *retval)
+linux_vhangup(struct proc *p, struct linux_vhangup_args *args, int *retval)
{
printf("Linux-emul(%d): vhangup() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_idle(struct proc *p, void *args, int *retval)
+linux_idle(struct proc *p, struct linux_idle_args *args, int *retval)
{
printf("Linux-emul(%d): idle() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_vm86(struct proc *p, void *args, int *retval)
+linux_vm86(struct proc *p, struct linux_vm86_args *args, int *retval)
{
printf("Linux-emul(%d): vm86() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_swapoff(struct proc *p, void *args, int *retval)
+linux_swapoff(struct proc *p, struct linux_swapoff_args *args, int *retval)
{
printf("Linux-emul(%d): swapoff() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_sysinfo(struct proc *p, void *args, int *retval)
+linux_sysinfo(struct proc *p, struct linux_sysinfo_args *args, int *retval)
{
printf("Linux-emul(%d): sysinfo() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_sigreturn(struct proc *p, void *args, int *retval)
-{
- printf("Linux-emul(%d): sigreturn() not supported\n", p->p_pid);
- return ENOSYS;
-}
-
-int
-linux_clone(struct proc *p, void *args, int *retval)
+linux_clone(struct proc *p, struct linux_clone_args *args, int *retval)
{
printf("Linux-emul(%d): clone() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_uname(struct proc *p, void *args, int *retval)
+linux_uname(struct proc *p, struct linux_uname_args *args, int *retval)
{
printf("Linux-emul(%d): uname() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_modify_ldt(struct proc *p, void *args, int *retval)
+linux_modify_ldt(struct proc *p, struct linux_modify_ldt_args *args, int *retval)
{
printf("Linux-emul(%d): modify_ldt() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_adjtimex(struct proc *p, void *args, int *retval)
+linux_adjtimex(struct proc *p, struct linux_adjtimex_args *args, int *retval)
{
printf("Linux-emul(%d): adjtimex() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_create_module(struct proc *p, void *args, int *retval)
+linux_create_module(struct proc *p, struct linux_create_module_args *args, int *retval)
{
printf("Linux-emul(%d): create_module() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_init_module(struct proc *p, void *args, int *retval)
+linux_init_module(struct proc *p, struct linux_init_module_args *args, int *retval)
{
printf("Linux-emul(%d): init_module() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_delete_module(struct proc *p, void *args, int *retval)
+linux_delete_module(struct proc *p, struct linux_delete_module_args *args, int *retval)
{
printf("Linux-emul(%d): delete_module() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_get_kernel_syms(struct proc *p, void *args, int *retval)
+linux_get_kernel_syms(struct proc *p, struct linux_get_kernel_syms_args *args, int *retval)
{
printf("Linux-emul(%d): get_kernel_syms() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_quotactl(struct proc *p, void *args, int *retval)
+linux_quotactl(struct proc *p, struct linux_quotactl_args *args, int *retval)
{
printf("Linux-emul(%d): quotactl() not supported\n", p->p_pid);
return ENOSYS;
}
int
-linux_bdflush(struct proc *p, void *args, int *retval)
+linux_bdflush(struct proc *p, struct linux_bdflush_args *args, int *retval)
{
printf("Linux-emul(%d): bdflush() not supported\n", p->p_pid);
return ENOSYS;
diff --git a/sys/alpha/linux/linux_genassym.c b/sys/alpha/linux/linux_genassym.c
new file mode 100644
index 0000000..c522948
--- /dev/null
+++ b/sys/alpha/linux/linux_genassym.c
@@ -0,0 +1,22 @@
+#include <stdio.h>
+#include <sys/param.h>
+#include <sys/buf.h>
+#include <sys/proc.h>
+#include <i386/linux/linux.h>
+
+extern int main __P((void));
+
+int
+main()
+{
+ struct linux_sigframe *linux_sigf = (struct linux_sigframe *)0;
+ struct linux_sigcontext *linux_sc = (struct linux_sigcontext *)0;
+
+ printf("#define\tLINUX_SIGF_HANDLER %d\n", &linux_sigf->sf_handler);
+ printf("#define\tLINUX_SIGF_SC %d\n", &linux_sigf->sf_sc);
+ printf("#define\tLINUX_SC_FS %d\n", &linux_sc->sc_fs);
+ printf("#define\tLINUX_SC_GS %d\n", &linux_sc->sc_gs);
+ printf("#define\tLINUX_SC_EFLAGS %d\n", &linux_sc->sc_eflags);
+
+ return (0);
+}
diff --git a/sys/alpha/linux/linux_sysvec.c b/sys/alpha/linux/linux_sysvec.c
new file mode 100644
index 0000000..9278102
--- /dev/null
+++ b/sys/alpha/linux/linux_sysvec.c
@@ -0,0 +1,358 @@
+/*-
+ * 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 withough 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.
+ *
+ * $Id: linux_sysent.c,v 1.4 1996/01/14 10:59:57 sos Exp $
+ */
+
+/* XXX we use functions that might not exist. */
+#define COMPAT_43 1
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/sysproto.h>
+#include <sys/sysent.h>
+#include <sys/imgact.h>
+#include <sys/signalvar.h>
+#include <vm/vm.h>
+#include <vm/vm_param.h>
+#include <vm/vm_prot.h>
+#include <vm/lock.h>
+#include <vm/vm_kern.h>
+#include <vm/vm_object.h>
+#include <vm/vm_page.h>
+#include <vm/vm_map.h>
+#include <vm/vm_pager.h>
+#include <vm/vm_extern.h>
+#include <sys/user.h>
+#include <sys/exec.h>
+#include <machine/cpu.h>
+#include <machine/frame.h>
+#include <machine/reg.h>
+#include <machine/specialreg.h>
+#include <machine/psl.h>
+#include <machine/sysarch.h>
+#include <machine/md_var.h>
+
+#include <i386/linux/linux.h>
+#include <i386/linux/linux_proto.h>
+#include <i386/linux/linux_syscall.h>
+
+/*
+ * Linux syscalls return negative errno's, we do positive and map them
+ */
+int bsd_to_linux_errno[ELAST] = {
+ -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,
+};
+
+int bsd_to_linux_signal[NSIG] = {
+ 0, LINUX_SIGHUP, LINUX_SIGINT, LINUX_SIGQUIT,
+ LINUX_SIGILL, LINUX_SIGTRAP, LINUX_SIGABRT, 0,
+ LINUX_SIGFPE, LINUX_SIGKILL, LINUX_SIGBUS, LINUX_SIGSEGV,
+ 0, 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_NSIG] = {
+ 0, SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGEMT,
+ SIGFPE, SIGKILL, SIGUSR1, SIGSEGV, SIGUSR2, SIGPIPE, SIGALRM, SIGTERM,
+ SIGBUS, SIGCHLD, SIGCONT, SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU, SIGIO,
+ SIGXCPU, SIGXFSZ, SIGVTALRM, SIGPROF, SIGWINCH, SIGURG, SIGURG, 0
+};
+
+int linux_fixup(int **stack_base, struct image_params *imgp)
+{
+ int *argv, *envp;
+
+ argv = *stack_base;
+ envp = *stack_base + (imgp->argc + 1);
+ (*stack_base)--;
+ **stack_base = (int)envp;
+ (*stack_base)--;
+ **stack_base = (int)argv;
+ (*stack_base)--;
+ **stack_base = (int)imgp->argc;
+ return 0; /* XXX */
+}
+
+extern struct sysent linux_sysent[LINUX_SYS_MAXSYSCALL];
+
+static void linux_sendsig(sig_t action,
+ int sig,
+ int returnmask,
+ unsigned code);
+
+extern int _ucodesel, _udatasel;
+
+/*
+ * 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(catcher, sig, mask, code)
+ sig_t catcher;
+ int sig;
+ int mask;
+ unsigned code;
+{
+ register struct proc *p = curproc;
+ register int *regs;
+ struct linux_sigframe *fp, frame;
+ struct sigacts *psp = p->p_sigacts;
+ int oonstack;
+
+ regs = p->p_md.md_regs;
+ oonstack = psp->ps_sigstk.ss_flags & SS_ONSTACK;
+
+#ifdef DEBUG
+ printf("Linux-emul(%d): linux_sendsig(%8x, %d, %d, %d)\n",
+ p->p_pid, catcher, sig, mask, code);
+#endif
+ /*
+ * Allocate space for the signal handler context.
+ */
+ if ((psp->ps_flags & SAS_ALTSTACK) && !oonstack &&
+ (psp->ps_sigonstack & sigmask(sig))) {
+ fp = (struct linux_sigframe *)(psp->ps_sigstk.ss_sp +
+ psp->ps_sigstk.ss_size - sizeof(struct linux_sigframe));
+ psp->ps_sigstk.ss_flags |= SS_ONSTACK;
+ } else {
+ fp = (struct linux_sigframe *)regs[tESP] - 1;
+ }
+
+ /*
+ * grow() will return FALSE if the fp will not fit inside the stack
+ * and the stack can not be grown. useracc will return FALSE
+ * if access is denied.
+ */
+ if ((grow(p, (int)fp) == FALSE) ||
+ (useracc((caddr_t)fp, sizeof (struct linux_sigframe), B_WRITE) == FALSE)) {
+ /*
+ * Process has trashed its stack; give it an illegal
+ * instruction to halt it in its tracks.
+ */
+ SIGACTION(p, SIGILL) = SIG_DFL;
+ sig = sigmask(SIGILL);
+ p->p_sigignore &= ~sig;
+ p->p_sigcatch &= ~sig;
+ p->p_sigmask &= ~sig;
+ psignal(p, SIGILL);
+ return;
+ }
+
+ /*
+ * 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];
+ else
+ sig = p->p_sysent->sv_sigsize + 1;
+ }
+
+ frame.sf_handler = catcher;
+ frame.sf_sig = sig;
+
+ /*
+ * Build the signal context to be used by sigreturn.
+ */
+ frame.sf_sc.sc_mask = mask;
+ __asm("movl %%gs,%w0" : "=r" (frame.sf_sc.sc_gs));
+ __asm("movl %%fs,%w0" : "=r" (frame.sf_sc.sc_fs));
+ frame.sf_sc.sc_es = regs[tES];
+ frame.sf_sc.sc_ds = regs[tDS];
+ frame.sf_sc.sc_edi = regs[tEDI];
+ frame.sf_sc.sc_esi = regs[tESI];
+ frame.sf_sc.sc_ebp = regs[tEBP];
+ frame.sf_sc.sc_ebx = regs[tEBX];
+ frame.sf_sc.sc_edx = regs[tEDX];
+ frame.sf_sc.sc_ecx = regs[tECX];
+ frame.sf_sc.sc_eax = regs[tEAX];
+ frame.sf_sc.sc_eip = regs[tEIP];
+ frame.sf_sc.sc_cs = regs[tCS];
+ frame.sf_sc.sc_eflags = regs[tEFLAGS];
+ frame.sf_sc.sc_esp_at_signal = regs[tESP];
+ frame.sf_sc.sc_ss = regs[tSS];
+ frame.sf_sc.sc_err = regs[tERR];
+ frame.sf_sc.sc_trapno = code; /* XXX ???? */
+
+ if (copyout(&frame, fp, sizeof(frame)) != 0) {
+ /*
+ * Process has trashed its stack; give it an illegal
+ * instruction to halt it in its tracks.
+ */
+ sigexit(p, SIGILL);
+ /* NOTREACHED */
+ }
+
+ /*
+ * Build context to run handler in.
+ */
+ regs[tESP] = (int)fp;
+ regs[tEIP] = (int)(((char *)PS_STRINGS) - *(p->p_sysent->sv_szsigcode));
+ regs[tEFLAGS] &= ~PSL_VM;
+ regs[tCS] = _ucodesel;
+ regs[tDS] = _udatasel;
+ regs[tES] = _udatasel;
+ regs[tSS] = _udatasel;
+}
+
+/*
+ * 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(p, args, retval)
+ struct proc *p;
+ struct linux_sigreturn_args *args;
+ int *retval;
+{
+ struct linux_sigcontext *scp, context;
+ register int *regs;
+ int eflags;
+
+ regs = p->p_md.md_regs;
+
+#ifdef DEBUG
+ printf("Linux-emul(%d): linux_sigreturn(%8x)\n", p->p_pid, args->scp);
+#endif
+ /*
+ * The trampoline code hands us the context.
+ * It is unsafe to keep track of it ourselves, in the event that a
+ * program jumps out of a signal handler.
+ */
+ scp = args->scp;
+ if (copyin((caddr_t)scp, &context, sizeof(*scp)) != 0)
+ return (EFAULT);
+
+ /*
+ * 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[tEFLAGS] & ~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)) {
+ trapsignal(p, SIGBUS, T_PROTFLT);
+ return(EINVAL);
+ }
+
+ p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK;
+ p->p_sigmask = context.sc_mask &~
+ (sigmask(SIGKILL)|sigmask(SIGCONT)|sigmask(SIGSTOP));
+ /*
+ * Restore signal context.
+ */
+ /* %fs and %gs were restored by the trampoline. */
+ regs[tES] = context.sc_es;
+ regs[tDS] = context.sc_ds;
+ regs[tEDI] = context.sc_edi;
+ regs[tESI] = context.sc_esi;
+ regs[tEBP] = context.sc_ebp;
+ regs[tEBX] = context.sc_ebx;
+ regs[tEDX] = context.sc_edx;
+ regs[tECX] = context.sc_ecx;
+ regs[tEAX] = context.sc_eax;
+ regs[tEIP] = context.sc_eip;
+ regs[tCS] = context.sc_cs;
+ regs[tEFLAGS] = eflags;
+ regs[tESP] = context.sc_esp_at_signal;
+ regs[tSS] = context.sc_ss;
+
+ return (EJUSTRETURN);
+}
+
+static void
+linux_prepsyscall(struct trapframe *tf, int *args, u_int *code, caddr_t *params)
+{
+ int i;
+ args[0] = tf->tf_ebx;
+ args[1] = tf->tf_ecx;
+ args[2] = tf->tf_edx;
+ args[3] = tf->tf_esi;
+ args[4] = tf->tf_edi;
+ *params = NULL; /* no copyin */
+}
+
+extern char linux_sigcode[];
+extern int linux_szsigcode;
+
+struct sysentvec linux_sysvec = {
+ sizeof (linux_sysent) / sizeof(linux_sysent[0]),
+ linux_sysent,
+ 0xff,
+ NSIG,
+ bsd_to_linux_signal,
+ ELAST,
+ bsd_to_linux_errno,
+ linux_fixup,
+ linux_sendsig,
+ linux_sigcode,
+ &linux_szsigcode,
+ linux_prepsyscall,
+};
OpenPOWER on IntegriCloud