diff options
author | Eric Andersen <andersen@codepoet.org> | 2002-07-18 15:00:07 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2002-07-18 15:00:07 +0000 |
commit | 35d29fcb08fadaf006561a058746b0fce76a6a74 (patch) | |
tree | b42a59394f8ee7dc7c11f71ae2d45b1e1beb834b /libc/stdlib/malloc-simple/alloc.c | |
parent | 3b1e82407a02aed6319c6686c5b06c2051a20cca (diff) |
Miles Bader implemented a new mmap based malloc which is much
smarter than the old "malloc-simple", and actually works, unlike
the old "malloc". So kill the old "malloc-simple" and the old
"malloc" and replace them with Miles' new malloc implementation.
Update Config files to match. Thanks Miles!
Diffstat (limited to 'libc/stdlib/malloc-simple/alloc.c')
-rw-r--r-- | libc/stdlib/malloc-simple/alloc.c | 141 |
1 files changed, 0 insertions, 141 deletions
diff --git a/libc/stdlib/malloc-simple/alloc.c b/libc/stdlib/malloc-simple/alloc.c deleted file mode 100644 index 1824507eb..000000000 --- a/libc/stdlib/malloc-simple/alloc.c +++ /dev/null @@ -1,141 +0,0 @@ - -/* - * For MMU hosts we need to track the size of the allocations otherwise - * munmap will fail to free the memory (EINVAL). - */ - -#include <features.h> -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <sys/mman.h> - - -#ifdef L_calloc_dbg - -void *calloc_dbg(size_t num, size_t size, char *function, char *file, - int line) -{ - void *ptr; - - fprintf(stderr, "calloc of %d bytes at %s @%s:%d = ", (int) (num * size), - function, file, line); - ptr = calloc(num, size); - fprintf(stderr, "%p\n", ptr); - return ptr; -} - -#endif - -#ifdef L_malloc_dbg - -void *malloc_dbg(size_t size, char *function, char *file, int line) -{ - void *result; - - fprintf(stderr, "malloc of %d bytes at %s @%s:%d = ", (int) size, function, - file, line); - result = malloc(size); - fprintf(stderr, "%p\n", result); - return result; -} - -#endif - -#ifdef L_free_dbg - -void free_dbg(void *ptr, char *function, char *file, int line) -{ - fprintf(stderr, "free of %p at %s @%s:%d\n", ptr, function, file, - line); - free(ptr); -} - -#endif - - -#ifdef L_calloc - -void *calloc(size_t num, size_t size) -{ - void *ptr = malloc(num * size); - - if (ptr) - memset(ptr, 0, num * size); - return ptr; -} - -#endif - -#ifdef L_malloc - -void *malloc(size_t size) -{ - void *result; - - /* Some programs will call malloc (0). Lets be strict and return NULL */ - if (size == 0) - return NULL; - -#ifdef __UCLIBC_HAS_MMU__ - result = mmap((void *) 0, size + sizeof(size_t), PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); -#else - result = mmap((void *) 0, size, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANONYMOUS, 0, 0); -#endif - - if (result == MAP_FAILED) - return 0; - -#ifdef __UCLIBC_HAS_MMU__ - * (size_t *) result = size; - return(result + sizeof(size_t)); -#else - return(result); -#endif -} - -#endif - -#ifdef L_free - -void free(void *ptr) -{ -#ifdef __UCLIBC_HAS_MMU__ - if (ptr) { - ptr -= sizeof(size_t); - munmap(ptr, * (size_t *) ptr + sizeof(size_t)); - } -#else - munmap(ptr, 0); -#endif -} - -#endif - -#ifdef L_realloc - -void *realloc(void *ptr, size_t size) -{ - void *newptr = NULL; - - if (size > 0) { - newptr = malloc(size); - if (newptr && ptr) { -#ifdef __UCLIBC_HAS_MMU__ - memcpy(newptr, ptr, * ((size_t *) (ptr - sizeof(size_t)))); -#else - memcpy(newptr, ptr, size); -#endif - free(ptr); - } - } - else - free(ptr); - return newptr; -} - -#endif |