]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
[PATCH] uml: move libc-dependent code from trap_user.c
authorGennady Sharapov <Gennady.V.Sharapov@intel.com>
Sun, 8 Jan 2006 09:01:31 +0000 (01:01 -0800)
committerLinus Torvalds <torvalds@g5.osdl.org>
Mon, 9 Jan 2006 04:13:39 +0000 (20:13 -0800)
The serial UML OS-abstraction layer patch (um/kernel dir).

This moves all systemcalls from trap_user.c file under os-Linux dir

Signed-off-by: Gennady Sharapov <Gennady.V.Sharapov@intel.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
14 files changed:
arch/um/include/kern_util.h
arch/um/include/os.h
arch/um/include/user_util.h
arch/um/kernel/skas/Makefile
arch/um/kernel/skas/trap_user.c [deleted file]
arch/um/kernel/trap_kern.c
arch/um/kernel/trap_user.c
arch/um/kernel/tt/trap_user.c
arch/um/kernel/um_arch.c
arch/um/os-Linux/Makefile
arch/um/os-Linux/skas/Makefile [new file with mode: 0644]
arch/um/os-Linux/skas/trap.c [new file with mode: 0644]
arch/um/os-Linux/trap.c [new file with mode: 0644]
arch/um/os-Linux/tt.c

index 58c0b10fcf2ddbf2990956f3998c5bacce731221..8f4e46d677ab08cb4305b85cc384a9e173d36bc0 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
  * Licensed under the GPL
  */
 #include "sysdep/ptrace.h"
 #include "sysdep/faultinfo.h"
 
+typedef void (*kern_hndl)(int, union uml_pt_regs *);
+
+struct kern_handlers {
+       kern_hndl relay_signal;
+       kern_hndl winch;
+       kern_hndl bus_handler;
+       kern_hndl page_fault;
+       kern_hndl sigio_handler;
+       kern_hndl timer_handler;
+};
+
+extern struct kern_handlers handlinfo_kern;
+
 extern int ncpus;
 extern char *linux_prog;
 extern char *gdb_init;
@@ -109,6 +122,8 @@ extern void arch_switch(void);
 extern void free_irq(unsigned int, void *);
 extern int um_in_interrupt(void);
 extern int cpu(void);
+extern void segv_handler(int sig, union uml_pt_regs *regs);
+extern void sigio_handler(int sig, union uml_pt_regs *regs);
 
 #endif
 
index cfc806e4610b58141dcaf9ebd920f61906c3deb4..dd72d66cf0ed18457361f0b004d02c2d1136f5c4 100644 (file)
@@ -9,6 +9,8 @@
 #include "uml-config.h"
 #include "asm/types.h"
 #include "../os/include/file.h"
+#include "sysdep/ptrace.h"
+#include "kern_util.h"
 
 #define OS_TYPE_FILE 1 
 #define OS_TYPE_DIR 2 
@@ -229,4 +231,8 @@ extern void unblock_signals(void);
 extern int get_signals(void);
 extern int set_signals(int enable);
 
+/* trap.c */
+extern void os_fill_handlinfo(struct kern_handlers h);
+extern void do_longjmp(void *p, int val);
+
 #endif
index b9984003e6035407c393c7466bcfac8f77c67831..c1dbd77b073f322ef3ee6369deeefb4235b04a73 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
  * Licensed under the GPL
  */
