Blame arch/nt64/pthread_arch.h

860627
#include <stddef.h>
860627
860627
#define	TP_ADJ(p)	(p)
c8159d
#define	CANCEL_REG_IP	0x1F
f6a559
#define MC_PC           uc_rip
860627
860627
extern uintptr_t __teb_sys_idx;
860627
extern uintptr_t __teb_libc_idx;
860627
860627
struct __os_tib {
860627
	void *	exception_list;
860627
	void *	stack_base;
860627
	void *	stack_limit;
860627
};
860627
860627
static __inline__ void * __os_get_teb_address(void)
860627
{
860627
	void * ptrRet;
860627
	__asm__ __volatile__ (
860627
		"mov %%gs:0x30, %0\n\t"
860627
		: "=r" (ptrRet) : :
860627
		);
860627
	return ptrRet;
860627
}
860627
860627
860627
static inline void __pthread_convert(void)
860627
{
860627
	/* (third-party thread support) */
860627
	__asm__ __volatile__ (
860627
		"push %rax\n\t"
860627
		"movq __psx_vtbl,%rax\n\t"
1cf6f6
		"sub $0x28,%rsp\n\t"
860627
		"call *(%rax)\n\t"
1cf6f6
		"add $0x28,%rsp\n\t"
860627
		"pop  %rax\n\t"
860627
		);
860627
}
860627
860627
860627
static inline struct pthread ** __psx_tlca(void)
860627
{
860627
	struct pthread **	ptlca;
860627
	struct __os_tib *	tib;
860627
	void **			slots;
860627
	void ***		xslots;
860627
	uintptr_t		sys_idx;
860627
860627
	tib = __os_get_teb_address();
860627
	sys_idx = __teb_sys_idx;
860627
860627
	if (sys_idx < 64) {
860627
		slots = (void **)((uintptr_t)tib + 0x1480);
860627
		ptlca = (struct pthread **)(slots[sys_idx]);
860627
	} else {
860627
		xslots = (void ***)((uintptr_t)tib + 0x1780);
860627
		slots  = *xslots;
860627
		ptlca = (struct pthread **)(slots[sys_idx - 64]);
860627
	}
860627
860627
	return ptlca;
860627
}
860627
860627
abd66e
#ifdef __MUSL_PRE___GET_TP
860627
static inline struct pthread * __pthread_self(void)
abd66e
#else
abd66e
static inline struct pthread * __get_tp(void)
abd66e
#endif
860627
{
860627
	struct pthread ** ptlca;
860627
860627
	ptlca = __psx_tlca();
860627
	if (ptlca) return *ptlca;
860627
860627
	/* (third-party thread) */
860627
	__pthread_convert();
860627
	ptlca = __psx_tlca();
860627
	return *ptlca;
860627
}
860627