[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

sys_cleartid and cleartid support for the main thread



The kernel patch adds a sys_cleartid syscall that behaves like
CLONE_SETTID | CLONE_CLEARTID.

The NPTL patch uses it.

Acceptable?

BTW, without this patch, I think that we should set main_thread = true
in the fork child.



Linux:

diff --exclude-from=/home/ldb/src/linux-exclude -urNdp linux-2.5.44_ldb_noctid/arch/i386/kernel/entry.S linux-2.5.44_ldb/arch/i386/kernel/entry.S
--- linux-2.5.44_ldb_noctid/arch/i386/kernel/entry.S	2002-11-04 18:40:10.000000000 +0100
+++ linux-2.5.44_ldb/arch/i386/kernel/entry.S	2002-11-04 19:39:49.000000000 +0100
@@ -747,6 +747,7 @@ ENTRY(sys_call_table)
 	.long sys_epoll_wait
 	.long sys_remap_file_pages
 	.long sys_tkilldet
+	.long sys_cleartid	
 
 	.rept NR_syscalls-(.-sys_call_table)/4
 		.long sys_ni_syscall
diff --exclude-from=/home/ldb/src/linux-exclude -urNdp linux-2.5.44_ldb_noctid/include/asm-i386/unistd.h linux-2.5.44_ldb/include/asm-i386/unistd.h
--- linux-2.5.44_ldb_noctid/include/asm-i386/unistd.h	2002-11-04 18:18:31.000000000 +0100
+++ linux-2.5.44_ldb/include/asm-i386/unistd.h	2002-11-05 00:08:33.000000000 +0100
@@ -263,6 +263,7 @@
 #define __NR_sys_epoll_wait	256  
 #define __NR_remap_file_pages	257
 #define __NR_tkilldet		258
+#define __NR_cleartid		259
 
 /* user-visible error numbers are in the range -1 - -124: see <asm-i386/errno.h> */
 
diff --exclude-from=/home/ldb/src/linux-exclude -urNdp linux-2.5.44_ldb_noctid/kernel/fork.c linux-2.5.44_ldb/kernel/fork.c
--- linux-2.5.44_ldb_noctid/kernel/fork.c	2002-10-12 06:21:31.000000000 +0200
+++ linux-2.5.44_ldb/kernel/fork.c	2002-11-04 19:36:59.000000000 +0100
@@ -937,6 +937,15 @@ bad_fork_free:
 	goto fork_out;
 }
 
+asmlinkage int
+sys_cleartid(int* user_tid)
+{
+	current->user_tid = user_tid;	
+	if(user_tid && put_user(current->pid, user_tid))
+		return -EFAULT;
+	return 0;
+}
+
 /*
  *  Ok, this is the main fork-routine.
  *



NPTL:

diff --exclude-from=/home/ldb/src/linux-exclude -urNdp nptl/cancellation.c nptl_ldb/cancellation.c
--- nptl/cancellation.c	2002-10-09 00:48:49.000000000 +0200
+++ nptl_ldb/cancellation.c	2002-11-05 00:05:42.000000000 +0100
@@ -44,16 +44,6 @@ __do_cancel (char *currentframe)
   /* Cleanup the thread-local storage.  */
   __cleanup_thread (self, currentframe);
 
-  /* In case this is the main thread the kernel won't notify any
-     joining threads.  Do this now if necessary.
-
-     It is unfortunate to have this code here but beside placing the
-     code in libc itself (which is not acceptable) the only other solution
-     is to instruct the kernel to clear the TID field in the thread
-     descriptor just as it happens for all the other threads.  */
-  if (__builtin_expect (self->main_thread, false))
-    lll_wake_tid (self->tid);
-
   /* Throw an exception.  */
   // XXX TBI
 
diff --exclude-from=/home/ldb/src/linux-exclude -urNdp nptl/descr.h nptl_ldb/descr.h
--- nptl/descr.h	2002-10-09 00:49:38.000000000 +0200
+++ nptl_ldb/descr.h	2002-11-05 00:05:08.000000000 +0100
@@ -86,9 +86,6 @@ struct pthread
   /* Flag which is set when specific data is set.  */
   bool specific_used;
 
-  /* True if this is the descriptor for the main thread.  */
-  bool main_thread;
-
   /* True if the user provided the stack.  */
   bool user_stack;
 
diff --exclude-from=/home/ldb/src/linux-exclude -urNdp nptl/init.c nptl_ldb/init.c
--- nptl/init.c	2002-10-09 00:55:35.000000000 +0200
+++ nptl_ldb/init.c	2002-11-04 23:03:13.000000000 +0100
@@ -17,6 +17,7 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
+#include <errno.h>
 #include <assert.h>
 #include <limits.h>
 #include <signal.h>
@@ -110,9 +111,8 @@ __pthread_initialize_minimal (void)
 
   /* Minimal initialization of the thread descriptor.  */
   pd = THREAD_SELF;
-  THREAD_SETMEM (pd, tid, gettid ());
+  INLINE_SYSCALL(cleartid, 1, &pd->tid);
   THREAD_SETMEM (pd, specific[0], &pd->specific_1stblock[0]);
-  THREAD_SETMEM (pd, main_thread, true);
   THREAD_SETMEM (pd, user_stack, true);
   if (LLL_LOCK_INITIALIZER != 0)
     THREAD_SETMEM (pd, lock, LLL_LOCK_INITIALIZER);
diff --exclude-from=/home/ldb/src/linux-exclude -urNdp nptl/sysdeps/unix/sysv/linux/fork.c nptl_ldb/sysdeps/unix/sysv/linux/fork.c
--- nptl/sysdeps/unix/sysv/linux/fork.c	2002-10-02 03:00:23.000000000 +0200
+++ nptl_ldb/sysdeps/unix/sysv/linux/fork.c	2002-11-04 23:36:45.000000000 +0100
@@ -76,7 +76,7 @@ __libc_fork (void)
 	*__fork_generation_pointer += 4;
 
       /* Re-initialize the thread descriptor.  */
-      THREAD_SETMEM (THREAD_SELF, tid, gettid ());
+      INLINE_SYSCALL(cleartid, 1, &THREAD_SELF->tid);
 
       /* Reset the file list.  These are recursive mutexes.  */
       fresetlockfiles ();

Attachment: pgp00044.pgp
Description: PGP signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]