Extract out KSE specific code from machine specific code

so that there is ony one copy of it. Fix that one copy
so that KSEs with no mailbox in a KSE program are not a cause
of page faults (this can legitmatly happen).

Submitted by:	(parts) davidxu
This commit is contained in:
Julian Elischer 2002-10-24 23:09:48 +00:00
parent d28e8b3a0d
commit 1434d3fe6f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=105900
8 changed files with 105 additions and 129 deletions

View File

@ -669,24 +669,8 @@ syscall(code, framep)
sticks = td->td_kse->ke_sticks;
if (td->td_ucred != p->p_ucred)
cred_update_thread(td);
if (p->p_flag & P_KSES) {
/*
* If we are doing a syscall in a KSE environment,
* note where our mailbox is. There is always the
* possibility that we could do this lazily (in sleep()),
* but for now do it every time.
*/
td->td_mailbox = (void *)fuword((caddr_t)td->td_kse->ke_mailbox
+ offsetof(struct kse_mailbox, km_curthread));
if ((td->td_mailbox == NULL) ||
(td->td_mailbox == (void *)-1)) {
td->td_mailbox = NULL; /* single thread it.. */
td->td_flags &= ~TDF_UNBOUND;
} else {
td->td_flags |= TDF_UNBOUND;
}
}
if (p->p_flag & P_KSES)
thread_user_enter(p, td);
#ifdef DIAGNOSTIC
alpha_fpstate_check(td);
#endif

View File

@ -963,44 +963,8 @@ syscall(frame)
td->td_frame = &frame;
if (td->td_ucred != p->p_ucred)
cred_update_thread(td);
if (p->p_flag & P_KSES) {
/*
* First check that we shouldn't just abort.
* But check if we are the single thread first!
* XXX p_singlethread not locked, but should be safe.
*/
if ((p->p_flag & P_WEXIT) && (p->p_singlethread != td)) {
PROC_LOCK(p);
mtx_lock_spin(&sched_lock);
thread_exit();
/* NOTREACHED */
}
/*
* If we are doing a syscall in a KSE environment,
* note where our mailbox is. There is always the
* possibility that we could do this lazily (in sleep()),
* but for now do it every time.
*/
#if 0
td->td_mailbox = (void *)fuword((caddr_t)td->td_kse->ke_mailbox
+ offsetof(struct kse_mailbox, km_curthread));
#else /* if user pointer arithmetic is ok in the kernel */
td->td_mailbox =
(void *)fuword(
(void *)&td->td_kse->ke_mailbox->km_curthread);
#endif
if ((td->td_mailbox == NULL) ||
(td->td_mailbox == (void *)-1)) {
td->td_mailbox = NULL; /* single thread it.. */
td->td_flags &= ~TDF_UNBOUND;
} else {
if (td->td_standin == NULL) {
td->td_standin = thread_alloc();
}
td->td_flags |= TDF_UNBOUND;
}
}
if (p->p_flag & P_KSES)
thread_user_enter(p, td);
params = (caddr_t)frame.tf_esp + sizeof(int);
code = frame.tf_eax;
orig_tf_eflags = frame.tf_eflags;

View File

@ -963,44 +963,8 @@ syscall(frame)
td->td_frame = &frame;
if (td->td_ucred != p->p_ucred)
cred_update_thread(td);
if (p->p_flag & P_KSES) {
/*
* First check that we shouldn't just abort.
* But check if we are the single thread first!
* XXX p_singlethread not locked, but should be safe.
*/
if ((p->p_flag & P_WEXIT) && (p->p_singlethread != td)) {
PROC_LOCK(p);
mtx_lock_spin(&sched_lock);
thread_exit();
/* NOTREACHED */
}
/*
* If we are doing a syscall in a KSE environment,
* note where our mailbox is. There is always the
* possibility that we could do this lazily (in sleep()),
* but for now do it every time.
*/
#if 0
td->td_mailbox = (void *)fuword((caddr_t)td->td_kse->ke_mailbox
+ offsetof(struct kse_mailbox, km_curthread));
#else /* if user pointer arithmetic is ok in the kernel */
td->td_mailbox =
(void *)fuword(
(void *)&td->td_kse->ke_mailbox->km_curthread);
#endif
if ((td->td_mailbox == NULL) ||
(td->td_mailbox == (void *)-1)) {
td->td_mailbox = NULL; /* single thread it.. */
td->td_flags &= ~TDF_UNBOUND;
} else {
if (td->td_standin == NULL) {
td->td_standin = thread_alloc();
}
td->td_flags |= TDF_UNBOUND;
}
}
if (p->p_flag & P_KSES)
thread_user_enter(p, td);
params = (caddr_t)frame.tf_esp + sizeof(int);
code = frame.tf_eax;
orig_tf_eflags = frame.tf_eflags;

View File

