2009-04-16  Ulrich Drepper  <drepper@redhat.com>
	[BZ #9957]
	* malloc/malloc.c (force_reg): Define.
	(sYSMALLOc): Load hook variable into variable
	before test and force into register.
	(sYSTRIm): Likewise.
	(public_mALLOc): Force hook value into register.
	(public_fREe): Likewise.
	(public_rEALLOc): Likewise.
	(public_mEMALIGn): Likewise.
	(public_vALLOc): Likewise.
	(public_pVALLOc): Likewise.
	(public_cALLOc): Likewise.
	(__posix_memalign): Likewise.
	* malloc/arena.c (ptmalloc_init): Load hook variable into variable
	before test and force into register.
	* malloc/hooks.c (top_check): Likewise.
	(public_s_ET_STATe): Pretty printing.

	* resolv/res_send.c (send_dg): Don't just ignore the result we got
	in case we only receive one reply in single-request mode.
This commit is contained in:
Ulrich Drepper 2009-04-16 21:22:16 +00:00
parent 74b3cf224e
commit df77455c4b
4 changed files with 64 additions and 26 deletions

View File

@ -1,3 +1,26 @@
2009-04-16 Ulrich Drepper <drepper@redhat.com>
[BZ #9957]
* malloc/malloc.c (force_reg): Define.
(sYSMALLOc): Load hook variable into variable
before test and force into register.
(sYSTRIm): Likewise.
(public_mALLOc): Force hook value into register.
(public_fREe): Likewise.
(public_rEALLOc): Likewise.
(public_mEMALIGn): Likewise.
(public_vALLOc): Likewise.
(public_pVALLOc): Likewise.
(public_cALLOc): Likewise.
(__posix_memalign): Likewise.
* malloc/arena.c (ptmalloc_init): Load hook variable into variable
before test and force into register.
* malloc/hooks.c (top_check): Likewise.
(public_s_ET_STATe): Pretty printing.
* resolv/res_send.c (send_dg): Don't just ignore the result we got
in case we only receive one reply in single-request mode.
2009-04-16 Jakub Jelinek <jakub@redhat.com> 2009-04-16 Jakub Jelinek <jakub@redhat.com>
* elf/dl-open.c (_dl_open): Bump GL(dl_nns) to 1 if no libraries * elf/dl-open.c (_dl_open): Bump GL(dl_nns) to 1 if no libraries

View File

@ -624,8 +624,9 @@ ptmalloc_init (void)
if (check_action != 0) if (check_action != 0)
__malloc_check_init(); __malloc_check_init();
} }
if(__malloc_initialize_hook != NULL) void (*hook) (void) = force_reg (__malloc_initialize_hook);
(*__malloc_initialize_hook)(); if (hook != NULL)
(*hook)();
__malloc_initialized = 1; __malloc_initialized = 1;
} }

View File

@ -235,8 +235,9 @@ top_check()
return -1; return -1;
} }
/* Call the `morecore' hook if necessary. */ /* Call the `morecore' hook if necessary. */
if (__after_morecore_hook) void (*hook) (void) = __after_morecore_hook;
(*__after_morecore_hook) (); if (hook)
(*hook) ();
main_arena.system_mem = (new_brk - mp_.sbrk_base) + sbrk_size; main_arena.system_mem = (new_brk - mp_.sbrk_base) + sbrk_size;
top(&main_arena) = (mchunkptr)(brk + front_misalign); top(&main_arena) = (mchunkptr)(brk + front_misalign);
@ -669,10 +670,10 @@ public_sET_STATe(Void_t* msptr)
!disallow_malloc_check) !disallow_malloc_check)
__malloc_check_init (); __malloc_check_init ();
else if (!ms->using_malloc_checking && using_malloc_checking) { else if (!ms->using_malloc_checking && using_malloc_checking) {
__malloc_hook = 0; __malloc_hook = NULL;
__free_hook = 0; __free_hook = NULL;
__realloc_hook = 0; __realloc_hook = NULL;
__memalign_hook = 0; __memalign_hook = NULL;
using_malloc_checking = 0; using_malloc_checking = 0;
} }
} }

View File