@@ -23,12 +23,7 @@ struct cpu_task {
 
 extern struct cpu_task cpu_tasks[];
 
-struct signal_info {
-       void (*handler)(int, union uml_pt_regs *);
-       int is_irq;
-};
-
-extern struct signal_info sig_info[];
+extern void (*sig_info[])(int, union uml_pt_regs *);
 
 extern unsigned long low_physmem;
 extern unsigned long high_physmem;
@@ -64,7 +59,6 @@ extern void setup_machinename(char *machine_out);
 extern void setup_hostinfo(void);
 extern void do_exec(int old_pid, int new_pid);
 extern void tracer_panic(char *msg, ...);
-extern void do_longjmp(void *p, int val);
 extern int detach(int pid, int sig);
 extern int attach(int pid);
 extern void kill_child_dead(int pid);
index 8de471b59c1c8188c35887cd18280594c9dc33dc..7a9fc16d71d4805df78eb6505516e3e88537aa78 100644 (file)
@@ -4,7 +4,7 @@
 #
 
 obj-y := clone.o exec_kern.o mem.o mem_user.o mmu.o process.o process_kern.o \
-       syscall.o tlb.o trap_user.o uaccess.o
+       syscall.o tlb.o uaccess.o
 
 USER_OBJS := process.o clone.o
 
diff --git a/arch/um/kernel/skas/trap_user.c b/arch/um/kernel/skas/trap_user.c
deleted file mode 100644 (file)
index 28403d2..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/* 
- * Copyright (C) 2002 - 2003 Jeff Dike (jdike@addtoit.com)
- * Licensed under the GPL
- */
-
-#include <signal.h>
-#include <errno.h>
-#include "user_util.h"
-#include "kern_util.h"
-#include "task.h"
-#include "sigcontext.h"
-#include "skas.h"
-#include "ptrace_user.h"
-#include "sysdep/ptrace.h"
-#include "sysdep/ptrace_user.h"
-#include "os.h"
-
-void sig_handler_common_skas(int sig, void *sc_ptr)
-{
-       struct sigcontext *sc = sc_ptr;
-       struct skas_regs *r;
-       struct signal_info *info;
-       int save_errno = errno;
-       int save_user;
-
-       /* This is done because to allow SIGSEGV to be delivered inside a SEGV
-        * handler.  This can happen in copy_user, and if SEGV is disabled,
-        * the process will die.
-        * XXX Figure out why this is better than SA_NODEFER
-        */
-       if(sig == SIGSEGV)
-               change_sig(SIGSEGV, 1);
-
-       r = &TASK_REGS(get_current())->skas;
-       save_user = r->is_user;
-       r->is_user = 0;
-        if ( sig == SIGFPE || sig == SIGSEGV ||
-             sig == SIGBUS || sig == SIGILL ||
-             sig == SIGTRAP ) {
-                GET_FAULTINFO_FROM_SC(r->faultinfo, sc);
-        }
-
-       change_sig(SIGUSR1, 1);
-       info = &sig_info[sig];
-       if(!info->is_irq) unblock_signals();
-
-       (*info->handler)(sig, (union uml_pt_regs *) r);
-
-       errno = save_errno;
-       r->is_user = save_user;
-}
-
-extern int ptrace_faultinfo;
-
-void user_signal(int sig, union uml_pt_regs *regs, int pid)
-{
-       struct signal_info *info;
-        int segv = ((sig == SIGFPE) || (sig == SIGSEGV) || (sig == SIGBUS) ||
-                    (sig == SIGILL) || (sig == SIGTRAP));
-
-       if (segv)
-               get_skas_faultinfo(pid, &regs->skas.faultinfo);
-       info = &sig_info[sig];
-       (*info->handler)(sig, regs);
-
-       unblock_signals();
-}
-
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * Emacs will notice this stuff at the end of the file and automatically
- * adjust the settings for this buffer only.  This must remain at the end
- * of the file.
- * ---------------------------------------------------------------------------
- * Local variables:
- * c-file-style: "linux"
- * End:
- */
index 0d4c10a736077702556fea90e281b82b109ada06..b79f805bdc00bde11dc81a3f87b0b69b845ef893 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com)
  * Licensed under the GPL
  */
@@ -29,6 +29,7 @@
 #ifdef CONFIG_MODE_SKAS
 #include "skas.h"
 #endif
