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.
This commit is contained in:
Ulrich Drepper 2003-12-17 23:52:56 +00:00
parent 0278652840
commit e796f92f68
14 changed files with 345 additions and 12 deletions

View File

@ -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> 2003-12-17 Andreas Jaeger <aj@suse.de>
* sysdeps/generic/system.c (__libc_system): Fix typo, reported by * sysdeps/generic/system.c (__libc_system): Fix typo, reported by

View 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> 2003-12-16 Steven Munroe <sjmunroe@us.ibm.com>
* sysdeps/powerpc/tcb-offsets.sym [!__powerpc64__]: Remove * sysdeps/powerpc/tcb-offsets.sym [!__powerpc64__]: Remove

View 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 \ tststack $(tests-nodelete-$(have-z-nodelete)) ecmutex ex14 ex15 ex16 \
ex17 ex18 tst-cancel tst-context bug-sleep \ ex17 ex18 tst-cancel tst-context bug-sleep \
tst-cancel1 tst-cancel2 tst-cancel3 tst-cancel4 tst-cancel5 \ 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 test-srcs = tst-signal
# These tests are linked with libc before libpthread # These tests are linked with libc before libpthread
tests-reverse += tst-cancel5 tests-reverse += tst-cancel5
generated += tst-stack1.mtrace tst-stack1-mem
ifeq ($(build-static),yes) ifeq ($(build-static),yes)
tests += tststatic tst-static-locale tst-cancel-static tests += tststatic tst-static-locale tst-cancel-static
tests-static += 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-tls1mode.so-no-z-defs = yes
tst-tls1modf.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 $(test-modules): $(objpfx)%.so: $(objpfx)%.os $(common-objpfx)shlib.lds
$(build-module) $(build-module)

View File

@ -903,13 +903,14 @@ static void pthread_free(pthread_descr th)
/* Unmap the stack. */ /* Unmap the stack. */
munmap(guardaddr, stacksize + guardsize); munmap(guardaddr, stacksize + guardsize);
}
#ifdef USE_TLS #ifdef USE_TLS
# if TLS_DTV_AT_TP # if TLS_DTV_AT_TP
th = (pthread_descr) ((char *) th + TLS_PRE_TCB_SIZE); th = (pthread_descr) ((char *) th + TLS_PRE_TCB_SIZE);
# endif # endif
_dl_deallocate_tls (th, true); _dl_deallocate_tls (th, true);
#endif #endif
}
} }
/* Handle threads that have exited */ /* Handle threads that have exited */

View File

@ -654,7 +654,7 @@ int __pthread_initialize_manager(void)
#ifdef USE_TLS #ifdef USE_TLS
/* Allocate memory for the thread descriptor and the dtv. */ /* Allocate memory for the thread descriptor and the dtv. */
tcbp = _dl_allocate_tls (NULL); tcbp = _dl_allocate_tls (NULL);
if (tcbp == NULL) { if (tcbp == NULL) {
free(__pthread_manager_thread_bos); free(__pthread_manager_thread_bos);
__libc_close(manager_pipe[0]); __libc_close(manager_pipe[0]);
@ -783,6 +783,9 @@ int __pthread_initialize_manager(void)
#endif #endif
} }
if (__builtin_expect (pid, 0) == -1) { if (__builtin_expect (pid, 0) == -1) {
#ifdef USE_TLS
_dl_deallocate_tls (tcbp, true);
#endif
free(__pthread_manager_thread_bos); free(__pthread_manager_thread_bos);
__libc_close(manager_pipe[0]); __libc_close(manager_pipe[0]);
__libc_close(manager_pipe[1]); __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); waitpid(__pthread_manager_thread.p_pid, NULL, __WCLONE);
#endif #endif
/* Since all threads have been asynchronously terminated /* Since all threads have been asynchronously terminated
(possibly holding locks), free cannot be used any more. */ (possibly holding locks), free cannot be used any more.
/*free (__pthread_manager_thread_bos);*/ 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; __pthread_manager_thread_bos = __pthread_manager_thread_tos = NULL;
} }
} }

98
linuxthreads/tst-stack1.c Normal file
View File

@ -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"

View File

