implement CLONE_CHILD_CLEARTID
PATCH 1/1 implement CLONE_CHILD_CLEARTID
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 <[email protected]>
--- linux-user/syscall.c | 15 ++++++++++----- 1 files changed, 10 insertions(+), 5 deletions(-)
linux-user/syscall.c +10 -5
@@ -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 );
Signature · 5 lines
1.5.6.5 -- "rm -rf" only sounds scary if you don't have backups