+#include "os.h"
 
 /* Note this is constrained to return 0, -EFAULT, -EACCESS, -ENOMEM by segv(). */
 int handle_page_fault(unsigned long address, unsigned long ip, 
@@ -125,6 +126,14 @@ out_of_memory:
        goto out;
 }
 
+struct kern_handlers handlinfo_kern = {
+       .relay_signal = relay_signal,
+       .winch = winch,
+       .bus_handler = relay_signal,
+       .page_fault = segv_handler,
+       .sigio_handler = sigio_handler,
+       .timer_handler = timer_handler
+};
 /*
  * We give a *copy* of the faultinfo in the regs to segv.
  * This must be done, since nesting SEGVs could overwrite
index e551107251248fad0f4584bc572fb58521aa877b..5590b5739db9f8aa29a77530c70180b6e3bd29e4 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
  * Licensed under the GPL
  */
 #include "user_util.h"
 #include "os.h"
 
-void kill_child_dead(int pid)
-{
-       kill(pid, SIGKILL);
-       kill(pid, SIGCONT);
-       do {
-               int n;
-               CATCH_EINTR(n = waitpid(pid, NULL, 0));
-               if (n > 0)
-                       kill(pid, SIGCONT);
-               else
-                       break;
-       } while(1);
-}
-
 void segv_handler(int sig, union uml_pt_regs *regs)
 {
         struct faultinfo * fi = UPT_FAULTINFO(regs);
@@ -55,43 +41,18 @@ void usr2_handler(int sig, union uml_pt_regs *regs)
        CHOOSE_MODE(syscall_handler_tt(sig, regs), (void) 0);
 }
 
-struct signal_info sig_info[] = {
-       [ SIGTRAP ] { .handler          = relay_signal,
-                     .is_irq           = 0 },
-       [ SIGFPE ] { .handler           = relay_signal,
-                    .is_irq            = 0 },
-       [ SIGILL ] { .handler           = relay_signal,
-                    .is_irq            = 0 },
-       [ SIGWINCH ] { .handler         = winch,
-                      .is_irq          = 1 },
-       [ SIGBUS ] { .handler           = bus_handler,
-                    .is_irq            = 0 },
-       [ SIGSEGV] { .handler           = segv_handler,
-                    .is_irq            = 0 },
-       [ SIGIO ] { .handler            = sigio_handler,
-                   .is_irq             = 1 },
-       [ SIGVTALRM ] { .handler        = timer_handler,
-                       .is_irq         = 1 },
-        [ SIGALRM ] { .handler          = timer_handler,
-                      .is_irq           = 1 },
-       [ SIGUSR2 ] { .handler          = usr2_handler,
-                     .is_irq           = 0 },
-};
+void (*sig_info[NSIG])(int, union uml_pt_regs *);
 
-void do_longjmp(void *b, int val)
+void os_fill_handlinfo(struct kern_handlers h)
 {
-       sigjmp_buf *buf = b;
-
-       siglongjmp(*buf, val);
+       sig_info[SIGTRAP] = h.relay_signal;
+       sig_info[SIGFPE] = h.relay_signal;
+       sig_info[SIGILL] = h.relay_signal;
+       sig_info[SIGWINCH] = h.winch;
+       sig_info[SIGBUS] = h.bus_handler;
+       sig_info[SIGSEGV] = h.page_fault;
+       sig_info[SIGIO] = h.sigio_handler;
+       sig_info[SIGVTALRM] = h.timer_handler;
+       sig_info[SIGALRM] = h.timer_handler;
+       sig_info[SIGUSR2] = usr2_handler;
 }
-
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * Emacs will notice this stuff at the end of the file and automatically
- * adjust the settings for this buffer only.  This must remain at the end
- * of the file.
- * ---------------------------------------------------------------------------
- * Local variables:
- * c-file-style: "linux"
- * End:
- */
index 7501900f8941feecb59ed63700962c6087a54262..a414c529fbcd78b91350db486527a1bf37742c2a 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
  * Licensed under the GPL
  */
