From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LTuxe-00018t-4t for qemu-devel@nongnu.org; Mon, 02 Feb 2009 04:19:22 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LTuxd-00018L-97 for qemu-devel@nongnu.org; Mon, 02 Feb 2009 04:19:21 -0500 Received: from [199.232.76.173] (port=41755 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LTuxc-00018F-Tf for qemu-devel@nongnu.org; Mon, 02 Feb 2009 04:19:20 -0500 Received: from [84.20.150.76] (port=57249 helo=narury.org) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LTuxc-0001NQ-DU for qemu-devel@nongnu.org; Mon, 02 Feb 2009 04:19:20 -0500 Received: from kos.to (localhost.localdomain [127.0.0.1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by narury.org (Postfix) with ESMTP id AC35B3274002 for ; Mon, 2 Feb 2009 11:19:14 +0200 (EET) Date: Mon, 2 Feb 2009 11:19:14 +0200 From: Riku Voipio Message-ID: <20090202091914.GA5699@kos.to> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH] implement CLONE_CHILD_CLEARTID Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org LauroV: I know that the clone implementation is far from the perfection and it is very hard to implement all the clone flags using a high level API (pthread). This patch doesn't break seriously the host libc/libpthread. Pthread uses the tid_address only for pthread_join. So, actually, this patch breaks the host pthread_join (and pthread_timedjoin_np), but it makes the emulated pthread_join work. As the qemu doesn't use pthread_join, I think it worth to apply this patch. Riku: Without this patch, even the simplest threaded apps fail to run. updated minorly to apply with current svn. Signed-off-by: Riku Voipio --- linux-user/syscall.c | 15 ++++++++++----- 1 files changed, 10 insertions(+), 5 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index c3f5425..ad814dd 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3344,6 +3344,7 @@ typedef struct { pthread_cond_t cond; pthread_t thread; uint32_t tid; + unsigned int flags; abi_ulong child_tidptr; abi_ulong parent_tidptr; sigset_t sigmask; @@ -3357,9 +3358,11 @@ static void *clone_func(void *arg) env = info->env; thread_env = env; info->tid = gettid(); - if (info->child_tidptr) + if (info->flags & CLONE_CHILD_SETTID) put_user_u32(info->tid, info->child_tidptr); - if (info->parent_tidptr) + if (info->flags & CLONE_CHILD_CLEARTID) + set_tid_address(g2h(info->child_tidptr)); + if (info->flags & CLONE_PARENT_SETTID) put_user_u32(info->tid, info->parent_tidptr); /* Enable signals. */ sigprocmask(SIG_SETMASK, &info->sigmask, NULL); @@ -3424,7 +3427,6 @@ static int do_fork(CPUState *env, unsigned int flags, abi_ulong newsp, nptl_flags = flags; flags &= ~CLONE_NPTL_FLAGS2; - /* TODO: Implement CLONE_CHILD_CLEARTID. */ if (nptl_flags & CLONE_SETTLS) cpu_set_tls (new_env, newtls); @@ -3436,7 +3438,9 @@ static int do_fork(CPUState *env, unsigned int flags, abi_ulong newsp, pthread_mutex_lock(&info.mutex); pthread_cond_init(&info.cond, NULL); info.env = new_env; - if (nptl_flags & CLONE_CHILD_SETTID) + info.flags = nptl_flags; + if (nptl_flags & CLONE_CHILD_SETTID || + nptl_flags & CLONE_CHILD_CLEARTID) info.child_tidptr = child_tidptr; if (nptl_flags & CLONE_PARENT_SETTID) info.parent_tidptr = parent_tidptr; @@ -3499,7 +3503,8 @@ static int do_fork(CPUState *env, unsigned int flags, abi_ulong newsp, ts = (TaskState *)env->opaque; if (flags & CLONE_SETTLS) cpu_set_tls (env, newtls); - /* TODO: Implement CLONE_CHILD_CLEARTID. */ + if (flags & CLONE_CHILD_CLEARTID) + set_tid_address(g2h(child_tidptr)); #endif } else { fork_end(0); -- 1.5.6.5 -- "rm -rf" only sounds scary if you don't have backups