- if (self->detached == 2)
- __syscall(SYS_set_tid_address, 0);
- __syscall(SYS_rt_sigprocmask, SIG_BLOCK,
- SIGALL_SET, 0, __SYSCALL_SSLEN);
+ /* Detached threads must avoid the kernel clear_child_tid
+ * feature, since the virtual address will have been
+ * unmapped and possibly already reused by a new mapping
+ * at the time the kernel would perform the write. In
+ * the case of threads that started out detached, the
+ * initial clone flags are correct, but if the thread was
+ * detached later (== 2), we need to clear it here. */
+ if (self->detached == 2) __syscall(SYS_set_tid_address, 0);
+
+ /* The following call unmaps the thread's stack mapping
+ * and then exits without touching the stack. */