@@ -18,8 +18,8 @@ void sig_handler_common_tt(int sig, void *sc_ptr)
 {
        struct sigcontext *sc = sc_ptr;
        struct tt_regs save_regs, *r;
-       struct signal_info *info;
        int save_errno = errno, is_user;
+       void (*handler)(int, union uml_pt_regs *);
 
        /* This is done because to allow SIGSEGV to be delivered inside a SEGV
         * handler.  This can happen in copy_user, and if SEGV is disabled,
@@ -40,10 +40,14 @@ void sig_handler_common_tt(int sig, void *sc_ptr)
        if(sig != SIGUSR2) 
                r->syscall = -1;
 
-       info = &sig_info[sig];
-       if(!info->is_irq) unblock_signals();
+       handler = sig_info[sig];
+
+       /* unblock SIGALRM, SIGVTALRM, SIGIO if sig isn't IRQ signal */
+       if (sig != SIGIO && sig != SIGWINCH &&
+           sig != SIGVTALRM && sig != SIGALRM)
+               unblock_signals();
 
-       (*info->handler)(sig, (union uml_pt_regs *) r);
+       handler(sig, (union uml_pt_regs *) r);
 
        if(is_user){
                interrupt_end();
index 26626b2b9172cfbd9a230cad4e95684682105825..73747ac197748d6deb1649f0b59b4b1aad1d7051 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * Copyright (C) 2000, 2002 Jeff Dike (jdike@karaya.com)
  * Licensed under the GPL
  */
@@ -363,6 +363,11 @@ int linux_main(int argc, char **argv)
        uml_start = CHOOSE_MODE_PROC(set_task_sizes_tt, set_task_sizes_skas, 0,
                                     &host_task_size, &task_size);
 
+       /*
+        * Setting up handlers to 'sig_info' struct
+        */
+       os_fill_handlinfo(handlinfo_kern);
+
        brk_start = (unsigned long) sbrk(0);
        CHOOSE_MODE_PROC(before_mem_tt, before_mem_skas, brk_start);
        /* Increase physical memory size for exec-shield users
index 11e30b13e318ffe756e873bc79737954c146311e..40c7d6b1df6804e01ae6576d19a59e73e52e9cc1 100644 (file)
@@ -4,11 +4,13 @@
 #
 
 obj-y = aio.o elf_aux.o file.o helper.o main.o mem.o process.o signal.o \
-       start_up.o time.o tt.o tty.o uaccess.o umid.o user_syms.o drivers/ \
-       sys-$(SUBARCH)/
+       start_up.o time.o trap.o tt.o tty.o uaccess.o umid.o user_syms.o \
+       drivers/ sys-$(SUBARCH)/
+
+obj-$(CONFIG_MODE_SKAS) += skas/
 
 USER_OBJS := aio.o elf_aux.o file.o helper.o main.o mem.o process.o signal.o \
-       start_up.o time.o tt.o tty.o uaccess.o umid.o
+       start_up.o time.o trap.o tt.o tty.o uaccess.o umid.o
 
 elf_aux.o: $(ARCH_DIR)/kernel-offsets.h
 CFLAGS_elf_aux.o += -I$(objtree)/arch/um
diff --git a/arch/um/os-Linux/skas/Makefile b/arch/um/os-Linux/skas/Makefile
new file mode 100644 (file)
index 0000000..eab5386
--- /dev/null
@@ -0,0 +1,10 @@
+#
+# Copyright (C) 2002 - 2004 Jeff Dike (jdike@addtoit.com)
+# Licensed under the GPL
+#
+
+obj-y := trap.o
+
+USER_OBJS := trap.o
+
+include arch/um/scripts/Makefile.rules
diff --git a/arch/um/os-Linux/skas/trap.c b/arch/um/os-Linux/skas/trap.c
new file mode 100644 (file)
index 0000000..818f30e
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2002 - 2003 Jeff Dike (jdike@addtoit.com)
+ * Licensed under the GPL
+ */
+
+#include <signal.h>
+#include <errno.h>
+#include "user_util.h"
+#include "kern_util.h"
+#include "task.h"
+#include "sigcontext.h"
+#include "skas.h"
+#include "ptrace_user.h"
+#include "sysdep/ptrace.h"
+#include "sysdep/ptrace_user.h"
+#include "os.h"
+
+void sig_handler_common_skas(int sig, void *sc_ptr)
+{
+       struct sigcontext *sc = sc_ptr;
+       struct skas_regs *r;
+       void (*handler)(int, union uml_pt_regs *);
+       int save_errno = errno;
+       int save_user;
+
+       /* This is done because to allow SIGSEGV to be delivered inside a SEGV
+        * handler.  This can happen in copy_user, and if SEGV is disabled,
+        * the process will die.
+        * XXX Figure out why this is better than SA_NODEFER
+        */
+       if(sig == SIGSEGV)
+               change_sig(SIGSEGV, 1);
+
+       r = &TASK_REGS(get_current())->skas;
+       save_user = r->is_user;
+       r->is_user = 0;
+        if ( sig == SIGFPE || sig == SIGSEGV ||
+             sig == SIGBUS || sig == SIGILL ||
+             sig == SIGTRAP ) {
+                GET_FAULTINFO_FROM_SC(r->faultinfo, sc);
+        }
+
+       change_sig(SIGUSR1, 1);
+
+       handler = sig_info[sig];
+
+       /* unblock SIGALRM, SIGVTALRM, SIGIO if sig isn't IRQ signal */
+       if (sig != SIGIO && sig != SIGWINCH &&
+           sig != SIGVTALRM && sig != SIGALRM)
+               unblock_signals();
+
+       handler(sig, (union uml_pt_regs *) r);
+
+       errno = save_errno;
+       r->is_user = save_user;
+}
+
+extern int ptrace_faultinfo;
+
+void user_signal(int sig, union uml_pt_regs *regs, int pid)
+{
+       void (*handler)(int, union uml_pt_regs *);
+        int segv = ((sig == SIGFPE) || (sig == SIGSEGV) || (sig == SIGBUS) ||
+                    (sig == SIGILL) || (sig == SIGTRAP));
+
+       if (segv)
+               get_skas_faultinfo(pid, &regs->skas.faultinfo);
+
+       handler = sig_info[sig];
+       handler(sig, (union uml_pt_regs *) regs);
+
+       unblock_signals();
+}
diff --git a/arch/um/os-Linux/trap.c b/arch/um/os-Linux/trap.c
new file mode 100644 (file)
index 0000000..6e7841c
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
+ * Licensed under the GPL
+ */
+
+#include <setjmp.h>
+#include <signal.h>
+#include "kern_util.h"
+#include "user_util.h"
+#include "os.h"
+
+void do_longjmp(void *b, int val)
+{
+       sigjmp_buf *buf = b;
+
+       siglongjmp(*buf, val);
+}
index 37828e5b35269903eff04e79f6885cee56c4e6b8..cb2648b79d0fd15090205da1f7595c7a2e639edf 100644 (file)
@@ -49,6 +49,20 @@ int protect_memory(unsigned long addr, unsigned long len, int r, int w, int x,
        return(0);
 }
 
+void kill_child_dead(int pid)
+{
+       kill(pid, SIGKILL);
+       kill(pid, SIGCONT);
+       do {
+               int n;
+               CATCH_EINTR(n = waitpid(pid, NULL, 0));
+               if (n > 0)
+                       kill(pid, SIGCONT);
+               else
+                       break;
+       } while(1);
+}
+
 /*
  *-------------------------
  * only for tt mode (will be deleted in future...)