* [Qemu-devel] [PATCH] implement CLONE_CHILD_CLEARTID
@ 2008-10-15 22:18 Lauro Ramos Venancio
0 siblings, 0 replies; 5+ messages in thread
From: Lauro Ramos Venancio @ 2008-10-15 22:18 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1.1: Type: text/plain, Size: 135 bytes --]
The attached patch implements the clone flag CLONE_CHILD_CLEARTID.
--
Lauro Ramos Venancio
INdT - Instituto Nokia de Tecnologia
[-- Attachment #1.2: clone_child_cleartid.patch --]
[-- Type: text/x-patch, Size: 2095 bytes --]
Index: qemu-arm-eabi/linux-user/syscall.c
===================================================================
--- qemu-arm-eabi.orig/linux-user/syscall.c 2008-10-13 19:10:54.000000000 -0300
+++ qemu-arm-eabi/linux-user/syscall.c 2008-10-13 19:31:01.000000000 -0300
@@ -3177,6 +3177,7 @@
pthread_cond_t cond;
pthread_t thread;
uint32_t tid;
+ unsigned int flags;
abi_ulong child_tidptr;
abi_ulong parent_tidptr;
sigset_t sigmask;
@@ -3190,9 +3191,11 @@
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);
@@ -3257,7 +3260,6 @@
nptl_flags = flags;
flags &= ~CLONE_NPTL_FLAGS2;
- /* TODO: Implement CLONE_CHILD_CLEARTID. */
if (nptl_flags & CLONE_SETTLS)
cpu_set_tls (new_env, newtls);
@@ -3269,7 +3271,9 @@
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;
@@ -3332,7 +3336,8 @@
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));
} else {
fork_end(0);
}
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH] implement CLONE_CHILD_CLEARTID
@ 2008-10-15 22:57 Lauro Ramos Venancio
2008-10-16 13:19 ` Paul Brook
0 siblings, 1 reply; 5+ messages in thread
From: Lauro Ramos Venancio @ 2008-10-15 22:57 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1.1: Type: text/plain, Size: 135 bytes --]
The attached patch implements the clone flag CLONE_CHILD_CLEARTID.
--
Lauro Ramos Venancio
INdT - Instituto Nokia de Tecnologia
[-- Attachment #1.2: clone_child_cleartid.patch --]
[-- Type: text/x-patch, Size: 2095 bytes --]
Index: qemu-arm-eabi/linux-user/syscall.c
===================================================================
--- qemu-arm-eabi.orig/linux-user/syscall.c 2008-10-13 19:10:54.000000000 -0300
+++ qemu-arm-eabi/linux-user/syscall.c 2008-10-13 19:31:01.000000000 -0300
@@ -3177,6 +3177,7 @@
pthread_cond_t cond;
pthread_t thread;
uint32_t tid;
+ unsigned int flags;
abi_ulong child_tidptr;
abi_ulong parent_tidptr;
sigset_t sigmask;
@@ -3190,9 +3191,11 @@
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);
@@ -3257,7 +3260,6 @@
nptl_flags = flags;
flags &= ~CLONE_NPTL_FLAGS2;
- /* TODO: Implement CLONE_CHILD_CLEARTID. */
if (nptl_flags & CLONE_SETTLS)
cpu_set_tls (new_env, newtls);
@@ -3269,7 +3271,9 @@
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;
@@ -3332,7 +3336,8 @@
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));
} else {
fork_end(0);
}
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] implement CLONE_CHILD_CLEARTID
2008-10-15 22:57 Lauro Ramos Venancio
@ 2008-10-16 13:19 ` Paul Brook
2008-10-16 14:28 ` Lauro Ramos Venancio
0 siblings, 1 reply; 5+ messages in thread
From: Paul Brook @ 2008-10-16 13:19 UTC (permalink / raw)
To: qemu-devel; +Cc: Lauro Ramos Venancio
On Wednesday 15 October 2008, Lauro Ramos Venancio wrote:
> The attached patch implements the clone flag CLONE_CHILD_CLEARTID.
Using the host set_tid_address is wrong. This is liable to break the host
libc/libpthread. The current set_tid_address implementation is similarly
broken.
Paul
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] implement CLONE_CHILD_CLEARTID
2008-10-16 13:19 ` Paul Brook
@ 2008-10-16 14:28 ` Lauro Ramos Venancio
0 siblings, 0 replies; 5+ messages in thread
From: Lauro Ramos Venancio @ 2008-10-16 14:28 UTC (permalink / raw)
To: Paul Brook; +Cc: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 771 bytes --]
On Thu, 2008-10-16 at 14:19 +0100, Paul Brook wrote:
> Using the host set_tid_address is wrong. This is liable to break the host
> libc/libpthread. The current set_tid_address implementation is similarly
> broken.
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.
--
Lauro Ramos Venancio
INdT - Instituto Nokia de Tecnologia
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH] implement CLONE_CHILD_CLEARTID
@ 2009-02-02 9:19 Riku Voipio
0 siblings, 0 replies; 5+ messages in thread
From: Riku Voipio @ 2009-02-02 9:19 UTC (permalink / raw)
To: qemu-devel
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-02-02 9:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-02 9:19 [Qemu-devel] [PATCH] implement CLONE_CHILD_CLEARTID Riku Voipio
-- strict thread matches above, loose matches on Subject: below --
2008-10-15 22:57 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
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).