qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Riku Voipio <riku.voipio@iki.fi>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] implement CLONE_CHILD_CLEARTID
Date: Mon, 2 Feb 2009 11:19:14 +0200	[thread overview]
Message-ID: <20090202091914.GA5699@kos.to> (raw)

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 <riku.voipio@iki.fi>
---
 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	other threads:[~2009-02-02  9:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-02  9:19 Riku Voipio [this message]
  -- strict thread matches above, loose matches on Subject: below --
2008-10-15 22:57 [Qemu-devel] [PATCH] implement CLONE_CHILD_CLEARTID Lauro Ramos Venancio
2008-10-16 13:19 ` Paul Brook
2008-10-16 14:28   ` Lauro Ramos Venancio
2008-10-15 22:18 Lauro Ramos Venancio

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090202091914.GA5699@kos.to \
    --to=riku.voipio@iki.fi \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).