diff --git a/lib/libkse/arch/amd64/include/pthread_md.h b/lib/libkse/arch/amd64/include/pthread_md.h index b6f05a83a1e9..1b39f085b56b 100644 --- a/lib/libkse/arch/amd64/include/pthread_md.h +++ b/lib/libkse/arch/amd64/include/pthread_md.h @@ -235,17 +235,31 @@ _thread_enter_uts(struct tcb *tcb, struct kcb *kcb) static __inline int _thread_switch(struct kcb *kcb, struct tcb *tcb, int setmbox) { + extern int _libkse_debug; + if ((kcb == NULL) || (tcb == NULL)) return (-1); kcb->kcb_curtcb = tcb; - if (setmbox != 0) - _amd64_restore_context(&tcb->tcb_tmbx.tm_context.uc_mcontext, - (intptr_t)&tcb->tcb_tmbx, - (intptr_t *)&kcb->kcb_kmbx.km_curthread); - else - _amd64_restore_context(&tcb->tcb_tmbx.tm_context.uc_mcontext, - 0, NULL); - /* We should not reach here. */ + + if (_libkse_debug == 0) { + tcb->tcb_tmbx.tm_lwp = kcb->kcb_kmbx.km_lwp; + if (setmbox != 0) + _amd64_restore_context( + &tcb->tcb_tmbx.tm_context.uc_mcontext, + (intptr_t)&tcb->tcb_tmbx, + (intptr_t *)&kcb->kcb_kmbx.km_curthread); + else + _amd64_restore_context( + &tcb->tcb_tmbx.tm_context.uc_mcontext, + 0, NULL); + /* We should not reach here. */ + } else { + if (setmbox) + kse_switchin(&tcb->tcb_tmbx, KSE_SWITCHIN_SETTMBX); + else + kse_switchin(&tcb->tcb_tmbx, 0); + } + return (-1); } #endif diff --git a/lib/libkse/arch/arm/include/pthread_md.h b/lib/libkse/arch/arm/include/pthread_md.h index 107eb03e9533..4cce2123f90b 100644 --- a/lib/libkse/arch/arm/include/pthread_md.h +++ b/lib/libkse/arch/arm/include/pthread_md.h @@ -227,15 +227,24 @@ _thread_enter_uts(struct tcb *tcb, struct kcb *kcb) static __inline int _thread_switch(struct kcb *kcb, struct tcb *tcb, int setmbox) { + extern int _libkse_debug; mcontext_t *mc; _tcb_set(kcb, tcb); mc = &tcb->tcb_tmbx.tm_context.uc_mcontext; - if (setmbox) - _thr_setcontext(mc, (intptr_t)&tcb->tcb_tmbx, - (intptr_t *)&kcb->kcb_kmbx.km_curthread); - else - _thr_setcontext(mc, 0, NULL); + if (_libkse_debug == 0) { + if (setmbox) + _thr_setcontext(mc, (intptr_t)&tcb->tcb_tmbx, + (intptr_t *)&kcb->kcb_kmbx.km_curthread); + else + _thr_setcontext(mc, 0, NULL); + } else { + if (setmbox) + kse_switchin(&tcb->tcb_tmbx, KSE_SWITCHIN_SETTMBX); + else + kse_switchin(&tcb->tcb_tmbx, 0); + } + /* We should not reach here. */ return (-1); } diff --git a/lib/libkse/arch/i386/include/pthread_md.h b/lib/libkse/arch/i386/include/pthread_md.h index 4bcb13075cde..28eefc1febd0 100644 --- a/lib/libkse/arch/i386/include/pthread_md.h +++ b/lib/libkse/arch/i386/include/pthread_md.h @@ -237,15 +237,27 @@ _thread_enter_uts(struct tcb *tcb, struct kcb *kcb) static __inline int _thread_switch(struct kcb *kcb, struct tcb *tcb, int setmbox) { + extern int _libkse_debug; + if ((kcb == NULL) || (tcb == NULL)) return (-1); kcb->kcb_curtcb = tcb; - if (setmbox != 0) - _thr_setcontext(&tcb->tcb_tmbx.tm_context.uc_mcontext, - (intptr_t)&tcb->tcb_tmbx, - (intptr_t *)&kcb->kcb_kmbx.km_curthread); - else - _thr_setcontext(&tcb->tcb_tmbx.tm_context.uc_mcontext, 0, NULL); + if (_libkse_debug == 0) { + tcb->tcb_tmbx.tm_lwp = kcb->kcb_kmbx.km_lwp; + if (setmbox != 0) + _thr_setcontext(&tcb->tcb_tmbx.tm_context.uc_mcontext, + (intptr_t)&tcb->tcb_tmbx, + (intptr_t *)&kcb->kcb_kmbx.km_curthread); + else + _thr_setcontext(&tcb->tcb_tmbx.tm_context.uc_mcontext, + 0, NULL); + } else { + if (setmbox) + kse_switchin(&tcb->tcb_tmbx, KSE_SWITCHIN_SETTMBX); + else + kse_switchin(&tcb->tcb_tmbx, 0); + } + /* We should not reach here. */ return (-1); } diff --git a/lib/libkse/arch/sparc64/include/pthread_md.h b/lib/libkse/arch/sparc64/include/pthread_md.h index 17ebc3b86ca5..b180e0a13d63 100644 --- a/lib/libkse/arch/sparc64/include/pthread_md.h +++ b/lib/libkse/arch/sparc64/include/pthread_md.h @@ -227,15 +227,25 @@ _thread_enter_uts(struct tcb *tcb, struct kcb *kcb) static __inline int _thread_switch(struct kcb *kcb, struct tcb *tcb, int setmbox) { + extern int _libkse_debug; mcontext_t *mc; _tcb_set(kcb, tcb); mc = &tcb->tcb_tmbx.tm_context.uc_mcontext; - if (setmbox) - _thr_setcontext(mc, (intptr_t)&tcb->tcb_tmbx, - (intptr_t *)&kcb->kcb_kmbx.km_curthread); - else - _thr_setcontext(mc, 0, NULL); + if (_libkse_debug == 0) { + tcb->tcb_tmbx.tm_lwp = kcb->kcb_kmbx.km_lwp; + if (setmbox) + _thr_setcontext(mc, (intptr_t)&tcb->tcb_tmbx, + (intptr_t *)&kcb->kcb_kmbx.km_curthread); + else + _thr_setcontext(mc, 0, NULL); + } else { + if (setmbox) + kse_switchin(&tcb->tcb_tmbx, KSE_SWITCHIN_SETTMBX); + else + kse_switchin(&tcb->tcb_tmbx, 0); + } + /* We should not reach here. */ return (-1); } diff --git a/lib/libpthread/arch/alpha/include/pthread_md.h b/lib/libpthread/arch/alpha/include/pthread_md.h index fd82aad9f568..f4702e019239 100644 --- a/lib/libpthread/arch/alpha/include/pthread_md.h +++ b/lib/libpthread/arch/alpha/include/pthread_md.h @@ -218,14 +218,27 @@ _thread_enter_uts(struct tcb *tcb, struct kcb *kcb) static __inline int _thread_switch(struct kcb *kcb, struct tcb *tcb, int setmbox) { + extern int _libkse_debug; + _tcb_set(kcb, tcb); - if (setmbox != 0) - _alpha_restore_context(&tcb->tcb_tmbx.tm_context.uc_mcontext, - (intptr_t)&tcb->tcb_tmbx, - (intptr_t *)&kcb->kcb_kmbx.km_curthread); - else - _alpha_restore_context(&tcb->tcb_tmbx.tm_context.uc_mcontext, - 0, NULL); + if (_libkse_debug == 0) { + tcb->tcb_tmbx.tm_lwp = kcb->kcb_kmbx.km_lwp; + if (setmbox != 0) + _alpha_restore_context( + &tcb->tcb_tmbx.tm_context.uc_mcontext, + (intptr_t)&tcb->tcb_tmbx, + (intptr_t *)&kcb->kcb_kmbx.km_curthread); + else + _alpha_restore_context( + &tcb->tcb_tmbx.tm_context.uc_mcontext, + 0, NULL); + } else { + if (setmbox) + kse_switchin(&tcb->tcb_tmbx, KSE_SWITCHIN_SETTMBX); + else + kse_switchin(&tcb->tcb_tmbx, 0); + } + /* We should not reach here. */ return (-1); } diff --git a/lib/libpthread/arch/amd64/include/pthread_md.h b/lib/libpthread/arch/amd64/include/pthread_md.h index b6f05a83a1e9..1b39f085b56b 100644 --- a/lib/libpthread/arch/amd64/include/pthread_md.h +++ b/lib/libpthread/arch/amd64/include/pthread_md.h @@ -235,17 +235,31 @@ _thread_enter_uts(struct tcb *tcb, struct kcb *kcb) static __inline int _thread_switch(struct kcb *kcb, struct tcb *tcb, int setmbox) { + extern int _libkse_debug; + if ((kcb == NULL) || (tcb == NULL)) return (-1); kcb->kcb_curtcb = tcb; - if (setmbox != 0) - _amd64_restore_context(&tcb->tcb_tmbx.tm_context.uc_mcontext, - (intptr_t)&tcb->tcb_tmbx, - (intptr_t *)&kcb->kcb_kmbx.km_curthread); - else - _amd64_restore_context(&tcb->tcb_tmbx.tm_context.uc_mcontext, - 0, NULL); - /* We should not reach here. */ + + if (_libkse_debug == 0) { + tcb->tcb_tmbx.tm_lwp = kcb->kcb_kmbx.km_lwp; + if (setmbox != 0) + _amd64_restore_context( + &tcb->tcb_tmbx.tm_context.uc_mcontext, + (intptr_t)&tcb->tcb_tmbx, + (intptr_t *)&kcb->kcb_kmbx.km_curthread); + else + _amd64_restore_context( + &tcb->tcb_tmbx.tm_context.uc_mcontext, + 0, NULL); + /* We should not reach here. */ + } else { + if (setmbox) + kse_switchin(&tcb->tcb_tmbx, KSE_SWITCHIN_SETTMBX); + else + kse_switchin(&tcb->tcb_tmbx, 0); + } + return (-1); } #endif diff --git a/lib/libpthread/arch/arm/include/pthread_md.h b/lib/libpthread/arch/arm/include/pthread_md.h index 107eb03e9533..4cce2123f90b 100644 --- a/lib/libpthread/arch/arm/include/pthread_md.h +++ b/lib/libpthread/arch/arm/include/pthread_md.h @@ -227,15 +227,24 @@ _thread_enter_uts(struct tcb *tcb, struct kcb *kcb) static __inline int _thread_switch(struct kcb *kcb, struct tcb *tcb, int setmbox) { + extern int _libkse_debug; mcontext_t *mc; _tcb_set(kcb, tcb); mc = &tcb->tcb_tmbx.tm_context.uc_mcontext; - if (setmbox) - _thr_setcontext(mc, (intptr_t)&tcb->tcb_tmbx, - (intptr_t *)&kcb->kcb_kmbx.km_curthread); - else - _thr_setcontext(mc, 0, NULL); + if (_libkse_debug == 0) { + if (setmbox) + _thr_setcontext(mc, (intptr_t)&tcb->tcb_tmbx, + (intptr_t *)&kcb->kcb_kmbx.km_curthread); + else + _thr_setcontext(mc, 0, NULL); + } else { + if (setmbox) + kse_switchin(&tcb->tcb_tmbx, KSE_SWITCHIN_SETTMBX); + else + kse_switchin(&tcb->tcb_tmbx, 0); + } + /* We should not reach here. */ return (-1); } diff --git a/lib/libpthread/arch/i386/include/pthread_md.h b/lib/libpthread/arch/i386/include/pthread_md.h index 4bcb13075cde..28eefc1febd0 100644 --- a/lib/libpthread/arch/i386/include/pthread_md.h +++ b/lib/libpthread/arch/i386/include/pthread_md.h @@ -237,15 +237,27 @@ _thread_enter_uts(struct tcb *tcb, struct kcb *kcb) static __inline int _thread_switch(struct kcb *kcb, struct tcb *tcb, int setmbox) { + extern int _libkse_debug; + if ((kcb == NULL) || (tcb == NULL)) return (-1); kcb->kcb_curtcb = tcb; - if (setmbox != 0) - _thr_setcontext(&tcb->tcb_tmbx.tm_context.uc_mcontext, - (intptr_t)&tcb->tcb_tmbx, - (intptr_t *)&kcb->kcb_kmbx.km_curthread); - else - _thr_setcontext(&tcb->tcb_tmbx.tm_context.uc_mcontext, 0, NULL); + if (_libkse_debug == 0) { + tcb->tcb_tmbx.tm_lwp = kcb->kcb_kmbx.km_lwp; + if (setmbox != 0) + _thr_setcontext(&tcb->tcb_tmbx.tm_context.uc_mcontext, + (intptr_t)&tcb->tcb_tmbx, + (intptr_t *)&kcb->kcb_kmbx.km_curthread); + else + _thr_setcontext(&tcb->tcb_tmbx.tm_context.uc_mcontext, + 0, NULL); + } else { + if (setmbox) + kse_switchin(&tcb->tcb_tmbx, KSE_SWITCHIN_SETTMBX); + else + kse_switchin(&tcb->tcb_tmbx, 0); + } + /* We should not reach here. */ return (-1); } diff --git a/lib/libpthread/arch/sparc64/include/pthread_md.h b/lib/libpthread/arch/sparc64/include/pthread_md.h index 17ebc3b86ca5..b180e0a13d63 100644 --- a/lib/libpthread/arch/sparc64/include/pthread_md.h +++ b/lib/libpthread/arch/sparc64/include/pthread_md.h @@ -227,15 +227,25 @@ _thread_enter_uts(struct tcb *tcb, struct kcb *kcb) static __inline int _thread_switch(struct kcb *kcb, struct tcb *tcb, int setmbox) { + extern int _libkse_debug; mcontext_t *mc; _tcb_set(kcb, tcb); mc = &tcb->tcb_tmbx.tm_context.uc_mcontext; - if (setmbox) - _thr_setcontext(mc, (intptr_t)&tcb->tcb_tmbx, - (intptr_t *)&kcb->kcb_kmbx.km_curthread); - else - _thr_setcontext(mc, 0, NULL); + if (_libkse_debug == 0) { + tcb->tcb_tmbx.tm_lwp = kcb->kcb_kmbx.km_lwp; + if (setmbox) + _thr_setcontext(mc, (intptr_t)&tcb->tcb_tmbx, + (intptr_t *)&kcb->kcb_kmbx.km_curthread); + else + _thr_setcontext(mc, 0, NULL); + } else { + if (setmbox) + kse_switchin(&tcb->tcb_tmbx, KSE_SWITCHIN_SETTMBX); + else + kse_switchin(&tcb->tcb_tmbx, 0); + } + /* We should not reach here. */ return (-1); }