-typedef char *(*__ptr_func_t)(void) __attribute__((const));
-#define __pthread_self() \
- ((pthread_t)(((__ptr_func_t)0xffff0fe0)()+8-sizeof(struct pthread)))
+#if __ARM_ARCH_4__ || __ARM_ARCH_4T__ || __ARM_ARCH == 4
+#define BLX "mov lr,pc\n\tbx"
+#else
+#define BLX "blx"
+#endif
+
+static inline pthread_t __pthread_self()
+{
+ extern hidden uintptr_t __a_gettp_ptr;
+ register uintptr_t p __asm__("r0");
+ __asm__ __volatile__ ( BLX " %1" : "=r"(p) : "r"(__a_gettp_ptr) : "cc", "lr" );
+ return (void *)(p-sizeof(struct pthread));
+}