libthr: Use <machine/tls.h> for most MD TLS details.
Note that on amd64 this effectively removes the unused tcb_spare field from the end of struct tcb since the definition of struct tcb in <x86/tls.h> does not include that field. Reviewed by: kib, jrtc27 Sponsored by: The University of Cambridge, Google Inc. Differential Revision: https://reviews.freebsd.org/D33352
This commit is contained in:
parent
1a62e9bc00
commit
75395023ff
@ -37,39 +37,10 @@
|
||||
#define _PTHREAD_MD_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <machine/sysarch.h>
|
||||
#include <machine/tls.h>
|
||||
|
||||
#define CPU_SPINWAIT
|
||||
|
||||
/*
|
||||
* Variant I tcb. The structure layout is fixed, don't blindly
|
||||
* change it.
|
||||
*/
|
||||
struct tcb {
|
||||
void *tcb_dtv;
|
||||
struct pthread *tcb_thread;
|
||||
};
|
||||
|
||||
/* Called from the thread to set its private data. */
|
||||
static __inline void
|
||||
_tcb_set(struct tcb *tcb)
|
||||
{
|
||||
|
||||
__asm __volatile("msr tpidr_el0, %x0" :: "r" (tcb));
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the current tcb.
|
||||
*/
|
||||
static __inline struct tcb *
|
||||
_tcb_get(void)
|
||||
{
|
||||
struct tcb *tcb;
|
||||
|
||||
__asm __volatile("mrs %x0, tpidr_el0" : "=r" (tcb));
|
||||
return (tcb);
|
||||
}
|
||||
|
||||
static __inline struct pthread *
|
||||
_get_curthread(void)
|
||||
{
|
||||
|
@ -37,62 +37,18 @@
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
#include <machine/sysarch.h>
|
||||
#include <machine/tls.h>
|
||||
|
||||
#define CPU_SPINWAIT __asm __volatile("pause")
|
||||
|
||||
/*
|
||||
* Variant II tcb, first two members are required by rtld,
|
||||
* %fs points to the structure.
|
||||
*/
|
||||
struct tcb {
|
||||
struct tcb *tcb_self; /* required by rtld */
|
||||
void *tcb_dtv; /* required by rtld */
|
||||
struct pthread *tcb_thread;
|
||||
void *tcb_spare[1];
|
||||
};
|
||||
|
||||
/*
|
||||
* Evaluates to the byte offset of the per-tcb variable name.
|
||||
*/
|
||||
#define __tcb_offset(name) __offsetof(struct tcb, name)
|
||||
|
||||
/*
|
||||
* Evaluates to the type of the per-tcb variable name.
|
||||
*/
|
||||
#define __tcb_type(name) __typeof(((struct tcb *)0)->name)
|
||||
|
||||
/*
|
||||
* Evaluates to the value of the per-tcb variable name.
|
||||
*/
|
||||
#define TCB_GET64(name) ({ \
|
||||
__tcb_type(name) __result; \
|
||||
\
|
||||
u_long __i; \
|
||||
__asm __volatile("movq %%fs:%1, %0" \
|
||||
: "=r" (__i) \
|
||||
: "m" (*(volatile u_long *)(__tcb_offset(name)))); \
|
||||
__result = (__tcb_type(name))__i; \
|
||||
\
|
||||
__result; \
|
||||
})
|
||||
|
||||
static __inline void
|
||||
_tcb_set(struct tcb *tcb)
|
||||
{
|
||||
amd64_set_fsbase(tcb);
|
||||
}
|
||||
|
||||
static __inline struct tcb *
|
||||
_tcb_get(void)
|
||||
{
|
||||
return (TCB_GET64(tcb_self));
|
||||
}
|
||||
|
||||
static __inline struct pthread *
|
||||
_get_curthread(void)
|
||||
{
|
||||
return (TCB_GET64(tcb_thread));
|
||||
struct pthread *thr;
|
||||
|
||||
__asm __volatile("movq %%fs:%1, %0" : "=r" (thr)
|
||||
: "m" (*(volatile u_long *)offsetof(struct tcb, tcb_thread)));
|
||||
return (thr);
|
||||
}
|
||||
|
||||
#define HAS__UMTX_OP_ERR 1
|
||||
|
@ -35,39 +35,10 @@
|
||||
#define _PTHREAD_MD_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <machine/sysarch.h>
|
||||
#include <machine/tls.h>
|
||||
|
||||
#define CPU_SPINWAIT
|
||||
|
||||
/*
|
||||
* Variant I tcb. The structure layout is fixed, don't blindly
|
||||
* change it.
|
||||
*/
|
||||
struct tcb {
|
||||
void *tcb_dtv; /* required by rtld */
|
||||
struct pthread *tcb_thread; /* our hook */
|
||||
};
|
||||
|
||||
/* Called from the thread to set its private data. */
|
||||
static __inline void
|
||||
_tcb_set(struct tcb *tcb)
|
||||
{
|
||||
sysarch(ARM_SET_TP, tcb);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the current tcb.
|
||||
*/
|
||||
static __inline struct tcb *
|
||||
_tcb_get(void)
|
||||
{
|
||||
struct tcb *tcb;
|
||||
|
||||
__asm __volatile("mrc p15, 0, %0, c13, c0, 3" \
|
||||
: "=r" (tcb));
|
||||
return (tcb);
|
||||
}
|
||||
|
||||
static __inline struct pthread *
|
||||
_get_curthread(void)
|
||||
{
|
||||
|
@ -37,64 +37,18 @@
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
#include <machine/sysarch.h>
|
||||
#include <machine/tls.h>
|
||||
|
||||
#define CPU_SPINWAIT __asm __volatile("pause")
|
||||
|
||||
/*
|
||||
* Variant II tcb, first two members are required by rtld,
|
||||
* %gs points to the structure.
|
||||
*/
|
||||
struct tcb {
|
||||
struct tcb *tcb_self; /* required by rtld */
|
||||
void *tcb_dtv; /* required by rtld */
|
||||
struct pthread *tcb_thread;
|
||||
};
|
||||
|
||||
/*
|
||||
* Evaluates to the byte offset of the per-tcb variable name.
|
||||
*/
|
||||
#define __tcb_offset(name) __offsetof(struct tcb, name)
|
||||
|
||||
/*
|
||||
* Evaluates to the type of the per-tcb variable name.
|
||||
*/
|
||||
#define __tcb_type(name) __typeof(((struct tcb *)0)->name)
|
||||
|
||||
/*
|
||||
* Evaluates to the value of the per-tcb variable name.
|
||||
*/
|
||||
#define TCB_GET32(name) ({ \
|
||||
__tcb_type(name) __result; \
|
||||
\
|
||||
u_int __i; \
|
||||
__asm __volatile("movl %%gs:%1, %0" \
|
||||
: "=r" (__i) \
|
||||
: "m" (*(volatile u_int *)(__tcb_offset(name)))); \
|
||||
__result = (__tcb_type(name))__i; \
|
||||
\
|
||||
__result; \
|
||||
})
|
||||
|
||||
/* Called from the thread to set its private data. */
|
||||
static __inline void
|
||||
_tcb_set(struct tcb *tcb)
|
||||
{
|
||||
i386_set_gsbase(tcb);
|
||||
}
|
||||
|
||||
/* Get the current kcb. */
|
||||
static __inline struct tcb *
|
||||
_tcb_get(void)
|
||||
{
|
||||
return (TCB_GET32(tcb_self));
|
||||
}
|
||||
|
||||
/* Get the current thread. */
|
||||
static __inline struct pthread *
|
||||
_get_curthread(void)
|
||||
{
|
||||
return (TCB_GET32(tcb_thread));
|
||||
struct pthread *thr;
|
||||
|
||||
__asm __volatile("movl %%gs:%1, %0" : "=r" (thr)
|
||||
: "m" (*(volatile u_int *)offsetof(struct tcb, tcb_thread)));
|
||||
return (thr);
|
||||
}
|
||||
|
||||
#define HAS__UMTX_OP_ERR 1
|
||||
|
@ -36,90 +36,10 @@
|
||||
#define _PTHREAD_MD_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <machine/sysarch.h>
|
||||
#include <machine/tls.h>
|
||||
|
||||
#define CPU_SPINWAIT
|
||||
|
||||
/*
|
||||
* Variant I tcb. The structure layout is fixed, don't blindly
|
||||
* change it!
|
||||
*/
|
||||
struct tcb {
|
||||
void *tcb_dtv;
|
||||
struct pthread *tcb_thread;
|
||||
};
|
||||
|
||||
/* Called from the thread to set its private data. */
|
||||
static __inline void
|
||||
_tcb_set(struct tcb *tcb)
|
||||
{
|
||||
|
||||
sysarch(MIPS_SET_TLS, tcb);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the current tcb.
|
||||
*/
|
||||
#ifdef TLS_USE_SYSARCH
|
||||
static __inline struct tcb *
|
||||
_tcb_get(void)
|
||||
{
|
||||
struct tcb *tcb;
|
||||
|
||||
sysarch(MIPS_GET_TLS, &tcb);
|
||||
return tcb;
|
||||
}
|
||||
|
||||
#else /* ! TLS_USE_SYSARCH */
|
||||
|
||||
# if defined(__mips_n64)
|
||||
static __inline struct tcb *
|
||||
_tcb_get(void)
|
||||
{
|
||||
uint64_t _rv;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
".set\tpush\n\t"
|
||||
".set\tmips64r2\n\t"
|
||||
"rdhwr\t%0, $29\n\t"
|
||||
".set\tpop"
|
||||
: "=r" (_rv));
|
||||
|
||||
/*
|
||||
* XXXSS See 'git show c6be4f4d2d1b71c04de5d3bbb6933ce2dbcdb317'
|
||||
*
|
||||
* Remove the offset since this really a request to get the TLS
|
||||
* pointer via sysarch() (in theory). Of course, this may go away
|
||||
* once the TLS code is rewritten.
|
||||
*/
|
||||
return (struct tcb *)(_rv - TLS_TP_OFFSET - TLS_TCB_SIZE);
|
||||
}
|
||||
# else /* mips 32 */
|
||||
static __inline struct tcb *
|
||||
_tcb_get(void)
|
||||
{
|
||||
uint32_t _rv;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
".set\tpush\n\t"
|
||||
".set\tmips32r2\n\t"
|
||||
"rdhwr\t%0, $29\n\t"
|
||||
".set\tpop"
|
||||
: "=r" (_rv));
|
||||
|
||||
/*
|
||||
* XXXSS See 'git show c6be4f4d2d1b71c04de5d3bbb6933ce2dbcdb317'
|
||||
*
|
||||
* Remove the offset since this really a request to get the TLS
|
||||
* pointer via sysarch() (in theory). Of course, this may go away
|
||||
* once the TLS code is rewritten.
|
||||
*/
|
||||
return (struct tcb *)(_rv - TLS_TP_OFFSET - TLS_TCB_SIZE);
|
||||
}
|
||||
# endif /* ! __mips_n64 */
|
||||
#endif /* ! TLS_USE_SYSARCH */
|
||||
|
||||
static __inline struct pthread *
|
||||
_get_curthread(void)
|
||||
{
|
||||
|
@ -36,51 +36,10 @@
|
||||
#define _PTHREAD_MD_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <machine/tls.h>
|
||||
|
||||
#define CPU_SPINWAIT
|
||||
|
||||
#ifdef __powerpc64__
|
||||
#define TP_OFFSET 0x7010
|
||||
#else
|
||||
#define TP_OFFSET 0x7008
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Variant I tcb. The structure layout is fixed, don't blindly
|
||||
* change it.
|
||||
* %r2 (32-bit) or %r13 (64-bit) points to end of the structure.
|
||||
*/
|
||||
struct tcb {
|
||||
void *tcb_dtv;
|
||||
struct pthread *tcb_thread;
|
||||
};
|
||||
|
||||
static __inline void
|
||||
_tcb_set(struct tcb *tcb)
|
||||
{
|
||||
#ifdef __powerpc64__
|
||||
__asm __volatile("mr 13,%0" ::
|
||||
"r"((uint8_t *)tcb + TP_OFFSET));
|
||||
#else
|
||||
__asm __volatile("mr 2,%0" ::
|
||||
"r"((uint8_t *)tcb + TP_OFFSET));
|
||||
#endif
|
||||
}
|
||||
|
||||
static __inline struct tcb *
|
||||
_tcb_get(void)
|
||||
{
|
||||
register struct tcb *tcb;
|
||||
|
||||
#ifdef __powerpc64__
|
||||
__asm __volatile("addi %0,13,%1" : "=r"(tcb) : "i"(-TP_OFFSET));
|
||||
#else
|
||||
__asm __volatile("addi %0,2,%1" : "=r"(tcb) : "i"(-TP_OFFSET));
|
||||
#endif
|
||||
|
||||
return (tcb);
|
||||
}
|
||||
|
||||
static __inline struct pthread *
|
||||
_get_curthread(void)
|
||||
{
|
||||
|
@ -42,39 +42,9 @@
|
||||
#define _PTHREAD_MD_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <machine/tls.h>
|
||||
|
||||
#define CPU_SPINWAIT
|
||||
#define TP_OFFSET sizeof(struct tcb)
|
||||
|
||||
/*
|
||||
* Variant I tcb. The structure layout is fixed, don't blindly
|
||||
* change it!
|
||||
*/
|
||||
struct tcb {
|
||||
void *tcb_dtv;
|
||||
struct pthread *tcb_thread;
|
||||
};
|
||||
|
||||
/* Called from the thread to set its private data. */
|
||||
static __inline void
|
||||
_tcb_set(struct tcb *tcb)
|
||||
{
|
||||
|
||||
__asm __volatile("addi tp, %0, %1" :: "r"(tcb), "I"(TP_OFFSET));
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the current tcb.
|
||||
*/
|
||||
static __inline struct tcb *
|
||||
_tcb_get(void)
|
||||
{
|
||||
struct tcb *_tcb;
|
||||
|
||||
__asm __volatile("addi %0, tp, %1" : "=r"(_tcb) : "I"(-TP_OFFSET));
|
||||
|
||||
return (_tcb);
|
||||
}
|
||||
|
||||
static __inline struct pthread *
|
||||
_get_curthread(void)
|
||||
|
Loading…
Reference in New Issue
Block a user