implement CLONE_CHILD_CLEARTID
PATCH 1/1 implement CLONE_CHILD_CLEARTID
The attached patch implements the clone flag CLONE_CHILD_CLEARTID.
Signature · 2 lines
Lauro Ramos Venancio INdT - Instituto Nokia de Tecnologia
linux-user/syscall.c +10 -5
@@ -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 ); }
Quoted 1 line · Lauro Ramos Venancio
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
Quoted 3 lines · Paul Brook
Using the host
set_tid_addressis wrong. This is liable to break the host libc/libpthread. The currentset_tid_addressimplementation 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.
Signature · 2 lines
Lauro Ramos Venancio INdT - Instituto Nokia de Tecnologia