fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / arch / um / os-Linux / skas / process.c
index bd89c6b..c4998cf 100644 (file)
@@ -8,14 +8,13 @@
 #include <unistd.h>
 #include <errno.h>
 #include <signal.h>
-#include <setjmp.h>
 #include <sched.h>
 #include "ptrace_user.h"
 #include <sys/wait.h>
 #include <sys/mman.h>
 #include <sys/user.h>
 #include <sys/time.h>
-#include <asm/unistd.h>
+#include <sys/syscall.h>
 #include <asm/types.h>
 #include "user.h"
 #include "sysdep/ptrace.h"
@@ -68,7 +67,7 @@ void wait_stub_done(int pid, int sig, char * fname)
 
        if((n < 0) || !WIFSTOPPED(status) ||
           (WSTOPSIG(status) != SIGUSR1 && WSTOPSIG(status) != SIGTRAP)){
-               unsigned long regs[HOST_FRAME_SIZE];
+               unsigned long regs[MAX_REG_NR];
 
                if(ptrace(PTRACE_GETREGS, pid, 0, regs) < 0)
                        printk("Failed to get registers from stub, "
@@ -77,7 +76,7 @@ void wait_stub_done(int pid, int sig, char * fname)
                        int i;
 
                        printk("Stub registers -\n");
-                       for(i = 0; i < HOST_FRAME_SIZE; i++)
+                       for(i = 0; i < ARRAY_SIZE(regs); i++)
                                printk("\t%d - %lx\n", i, regs[i]);
                }
                panic("%s : failed to wait for SIGUSR1/SIGTRAP, "
@@ -156,11 +155,15 @@ extern int __syscall_stub_start;
 static int userspace_tramp(void *stack)
 {
        void *addr;
+       int err;
 
        ptrace(PTRACE_TRACEME, 0, 0, 0);
 
-       init_new_thread_signals(1);
-       enable_timer();
+       init_new_thread_signals();
+       err = set_interval(1);
+       if(err)
+               panic("userspace_tramp - setting timer failed, errno = %d\n",
+                     err);
 
        if(!proc_mm){
                /* This has a pte, but it can't be mapped in with the usual
@@ -190,14 +193,25 @@ static int userspace_tramp(void *stack)
                }
        }
        if(!ptrace_faultinfo && (stack != NULL)){
+               struct sigaction sa;
+
                unsigned long v = UML_CONFIG_STUB_CODE +
                                  (unsigned long) stub_segv_handler -
                                  (unsigned long) &__syscall_stub_start;
 
                set_sigstack((void *) UML_CONFIG_STUB_DATA, page_size());
-               set_handler(SIGSEGV, (void *) v, SA_ONSTACK,
-                           SIGIO, SIGWINCH, SIGALRM, SIGVTALRM,
-                           SIGUSR1, -1);
+               sigemptyset(&sa.sa_mask);
+               sigaddset(&sa.sa_mask, SIGIO);
+               sigaddset(&sa.sa_mask, SIGWINCH);
+               sigaddset(&sa.sa_mask, SIGALRM);
+               sigaddset(&sa.sa_mask, SIGVTALRM);
+               sigaddset(&sa.sa_mask, SIGUSR1);
+               sa.sa_flags = SA_ONSTACK;
+               sa.sa_handler = (void *) v;
+               sa.sa_restorer = NULL;
+               if(sigaction(SIGSEGV, &sa, NULL) < 0)
+                       panic("userspace_tramp - setting SIGSEGV handler "
+                             "failed - errno = %d\n", errno);
        }
 
        os_stop_process(os_getpid());
@@ -314,7 +328,7 @@ void userspace(union uml_pt_regs *regs)
 int copy_context_skas0(unsigned long new_stack, int pid)
 {
        int err;
-       unsigned long regs[HOST_FRAME_SIZE];
+       unsigned long regs[MAX_REG_NR];
        unsigned long fp_regs[HOST_FP_SIZE];
        unsigned long current_stack = current_stub_stack();
        struct stub_data *data = (struct stub_data *) current_stack;
@@ -430,59 +444,22 @@ void map_stub_pages(int fd, unsigned long code,
        }
 }
 
-void new_thread(void *stack, void **switch_buf_ptr, void **fork_buf_ptr,
-               void (*handler)(int))
+void new_thread(void *stack, jmp_buf *buf, void (*handler)(void))
 {
-       unsigned long flags;
-       jmp_buf switch_buf, fork_buf;
-       int enable;
-
-       *switch_buf_ptr = &switch_buf;
-       *fork_buf_ptr = &fork_buf;
-
-       /* Somewhat subtle - siglongjmp restores the signal mask before doing
-        * the longjmp.  This means that when jumping from one stack to another
-        * when the target stack has interrupts enabled, an interrupt may occur
-        * on the source stack.  This is bad when starting up a process because
-        * it's not supposed to get timer ticks until it has been scheduled.
-        * So, we disable interrupts around the sigsetjmp to ensure that
-        * they can't happen until we get back here where they are safe.
-        */
-       flags = get_signals();
-       block_signals();
-       if(UML_SETJMP(&fork_buf, enable) == 0)
-               new_thread_proc(stack, handler);
-
-       remove_sigstack();
-
-       set_signals(flags);
+       (*buf)[0].JB_IP = (unsigned long) handler;
+       (*buf)[0].JB_SP = (unsigned long) stack +
+               (PAGE_SIZE << UML_CONFIG_KERNEL_STACK_ORDER) - sizeof(void *);
 }
 
 #define INIT_JMP_NEW_THREAD 0
-#define INIT_JMP_REMOVE_SIGSTACK 1
-#define INIT_JMP_CALLBACK 2
-#define INIT_JMP_HALT 3
-#define INIT_JMP_REBOOT 4
+#define INIT_JMP_CALLBACK 1
+#define INIT_JMP_HALT 2
+#define INIT_JMP_REBOOT 3
 
-void thread_wait(void *sw, void *fb)
+void switch_threads(jmp_buf *me, jmp_buf *you)
 {
-       jmp_buf buf, **switch_buf = sw, *fork_buf;
-       int enable;
-
-       *switch_buf = &buf;
-       fork_buf = fb;
-       if(UML_SETJMP(&buf, enable) == 0)
-               siglongjmp(*fork_buf, INIT_JMP_REMOVE_SIGSTACK);
-}
-
-void switch_threads(void *me, void *next)
-{
-       jmp_buf my_buf, **me_ptr = me, *next_buf = next;
-       int enable;
-
-       *me_ptr = &my_buf;
-       if(UML_SETJMP(&my_buf, enable) == 0)
-               UML_LONGJMP(next_buf, 1);
+       if(UML_SETJMP(me) == 0)
+               UML_LONGJMP(you, 1);
 }
 
 static jmp_buf initial_jmpbuf;
@@ -492,23 +469,21 @@ static void (*cb_proc)(void *arg);
 static void *cb_arg;
 static jmp_buf *cb_back;
 
-int start_idle_thread(void *stack, void *switch_buf_ptr, void **fork_buf_ptr)
+int start_idle_thread(void *stack, jmp_buf *switch_buf)
 {
-       jmp_buf **switch_buf = switch_buf_ptr;
-       int n, enable;
+       int n;
 
        set_handler(SIGWINCH, (__sighandler_t) sig_handler,
                    SA_ONSTACK | SA_RESTART, SIGUSR1, SIGIO, SIGALRM,
                    SIGVTALRM, -1);
 
-       *fork_buf_ptr = &initial_jmpbuf;
-       n = UML_SETJMP(&initial_jmpbuf, enable);
+       n = UML_SETJMP(&initial_jmpbuf);
        switch(n){
        case INIT_JMP_NEW_THREAD:
-               new_thread_proc((void *) stack, new_thread_handler);
-               break;
-       case INIT_JMP_REMOVE_SIGSTACK:
-               remove_sigstack();
+               (*switch_buf)[0].JB_IP = (unsigned long) new_thread_handler;
+               (*switch_buf)[0].JB_SP = (unsigned long) stack +
+                       (PAGE_SIZE << UML_CONFIG_KERNEL_STACK_ORDER) -
+                       sizeof(void *);
                break;
        case INIT_JMP_CALLBACK:
                (*cb_proc)(cb_arg);
@@ -523,20 +498,19 @@ int start_idle_thread(void *stack, void *switch_buf_ptr, void **fork_buf_ptr)
        default:
                panic("Bad sigsetjmp return in start_idle_thread - %d\n", n);
        }
-       UML_LONGJMP(*switch_buf, 1);
+       UML_LONGJMP(switch_buf, 1);
 }
 
 void initial_thread_cb_skas(void (*proc)(void *), void *arg)
 {
        jmp_buf here;
-       int enable;
 
        cb_proc = proc;
        cb_arg = arg;
        cb_back = &here;
 
        block_signals();
-       if(UML_SETJMP(&here, enable) == 0)
+       if(UML_SETJMP(&here) == 0)
                UML_LONGJMP(&initial_jmpbuf, INIT_JMP_CALLBACK);
        unblock_signals();