diff options
author | Pixel <pixel@nobis-crew.org> | 2011-02-05 08:35:05 -0800 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2011-02-05 08:35:05 -0800 |
commit | 0044f9480cfa8d5cf0a3d84e84be25e32b588726 (patch) | |
tree | bea91e4141bb77722e95885f81c545c40ed919cf | |
parent | 0736203a630b2fbc2bc3e6383e4aec9285bba184 (diff) |
Making malloc / free / realloc function pointers to be able to wrap them later for thread-safe reasons.
-rw-r--r-- | libc/LIB.status | 2 | ||||
-rw-r--r-- | libc/include/malloc.h | 14 | ||||
-rw-r--r-- | libc/src/malloc.c | 10 |
3 files changed, 19 insertions, 7 deletions
diff --git a/libc/LIB.status b/libc/LIB.status index 8827b2c..b2961a6 100644 --- a/libc/LIB.status +++ b/libc/LIB.status @@ -90,7 +90,7 @@ putchar - missing getdelim - missing, gnu replacement to gets getline - missing, gnu replacement to gets *puts - missing -ungetc - missing +ungetc - missing, won't implement, as we don't bufferize at all. fread - ok, inlined fwrite - ok, inlined fseek - missing diff --git a/libc/include/malloc.h b/libc/include/malloc.h index 8dbfc05..ee877a1 100644 --- a/libc/include/malloc.h +++ b/libc/include/malloc.h @@ -5,9 +5,17 @@ #include <stddef.h> #include <string.h> -void * malloc(size_t size); -void free(void *ptr); -void * realloc(void *ptr, size_t size); +typedef void * (*malloc_t)(size_t size); +typedef void (*free_t)(void * ptr); +typedef void * (*realloc_t)(void * ptr, size_t size); + +void * base_malloc(size_t size); +void base_free(void * ptr); +void * base_realloc(void * ptr, size_t size); + +extern malloc_t malloc; +extern free_t free; +extern realloc_t realloc; static inline void * calloc(size_t nmemb, size_t size) { void * r = malloc(nmemb * size); diff --git a/libc/src/malloc.c b/libc/src/malloc.c index 2b8a806..fb6d954 100644 --- a/libc/src/malloc.c +++ b/libc/src/malloc.c @@ -30,7 +30,7 @@ static heap_t * find_fit(heap_t * head, size_t size) { return prev; } -void * malloc(size_t size) { +void * base_malloc(size_t size) { void * ptr = NULL, * heap_ptr; heap_t * new, * prev; @@ -103,7 +103,7 @@ void * malloc(size_t size) { return ptr; } -void * realloc(void * ptr, size_t size) { +void * base_realloc(void * ptr, size_t size) { heap_t * prev; void * new = NULL; @@ -155,7 +155,7 @@ void * realloc(void * ptr, size_t size) { return new; } -void free(void * ptr) { +void base_free(void * ptr) { heap_t * cur; void * top; size_t size; @@ -200,3 +200,7 @@ void free(void * ptr) { __attribute__((weak)) void * __builtin_new(size_t size) { return malloc(size); } __attribute__((weak)) void __builtin_delete(void * ptr) { free(ptr); } + +malloc_t malloc = base_malloc; +free_t free = base_free; +realloc_t realloc = base_realloc; |