aboutsummaryrefslogtreecommitdiff
path: root/malloc/malloc.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1997-09-27 00:21:42 +0000
committerUlrich Drepper <drepper@redhat.com>1997-09-27 00:21:42 +0000
commita2b08ee54130cf3a74655856e6ca6c29874a9df2 (patch)
tree71e7d867304f432bc57043e0c54a5cf101835651 /malloc/malloc.c
parent650425ceb40e840b2123b6c8cc65389589f41218 (diff)
downloadglibc-a2b08ee54130cf3a74655856e6ca6c29874a9df2.zip
glibc-a2b08ee54130cf3a74655856e6ca6c29874a9df2.tar.gz
glibc-a2b08ee54130cf3a74655856e6ca6c29874a9df2.tar.bz2
1997-09-27 01:14 Ulrich Drepper <drepper@cygnus.com> * Makeconfig (extra-objs): Depend in before-compile. * configure.in: Locate Perl and substitute with complete path. * config.make.in: Add PERL for substitution. * elf/Makefile (routines): Add dl-addr. * elf/dladdr.c: Move the real code into ... * elf/dl-addr.c: New file. * elf/link.h: Add prototype for _dl_addr. * elf/dladdr.c (dladdr): Change address argument to be const. * elf/dlfcn.h: Likewise. * locale/C_name.c: Add _nl_POSIX_name. * locale/localeinfo.h: Add declaration of _nl_POSIX_name. * locale/findlocale.c (_nl_find_locale): Use _nl_POSIX_name. (_nl_remove_locale): Free name of data set. * locale/setlocale.c (clever_copy): Remove. (new_composite_name): Use _nl_C_name and _nl_POSIX_name in compare. (setname): Only remove old name when it is for category LC_ALL. Change malloc, free, realloc, and memalign hooks for glibc to take another parameter indicating the location of the caller. * malloc/malloc.c: Change hook functions and variables. * malloc/malloc.h: Likewise. * malloc/mcheck.c: Likewise. Make sure later hooked function also get the original caller address. * malloc/mtrace.c: Likewise. (tr_where): If no information in _mtrace_file is given use the information about the caller. * malloc/Makefile (distribute): Replace mtrace.awk by mtrace.pl. Add rules to install mtrace.pl after rewriting. * malloc/mtrace.pl: New file. Based on the old AWK script but with extended functionality. * malloc/mtrace.awk: Removed. * po/fr.po: New version. * string/Makefile: Do use builtins for tester.c and inl-tester.c. * string/tester.c: Rewrite. Split in many small functions to not exceed gcc's limits. * sysdeps/unix/sysv/linux/syscalls.list: Add prctl. 1997-09-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> * string/bits/string2.h (__stpcpy_small): Don't use casts as lvalues. 1997-09-26 Andreas Jaeger <aj@arthur.rhein-neckar.de> * manual/time.texi (Formatting Date and Time): Clarify explanation of strftime flags a bit. Suggested by Robert Bihlmeyer <robbe@orcus.priv.at>. 1997-09-25 00:13 David S. Miller <davem@tanya.rutgers.edu> * sysdeps/libm-ieee754/s_exp2f.c: Protect _GNU_SOURCE definition. Fix typo, it is FLT_MANT_DIG. 1997-09-24 18:52 H.J. Lu <hjl@gnu.ai.mit.edu> * math/atest-exp2.c: Include <stdlib/gmp.h> instead of <gmp.h>. 1997-08-27 08:10 H.J. Lu <hjl@gnu.ai.mit.edu> * libio/libio.h, libio/libioP.h: Support libio in libstdc++. * libio/libio.h (_IO_peekc): Defined as _IO_peekc_unlocked if _IO_MTSAFE_IO is undefined. 1997-09-24 23:27 Richard Henderson <rth@cygnus.com> * elf/dl-runtime.c (fixup): Don't go through elf_machine_relplt, but lookup the value of the target symbol ourselves and call the new elf_machine_fixup_plt. This kills the ELF_FIXUP_RETURN_VALUE hack. (profile_fixup): Likewise, but don't fix up the plt. * elf/rtld.c (_dl_main): ELF_MACHINE_RELOC_NOPLT renamed _JMP_SLOT. * sysdeps/alpha/dl-machine.h (ELF_MACHINE_RELOC_NOPLT): Renamed. (elf_alpha_fix_plt): Renamed elf_machine_fixup_plt. * sysdeps/i386/dl-machine.h (elf_machine_relplt): Killed. (ELF_MACHINE_JMP_SLOT): Renamed. (elf_machine_fixup_plt): New function. * sysdeps/m68k/dl-machine.h: Likewise. * sysdeps/powerpc/dl-machine.h: Likewise. (elf_machine_rela): Moved JMP_SLOT fixup out to elf_machine_fixup_plt. * sysdeps/sparc/sparc32/dl-machine.h: Likewise. * sysdeps/sparc/sparc64/dl-machine.h: Likewise. * sysdeps/stub/dl-machine.h: Update, sorta. * sysdeps/alpha/dl-machine.h (elf_machine_runtime_setup): Do profiling. (TRAMPOLINE_TEMPLATE): From the carcas of _RUNTIME_TRAMPOLINE, do both normal and profile code. (elf_machine_rela): Handle r_addend for .got and .plt too.
Diffstat (limited to 'malloc/malloc.c')
-rw-r--r--malloc/malloc.c117
1 files changed, 114 insertions, 3 deletions
diff --git a/malloc/malloc.c b/malloc/malloc.c
index fb51483..17350eb 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -1178,7 +1178,19 @@ static int main_trim(size_t pad);
#ifndef NO_THREADS
static int heap_trim(heap_info *heap, size_t pad);
#endif
-#if defined(_LIBC) || defined(MALLOC_HOOKS)
+#ifdef _LIBC
+static Void_t* malloc_check(size_t sz, const Void_t *caller);
+static void free_check(Void_t* mem, const Void_t *caller);
+static Void_t* realloc_check(Void_t* oldmem, size_t bytes,
+ const Void_t *caller);
+static Void_t* memalign_check(size_t alignment, size_t bytes,
+ const Void_t *caller);
+static Void_t* malloc_starter(size_t sz, const Void_t *caller);
+static void free_starter(Void_t* mem, const Void_t *caller);
+static Void_t* malloc_atfork(size_t sz, const Void_t *caller);
+static void free_atfork(Void_t* mem, const Void_t *caller);
+#else
+#ifdef MALLOC_HOOKS
static Void_t* malloc_check(size_t sz);
static void free_check(Void_t* mem);
static Void_t* realloc_check(Void_t* oldmem, size_t bytes);
@@ -1188,6 +1200,7 @@ static void free_starter(Void_t* mem);
static Void_t* malloc_atfork(size_t sz);
static void free_atfork(Void_t* mem);
#endif
+#endif
#else
@@ -1520,11 +1533,19 @@ int __malloc_initialized = 0;
temporarily, because the `atfork' handler mechanism may use
malloc/free internally (e.g. in LinuxThreads). */
-#if defined(_LIBC) || defined(MALLOC_HOOKS)
+#ifdef _LIBC
+static __malloc_ptr_t (*save_malloc_hook) __MALLOC_P ((size_t __size,
+ const __malloc_ptr_t));
+static void (*save_free_hook) __MALLOC_P ((__malloc_ptr_t __ptr,
+ const __malloc_ptr_t));
+static Void_t* save_arena;
+#else
+#ifdef MALLOC_HOOKS
static __malloc_ptr_t (*save_malloc_hook) __MALLOC_P ((size_t __size));
static void (*save_free_hook) __MALLOC_P ((__malloc_ptr_t __ptr));
static Void_t* save_arena;
#endif
+#endif
static void
ptmalloc_lock_all __MALLOC_P((void))
@@ -1639,11 +1660,15 @@ thread_atfork_static(ptmalloc_lock_all, ptmalloc_unlock_all, \
initialization routine, then do the normal work. */
static Void_t*
+#ifdef _LIBC
+malloc_hook_ini(size_t sz, const __malloc_ptr_t caller)
+#else
#if __STD_C
malloc_hook_ini(size_t sz)
#else
malloc_hook_ini(sz) size_t sz;
#endif
+#endif
{
__malloc_hook = NULL;
__realloc_hook = NULL;
@@ -1653,11 +1678,15 @@ malloc_hook_ini(sz) size_t sz;
}
static Void_t*
+#ifdef _LIBC
+realloc_hook_ini(Void_t* ptr, size_t sz, const __malloc_ptr_t caller)
+#else
#if __STD_C
realloc_hook_ini(Void_t* ptr, size_t sz)
#else
realloc_hook_ini(ptr, sz) Void_t* ptr; size_t sz;
#endif
+#endif
{
__malloc_hook = NULL;
__realloc_hook = NULL;
@@ -1667,11 +1696,15 @@ realloc_hook_ini(ptr, sz) Void_t* ptr; size_t sz;
}
static Void_t*
+#ifdef _LIBC
+memalign_hook_ini(size_t sz, size_t alignment, const __malloc_ptr_t caller)
+#else
#if __STD_C
memalign_hook_ini(size_t sz, size_t alignment)
#else
memalign_hook_ini(sz, alignment) size_t sz; size_t alignment;
#endif
+#endif
{
__malloc_hook = NULL;
__realloc_hook = NULL;
@@ -1681,6 +1714,18 @@ memalign_hook_ini(sz, alignment) size_t sz; size_t alignment;
}
void weak_variable (*__malloc_initialize_hook) __MALLOC_P ((void)) = NULL;
+#ifdef _LIBC
+void weak_variable (*__free_hook) __MALLOC_P ((__malloc_ptr_t __ptr,
+ const __malloc_ptr_t)) = NULL;
+__malloc_ptr_t weak_variable (*__malloc_hook)
+ __MALLOC_P ((size_t __size, const __malloc_ptr_t)) = malloc_hook_ini;
+__malloc_ptr_t weak_variable (*__realloc_hook)
+ __MALLOC_P ((__malloc_ptr_t __ptr, size_t __size, const __malloc_ptr_t))
+ = realloc_hook_ini;
+__malloc_ptr_t weak_variable (*__memalign_hook)
+ __MALLOC_P ((size_t __size, size_t __alignment, const __malloc_ptr_t))
+ = memalign_hook_ini;
+#else
void weak_variable (*__free_hook) __MALLOC_P ((__malloc_ptr_t __ptr)) = NULL;
__malloc_ptr_t weak_variable (*__malloc_hook)
__MALLOC_P ((size_t __size)) = malloc_hook_ini;
@@ -1688,6 +1733,7 @@ __malloc_ptr_t weak_variable (*__realloc_hook)
__MALLOC_P ((__malloc_ptr_t __ptr, size_t __size)) = realloc_hook_ini;
__malloc_ptr_t weak_variable (*__memalign_hook)
__MALLOC_P ((size_t __size, size_t __alignment)) = memalign_hook_ini;
+#endif
void weak_variable (*__after_morecore_hook) __MALLOC_P ((void)) = NULL;
/* Activate a standard set of debugging hooks. */
@@ -2489,7 +2535,11 @@ Void_t* mALLOc(bytes) size_t bytes;
if (__malloc_hook != NULL) {
Void_t* result;
+#ifdef _LIBC
+ result = (*__malloc_hook)(bytes, __builtin_return_address (0));
+#else
result = (*__malloc_hook)(bytes);
+#endif
return result;
}
#endif
@@ -2780,7 +2830,11 @@ void fREe(mem) Void_t* mem;
#if defined(_LIBC) || defined(MALLOC_HOOKS)
if (__free_hook != NULL) {
+#ifdef _LIBC
+ (*__free_hook)(mem, __builtin_return_address (0));
+#else
(*__free_hook)(mem);
+#endif
return;
}
#endif
@@ -2980,7 +3034,11 @@ Void_t* rEALLOc(oldmem, bytes) Void_t* oldmem; size_t bytes;
if (__realloc_hook != NULL) {
Void_t* result;
+#ifdef _LIBC
+ result = (*__realloc_hook)(oldmem, bytes, __builtin_return_address (0));
+#else
result = (*__realloc_hook)(oldmem, bytes);
+#endif
return result;
}
#endif
@@ -3242,7 +3300,12 @@ Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes;
if (__memalign_hook != NULL) {
Void_t* result;
+#ifdef _LIBC
+ result = (*__memalign_hook)(alignment, bytes,
+ __builtin_return_address (0));
+#else
result = (*__memalign_hook)(alignment, bytes);
+#endif
return result;
}
#endif
@@ -3413,10 +3476,14 @@ Void_t* cALLOc(n, elem_size) size_t n; size_t elem_size;
#if defined(_LIBC) || defined(MALLOC_HOOKS)
if (__malloc_hook != NULL) {
sz = n * elem_size;
+#ifdef _LIBC
+ mem = (*__malloc_hook)(sz, __builtin_return_address (0));
+#else
mem = (*__malloc_hook)(sz);
+#endif
if(mem == 0)
return 0;
-#ifdef HAVE_MEMCPY
+#ifdef HAVE_MEMSET
return memset(mem, 0, sz);
#else
while(sz > 0) ((char*)mem)[--sz] = 0; /* rather inefficient */
@@ -4106,11 +4173,15 @@ mem2chunk_check(mem) Void_t* mem;
}
static Void_t*
+#ifdef _LIBC
+malloc_check(size_t sz, const Void_t *caller)
+#else
#if __STD_C
malloc_check(size_t sz)
#else
malloc_check(sz) size_t sz;
#endif
+#endif
{
mchunkptr victim;
INTERNAL_SIZE_T nb = request2size(sz + 1);
@@ -4129,11 +4200,15 @@ malloc_check(sz) size_t sz;
}
static void
+#ifdef _LIBC
+free_check(Void_t* mem, const Void_t *caller)
+#else
#if __STD_C
free_check(Void_t* mem)
#else
free_check(mem) Void_t* mem;
#endif
+#endif
{
mchunkptr p;
@@ -4166,16 +4241,24 @@ free_check(mem) Void_t* mem;
}
static Void_t*
+#ifdef _LIBC
+realloc_check(Void_t* oldmem, size_t bytes, const Void_t *caller)
+#else
#if __STD_C
realloc_check(Void_t* oldmem, size_t bytes)
#else
realloc_check(oldmem, bytes) Void_t* oldmem; size_t bytes;
#endif
+#endif
{
mchunkptr oldp, newp;
INTERNAL_SIZE_T nb, oldsize;
+#ifdef _LIBC
+ if (oldmem == 0) return malloc_check(bytes, NULL);
+#else
if (oldmem == 0) return malloc_check(bytes);
+#endif
(void)mutex_lock(&main_arena.mutex);
oldp = mem2chunk_check(oldmem);
if(!oldp) {
@@ -4187,7 +4270,11 @@ realloc_check(oldmem, bytes) Void_t* oldmem; size_t bytes;
case 2:
abort();
}
+#ifdef _LIBC
+ return malloc_check(bytes, NULL);
+#else
return malloc_check(bytes);
+#endif
}
oldsize = chunksize(oldp);
@@ -4240,16 +4327,24 @@ realloc_check(oldmem, bytes) Void_t* oldmem; size_t bytes;
}
static Void_t*
+#ifdef _LIBC
+memalign_check(size_t alignment, size_t bytes, const Void_t *caller)
+#else
#if __STD_C
memalign_check(size_t alignment, size_t bytes)
#else
memalign_check(alignment, bytes) size_t alignment; size_t bytes;
#endif
+#endif
{
INTERNAL_SIZE_T nb;
mchunkptr p;
+#ifdef _LIBC
+ if (alignment <= MALLOC_ALIGNMENT) return malloc_check(bytes, NULL);
+#else
if (alignment <= MALLOC_ALIGNMENT) return malloc_check(bytes);
+#endif
if (alignment < MINSIZE) alignment = MINSIZE;
nb = request2size(bytes+1);
@@ -4270,11 +4365,15 @@ memalign_check(alignment, bytes) size_t alignment; size_t bytes;
ptmalloc_init() hasn't completed yet. */
static Void_t*
+#ifdef _LIBC
+malloc_starter(size_t sz, const Void_t *caller)
+#else
#if __STD_C
malloc_starter(size_t sz)
#else
malloc_starter(sz) size_t sz;
#endif
+#endif
{
mchunkptr victim = chunk_alloc(&main_arena, request2size(sz));
@@ -4282,11 +4381,15 @@ malloc_starter(sz) size_t sz;
}
static void
+#ifdef _LIBC
+free_starter(Void_t* mem, const Void_t *caller)
+#else
#if __STD_C
free_starter(Void_t* mem)
#else
free_starter(mem) Void_t* mem;
#endif
+#endif
{
mchunkptr p;
@@ -4305,11 +4408,15 @@ free_starter(mem) Void_t* mem;
is active. */
static Void_t*
+#ifdef _LIBC
+malloc_atfork (size_t sz, const Void_t *caller)
+#else
#if __STD_C
malloc_atfork(size_t sz)
#else
malloc_atfork(sz) size_t sz;
#endif
+#endif
{
Void_t *vptr = NULL;
@@ -4328,11 +4435,15 @@ malloc_atfork(sz) size_t sz;
}
static void
+#ifdef _LIBC
+free_atfork(Void_t* mem, const Void_t *caller)
+#else
#if __STD_C
free_atfork(Void_t* mem)
#else
free_atfork(mem) Void_t* mem;
#endif
+#endif
{
Void_t *vptr = NULL;
arena *ar_ptr;