@ -808,24 +808,8 @@ syscall(int code, u_int64_t *args, struct trapframe *framep)
framep->tf_cr_iip += 16;
}
if (p->p_flag & P_KSES) {
/*
* If we are doing a syscall in a KSE environment,
* note where our mailbox is. There is always the
* possibility that we could do this lazily (in sleep()),
* but for now do it every time.
*/
td->td_mailbox = (void *)fuword((caddr_t)td->td_kse->ke_mailbox
+ offsetof(struct kse_mailbox, km_curthread));
if ((td->td_mailbox == NULL) ||
(td->td_mailbox == (void *)-1)) {
td->td_mailbox = NULL; /* single thread it.. */
td->td_flags &= ~TDF_UNBOUND;
} else {
td->td_flags |= TDF_UNBOUND;
}
}
if (p->p_flag & P_KSES)
thread_user_enter(p, td);
#ifdef DIAGNOSTIC
ia64_fpstate_check(td);
#endif

View File

@ -1157,6 +1157,53 @@ return (NULL);
return (td2);
}
/*
* setup done on the thread when it enters the kernel.
* XXXKSE Presently only for syscalls but eventually all kernel entries.
*/
void
thread_user_enter(struct proc *p, struct thread *td)
{
struct kse *ke;
/*
* First check that we shouldn't just abort.
* But check if we are the single thread first!
* XXX p_singlethread not locked, but should be safe.
*/
if ((p->p_flag & P_WEXIT) && (p->p_singlethread != td)) {
PROC_LOCK(p);
mtx_lock_spin(&sched_lock);
thread_exit();
/* NOTREACHED */
}
/*
* If we are doing a syscall in a KSE environment,
* note where our mailbox is. There is always the
* possibility that we could do this lazily (in sleep()),
* but for now do it every time.
*/
if ((ke = td->td_kse->ke_mailbox)) {
#if 0
td->td_mailbox = (void *)fuword((caddr_t)ke->ke_mailbox
+ offsetof(struct kse_mailbox, km_curthread));
#else /* if user pointer arithmetic is ok in the kernel */
td->td_mailbox =
(void *)fuword( (void *)&ke->ke_mailbox->km_curthread);
#endif
if ((td->td_mailbox == NULL) ||
(td->td_mailbox == (void *)-1)) {
td->td_mailbox = NULL; /* single thread it.. */
td->td_flags &= ~TDF_UNBOUND;
} else {
if (td->td_standin == NULL)
td->td_standin = thread_alloc();
td->td_flags |= TDF_UNBOUND;
}
}
}
/*
* The extra work we go through if we are a threaded process when we
* return to userland.

View File

@ -1157,6 +1157,53 @@ return (NULL);
return (td2);
}
/*
* setup done on the thread when it enters the kernel.
* XXXKSE Presently only for syscalls but eventually all kernel entries.
*/
void
thread_user_enter(struct proc *p, struct thread *td)
{
struct kse *ke;
/*
* First check that we shouldn't just abort.
* But check if we are the single thread first!
* XXX p_singlethread not locked, but should be safe.
*/
if ((p->p_flag & P_WEXIT) && (p->p_singlethread != td)) {
PROC_LOCK(p);
mtx_lock_spin(&sched_lock);
thread_exit();
/* NOTREACHED */
}
/*
* If we are doing a syscall in a KSE environment,
* note where our mailbox is. There is always the
* possibility that we could do this lazily (in sleep()),
* but for now do it every time.
*/
if ((ke = td->td_kse->ke_mailbox)) {
#if 0
td->td_mailbox = (void *)fuword((caddr_t)ke->ke_mailbox
+ offsetof(struct kse_mailbox, km_curthread));
#else /* if user pointer arithmetic is ok in the kernel */
td->td_mailbox =
(void *)fuword( (void *)&ke->ke_mailbox->km_curthread);
#endif
if ((td->td_mailbox == NULL) ||
(td->td_mailbox == (void *)-1)) {
td->td_mailbox = NULL; /* single thread it.. */
td->td_flags &= ~TDF_UNBOUND;
} else {
if (td->td_standin == NULL)
td->td_standin = thread_alloc();
td->td_flags |= TDF_UNBOUND;
}
}
}
/*
* The extra work we go through if we are a threaded process when we
* return to userland.

View File

@ -575,23 +575,8 @@ syscall(struct trapframe *tf)
td->td_frame = tf;
if (td->td_ucred != p->p_ucred)
cred_update_thread(td);
if (p->p_flag & P_KSES) {
/*
* If we are doing a syscall in a KSE environment,
* note where our mailbox is. There is always the
* possibility that we could do this lazily (in sleep()),
* but for now do it every time.
*/
td->td_mailbox = (void *)fuword((caddr_t)td->td_kse->ke_mailbox
+ offsetof(struct kse_mailbox, km_curthread));
if ((td->td_mailbox == NULL) ||
(td->td_mailbox == (void *)-1)) {
td->td_mailbox = NULL; /* single thread it.. */
td->td_flags &= ~TDF_UNBOUND;
} else {
td->td_flags |= TDF_UNBOUND;
}
}
if (p->p_flag & P_KSES)
thread_user_enter(p, td);
code = tf->tf_global[1];
/*

View File

@ -931,6 +931,7 @@ void thread_suspend_one(struct thread *td);
void thread_unsuspend(struct proc *p);
void thread_unsuspend_one(struct thread *td);
int thread_userret(struct thread *td, struct trapframe *frame);
void thread_user_enter(struct proc *p, struct thread *td);
void thread_sanity_check(struct thread *td, char *);
#endif /* _KERNEL */