Create a ucontext for the system call to work in; its cloned from the new

pcb's call `userland' ucontext.
This commit is contained in:
reinoud 2011-09-08 12:01:22 +00:00
parent 6438f483a9
commit dbc71f3ad4
3 changed files with 25 additions and 18 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cpu.c,v 1.34 2011/09/06 09:55:04 jmcneill Exp $ */
/* $NetBSD: cpu.c,v 1.35 2011/09/08 12:01:22 reinoud Exp $ */
/*-
* Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca>
@ -29,7 +29,7 @@
#include "opt_cpu.h"
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.34 2011/09/06 09:55:04 jmcneill Exp $");
__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.35 2011/09/08 12:01:22 reinoud Exp $");
#include <sys/param.h>
#include <sys/conf.h>
@ -296,6 +296,7 @@ printf("switching to userland\n");
panic("%s: shouldn't return", __func__);
}
extern int syscall(lwp_t *l);
void
cpu_lwp_fork(struct lwp *l1, struct lwp *l2, void *stack, size_t stacksize,
void (*func)(void *), void *arg)
@ -324,12 +325,23 @@ cpu_lwp_fork(struct lwp *l1, struct lwp *l2, void *stack, size_t stacksize,
if (thunk_getcontext(&pcb2->pcb_ucp))
panic("getcontext failed");
/* set up the ucontext for the userland */
pcb2->pcb_ucp.uc_stack.ss_sp = stack;
pcb2->pcb_ucp.uc_stack.ss_size = stacksize;
pcb2->pcb_ucp.uc_link = NULL;
pcb2->pcb_ucp.uc_flags = _UC_STACK | _UC_CPU;
thunk_makecontext(&pcb2->pcb_ucp, (void (*)(void))cpu_lwp_trampoline,
2, func, arg);
/* set up the ucontext for the syscall */
pcb2->pcb_ucp.uc_flags = _UC_CPU;
/* hack for it sets the stack anyway!! */
pcb2->pcb_syscall_ucp.uc_stack.ss_sp =
((uint8_t *) pcb2->pcb_syscall_ucp.uc_stack.ss_sp) - 4;
pcb2->pcb_syscall_ucp.uc_stack.ss_size = 0;
thunk_makecontext_1(&pcb2->pcb_syscall_ucp, (void (*)(void)) syscall,
l2);
}
void
@ -337,7 +349,6 @@ cpu_initclocks(void)
{
}
int syscall(lwp_t *l, struct trapframe *tr);
void
cpu_startup(void)
{
@ -355,8 +366,8 @@ cpu_startup(void)
uvm_lwp_setuarea(&lwp0, (vaddr_t)&lwp0pcb);
/* init trapframe (going nowhere!), maybe a panic func? */
lwp0pcb.pcb_tf.tf_syscall = syscall;
memcpy(&lwp0pcb.pcb_userland_ucp, &lwp0pcb.pcb_ucp, sizeof(ucontext_t));
memcpy(&lwp0pcb.pcb_syscall_ucp, &lwp0pcb.pcb_ucp, sizeof(ucontext_t));
// thunk_makecontext_trapframe2go(&lwp0pcb.pcb_userland_ucp, NULL, NULL);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcb.h,v 1.10 2011/09/04 21:01:39 reinoud Exp $ */
/* $NetBSD: pcb.h,v 1.11 2011/09/08 12:01:22 reinoud Exp $ */
/*-
* Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca>
@ -37,22 +37,18 @@
* XXX move to frame.h?
*/
/* XXX unused XXX */
typedef struct trapframe {
int (*tf_syscall)(lwp_t *, struct trapframe *);
int tf_reason; /* XXX unused */
uintptr_t tf_io[8]; /* to transport info */
} trapframe_t;
//typedef ucontext_t trapframe;
struct pcb {
ucontext_t pcb_ucp; /* lwp switchframe */
ucontext_t pcb_userland_ucp; /* userland switchframe */
ucontext_t pcb_syscall_ucp; /* to switch to for syscall */
bool pcb_needfree;
struct trapframe pcb_tf;
void * pcb_onfault; /* on fault handler */
int pcb_errno; /* save/restore place */
int pcb_oldspl;
};
#endif /* !_ARCH_USERMODE_INCLUDE_PCB_H */

View File

@ -1,4 +1,4 @@
/* $NetBSD: syscall.c,v 1.5 2011/08/29 12:37:20 reinoud Exp $ */
/* $NetBSD: syscall.c,v 1.6 2011/09/08 12:01:22 reinoud Exp $ */
/*-
* Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca>
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.5 2011/08/29 12:37:20 reinoud Exp $");
__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.6 2011/09/08 12:01:22 reinoud Exp $");
#include <sys/types.h>
#include <sys/param.h>
@ -41,7 +41,7 @@ __KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.5 2011/08/29 12:37:20 reinoud Exp $");
#include <machine/pcb.h>
#include <machine/thunk.h>
int syscall(lwp_t *l, struct trapframe *tr);
extern int syscall(lwp_t *l);
void
child_return(void *arg)
@ -60,8 +60,8 @@ printf("child returned! arg %p\n", arg);
int
syscall(lwp_t *l, struct trapframe *tr)
syscall(lwp_t *l)
{
printf("syscall called for lwp %p, trapframe %p!\n", l, tr);
printf("syscall called for lwp %p!\n", l);
return ENOENT;
}