This commit is contained in:
Marcel Moolenaar 2006-09-01 06:15:00 +00:00
parent 3614156c7d
commit 8e61dbecfc
2 changed files with 11 additions and 17 deletions

View File

@ -37,7 +37,7 @@
#include <sys/types.h> #include <sys/types.h>
#define DTV_OFFSET offsetof(struct tcb, tcb_dtv) #define DTV_OFFSET offsetof(struct tcb, tcb_dtv)
#define TLS_TP_OFFSET 0x7000 #define TLS_TP_OFFSET 0x7008
/* /*
* Variant I tcb. The structure layout is fixed, don't blindly * Variant I tcb. The structure layout is fixed, don't blindly
@ -49,26 +49,24 @@ struct tcb {
struct pthread *tcb_thread; struct pthread *tcb_thread;
}; };
register uint8_t *_tp __asm("%r2");
#define _tcb ((struct tcb *)(_tp - TLS_TP_OFFSET - sizeof(struct tcb)))
struct tcb *_tcb_ctor(struct pthread *, int); struct tcb *_tcb_ctor(struct pthread *, int);
void _tcb_dtor(struct tcb *); void _tcb_dtor(struct tcb *);
static __inline void static __inline void
_tcb_set(struct tcb *tcb) _tcb_set(struct tcb *tcb)
{ {
uint8_t *tp; register uint8_t *_tp __asm__("%r2");
tp = (uint8_t *)tcb + TLS_TP_OFFSET + sizeof(struct tcb); __asm __volatile("mr %0,%1" : "=r"(_tp) :
__asm __volatile("mr %0,%1" : "=r"(_tp) : "r"(tp)); "r"((uint8_t *)tcb + TLS_TP_OFFSET));
} }
static __inline struct tcb * static __inline struct tcb *
_tcb_get(void) _tcb_get(void)
{ {
return (_tcb); register uint8_t *_tp __asm__("%r2");
return ((struct tcb *)(_tp - TLS_TP_OFFSET));
} }
extern struct pthread *_thr_initial; extern struct pthread *_thr_initial;
@ -77,7 +75,7 @@ static __inline struct pthread *
_get_curthread(void) _get_curthread(void)
{ {
if (_thr_initial) if (_thr_initial)
return (_tcb->tcb_thread); return (_tcb_get()->tcb_thread);
return (NULL); return (NULL);
} }

View File

@ -38,13 +38,9 @@ struct tcb *
_tcb_ctor(struct pthread *thread, int initial) _tcb_ctor(struct pthread *thread, int initial)
{ {
struct tcb *tcb; struct tcb *tcb;
void *oldtls;
if (initial) tcb = _rtld_allocate_tls((initial) ? _tcb_get() : NULL,
oldtls = _tcb_get(); sizeof(struct tcb), 1);
else
oldtls = NULL;
tcb = _rtld_allocate_tls(oldtls, sizeof(struct tcb), 16);
if (tcb) if (tcb)
tcb->tcb_thread = thread; tcb->tcb_thread = thread;
return (tcb); return (tcb);
@ -54,5 +50,5 @@ _tcb_ctor(struct pthread *thread, int initial)
void void
_tcb_dtor(struct tcb *tcb) _tcb_dtor(struct tcb *tcb)
{ {
_rtld_free_tls(tcb, sizeof(struct tcb), 16); _rtld_free_tls(tcb, sizeof(struct tcb), 1);
} }