overhaul clone syscall wrapping
several things are changed. first, i have removed the old __uniclone
function signature and replaced it with the "standard" linux
__clone/clone signature. this was necessary to expose clone to
applications anyway, and it makes it easier to port __clone to new
archs, since it's now testable independently of pthread_create.
secondly, i have removed all references to the ugly ldt descriptor
structure (i386 only) from the c code and pthread structure. in places
where it is needed, it is now created on the stack just when it's
needed, in assembly code. thus, the i386 __clone function takes the
desired thread pointer as its argument, rather than an ldt descriptor
pointer, just like on all other sane archs. this should not affect
applications since there is really no way an application can use clone
with threads/tls in a way that doesn't horribly conflict with and
clobber the underlying implementation's use. applications are expected
to use clone only for creating actual processes, possibly with new
namespace features and whatnot.
diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c
index bef2553..f7768d8 100644
--- a/src/thread/pthread_create.c
+++ b/src/thread/pthread_create.c
@@ -52,11 +52,13 @@
self->cancelbuf = self->cancelbuf->__next;
}
-static void start(pthread_t self)
+static int start(void *p)
{
+ pthread_t self = p;
if (self->unblock_cancel)
__syscall(SYS_rt_sigprocmask, SIG_UNBLOCK, SIGPT_SET, 0, 8);
pthread_exit(self->start(self->start_arg));
+ return 0;
}
#define ROUND(x) (((x)+PAGE_SIZE-1)&-PAGE_SIZE)
@@ -115,14 +117,12 @@
new->tsd = (void *)tsd;
if (attr) new->detached = attr->_a_detach;
new->unblock_cancel = self->cancel;
- memcpy(new->tlsdesc, self->tlsdesc, sizeof new->tlsdesc);
- new->tlsdesc[1] = (uintptr_t)new;
- stack = (void *)((uintptr_t)new-1 & ~(uintptr_t)15);
+ stack = (void *)new;
__synccall_lock();
a_inc(&libc.threads_minus_1);
- ret = __uniclone(stack, start, new);
+ ret = __clone(start, stack, 0x7d8f00, new, &new->tid, new, &new->tid);
__synccall_unlock();