From cf53efae4b322ac5968c14eff8a993d7e838e40f Mon Sep 17 00:00:00 2001 From: schulz Date: Sat, 20 Nov 2010 10:13:01 +0000 Subject: [PATCH] Provide our own malloc, free and calloc functions in AROSBootstrap. Since this is the only executable loaded by Host directly, it's global functions will be visible for all shared objects loaded by dlopen. Therefore, AROSBootstrap memory managment routines will be used. These operations were singlethreaded in libc code and so they have to be on AROS. This commit fixes random lockups of hosted targets (mostly visible on slower machines) git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@35652 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- arch/all-hosted/bootstrap/bootstrap.c | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/arch/all-hosted/bootstrap/bootstrap.c b/arch/all-hosted/bootstrap/bootstrap.c index 9573d6932d..01cca7c868 100644 --- a/arch/all-hosted/bootstrap/bootstrap.c +++ b/arch/all-hosted/bootstrap/bootstrap.c @@ -23,6 +23,8 @@ #include #include +#include + #include "bootstrap.h" #include "elfloader32.h" #include "filesystem.h" @@ -117,6 +119,51 @@ char *join_string(int argc, char **argv) return str; } +static int memnest; +#define MEMLOCK if (SysBase != NULL) Forbid(); +#define MEMUNLOCK if (SysBase != NULL) Permit(); + +extern struct ExecBase *SysBase; +extern void * __libc_malloc(size_t); +extern void __libc_free(void *); +extern void * __libc_calloc(size_t, size_t); +extern void * __libc_realloc(void * mem, size_t newsize); + +void * malloc(size_t size) +{ + void *res; + + MEMLOCK + memnest++; + res = __libc_malloc(size); + memnest--; + MEMUNLOCK + + return res; +} + +void free(void * addr) +{ + MEMLOCK + memnest++; + __libc_free(addr); + memnest--; + MEMUNLOCK +} + +void * calloc(size_t n, size_t size) +{ + void *res; + + MEMLOCK + memnest++; + res = __libc_calloc(n, size); + memnest--; + MEMUNLOCK + + return res; +} + int bootstrap(int argc, char ** argv) { int i = 1; -- 2.11.4.GIT