From 7644b9ad9f305729ec891dec235c3d72345d3ec8 Mon Sep 17 00:00:00 2001 From: marcel Date: Sat, 2 Sep 2006 01:16:56 +0000 Subject: [PATCH] MFC TLS fixes. --- lib/libc/powerpc/gen/_set_tp.c | 4 ++-- lib/libthr/arch/ia64/ia64/pthread_md.c | 10 +++------- lib/libthr/arch/ia64/include/pthread_md.h | 14 +++++++------- lib/libthr/arch/powerpc/include/pthread_md.h | 16 +++++++++------- lib/libthr/arch/powerpc/powerpc/pthread_md.c | 10 +++------- 5 files changed, 24 insertions(+), 30 deletions(-) diff --git a/lib/libc/powerpc/gen/_set_tp.c b/lib/libc/powerpc/gen/_set_tp.c index 045416ddafdf..5a89698b82c5 100644 --- a/lib/libc/powerpc/gen/_set_tp.c +++ b/lib/libc/powerpc/gen/_set_tp.c @@ -29,7 +29,7 @@ void _set_tp(void *tpval) { - register void* tp __asm__("r2"); + register void *tp __asm__("r2"); - tp = (char*) tpval + 0x7008; + __asm __volatile("mr %0,%1" : "=r"(tp) : "r"((char*)tpval + 0x7008)); } diff --git a/lib/libthr/arch/ia64/ia64/pthread_md.c b/lib/libthr/arch/ia64/ia64/pthread_md.c index a6f7defc1056..c2ad71a4f775 100644 --- a/lib/libthr/arch/ia64/ia64/pthread_md.c +++ b/lib/libthr/arch/ia64/ia64/pthread_md.c @@ -39,13 +39,9 @@ struct tcb * _tcb_ctor(struct pthread *thread, int initial) { struct tcb *tcb; - void *oldtls; - if (initial) - oldtls = _tp; - else - oldtls = NULL; - tcb = _rtld_allocate_tls(oldtls, sizeof(struct tcb), 16); + tcb = _rtld_allocate_tls((initial) ? _tcb_get() : NULL, + sizeof(struct tcb), 16); if (tcb) tcb->tcb_thread = thread; return (tcb); @@ -54,5 +50,5 @@ _tcb_ctor(struct pthread *thread, int initial) void _tcb_dtor(struct tcb *tcb) { - _rtld_free_tls(tcb, sizeof(tcb), 16); + _rtld_free_tls(tcb, sizeof(struct tcb), 16); } diff --git a/lib/libthr/arch/ia64/include/pthread_md.h b/lib/libthr/arch/ia64/include/pthread_md.h index aee5dd2b1c4c..eff38bb172d8 100644 --- a/lib/libthr/arch/ia64/include/pthread_md.h +++ b/lib/libthr/arch/ia64/include/pthread_md.h @@ -42,10 +42,6 @@ struct tcb { struct pthread *tcb_thread; }; -register struct tcb *_tp __asm("%r13"); - -#define _tcb _tp - /* * The tcb constructors. */ @@ -56,13 +52,17 @@ void _tcb_dtor(struct tcb *); static __inline void _tcb_set(struct tcb *tcb) { - _tp = tcb; + register struct tcb *tp __asm("%r13"); + + __asm __volatile("mov %0 = %1;;" : "=r"(tp) : "r"(tcb)); } static __inline struct tcb * _tcb_get(void) { - return (_tcb); + register struct tcb *tp __asm("%r13"); + + return (tp); } extern struct pthread *_thr_initial; @@ -71,7 +71,7 @@ static __inline struct pthread * _get_curthread(void) { if (_thr_initial) - return (_tcb->tcb_thread); + return (_tcb_get()->tcb_thread); return (NULL); } diff --git a/lib/libthr/arch/powerpc/include/pthread_md.h b/lib/libthr/arch/powerpc/include/pthread_md.h index 008c4cd702a1..e8ca8b3d891b 100644 --- a/lib/libthr/arch/powerpc/include/pthread_md.h +++ b/lib/libthr/arch/powerpc/include/pthread_md.h @@ -37,6 +37,7 @@ #include #define DTV_OFFSET offsetof(struct tcb, tcb_dtv) +#define TP_OFFSET 0x7008 /* * Variant I tcb. The structure layout is fixed, don't blindly @@ -48,23 +49,24 @@ struct tcb { struct pthread *tcb_thread; }; -register uint8_t *_tp __asm("%r2"); - -#define _tcb ((struct tcb *)(_tp - sizeof(struct tcb))) - struct tcb *_tcb_ctor(struct pthread *, int); void _tcb_dtor(struct tcb *); static __inline void _tcb_set(struct tcb *tcb) { - _tp = (uint8_t *)tcb + sizeof(struct tcb); + register uint8_t *_tp __asm__("%r2"); + + __asm __volatile("mr %0,%1" : "=r"(_tp) : + "r"((uint8_t *)tcb + TP_OFFSET)); } static __inline struct tcb * _tcb_get(void) { - return (_tcb); + register uint8_t *_tp __asm__("%r2"); + + return ((struct tcb *)(_tp - TP_OFFSET)); } extern struct pthread *_thr_initial; @@ -73,7 +75,7 @@ static __inline struct pthread * _get_curthread(void) { if (_thr_initial) - return (_tcb->tcb_thread); + return (_tcb_get()->tcb_thread); return (NULL); } diff --git a/lib/libthr/arch/powerpc/powerpc/pthread_md.c b/lib/libthr/arch/powerpc/powerpc/pthread_md.c index aa02a8dbfa81..66f043e294a7 100644 --- a/lib/libthr/arch/powerpc/powerpc/pthread_md.c +++ b/lib/libthr/arch/powerpc/powerpc/pthread_md.c @@ -38,13 +38,9 @@ struct tcb * _tcb_ctor(struct pthread *thread, int initial) { struct tcb *tcb; - void *oldtls; - if (initial) - oldtls = _tp; - else - oldtls = NULL; - tcb = _rtld_allocate_tls(oldtls, sizeof(struct tcb), 16); + tcb = _rtld_allocate_tls((initial) ? _tcb_get() : NULL, + sizeof(struct tcb), 1); if (tcb) tcb->tcb_thread = thread; return (tcb); @@ -54,5 +50,5 @@ _tcb_ctor(struct pthread *thread, int initial) void _tcb_dtor(struct tcb *tcb) { - _rtld_free_tls(tcb, sizeof(tcb), 16); + _rtld_free_tls(tcb, sizeof(struct tcb), 1); }