+#if defined(__i386__) || defined(__ppc64__)
+/*
+ * Inside libSystem, we can use r13 or %gs directly to get access to the
+ * thread-specific data area. The current thread is in the first slot.
+ */
+inline static pthread_t __attribute__((__pure__))
+_pthread_self_direct(void)
+{
+ pthread_t ret;
+#if defined(__i386__)
+ asm("movl %%gs:%P1, %0" : "=r" (ret) : "i" (offsetof(struct _pthread, tsd[0])));
+#elif defined(__ppc64__)
+ register const pthread_t __pthread_self asm ("r13");
+ ret = __pthread_self;
+#endif
+ return ret;
+}
+#define pthread_self() _pthread_self_direct()
+#endif
+