vserver 1.9.5.x5
[linux-2.6.git] / arch / um / kernel / skas / process_kern.c
index 128146c..5d096ea 100644 (file)
@@ -6,6 +6,12 @@
 #include "linux/sched.h"
 #include "linux/slab.h"
 #include "linux/ptrace.h"
+#include "linux/proc_fs.h"
+#include "linux/file.h"
+#include "linux/errno.h"
+#include "linux/init.h"
+#include "asm/uaccess.h"
+#include "asm/atomic.h"
 #include "kern_util.h"
 #include "time_user.h"
 #include "signal_user.h"
 #include "os.h"
 #include "user_util.h"
 #include "tlb.h"
-#include "frame.h"
 #include "kern.h"
 #include "mode.h"
-
-int singlestepping_skas(void)
-{
-       int ret = current->ptrace & PT_DTRACE;
-
-       current->ptrace &= ~PT_DTRACE;
-       return(ret);
-}
+#include "proc_mm.h"
+#include "registers.h"
 
 void *switch_to_skas(void *prev, void *next)
 {
@@ -61,11 +60,13 @@ void new_thread_handler(int sig)
        thread_wait(&current->thread.mode.skas.switch_buf, 
                    current->thread.mode.skas.fork_buf);
 
-#ifdef CONFIG_SMP
-       schedule_tail(NULL);
-#endif
+       if(current->thread.prev_sched != NULL)
+               schedule_tail(current->thread.prev_sched);
        current->thread.prev_sched = NULL;
 
+       /* The return value is 1 if the kernel thread execs a process,
+        * 0 if it just exits
+        */
        n = run_kernel_thread(fn, arg, &current->thread.exec_buf);
        if(n == 1)
                userspace(&current->thread.regs.regs);
@@ -93,11 +94,11 @@ void fork_handler(int sig)
                    current->thread.mode.skas.fork_buf);
        
        force_flush_all();
-#ifdef CONFIG_SMP
+       if(current->thread.prev_sched == NULL)
+               panic("blech");
+
        schedule_tail(current->thread.prev_sched);
-#endif
        current->thread.prev_sched = NULL;
-       unblock_signals();
 
        userspace(&current->thread.regs.regs);
 }
@@ -118,25 +119,41 @@ int copy_thread_skas(int nr, unsigned long clone_flags, unsigned long sp,
                handler = fork_handler;
        }
        else {
-               memcpy(p->thread.regs.regs.skas.regs, exec_regs, 
-                      sizeof(p->thread.regs.regs.skas.regs));
-               memcpy(p->thread.regs.regs.skas.fp, exec_fp_regs, 
-                      sizeof(p->thread.regs.regs.skas.fp));
-               memcpy(p->thread.regs.regs.skas.xfp, exec_fpx_regs, 
-                      sizeof(p->thread.regs.regs.skas.xfp));
+               init_thread_registers(&p->thread.regs.regs);
                 p->thread.request.u.thread = current->thread.request.u.thread;
                handler = new_thread_handler;
        }
 
-       new_thread((void *) p->thread.kernel_stack, 
-                  &p->thread.mode.skas.switch_buf, 
+       new_thread(p->thread_info, &p->thread.mode.skas.switch_buf,
                   &p->thread.mode.skas.fork_buf, handler);
        return(0);
 }
 
+int new_mm(int from)
+{
+       struct proc_mm_op copy;
+       int n, fd;
+
+       fd = os_open_file("/proc/mm", of_cloexec(of_write(OPENFLAGS())), 0);
+       if(fd < 0)
+               return(fd);
+
+       if(from != -1){
+               copy = ((struct proc_mm_op) { .op       = MM_COPY_SEGMENTS,
+                                             .u        =
+                                             { .copy_segments  = from } } );
+               n = os_write_file(fd, &copy, sizeof(copy));
+               if(n != sizeof(copy))
+                       printk("new_mm : /proc/mm copy_segments failed, "
+                              "err = %d\n", -n);
+       }
+
+       return(fd);
+}
+
 void init_idle_skas(void)
 {
-       cpu_tasks[current->thread_info->cpu].pid = os_getpid();
+       cpu_tasks[current_thread->cpu].pid = os_getpid();
        default_idle();
 }
 
@@ -160,27 +177,28 @@ static int start_kernel_proc(void *unused)
 
 int start_uml_skas(void)
 {
-       start_userspace();
-       capture_signal_stack();
+       start_userspace(0);
 
        init_new_thread_signals(1);
-       idle_timer();
+       uml_idle_timer();
 
        init_task.thread.request.u.thread.proc = start_kernel_proc;
        init_task.thread.request.u.thread.arg = NULL;
-       return(start_idle_thread((void *) init_task.thread.kernel_stack,
+       return(start_idle_thread(init_task.thread_info,
                                 &init_task.thread.mode.skas.switch_buf,
                                 &init_task.thread.mode.skas.fork_buf));
 }
 
 int external_pid_skas(struct task_struct *task)
 {
-       return(userspace_pid);
+#warning Need to look up userspace_pid by cpu
+       return(userspace_pid[0]);
 }
 
 int thread_pid_skas(struct task_struct *task)
 {
-       return(userspace_pid);
+#warning Need to look up userspace_pid by cpu
+       return(userspace_pid[0]);
 }
 
 /*