diff options
author | julian <julian@FreeBSD.org> | 2002-10-24 23:09:48 +0000 |
---|---|---|
committer | julian <julian@FreeBSD.org> | 2002-10-24 23:09:48 +0000 |
commit | 59e8ad5a4cd503ce5e0ec12e11609971683ab5cc (patch) | |
tree | 62423a3307545934139e299f4e19177031d11875 /sys/kern | |
parent | f1e4ff6b707f91cd9b24d6adef67a812a71a736c (diff) | |
download | FreeBSD-src-59e8ad5a4cd503ce5e0ec12e11609971683ab5cc.zip FreeBSD-src-59e8ad5a4cd503ce5e0ec12e11609971683ab5cc.tar.gz |
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
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_kse.c | 47 | ||||
-rw-r--r-- | sys/kern/kern_thread.c | 47 |
2 files changed, 94 insertions, 0 deletions
diff --git a/sys/kern/kern_kse.c b/sys/kern/kern_kse.c index 02a62f6..d47f32e 100644 --- a/sys/kern/kern_kse.c +++ b/sys/kern/kern_kse.c @@ -1158,6 +1158,53 @@ return (NULL); } /* + * 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. * diff --git a/sys/kern/kern_thread.c b/sys/kern/kern_thread.c index 02a62f6..d47f32e 100644 --- a/sys/kern/kern_thread.c +++ b/sys/kern/kern_thread.c @@ -1158,6 +1158,53 @@ return (NULL); } /* + * 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. * |