qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] implement CLONE_CHILD_CLEARTID


From: Riku Voipio
Subject: [Qemu-devel] [PATCH] implement CLONE_CHILD_CLEARTID
Date: Mon, 2 Feb 2009 11:19:14 +0200
User-agent: Mutt/1.5.18 (2008-05-17)

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 <address@hidden>
---
 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]