]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Update.
authorUlrich Drepper <drepper@redhat.com>
Wed, 17 Dec 2003 23:52:56 +0000 (23:52 +0000)
committerUlrich Drepper <drepper@redhat.com>
Wed, 17 Dec 2003 23:52:56 +0000 (23:52 +0000)
2003-12-17  Jakub Jelinek  <jakub@redhat.com>

* malloc/mtrace.c (tr_old_memalign_hook): New variable.
(tr_memalignhook): New function.
(mtrace): Register tr_memalignhook.
(muntrace): Deregister tr_memalignhook.
* malloc/malloc.c (__posix_memalign): If __memalign_hook != NULL,
call it directly instead of memalign_internal.

2003-12-17  Ulrich Drepper  <drepper@redhat.com>

* misc/mntent_r.c: Change encoding to match recently change decoder.
Patch by Alexander Achenbach <xela@slit.de>.

2003-12-16  Steven Munroe  <sjmunroe@us.ibm.com>

* sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h: Correct definition of
vrregset_t.

2003-12-16  Steven Munroe  <sjmunroe@us.ibm.com>

* sysdeps/unix/sysv/linux/powerpc/sys/procfs.h [!__PPC64_ELF_H]: Extent
conditional to include typedef elf_vrreg_t.

2002-12-17  Paolo Bonzini  <bonzini@gnu.org>

* posix/regexec.c (re_search_internal): Limit search to the
beginning of the buffer if the initial states are empty for
contexts that do not include CONTEXT_BEGBUF or, if
!preg->newline_anchor, that do not include any one of
CONTEXT_BEGBUF and CONTEXT_NEWLINE.

14 files changed:
ChangeLog
linuxthreads/ChangeLog
linuxthreads/Makefile
linuxthreads/manager.c
linuxthreads/pthread.c
linuxthreads/tst-stack1.c [new file with mode: 0644]
malloc/malloc.c
malloc/mtrace.c
misc/mntent_r.c
nptl/ChangeLog
nptl/Makefile
nptl/tst-stack3.c [new file with mode: 0644]
sysdeps/unix/sysv/linux/powerpc/sys/procfs.h
sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h

index 92e8d68acfb1dd3ce0618207fb981cf47b303ae7..72b76776cab3b643ded4f5a336dba0f2eff0e0a5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,35 @@
+2003-12-17  Jakub Jelinek  <jakub@redhat.com>
+
+       * malloc/mtrace.c (tr_old_memalign_hook): New variable.
+       (tr_memalignhook): New function.
+       (mtrace): Register tr_memalignhook.
+       (muntrace): Deregister tr_memalignhook.
+       * malloc/malloc.c (__posix_memalign): If __memalign_hook != NULL,
+       call it directly instead of memalign_internal.
+
+2003-12-17  Ulrich Drepper  <drepper@redhat.com>
+
+       * misc/mntent_r.c: Change encoding to match recently change decoder.
+       Patch by Alexander Achenbach <xela@slit.de>.
+
+2003-12-16  Steven Munroe  <sjmunroe@us.ibm.com>
+
+       * sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h: Correct definition of
+       vrregset_t.
+
+2003-12-16  Steven Munroe  <sjmunroe@us.ibm.com>
+
+       * sysdeps/unix/sysv/linux/powerpc/sys/procfs.h [!__PPC64_ELF_H]: Extent
+       conditional to include typedef elf_vrreg_t.
+
+2002-12-17  Paolo Bonzini  <bonzini@gnu.org>
+
+       * posix/regexec.c (re_search_internal): Limit search to the
+       beginning of the buffer if the initial states are empty for
+       contexts that do not include CONTEXT_BEGBUF or, if
+       !preg->newline_anchor, that do not include any one of
+       CONTEXT_BEGBUF and CONTEXT_NEWLINE.
+
 2003-12-17  Andreas Jaeger  <aj@suse.de>
 
        * sysdeps/generic/system.c (__libc_system): Fix typo, reported by