@ -564,6 +564,13 @@ Void_t* memcpy();
#endif #endif
#endif #endif
/* Force a value to be in a register and stop the compiler referring
to the source (mostly memory location) again. */
#define force_reg(val) \
({ __typeof (val) _v; asm ("" : "=r" (_v) : "0" (val)); _v; })
/* /*
MALLOC_FAILURE_ACTION is the action to take before "return 0" when MALLOC_FAILURE_ACTION is the action to take before "return 0" when
malloc fails to be able to return memory, either because memory is malloc fails to be able to return memory, either because memory is
@ -3165,8 +3172,9 @@ static Void_t* sYSMALLOc(nb, av) INTERNAL_SIZE_T nb; mstate av;
if (brk != (char*)(MORECORE_FAILURE)) { if (brk != (char*)(MORECORE_FAILURE)) {
/* Call the `morecore' hook if necessary. */ /* Call the `morecore' hook if necessary. */
if (__builtin_expect (__after_morecore_hook != NULL, 0)) void (*hook) (void) = force_reg (__after_morecore_hook);
(*__after_morecore_hook) (); if (__builtin_expect (hook != NULL, 0))
(*hook) ();
} else { } else {
/* /*
If have mmap, try using it as a backup when MORECORE fails or If have mmap, try using it as a backup when MORECORE fails or
@ -3302,10 +3310,12 @@ static Void_t* sYSMALLOc(nb, av) INTERNAL_SIZE_T nb; mstate av;
if (snd_brk == (char*)(MORECORE_FAILURE)) { if (snd_brk == (char*)(MORECORE_FAILURE)) {
correction = 0; correction = 0;
snd_brk = (char*)(MORECORE(0)); snd_brk = (char*)(MORECORE(0));
} else } else {
/* Call the `morecore' hook if necessary. */ /* Call the `morecore' hook if necessary. */
if (__builtin_expect (__after_morecore_hook != NULL, 0)) void (*hook) (void) = force_reg (__after_morecore_hook);
(*__after_morecore_hook) (); if (__builtin_expect (hook != NULL, 0))
(*hook) ();
}
} }
/* handle non-contiguous cases */ /* handle non-contiguous cases */
@ -3453,8 +3463,9 @@ static int sYSTRIm(pad, av) size_t pad; mstate av;
MORECORE(-extra); MORECORE(-extra);
/* Call the `morecore' hook if necessary. */ /* Call the `morecore' hook if necessary. */
if (__builtin_expect (__after_morecore_hook != NULL, 0)) void (*hook) (void) = force_reg (__after_morecore_hook);
(*__after_morecore_hook) (); if (__builtin_expect (hook != NULL, 0))
(*hook) ();
new_brk = (char*)(MORECORE(0)); new_brk = (char*)(MORECORE(0));
if (new_brk != (char*)MORECORE_FAILURE) { if (new_brk != (char*)MORECORE_FAILURE) {
@ -3579,7 +3590,8 @@ public_mALLOc(size_t bytes)
mstate ar_ptr; mstate ar_ptr;
Void_t *victim; Void_t *victim;
__malloc_ptr_t (*hook) (size_t, __const __malloc_ptr_t) = __malloc_hook; __malloc_ptr_t (*hook) (size_t, __const __malloc_ptr_t)
= force_reg (__malloc_hook);
if (__builtin_expect (hook != NULL, 0)) if (__builtin_expect (hook != NULL, 0))
return (*hook)(bytes, RETURN_ADDRESS (0)); return (*hook)(bytes, RETURN_ADDRESS (0));
@ -3655,7 +3667,8 @@ public_fREe(Void_t* mem)
mstate ar_ptr; mstate ar_ptr;
mchunkptr p; /* chunk corresponding to mem */ mchunkptr p; /* chunk corresponding to mem */
void (*hook) (__malloc_ptr_t, __const __malloc_ptr_t) = __free_hook; void (*hook) (__malloc_ptr_t, __const __malloc_ptr_t)
= force_reg (__free_hook);
if (__builtin_expect (hook != NULL, 0)) { if (__builtin_expect (hook != NULL, 0)) {
(*hook)(mem, RETURN_ADDRESS (0)); (*hook)(mem, RETURN_ADDRESS (0));
return; return;
@ -3713,7 +3726,7 @@ public_rEALLOc(Void_t* oldmem, size_t bytes)
Void_t* newp; /* chunk to return */ Void_t* newp; /* chunk to return */
__malloc_ptr_t (*hook) (__malloc_ptr_t, size_t, __const __malloc_ptr_t) = __malloc_ptr_t (*hook) (__malloc_ptr_t, size_t, __const __malloc_ptr_t) =
__realloc_hook; force_reg (__realloc_hook);
if (__builtin_expect (hook != NULL, 0)) if (__builtin_expect (hook != NULL, 0))
return (*hook)(oldmem, bytes, RETURN_ADDRESS (0)); return (*hook)(oldmem, bytes, RETURN_ADDRESS (0));
@ -3825,7 +3838,7 @@ public_mEMALIGn(size_t alignment, size_t bytes)
__malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, size_t, __malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, size_t,
__const __malloc_ptr_t)) = __const __malloc_ptr_t)) =
__memalign_hook; force_reg (__memalign_hook);
if (__builtin_expect (hook != NULL, 0)) if (__builtin_expect (hook != NULL, 0))
return (*hook)(alignment, bytes, RETURN_ADDRESS (0)); return (*hook)(alignment, bytes, RETURN_ADDRESS (0));
@ -3882,7 +3895,7 @@ public_vALLOc(size_t bytes)
__malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, size_t, __malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, size_t,
__const __malloc_ptr_t)) = __const __malloc_ptr_t)) =
__memalign_hook; force_reg (__memalign_hook);
if (__builtin_expect (hook != NULL, 0)) if (__builtin_expect (hook != NULL, 0))
return (*hook)(pagesz, bytes, RETURN_ADDRESS (0)); return (*hook)(pagesz, bytes, RETURN_ADDRESS (0));
@ -3929,7 +3942,7 @@ public_pVALLOc(size_t bytes)
__malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, size_t, __malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, size_t,
__const __malloc_ptr_t)) = __const __malloc_ptr_t)) =
__memalign_hook; force_reg (__memalign_hook);
if (__builtin_expect (hook != NULL, 0)) if (__builtin_expect (hook != NULL, 0))
return (*hook)(pagesz, rounded_bytes, RETURN_ADDRESS (0)); return (*hook)(pagesz, rounded_bytes, RETURN_ADDRESS (0));
@ -3970,8 +3983,6 @@ public_cALLOc(size_t n, size_t elem_size)
unsigned long clearsize; unsigned long clearsize;
unsigned long nclears; unsigned long nclears;
INTERNAL_SIZE_T* d; INTERNAL_SIZE_T* d;
__malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, __const __malloc_ptr_t)) =
__malloc_hook;
/* size_t is unsigned so the behavior on overflow is defined. */ /* size_t is unsigned so the behavior on overflow is defined. */
bytes = n * elem_size; bytes = n * elem_size;
@ -3984,6 +3995,8 @@ public_cALLOc(size_t n, size_t elem_size)
} }
} }
__malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, __const __malloc_ptr_t)) =
force_reg (__malloc_hook);
if (__builtin_expect (hook != NULL, 0)) { if (__builtin_expect (hook != NULL, 0)) {
sz = bytes; sz = bytes;
mem = (*hook)(sz, RETURN_ADDRESS (0)); mem = (*hook)(sz, RETURN_ADDRESS (0));
@ -6192,9 +6205,6 @@ 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 *). */
@ -6205,6 +6215,9 @@ __posix_memalign (void **memptr, size_t alignment, size_t size)
/* Call the hook here, so that caller is posix_memalign's caller /* Call the hook here, so that caller is posix_memalign's caller
and not posix_memalign itself. */ and not posix_memalign itself. */
__malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, size_t,
__const __malloc_ptr_t)) =
force_reg (__memalign_hook);
if (__builtin_expect (hook != NULL, 0)) if (__builtin_expect (hook != NULL, 0))
mem = (*hook)(alignment, size, RETURN_ADDRESS (0)); mem = (*hook)(alignment, size, RETURN_ADDRESS (0));
else else