summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog32
-rw-r--r--linuxthreads/ChangeLog13
-rw-r--r--linuxthreads/Makefile14
-rw-r--r--linuxthreads/manager.c7
-rw-r--r--linuxthreads/pthread.c17
-rw-r--r--linuxthreads/tst-stack1.c98
-rw-r--r--malloc/malloc.c10
-rw-r--r--malloc/mtrace.c39
-rw-r--r--misc/mntent_r.c9
-rw-r--r--nptl/ChangeLog8
-rw-r--r--nptl/Makefile8
-rw-r--r--nptl/tst-stack3.c98
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/sys/procfs.h2
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h2
14 files changed, 345 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 92e8d68acf..72b76776ca 100644
--- 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
diff --git a/linuxthreads/ChangeLog b/linuxthreads/ChangeLog
index 882c478aa4..7691b94ac4 100644
--- a/linuxthreads/ChangeLog
+++ b/linuxthreads/ChangeLog
@@ -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
diff --git a/linuxthreads/Makefile b/linuxthreads/Makefile
index f3a9c02e5f..df7367b2b3 100644
--- a/linuxthreads/Makefile
+++ b/linuxthreads/Makefile
@@ -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)
diff --git a/linuxthreads/manager.c b/linuxthreads/manager.c
index 462ce4a0d4..876dd32772 100644
--- a/linuxthreads/manager.c
+++ b/linuxthreads/manager.c
@@ -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 */
diff --git a/linuxthreads/pthread.c b/linuxthreads/pthread.c
index 11d2ef7dd1..124aa5243d 100644
--- a/linuxthreads/pthread.c
+++ b/linuxthreads/pthread.c
@@ -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
index 0000000000..fa9aeddd9c
--- /dev/null
+++ b/linuxthreads/tst-stack1.c
@@ -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"
diff --git a/malloc/malloc.c b/malloc/malloc.c
index c26d6676aa..4e959d20a2 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -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;
diff --git a/malloc/mtrace.c b/malloc/mtrace.c
index 6cdd5f3324..c4239ddfba 100644
--- a/malloc/mtrace.c
+++ b/malloc/mtrace.c
@@ -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;
}
diff --git a/misc/mntent_r.c b/misc/mntent_r.c
index 2623ec3b70..1476c86ee2 100644
--- a/misc/mntent_r.c
+++ b/misc/mntent_r.c
@@ -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;
}
@@ -220,6 +220,13 @@ weak_alias (__getmntent_r, getmntent_r)
*wp++ = '\\'; \
*wp++ = '0'; \
*wp++ = '1'; \
+ *wp++ = '1'; \
+ } \
+ else if (*rp == '\n') \
+ { \
+ *wp++ = '\\'; \
+ *wp++ = '0'; \
+ *wp++ = '1'; \
*wp++ = '2'; \
} \
else if (*rp == '\\') \
diff --git a/nptl/ChangeLog b/nptl/ChangeLog
index 472187f500..4c8661bbce 100644
--- a/nptl/ChangeLog
+++ b/nptl/ChangeLog
@@ -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):
diff --git a/nptl/Makefile b/nptl/Makefile
index 78613858be..c2c4746681 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -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
index 0000000000..fa9aeddd9c
--- /dev/null
+++ b/nptl/tst-stack3.c
@@ -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"
diff --git a/sysdeps/unix/sysv/linux/powerpc/sys/procfs.h b/sysdeps/unix/sysv/linux/powerpc/sys/procfs.h
index 1322971da4..8e694c2ad3 100644
--- a/sysdeps/unix/sysv/linux/powerpc/sys/procfs.h
+++ b/sysdeps/unix/sysv/linux/powerpc/sys/procfs.h
@@ -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
{
diff --git a/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h b/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h
index 4bb8bb26d0..b75e25a3c8 100644
--- a/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h
+++ b/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h
@@ -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. */