@ -5389,13 +5389,21 @@ int
__posix_memalign (void **memptr, size_t alignment, size_t size) __posix_memalign (void **memptr, size_t alignment, size_t size)
{ {
void *mem; 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 /* Test whether the SIZE argument is valid. It must be a power of
two multiple of sizeof (void *). */ two multiple of sizeof (void *). */
if (alignment % sizeof (void *) != 0 || !powerof2 (alignment) != 0) if (alignment % sizeof (void *) != 0 || !powerof2 (alignment) != 0)
return EINVAL; 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) { if (mem != NULL) {
*memptr = mem; *memptr = mem;

View 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, static __ptr_t (*tr_old_realloc_hook) __P ((__ptr_t ptr,
__malloc_size_t size, __malloc_size_t size,
const __ptr_t)); 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 /* This function is called when the block being alloc'd, realloc'd, or
freed has an address matching the variable "mallwatch". In a debugger, freed has an address matching the variable "mallwatch". In a debugger,
@ -233,6 +236,39 @@ tr_reallochook (ptr, size, caller)
return hdr; 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 #ifdef _LIBC
@ -300,6 +336,8 @@ mtrace ()
__malloc_hook = tr_mallochook; __malloc_hook = tr_mallochook;
tr_old_realloc_hook = __realloc_hook; tr_old_realloc_hook = __realloc_hook;
__realloc_hook = tr_reallochook; __realloc_hook = tr_reallochook;
tr_old_memalign_hook = __memalign_hook;
__memalign_hook = tr_memalignhook;
#ifdef _LIBC #ifdef _LIBC
if (!added_atexit_handler) if (!added_atexit_handler)
{ {
@ -327,4 +365,5 @@ muntrace ()
__free_hook = tr_old_free_hook; __free_hook = tr_old_free_hook;
__malloc_hook = tr_old_malloc_hook; __malloc_hook = tr_old_malloc_hook;
__realloc_hook = tr_old_realloc_hook; __realloc_hook = tr_old_realloc_hook;
__memalign_hook = tr_old_memalign_hook;
} }

View File

@ -86,7 +86,7 @@ decode_name (char *buf)
} }
else if (rp[0] == '\\' && rp[1] == '0' && rp[2] == '1' && rp[3] == '1') else if (rp[0] == '\\' && rp[1] == '0' && rp[2] == '1' && rp[3] == '1')
{ {
/* \012 is a TAB. */ /* \011 is a TAB. */
*wp++ = '\t'; *wp++ = '\t';
rp += 3; rp += 3;
} }
@ -216,6 +216,13 @@ weak_alias (__getmntent_r, getmntent_r)
*wp++ = '0'; \ *wp++ = '0'; \
} \ } \
else if (*rp == '\t') \ else if (*rp == '\t') \
{ \
*wp++ = '\\'; \
*wp++ = '0'; \
*wp++ = '1'; \
*wp++ = '1'; \
} \
else if (*rp == '\n') \
{ \ { \
*wp++ = '\\'; \ *wp++ = '\\'; \
*wp++ = '0'; \ *wp++ = '0'; \

View 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> 2003-12-10 David Mosberger <davidm@hpl.hp.com>
* sysdeps/unix/sysv/linux/ia64/pt-initfini.c (_init_EPILOG_BEGINS): * sysdeps/unix/sysv/linux/ia64/pt-initfini.c (_init_EPILOG_BEGINS):

View File

@ -223,7 +223,7 @@ tests = tst-attr1 tst-attr2 tst-attr3 \
tst-exec1 tst-exec2 tst-exec3 tst-exec4 \ tst-exec1 tst-exec2 tst-exec3 tst-exec4 \
tst-exit1 \ tst-exit1 \
tst-stdio1 tst-stdio2 \ tst-stdio1 tst-stdio2 \
tst-stack1 tst-stack2 \ tst-stack1 tst-stack2 tst-stack3 \
tst-unload \ tst-unload \
tst-dlsym1 \ tst-dlsym1 \
tst-sysconf \ tst-sysconf \
@ -405,6 +405,12 @@ LDFLAGS-tst-atfork2 = -rdynamic
tst-atfork2-ENV = MALLOC_TRACE=$(objpfx)tst-atfork2.mtrace tst-atfork2-ENV = MALLOC_TRACE=$(objpfx)tst-atfork2.mtrace
$(objpfx)tst-atfork2mod.so: $(shared-thread-library) $(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-cleanup4: $(objpfx)tst-cleanup4aux.o $(shared-thread-library)
$(objpfx)tst-cleanupx4: $(objpfx)tst-cleanup4aux.o $(shared-thread-library) $(objpfx)tst-cleanupx4: $(objpfx)tst-cleanup4aux.o $(shared-thread-library)

98
nptl/tst-stack3.c Normal file
View File

@ -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"

View File

@ -45,7 +45,6 @@ typedef elf_greg_t elf_gregset_t[ELF_NGREG];
typedef double elf_fpreg_t; typedef double elf_fpreg_t;
typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG]; typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
#endif
/* gcc 3.1 and newer support __uint128_t. */ /* gcc 3.1 and newer support __uint128_t. */
#if !__GNUC_PREREQ(3,1) #if !__GNUC_PREREQ(3,1)
@ -57,6 +56,7 @@ typedef struct {
/* Altivec registers */ /* Altivec registers */
typedef __uint128_t elf_vrreg_t; typedef __uint128_t elf_vrreg_t;
typedef elf_vrreg_t elf_vrregset_t[ELF_NVRREG]; typedef elf_vrreg_t elf_vrregset_t[ELF_NVRREG];
#endif
struct elf_siginfo struct elf_siginfo
{ {

View File

@ -47,9 +47,9 @@ typedef struct _libc_fpstate
typedef struct _libc_vrstate typedef struct _libc_vrstate
{ {
unsigned int vrregs[32][4]; unsigned int vrregs[32][4];
unsigned int vscr;
unsigned int vrsave; unsigned int vrsave;
unsigned int _pad[2]; unsigned int _pad[2];
unsigned int vscr;
} vrregset_t; } vrregset_t;
/* Context to describe whole processor state. */ /* Context to describe whole processor state. */