Index: head/libexec/rtld-elf/malloc.c =================================================================== --- head/libexec/rtld-elf/malloc.c +++ head/libexec/rtld-elf/malloc.c @@ -153,7 +153,7 @@ */ void * -malloc(size_t nbytes) +__crt_malloc(size_t nbytes) { union overhead *op; int bucket; @@ -236,7 +236,7 @@ } void * -calloc(size_t num, size_t size) +__crt_calloc(size_t num, size_t size) { void *ret; @@ -245,7 +245,7 @@ return (NULL); } - if ((ret = malloc(num * size)) != NULL) + if ((ret = __crt_malloc(num * size)) != NULL) memset(ret, 0, num * size); return (ret); @@ -298,7 +298,7 @@ } void -free(void * cp) +__crt_free(void *cp) { int size; union overhead *op; @@ -339,7 +339,7 @@ static int realloc_srchlen = 4; /* 4 should be plenty, -1 =>'s whole list */ void * -realloc(void *cp, size_t nbytes) +__crt_realloc(void *cp, size_t nbytes) { u_int onb; int i; @@ -348,7 +348,7 @@ int was_alloced = 0; if (cp == NULL) - return (malloc(nbytes)); + return (__crt_malloc(nbytes)); op = (union overhead *)((caddr_t)cp - sizeof (union overhead)); if (op->ov_magic == MAGIC) { was_alloced++; @@ -393,10 +393,10 @@ #endif return(cp); } else - free(cp); + __crt_free(cp); } - if ((res = malloc(nbytes)) == NULL) - return (NULL); + if ((res = __crt_malloc(nbytes)) == NULL) + return (NULL); if (cp != res) /* common optimization if "compacting" */ bcopy(cp, res, (nbytes < onb) ? nbytes : onb); return (res); @@ -467,9 +467,11 @@ caddr_t addr = (caddr_t) (((long)pagepool_start + pagesz - 1) & ~(pagesz - 1)); if (munmap(addr, pagepool_end - addr) != 0) { +#ifdef IN_RTLD rtld_fdprintf(STDERR_FILENO, _BASENAME_RTLD ": " "morepages: cannot munmap %p: %s\n", addr, rtld_strerror(errno)); +#endif } } @@ -478,9 +480,11 @@ if ((pagepool_start = mmap(0, n * pagesz, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, fd, 0)) == (caddr_t)-1) { +#ifdef IN_RTLD rtld_fdprintf(STDERR_FILENO, _BASENAME_RTLD ": morepages: " "cannot mmap anonymous memory: %s\n", rtld_strerror(errno)); +#endif return 0; } pagepool_end = pagepool_start + n * pagesz; Index: head/libexec/rtld-elf/rtld.h =================================================================== --- head/libexec/rtld-elf/rtld.h +++ head/libexec/rtld-elf/rtld.h @@ -409,4 +409,9 @@ void init_pltgot(Obj_Entry *); void allocate_initial_tls(Obj_Entry *); +void *__crt_calloc(size_t num, size_t size); +void __crt_free(void *cp); +void *__crt_malloc(size_t nbytes); +void *__crt_realloc(void *cp, size_t nbytes); + #endif /* } */ Index: head/libexec/rtld-elf/rtld.c =================================================================== --- head/libexec/rtld-elf/rtld.c +++ head/libexec/rtld-elf/rtld.c @@ -66,6 +66,7 @@ #include "paths.h" #include "rtld_tls.h" #include "rtld_printf.h" +#include "rtld_malloc.h" #include "rtld_utrace.h" #include "notes.h" @@ -5636,4 +5637,33 @@ for (i = 0; i < len; i++) ((char *)dest)[i] = 0; +} + +/* malloc */ +void * +malloc(size_t nbytes) +{ + + return (__crt_malloc(nbytes)); +} + +void * +calloc(size_t num, size_t size) +{ + + return (__crt_calloc(num, size)); +} + +void +free(void *cp) +{ + + __crt_free(cp); +} + +void * +realloc(void *cp, size_t nbytes) +{ + + return (__crt_realloc(cp, nbytes)); } Index: head/libexec/rtld-elf/xmalloc.c =================================================================== --- head/libexec/rtld-elf/xmalloc.c +++ head/libexec/rtld-elf/xmalloc.c @@ -33,13 +33,14 @@ #include #include "rtld.h" #include "rtld_printf.h" +#include "rtld_malloc.h" void * xcalloc(size_t number, size_t size) { void *p; - p = calloc(number, size); + p = __crt_calloc(number, size); if (p == NULL) { rtld_fdputstr(STDERR_FILENO, "Out of memory\n"); _exit(1); @@ -50,12 +51,15 @@ void * xmalloc(size_t size) { - void *p = malloc(size); - if (p == NULL) { - rtld_fdputstr(STDERR_FILENO, "Out of memory\n"); - _exit(1); - } - return p; + + void *p; + + p = __crt_malloc(size); + if (p == NULL) { + rtld_fdputstr(STDERR_FILENO, "Out of memory\n"); + _exit(1); + } + return (p); } char *