index 882c478aa4b21653d9396846440453ce6d936d60..7691b94ac448ae8ae9d975b9e52c7e90f49195e0 100644 (file)
@@ -1,3 +1,16 @@
+2003-12-17  Jakub Jelinek  <jakub@redhat.com>
+
+       * manager.c (pthread_free): Call _dl_deallocate_tls even for
+       p_userstack threads.
+       * pthread.c (__pthread_initialize_manager): Call _dl_deallocate_tls
+       on error.
+       (pthread_onexit_process): Update comment.
+       * Makefile (tests): Add tst-stack1.  Depend on $(objpfx)tst-stack1-mem.
+       (generated): Add tst-stack1.mtrace and tst-stack1-mem.
+       (tst-stack1-ENV): Set.
+       ($(objpfx)tst-stack1-mem): New.
+       * tst-stack1.c: New test.
+
 2003-12-16  Steven Munroe  <sjmunroe@us.ibm.com>
 
        * sysdeps/powerpc/tcb-offsets.sym [!__powerpc64__]: Remove
index f3a9c02e5fe2da1df5c841f5fe0d9b9b395ca421..df7367b2b3acf0b46c649e147a31ff154762dedc 100644 (file)
@@ -109,11 +109,14 @@ tests = ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9 $(librt-tests) ex12 ex13 joinrace \
        tststack $(tests-nodelete-$(have-z-nodelete)) ecmutex ex14 ex15 ex16 \
        ex17 ex18 tst-cancel tst-context bug-sleep \
        tst-cancel1 tst-cancel2 tst-cancel3 tst-cancel4 tst-cancel5 \
-       tst-cancel6 tst-cancel7 tst-cancel8 tst-popen tst-popen2 tst-attr1
+       tst-cancel6 tst-cancel7 tst-cancel8 tst-popen tst-popen2 tst-attr1 \
+       tst-stack1
 test-srcs = tst-signal
 # These tests are linked with libc before libpthread
 tests-reverse += tst-cancel5
 
+generated += tst-stack1.mtrace tst-stack1-mem
+
 ifeq ($(build-static),yes)
 tests += tststatic tst-static-locale tst-cancel-static
 tests-static += tststatic tst-static-locale tst-cancel-static
@@ -139,6 +142,15 @@ tst-tls1modd.so-no-z-defs = yes
 tst-tls1mode.so-no-z-defs = yes
 tst-tls1modf.so-no-z-defs = yes
 
+tests: $(objpfx)tst-stack1-mem
+tst-stack1-ENV = MALLOC_TRACE=$(objpfx)tst-stack1.mtrace
+
+# There are still up to 3 objects unfreed:
+# manager thread's stack, tls block and dtv
+$(objpfx)tst-stack1-mem: $(objpfx)tst-stack1.out
+       $(common-objpfx)malloc/mtrace $(objpfx)tst-stack1.mtrace > $@ \
+       || [ `grep ^0 $@ | wc -l` -le 3 ]
+
 $(test-modules): $(objpfx)%.so: $(objpfx)%.os $(common-objpfx)shlib.lds
        $(build-module)
 
index 462ce4a0d46599d9d32d6dc6a9e50f529740ad31..876dd327728f20d852f01f1a5877c2f82163aa5d 100644 (file)
@@ -903,13 +903,14 @@ static void pthread_free(pthread_descr th)
       /* Unmap the stack.  */
       munmap(guardaddr, stacksize + guardsize);
 
+    }
+
 #ifdef USE_TLS
 # if TLS_DTV_AT_TP
-      th = (pthread_descr) ((char *) th + TLS_PRE_TCB_SIZE);
+  th = (pthread_descr) ((char *) th + TLS_PRE_TCB_SIZE);
 # endif
-      _dl_deallocate_tls (th, true);
+  _dl_deallocate_tls (th, true);
 #endif
-    }
 }
 
 /* Handle threads that have exited */
index 11d2ef7dd196d34f99eeed2104758749c7daf09c..124aa5243d796d481d8fa18396c02d1bdc90461f 100644 (file)
@@ -654,7 +654,7 @@ int __pthread_initialize_manager(void)
 
 #ifdef USE_TLS
   /* Allocate memory for the thread descriptor and the dtv.  */
