Blame arch/nt32/pthread_arch.h

296178
#include <stddef.h>
296178
296178
#define	TP_ADJ(p)	(p)
296178
#define	CANCEL_REG_IP	16
f6a559
#define MC_PC           uc_eip
296178
296178
extern uintptr_t __teb_sys_idx;
296178
extern uintptr_t __teb_libc_idx;
296178
296178
struct __os_tib {
296178
	void *	exception_list;
296178
	void *	stack_base;
296178
	void *	stack_limit;
296178
};
296178
296178
static __inline__ void * __os_get_teb_address(void)
296178
{
296178
	void * ptrRet;
296178
	__asm__ __volatile__ (
296178
		"mov %%fs:0x18, %0\n\t"
296178
		: "=r" (ptrRet) : :
296178
		);
296178
	return ptrRet;
296178
}
296178
296178
296178
static inline void __pthread_convert(void)
296178
{
296178
	/* (third-party thread support) */
296178
	__asm__ __volatile__ (
296178
		"push %eax\n\t"
296178
		"mov  ___psx_vtbl,%eax\n\t"
296178
		"call *(%eax)\n\t"
296178
		"pop  %eax\n\t"
296178
		);
296178
}
296178
296178
296178
static inline struct pthread ** __psx_tlca(void)
296178
{
296178
	struct pthread **	ptlca;
296178
	struct __os_tib *	tib;
296178
	void **			slots;
296178
	void ***		xslots;
296178
	uintptr_t		sys_idx;
296178
296178
	tib = __os_get_teb_address();
296178
	sys_idx = __teb_sys_idx;
296178
296178
	if (sys_idx < 64) {
296178
		slots = (void **)((uintptr_t)tib + 0xa40);
296178
		ptlca = (struct pthread **)(slots[sys_idx]);
296178
	} else {
296178
		xslots = (void ***)((uintptr_t)tib + 0xbc0);
296178
		slots  = *xslots;
296178
		ptlca = (struct pthread **)(slots[sys_idx - 64]);
296178
	}
296178
296178
	return ptlca;
296178
}
296178
296178
296178
static inline struct pthread * __pthread_self(void)
296178
{
296178
	struct pthread ** ptlca;
296178
296178
	ptlca = __psx_tlca();
296178
	if (ptlca) return *ptlca;
296178
296178
	/* (third-party thread) */
296178
	__pthread_convert();
296178
	ptlca = __psx_tlca();
296178
	return *ptlca;
296178
}
296178