amd64: Implement cpu_prepare_lwp().
authorJordan Gordeev <jgordeev@dir.bg>
Wed, 3 Jun 2009 16:11:46 +0000 (19:11 +0300)
committerJordan Gordeev <jgordeev@dir.bg>
Fri, 5 Jun 2009 18:57:03 +0000 (21:57 +0300)
Adapted from i386.

sys/platform/pc64/amd64/vm_machdep.c

index c9b4d16..56a5b94 100644 (file)
@@ -196,7 +196,30 @@ cpu_fork(struct lwp *lp1, struct lwp *lp2, int flags)
 int
 cpu_prepare_lwp(struct lwp *lp, struct lwp_params *params)
 {
-       panic("dummy called in vm_machdep.c: line: %d", __LINE__);
+       struct trapframe *regs = lp->lwp_md.md_regs;
+       void *bad_return = NULL;
+       int error;
+
+       regs->tf_rip = (long)params->func;
+       regs->tf_rsp = (long)params->stack;
+       /* Set up argument for function call */
+       regs->tf_rsp -= sizeof(params->arg);
+       error = 
+           copyout(&params->arg, (void *)regs->tf_rsp, sizeof(params->arg));
+       if (error)
+               return (error);
+       /*
+        * Set up fake return address.  As the lwp function may never return,
+        * we simply copy out a NULL pointer and force the lwp to receive
+        * a SIGSEGV if it returns anyways.
+        */
+       regs->tf_rsp -= sizeof(void *);
+       error = copyout(&bad_return, (void *)regs->tf_rsp, sizeof(bad_return));
+       if (error)
+               return (error);
+
+       cpu_set_fork_handler(lp,
+           (void (*)(void *, struct trapframe *))generic_lwp_return, lp);
        return (0);
 }