Quellcode durchsuchen

nptl: nios2: pass the child tid pointer in the right clone slot

ARCH_FORK was copied from an architecture that selects CLONE_BACKWARDS,
where the kernel's clone() takes the child tid pointer last, after the
TLS argument.  nios2 uses the generic order (flags, newsp, parent_tid,
child_tid, tls), so &THREAD_SELF->tid arrived as the TLS argument and the
child tid pointer was NULL.  CLONE_CHILD_SETTID then wrote nowhere and
the child kept the parent's tid, which breaks everything deriving a
kernel identity from the descriptor after a fork:

  parent: gettid=1579855  clock_gettime(thread clock) ok
  child : gettid=1579860  but pd->tid still 1579855
          -> clock_gettime EINVAL, pthread_kill ESRCH

test-skeleton.c forks in every test, so on nios2 this showed up as
failures in tst-basic3, tst-cancel21, tst-cancelx21, tst-clockid,
tst-fork4, tst-join1, tst-kill5 and tst-mutex9; all of them pass now.

Checked the other targets while here: arm, i386, arc, xtensa, riscv,
aarch64 and nds32 select CLONE_BACKWARDS and microblaze
CLONE_BACKWARDS3, so their tid pointer in the last slot is correct; sh,
m68k, csky, or1k, alpha and x86_64 use the generic order and already
pass it in the fourth.

Signed-off-by: Ramin Moussavi <lordrasmus@gmail.com>
ramin vor 3 Tagen
Ursprung
Commit
29b01e77a7
1 geänderte Dateien mit 4 neuen und 1 gelöschten Zeilen
  1. 4 1
      libpthread/nptl/sysdeps/unix/sysv/linux/nios2/fork.c

+ 4 - 1
libpthread/nptl/sysdeps/unix/sysv/linux/nios2/fork.c

@@ -22,9 +22,12 @@
 #include <tls.h>
 
 
+/* nios2 uses the generic clone argument order, i.e. the child tid pointer
+   comes before the TLS argument -- not last as on arm, where this file was
+   copied from.  */
 #define ARCH_FORK()							\
   INLINE_SYSCALL (clone, 5,						\
 		  CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD,	\
-		  NULL, NULL, NULL, &THREAD_SELF->tid)
+		  NULL, NULL, &THREAD_SELF->tid, NULL)
 
 #include "../fork.c"