-  tcbp  = _dl_allocate_tls (NULL);
+  tcbp = _dl_allocate_tls (NULL);
   if (tcbp == NULL) {
     free(__pthread_manager_thread_bos);
     __libc_close(manager_pipe[0]);
@@ -783,6 +783,9 @@ int __pthread_initialize_manager(void)
 #endif
     }
   if (__builtin_expect (pid, 0) == -1) {
+#ifdef USE_TLS
+    _dl_deallocate_tls (tcbp, true);
+#endif
     free(__pthread_manager_thread_bos);
     __libc_close(manager_pipe[0]);
     __libc_close(manager_pipe[1]);
@@ -1014,8 +1017,16 @@ static void pthread_onexit_process(int retcode, void *arg)
        waitpid(__pthread_manager_thread.p_pid, NULL, __WCLONE);
 #endif
        /* Since all threads have been asynchronously terminated
-           (possibly holding locks), free cannot be used any more.  */
-       /*free (__pthread_manager_thread_bos);*/
+           (possibly holding locks), free cannot be used any more.
+           For mtrace, we'd like to print something though.  */
+       /* #ifdef USE_TLS
+          tcbhead_t *tcbp = (tcbhead_t *) manager_thread;
+          # if TLS_DTV_AT_TP
+          tcbp = (tcbhead_t) ((char *) tcbp + TLS_PRE_TCB_SIZE);
+          # endif
+          _dl_deallocate_tls (tcbp, true);
+          #endif
+          free (__pthread_manager_thread_bos); */
        __pthread_manager_thread_bos = __pthread_manager_thread_tos = NULL;
       }
   }
diff --git a/linuxthreads/tst-stack1.c b/linuxthreads/tst-stack1.c
new file mode 100644 (file)
index 0000000..fa9aedd
--- /dev/null
@@ -0,0 +1,98 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+/* Test whether pthread_create/pthread_join with user defined stacks
+   doesn't leak memory.  */
+
+#include <limits.h>
+#include <mcheck.h>
+#include <pthread.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+static int seen;
+
+static void *
+tf (void *p)
+{
+  ++seen;
+  return NULL;
+}
+
+static int
+do_test (void)
+{
+  mtrace ();
+
+  void *stack;
+  int res = posix_memalign (&stack, getpagesize (), 4 * PTHREAD_STACK_MIN);
+  if (res)
+    {
+      printf ("malloc failed %s\n", strerror (res));
+      return 1;
+    }
+
+  pthread_attr_t attr;
+  pthread_attr_init (&attr);
+
+  int result = 0;
+  res = pthread_attr_setstack (&attr, stack, 4 * PTHREAD_STACK_MIN);
+  if (res)
+    {
+      printf ("pthread_attr_setstack failed %d\n", res);
+      result = 1;
+    }
+
+  for (int i = 0; i < 16; ++i)
+    {
+      /* Create the thread.  */
+      pthread_t th;
+      res = pthread_create (&th, &attr, tf, NULL);
+      if (res)
+       {
+         printf ("pthread_create failed %d\n", res);
+         result = 1;
+       }
+      else
+       {
+         res = pthread_join (th, NULL);
+         if (res)
+           {
+             printf ("pthread_join failed %d\n", res);
+             result = 1;
+           }
+       }
+    }
+
+  pthread_attr_destroy (&attr);
+
+  if (seen != 16)
+    {
+      printf ("seen %d != 16\n", seen);
+      result = 1;
+    }
+
+  free (stack);
+  return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
index c26d6676aa49043cc2c2a8a09a9770e0db36e420..4e959d20a2828423a5db2a4cda788f11c619e268 100644 (file)
@@ -5389,13 +5389,21 @@ int
 __posix_memalign (void **memptr, size_t alignment, size_t size)
 {
   void *mem;
+  __malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, size_t,
+                                       __const __malloc_ptr_t)) =
+    __memalign_hook;
 
   /* Test whether the SIZE argument is valid.  It must be a power of
      two multiple of sizeof (void *).  */
   if (alignment % sizeof (void *) != 0 || !powerof2 (alignment) != 0)
     return EINVAL;
 
