diff options
author | Roland McGrath <roland@gnu.org> | 2002-11-14 03:59:56 +0000 |
---|---|---|
committer | Roland McGrath <roland@gnu.org> | 2002-11-14 03:59:56 +0000 |
commit | 6e3d59bc0581399e0d8218f7b7fb10961735a82b (patch) | |
tree | cc8ae99aadd6f0b845944b173aa3d7b3102e8686 /malloc/mcheck.c | |
parent | cdedcc7943114bbbcbc2be1a0ef5716b0ef2e862 (diff) | |
download | glibc-6e3d59bc0581399e0d8218f7b7fb10961735a82b.tar.gz glibc-6e3d59bc0581399e0d8218f7b7fb10961735a82b.tar.xz glibc-6e3d59bc0581399e0d8218f7b7fb10961735a82b.zip |
* scripts/abilist.awk: New file.
* Makefile (distribute): Add it. * Makerules ($(objpfx)%.dynsym, $(objpfx)%.symlist): New rules. (tests): Depend on .symlist file for each $(install-lib.so-versioned). [! subdir] (tests): Depend on libc.symlist. (generated): Add those files. * aclocal.m4 (LIBC_PROG_BINUTILS): Check for objdump, set OBJDUMP. * configure: Regenerated. * config.make.in (OBJDUMP): New variable, substituted by configure. * malloc/mcheck.c (struct hdr): New members `block' and `magic2'. (mallochook, reallochook): Set them up. (checkhdr): Check HDR->magic2 value. (freehook): Reset HDR->magic2. (memalignhook): New static function. (old_memalign_hook): New static variable. (mcheck, reallochook): Set __memalign_hook to memalignhook.
Diffstat (limited to 'malloc/mcheck.c')
-rw-r--r-- | malloc/mcheck.c | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/malloc/mcheck.c b/malloc/mcheck.c index c67636c289..8cae506e4d 100644 --- a/malloc/mcheck.c +++ b/malloc/mcheck.c @@ -30,6 +30,9 @@ /* Old hook values. */ static void (*old_free_hook) __P ((__ptr_t ptr, __const __ptr_t)); static __ptr_t (*old_malloc_hook) __P ((__malloc_size_t size, const __ptr_t)); +static __ptr_t (*old_memalign_hook) __P ((__malloc_size_t alignment, + __malloc_size_t size, + const __ptr_t)); static __ptr_t (*old_realloc_hook) __P ((__ptr_t ptr, __malloc_size_t size, __const __ptr_t)); @@ -49,6 +52,8 @@ struct hdr unsigned long int magic; /* Magic number to check header integrity. */ struct hdr *prev; struct hdr *next; + __ptr_t block; /* Real block allocated, for memalign. */ + unsigned long int magic2; /* Extra, keeps us doubleword aligned. */ }; /* This is the beginning of the list of all memory blocks allocated. @@ -100,6 +105,8 @@ checkhdr (hdr) case MAGICWORD: if (((char *) &hdr[1])[hdr->size] != MAGICBYTE) status = MCHECK_TAIL; + else if ((hdr->magic2 ^ (uintptr_t) hdr->block) != MAGICWORD) + status = MCHECK_HEAD; else status = MCHECK_OK; break; @@ -190,10 +197,11 @@ freehook (ptr, caller) struct hdr *hdr = ((struct hdr *) ptr) - 1; checkhdr (hdr); hdr->magic = MAGICFREE; + hdr->magic2 = MAGICFREE; unlink_blk (hdr); hdr->prev = hdr->next = NULL; flood (ptr, FREEFLOOD, hdr->size); - ptr = (__ptr_t) hdr; + ptr = hdr->block; } __free_hook = old_free_hook; if (old_free_hook != NULL) @@ -226,6 +234,44 @@ mallochook (size, caller) hdr->size = size; link_blk (hdr); + hdr->block = hdr; + hdr->magic2 = (uintptr_t) hdr ^ MAGICWORD; + ((char *) &hdr[1])[size] = MAGICBYTE; + flood ((__ptr_t) (hdr + 1), MALLOCFLOOD, size); + return (__ptr_t) (hdr + 1); +} + +static __ptr_t memalignhook __P ((__malloc_size_t, __malloc_size_t, + const __ptr_t)); +static __ptr_t +memalignhook (alignment, size, caller) + __malloc_size_t alignment, size; + const __ptr_t caller; +{ + struct hdr *hdr; + __malloc_size_t slop; + char *block; + + if (pedantic) + mcheck_check_all (); + + slop = (sizeof *hdr + alignment - 1) & -alignment; + + __memalign_hook = old_memalign_hook; + if (old_memalign_hook != NULL) + block = (*old_memalign_hook) (alignment, slop + size + 1, caller); + else + block = memalign (alignment, slop + size + 1); + __memalign_hook = memalignhook; + if (block == NULL) + return NULL; + + hdr = ((struct hdr *) (block + slop)) - 1; + + hdr->size = size; + link_blk (hdr); + hdr->block = (__ptr_t) block; + hdr->magic2 = (uintptr_t) block ^ MAGICWORD; ((char *) &hdr[1])[size] = MAGICBYTE; flood ((__ptr_t) (hdr + 1), MALLOCFLOOD, size); return (__ptr_t) (hdr + 1); @@ -261,6 +307,7 @@ reallochook (ptr, size, caller) } __free_hook = old_free_hook; __malloc_hook = old_malloc_hook; + __memalign_hook = old_memalign_hook; __realloc_hook = old_realloc_hook; if (old_realloc_hook != NULL) hdr = (struct hdr *) (*old_realloc_hook) ((__ptr_t) hdr, @@ -271,12 +318,15 @@ reallochook (ptr, size, caller) sizeof (struct hdr) + size + 1); __free_hook = freehook; __malloc_hook = mallochook; + __memalign_hook = memalignhook; __realloc_hook = reallochook; if (hdr == NULL) return NULL; hdr->size = size; link_blk (hdr); + hdr->block = hdr; + hdr->magic2 = (uintptr_t) hdr ^ MAGICWORD; ((char *) &hdr[1])[size] = MAGICBYTE; if (size > osize) flood ((char *) (hdr + 1) + osize, MALLOCFLOOD, size - osize); @@ -334,6 +384,8 @@ mcheck (func) __free_hook = freehook; old_malloc_hook = __malloc_hook; __malloc_hook = mallochook; + old_memalign_hook = __memalign_hook; + __memalign_hook = memalignhook; old_realloc_hook = __realloc_hook; __realloc_hook = reallochook; mcheck_used = 1; |