+#if 0
+ int (*$pthread_attr_destroy)(pthread_attr_t *);
+ cyset($pthread_attr_destroy, "_pthread_attr_destroy", pthread);
+
+ $pthread_attr_destroy(&attr);
+#endif
+
+#if defined(__arm__) || defined(__arm64__)
+ uintptr_t tpid;
+#if defined(__arm__)
+ __asm__ ("mrc p15, 0, %0, c13, c0, 3\n" : "=r" (tpid));
+#elif defined(__arm64__)
+ __asm__ ("mrs %0, tpidrro_el0\n" : "=r" (tpid));
+#else
+#error XXX
+#endif
+
+ void **tsd;
+ tsd = reinterpret_cast<void **>(tpid & ~3);
+ if (tsd != NULL)
+ tsd[0] = &self;
+#else
+ _pthread_setspecific_direct(0, &self);
+#endif
+
+ int (*$pthread_join)(pthread_t, void **);
+ cyset($pthread_join, "_pthread_join", pthread);
+
+ void *status;
+ $pthread_join(thread, &status);
+
+ const mach_header_xx *kernel(NULL);
+ if (kernel == NULL)
+ kernel = Library(baton, "/usr/lib/system/libsystem_kernel.dylib");
+ if (kernel == NULL)
+ kernel = Library(baton, "/usr/lib/libSystem.B.dylib");