-  mem = __memalign_internal (alignment, size);
+  /* Call the hook here, so that caller is posix_memalign's caller
+     and not posix_memalign itself.  */
+  if (hook != NULL)
+    mem = (*hook)(alignment, size, RETURN_ADDRESS (0));
+  else
+    mem = __memalign_internal (alignment, size);
 
   if (mem != NULL) {
     *memptr = mem;
index 6cdd5f332498acc1aeb2cdcffec5e9a26288216b..c4239ddfba6af8e8aaefcf88619b4c75489ee176 100644 (file)
@@ -71,6 +71,9 @@ static __ptr_t (*tr_old_malloc_hook) __P ((__malloc_size_t size,
 static __ptr_t (*tr_old_realloc_hook) __P ((__ptr_t ptr,
                                            __malloc_size_t size,
                                            const __ptr_t));
+static __ptr_t (*tr_old_memalign_hook) __P ((__malloc_size_t __alignment,
+                                            __malloc_size_t __size,
+                                            __const __ptr_t));
 
 /* This function is called when the block being alloc'd, realloc'd, or
    freed has an address matching the variable "mallwatch".  In a debugger,
@@ -233,6 +236,39 @@ tr_reallochook (ptr, size, caller)
   return hdr;
 }
 
+static __ptr_t tr_memalignhook __P ((__malloc_size_t, __malloc_size_t,
+                                    const __ptr_t));
+static __ptr_t
+tr_memalignhook (alignment, size, caller)
+     __malloc_size_t alignment, size;
+     const __ptr_t caller;
+{
+  __ptr_t hdr;
+
+  __libc_lock_lock (lock);
+
+  __memalign_hook = tr_old_memalign_hook;
+  __malloc_hook = tr_old_malloc_hook;
+  if (tr_old_memalign_hook != NULL)
+    hdr = (__ptr_t) (*tr_old_memalign_hook) (alignment, size, caller);
+  else
+    hdr = (__ptr_t) memalign (alignment, size);
+  __memalign_hook = tr_memalignhook;
+  __malloc_hook = tr_mallochook;
+
+  tr_where (caller);
+  /* We could be printing a NULL here; that's OK.  */
+  fprintf (mallstream, "+ %p %#lx\n", hdr, (unsigned long int) size);
+
+  __libc_lock_unlock (lock);
+
+  if (hdr == mallwatch)
+    tr_break ();
+
+  return hdr;
+}
+
+
 
 #ifdef _LIBC
 
@@ -300,6 +336,8 @@ mtrace ()
          __malloc_hook = tr_mallochook;
          tr_old_realloc_hook = __realloc_hook;
          __realloc_hook = tr_reallochook;
+         tr_old_memalign_hook = __memalign_hook;
+         __memalign_hook = tr_memalignhook;
 #ifdef _LIBC
          if (!added_atexit_handler)
            {
@@ -327,4 +365,5 @@ muntrace ()
   __free_hook = tr_old_free_hook;
   __malloc_hook = tr_old_malloc_hook;
   __realloc_hook = tr_old_realloc_hook;
+  __memalign_hook = tr_old_memalign_hook;
 }
index 2623ec3b707aa1390308bfe2fee3c226b4bb9742..1476c86ee2da183006b2a947b8c319afee2fb89a 100644 (file)
@@ -86,7 +86,7 @@ decode_name (char *buf)
       }
     else if (rp[0] == '\\' && rp[1] == '0' && rp[2] == '1' && rp[3] == '1')
       {
-       /* \012 is a TAB.  */
+       /* \011 is a TAB.  */
        *wp++ = '\t';
        rp += 3;
       }
@@ -216,6 +216,13 @@ weak_alias (__getmntent_r, getmntent_r)
              *wp++ = '0';                                                    \
            }                                                                 \
          else if (*rp == '\t')                                               \
