]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Update.
authorUlrich Drepper <drepper@redhat.com>
Sat, 5 Apr 2003 09:36:56 +0000 (09:36 +0000)
committerUlrich Drepper <drepper@redhat.com>
Sat, 5 Apr 2003 09:36:56 +0000 (09:36 +0000)
2003-04-05  Ulrich Drepper  <drepper@redhat.com>

* malloc/thread-m.h [PTHREAD_MUTEX_INITIALIZER]: If
HAVE_register_atfork_malloc is defined use __register_atfork_malloc
instead of __register_atfork.

ChangeLog
malloc/thread-m.h
nptl/ChangeLog
nptl/sysdeps/unix/sysv/linux/fork.h
nptl/sysdeps/unix/sysv/linux/register-atfork.c

index 8615addc3135490a2c66dc3c8748fcae8d7efb53..35a4b26857eb012f852c6bec31c2d151a7f08601 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2003-04-05  Ulrich Drepper  <drepper@redhat.com>
+
+       * malloc/thread-m.h [PTHREAD_MUTEX_INITIALIZER]: If
+       HAVE_register_atfork_malloc is defined use __register_atfork_malloc
+       instead of __register_atfork.
+
 2003-04-05  Jakub Jelinek  <jakub@redhat.com>
 
        * stdio-common/reg-printf.c (__register_printf_function): Calloc
index d65ba913b2a8a83fde9d2083a14d22fd0cc5a33a..71409ebc0ebe049ce362c24e1b18239e47f62d15 100644 (file)
@@ -1,6 +1,6 @@
 /* Basic platform-independent macro definitions for mutexes and
    thread-specific data.
-   Copyright (C) 1996,1997,1998,2000,2001,2002 Free Software Foundation, Inc.
+   Copyright (C) 1996-1998,2000,2001,2002,2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Wolfram Gloger <wg@malloc.de>, 2001.
 
@@ -77,13 +77,24 @@ extern void *__dso_handle __attribute__ ((__weak__));
 
 #include <fork.h>
 
-#ifdef SHARED
-# define thread_atfork(prepare, parent, child) \
-   __register_atfork (prepare, parent, child, __dso_handle)
+#ifdef HAVE_register_atfork_malloc
+# ifdef SHARED
+#  define thread_atfork(prepare, parent, child) \
+   __register_atfork_malloc (prepare, parent, child, __dso_handle)
+# else
+#  define thread_atfork(prepare, parent, child) \
+   __register_atfork_malloc (prepare, parent, child,                         \
+                            &__dso_handle == NULL ? NULL : __dso_handle)
+# endif
 #else
-# define thread_atfork(prepare, parent, child) \
+# ifdef SHARED
+#  define thread_atfork(prepare, parent, child) \
+   __register_atfork (prepare, parent, child, __dso_handle)
+# else
+#  define thread_atfork(prepare, parent, child) \
    __register_atfork (prepare, parent, child,                                \
                      &__dso_handle == NULL ? NULL : __dso_handle)
+# endif
 #endif
 
 #elif defined(MUTEX_INITIALIZER)
index 7273ece303cc4f106d8bc59a8470b3b67735e4a5..c798977cc6e4ce78b4bc51b7896b2c1d8dcea77d 100644 (file)
@@ -1,3 +1,12 @@
+2003-04-05  Ulrich Drepper  <drepper@redhat.com>
+
+       * sysdeps/unix/sysv/linux/register-atfork.c: Define malloc_prepare,
+       malloc_parent, and malloc_child statically.
+       (__register_atfork_malloc): New function.
+       (free_mem): Don't free any of the malloc_* variables on the list.
+       * sysdeps/unix/sysv/linux/fork.h: Declare __register_atfork_malloc.
+       Define HAVE_register_atfork_malloc.
+
 2003-04-04  Ulrich Drepper  <drepper@redhat.com>
 
        * sysdeps/pthread/createthread.c (create_thread): Add some more
index f3f4c38a55e32b9af32828dffde7bdba0801d9c0..e59ae879640febba4b7788dce7abf6ec0b00e1b2 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
 
@@ -54,4 +54,9 @@ extern int __register_atfork (void (*__prepare) (void),
                              void (*__parent) (void),
                              void (*__child) (void),
                              void *dso_handle);
-libc_hidden_proto (__register_atfork)
+
+extern void __register_atfork_malloc (void (*prepare) (void),
+                                     void (*parent) (void),
+                                     void (*child) (void),
+                                     void *dso_handle) attribute_hidden;
+#define HAVE_register_atfork_malloc
index 2f63c781ab907a5e02cd39a6bbcad4a927e9e994..6dbc163175c09deae1608cc28da43eeab4cdd6ba 100644 (file)
@@ -89,7 +89,45 @@ __register_atfork (prepare, parent, child, dso_handle)
 
   return 0;
 }
-libc_hidden_def (__register_atfork)
+
+
+/* Three static memory blocks used when registering malloc.  */
+static struct fork_handler malloc_prepare;
+static struct fork_handler malloc_parent;
+static struct fork_handler malloc_child;
+
+
+void
+attribute_hidden
+__register_atfork_malloc (prepare, parent, child, dso_handle)
+     void (*prepare) (void);
+     void (*parent) (void);
+     void (*child) (void);
+     void *dso_handle;
+{
+  /* Pre-fork handler.  */
+  malloc_prepare.handler = prepare;
+  malloc_prepare.dso_handle = dso_handle;
+
+  /* Parent handler.  */
+  malloc_parent.handler = parent;
+  malloc_parent.dso_handle = dso_handle;
+
+  /* Child handler.  */
+  malloc_child.handler = child;
+  malloc_child.dso_handle = dso_handle;
+
+  /* Get the lock to not conflict with running forks.  */
+  lll_lock (__fork_lock);
+
+  /* Now that we have all the handlers allocate enqueue them.  */
+  list_add_tail (&malloc_prepare.list, &__fork_prepare_list);
+  list_add_tail (&malloc_parent.list, &__fork_parent_list);
+  list_add_tail (&malloc_child.list, &__fork_child_list);
+
+  /* Release the lock.  */
+  lll_unlock (__fork_lock);
+}
 
 
 libc_freeres_fn (free_mem)
@@ -104,22 +142,26 @@ libc_freeres_fn (free_mem)
     {
       list_del (runp);
 
-      free (list_entry (runp, struct fork_handler, list));
+      struct fork_handler *p = list_entry (runp, struct fork_handler, list);
+      if (p != &malloc_prepare)
+       free (p);
     }
 
   list_for_each_prev_safe (runp, prevp, &__fork_parent_list)
     {
       list_del (runp);
 
-      free (list_entry (runp, struct fork_handler, list));
+      struct fork_handler *p = list_entry (runp, struct fork_handler, list);
+      if (p != &malloc_parent)
+       free (p);
     }
 
   list_for_each_prev_safe (runp, prevp, &__fork_child_list)
     {
       list_del (runp);
 
-      void *p = list_entry (runp, struct fork_handler, list);
-      if (p != (void *) &__pthread_child_handler)
+      struct fork_handler *p = list_entry (runp, struct fork_handler, list);
+      if (p != &__pthread_child_handler && p != &malloc_child)
        free (p);
     }