From 507b03186a50e9219c948ceb9c313a843c567872 Mon Sep 17 00:00:00 2001 From: David Xu Date: Mon, 12 Jul 2004 07:39:20 +0000 Subject: [PATCH] Change kse_switchin to accept kse_thr_mailbox pointer, the syscall will be used heavily in debugging KSE threads. This breaks libpthread on IA64, but because libpthread was not in 5.2.1 release, I would like to change it so we needn't to introduce another syscall. --- sys/kern/kern_kse.c | 29 ++++++++++++++++++++--------- sys/kern/syscalls.master | 4 ++-- sys/sys/kse.h | 5 ++++- sys/sys/sysproto.h | 5 ++--- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/sys/kern/kern_kse.c b/sys/kern/kern_kse.c index 349812714fdb..0b4e7c55cc72 100644 --- a/sys/kern/kern_kse.c +++ b/sys/kern/kern_kse.c @@ -126,25 +126,36 @@ upcall_remove(struct thread *td) #ifndef _SYS_SYSPROTO_H_ struct kse_switchin_args { - const struct __mcontext *mcp; - long val; - long *loc; + struct kse_thr_mailbox *tmbx; + int flags; }; #endif int kse_switchin(struct thread *td, struct kse_switchin_args *uap) { - mcontext_t mc; + struct kse_thr_mailbox tmbx; + struct kse_upcall *ku; int error; - error = (uap->mcp == NULL) ? EINVAL : 0; + if ((ku = td->td_upcall) == NULL || TD_CAN_UNBIND(td)) + return (EINVAL); + error = (uap->tmbx == NULL) ? EINVAL : 0; if (!error) - error = copyin(uap->mcp, &mc, sizeof(mc)); - if (!error && uap->loc != NULL) - error = (suword(uap->loc, uap->val) != 0) ? EINVAL : 0; + error = copyin(uap->tmbx, &tmbx, sizeof(tmbx)); + if (!error && (uap->flags & KSE_SWITCHIN_SETTMBX)) + error = (suword(&ku->ku_mailbox->km_curthread, + (long)uap->tmbx) != 0 ? EINVAL : 0); if (!error) - error = set_mcontext(td, &mc); + error = set_mcontext(td, &tmbx.tm_context.uc_mcontext); + if (!error) { + if (uap->flags & KSE_SWITCHIN_SETTMBX) { + td->td_mailbox = uap->tmbx; + mtx_lock_spin(&sched_lock); + td->td_flags |= TDF_CAN_UNBIND; + mtx_unlock_spin(&sched_lock); + } + } return ((error == 0) ? EJUSTRETURN : error); } diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master index acab8e01e571..05d8ffa751a2 100644 --- a/sys/kern/syscalls.master +++ b/sys/kern/syscalls.master @@ -626,8 +626,8 @@ int attrnamespace, void *data, size_t nbytes); } 439 STD { ssize_t extattr_list_link(const char *path, \ int attrnamespace, void *data, size_t nbytes); } -440 MSTD { int kse_switchin(const struct __mcontext *mcp, \ - long val, long *loc); } +440 MSTD { int kse_switchin(struct kse_thr_mailbox *tmbx, \ + int flags); } 441 MNOSTD { int ksem_timedwait(semid_t id, struct timespec *abstime); } 442 MSTD { int thr_suspend(const struct timespec *timeout); } 443 MSTD { int thr_wake(long id); } diff --git a/sys/sys/kse.h b/sys/sys/kse.h index 286b82a9f6ac..2d02eb788395 100644 --- a/sys/sys/kse.h +++ b/sys/sys/kse.h @@ -96,6 +96,9 @@ struct kse_mailbox { /* These flags are kept in tm_flags */ #define TMF_NOUPCALL 0x01 +/* Flags for kse_switchin */ +#define KSE_SWITCHIN_SETTMBX 0x01 + /* Commands for kse_thr_interrupt */ #define KSE_INTR_INTERRUPT 0x01 #define KSE_INTR_RESTART 0x02 @@ -108,7 +111,7 @@ int kse_exit(void); int kse_release(struct timespec *); int kse_thr_interrupt(struct kse_thr_mailbox *, int, long); int kse_wakeup(struct kse_mailbox *); -int kse_switchin(mcontext_t *, long, long *); +int kse_switchin(struct kse_thr_mailbox *, int flags); #endif /* !_KERNEL */ #endif /* !_SYS_KSE_H_ */ diff --git a/sys/sys/sysproto.h b/sys/sys/sysproto.h index 37ae6289f06b..a8e3a6b5a7dd 100644 --- a/sys/sys/sysproto.h +++ b/sys/sys/sysproto.h @@ -1289,9 +1289,8 @@ struct extattr_list_link_args { char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)]; }; struct kse_switchin_args { - char mcp_l_[PADL_(const struct __mcontext *)]; const struct __mcontext * mcp; char mcp_r_[PADR_(const struct __mcontext *)]; - char val_l_[PADL_(long)]; long val; char val_r_[PADR_(long)]; - char loc_l_[PADL_(long *)]; long * loc; char loc_r_[PADR_(long *)]; + char tmbx_l_[PADL_(struct kse_thr_mailbox *)]; struct kse_thr_mailbox * tmbx; char tmbx_r_[PADR_(struct kse_thr_mailbox *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; }; struct ksem_timedwait_args { char id_l_[PADL_(semid_t)]; semid_t id; char id_r_[PADR_(semid_t)];