+           {                                                                 \
+             *wp++ = '\\';                                                   \
+             *wp++ = '0';                                                    \
+             *wp++ = '1';                                                    \
+             *wp++ = '1';                                                    \
+           }                                                                 \
+         else if (*rp == '\n')                                               \
            {                                                                 \
              *wp++ = '\\';                                                   \
              *wp++ = '0';                                                    \
index 472187f500367338760d25bb782a1e90a17351ce..4c8661bbced734812ba3080642942e30836f7ae3 100644 (file)
@@ -1,3 +1,11 @@
+2003-12-17  Jakub Jelinek  <jakub@redhat.com>
+
+       * Makefile (tests): Add tst-stack3.  Depend on $(objpfx)tst-stack3-mem.
+       (generated): Add tst-stack3.mtrace and tst-stack3-mem.
+       (tst-stack3-ENV): Set.
+       ($(objpfx)tst-stack3-mem): New.
+       * tst-stack3.c: New test.
+
 2003-12-10  David Mosberger  <davidm@hpl.hp.com>
 
        * sysdeps/unix/sysv/linux/ia64/pt-initfini.c (_init_EPILOG_BEGINS):
index 78613858be1a44aa593dd1da2e858f03a51f24eb..c2c47466817c1b03364fd8ba209964302813e567 100644 (file)
@@ -223,7 +223,7 @@ tests = tst-attr1 tst-attr2 tst-attr3 \
        tst-exec1 tst-exec2 tst-exec3 tst-exec4 \
        tst-exit1 \
        tst-stdio1 tst-stdio2 \
-       tst-stack1 tst-stack2 \
+       tst-stack1 tst-stack2 tst-stack3 \
        tst-unload \
        tst-dlsym1 \
        tst-sysconf \
@@ -405,6 +405,12 @@ LDFLAGS-tst-atfork2 = -rdynamic
 tst-atfork2-ENV = MALLOC_TRACE=$(objpfx)tst-atfork2.mtrace
 $(objpfx)tst-atfork2mod.so: $(shared-thread-library)
 
+tests: $(objpfx)tst-stack3-mem
+tst-stack3-ENV = MALLOC_TRACE=$(objpfx)tst-stack3.mtrace
+$(objpfx)tst-stack3-mem: $(objpfx)tst-stack3.out
+       $(common-objpfx)malloc/mtrace $(objpfx)tst-stack3.mtrace > $@
+generated += tst-stack3-mem tst-stack3.mtrace
+
 $(objpfx)tst-cleanup4: $(objpfx)tst-cleanup4aux.o $(shared-thread-library)
 $(objpfx)tst-cleanupx4: $(objpfx)tst-cleanup4aux.o $(shared-thread-library)
 
diff --git a/nptl/tst-stack3.c b/nptl/tst-stack3.c
new file mode 100644 (file)
index 0000000..fa9aedd
--- /dev/null
@@ -0,0 +1,98 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+/* Test whether pthread_create/pthread_join with user defined stacks
+   doesn't leak memory.  */
+
+#include <limits.h>
+#include <mcheck.h>
+#include <pthread.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+static int seen;
+
+static void *
+tf (void *p)
+{
+  ++seen;
+  return NULL;
+}
+
+static int
+do_test (void)
+{
+  mtrace ();
+
+  void *stack;
+  int res = posix_memalign (&stack, getpagesize (), 4 * PTHREAD_STACK_MIN);
+  if (res)
+    {
+      printf ("malloc failed %s\n", strerror (res));
+      return 1;
+    }
+
+  pthread_attr_t attr;
+  pthread_attr_init (&attr);
+
+  int result = 0;
+  res = pthread_attr_setstack (&attr, stack, 4 * PTHREAD_STACK_MIN);
+  if (res)
+    {
+      printf ("pthread_attr_setstack failed %d\n", res);
+      result = 1;
+    }
+
+  for (int i = 0; i < 16; ++i)
+    {
+      /* Create the thread.  */
+      pthread_t th;
+      res = pthread_create (&th, &attr, tf, NULL);
+      if (res)
+       {
+         printf ("pthread_create failed %d\n", res);
+         result = 1;
+       }
+      else
+       {
+         res = pthread_join (th, NULL);
+         if (res)
+           {
+             printf ("pthread_join failed %d\n", res);
+             result = 1;
+           }
+       }
+    }
+
+  pthread_attr_destroy (&attr);
+
+  if (seen != 16)
+    {
+      printf ("seen %d != 16\n", seen);
+      result = 1;
+    }
+
+  free (stack);
+  return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
index 1322971da49cee9a04d35a72c876ec97e4861c90..8e694c2ad35bd558a34c73afaf857330f7c0a686 100644 (file)
@@ -45,7 +45,6 @@ typedef elf_greg_t elf_gregset_t[ELF_NGREG];
 
 typedef double elf_fpreg_t;
 typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
-#endif
 
 /* gcc 3.1 and newer support __uint128_t.  */
 #if !__GNUC_PREREQ(3,1)
@@ -57,6 +56,7 @@ typedef struct {
 /* Altivec registers */
 typedef __uint128_t elf_vrreg_t;
 typedef elf_vrreg_t elf_vrregset_t[ELF_NVRREG];
+#endif
 
 struct elf_siginfo
   {
index 4bb8bb26d03fce5bf3c3e152708fdf7fe5be398f..b75e25a3c84c852b22e1690ff530d3ddb8dff257 100644 (file)
@@ -47,9 +47,9 @@ typedef struct _libc_fpstate
 typedef struct _libc_vrstate
 {
        unsigned int vrregs[32][4];
-       unsigned int vscr;
        unsigned int vrsave;
        unsigned int _pad[2];
+       unsigned int vscr;
 } vrregset_t;
 
 /* Context to describe whole processor state.  */