fix filenames
[AROS.git] / arch / all-linux / bootstrap / malloc.c
blob4ee4d2a5a04c0ec40dffc750e0fb415f71b11e69
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /*
7 * AROS-thread-safe versions of libc memory allocation routines
8 * This does not work with Android's bionic.
9 */
11 /* TODO:
12 This code is compiled with the kernel compiler but calls code
13 from exec.library. This can only work if function calling
14 convention for kernel and target compiler are the same.
15 Up to now this seems to be the case for all linux hosted ports
16 as UNIX calling is often taken as reference for the AROS
17 implementation.
20 #ifndef __ANDROID__
22 #include <proto/exec.h>
23 #include <sys/types.h>
25 static int memnest;
26 #define MEMLOCK if (SysBase != NULL) Forbid();
27 #define MEMUNLOCK if (SysBase != NULL) Permit();
29 extern struct ExecBase *SysBase;
30 extern void * __libc_malloc(size_t);
31 extern void __libc_free(void *);
32 extern void * __libc_calloc(size_t, size_t);
33 extern void * __libc_realloc(void * mem, size_t newsize);
35 void * malloc(size_t size)
37 void *res;
39 MEMLOCK
40 memnest++;
41 res = __libc_malloc(size);
42 memnest--;
43 MEMUNLOCK
45 return res;
48 void free(void * addr)
50 MEMLOCK
51 memnest++;
52 __libc_free(addr);
53 memnest--;
54 MEMUNLOCK
57 void * calloc(size_t n, size_t size)
59 void *res;
61 MEMLOCK
62 memnest++;
63 res = __libc_calloc(n, size);
64 memnest--;
65 MEMUNLOCK
67 return res;
70 void *realloc(void *ptr, size_t size)
72 void *res;
74 MEMLOCK
75 memnest++;
76 res = __libc_realloc(ptr, size);
77 memnest--;
78 MEMUNLOCK;
80 return res;
83 #endif