]>
Commit | Line | Data |
---|---|---|
320054e8 DG |
1 | /* |
2 | * This file is a wrapper around malloc.c, which is the upstream source file. | |
3 | * It sets configuration flags and controls which symbols are exported. | |
4 | */ | |
5 | ||
6 | #include <stddef.h> | |
7ba6adfc | 7 | #include <malloc.h> |
320054e8 | 8 | |
dbfccac2 DG |
9 | /* Define configuration macros for dlmalloc. */ |
10 | ||
11 | /* WebAssembly doesn't have mmap-style memory allocation. */ | |
12 | #define HAVE_MMAP 0 | |
13 | ||
14 | /* WebAssembly doesn't support shrinking linear memory. */ | |
15 | #define MORECORE_CANNOT_TRIM 1 | |
16 | ||
17 | /* Disable sanity checks to reduce code size. */ | |
18 | #define ABORT __builtin_unreachable() | |
19 | ||
20 | /* If threads are enabled, enable support for threads. */ | |
320054e8 | 21 | #ifdef _REENTRANT |
dbfccac2 DG |
22 | #define USE_LOCKS 1 |
23 | #endif | |
24 | ||
25 | /* Make malloc deterministic. */ | |
26 | #define LACKS_TIME_H 1 | |
27 | ||
dbfccac2 DG |
28 | /* Disable malloc statistics generation to reduce code size. */ |
29 | #define NO_MALLINFO 1 | |
30 | #define NO_MALLOC_STATS 1 | |
31 | ||
32 | /* | |
33 | * Declare errno values used by dlmalloc. We define them like this to avoid | |
34 | * putting specific errno values in the ABI. | |
35 | */ | |
36 | extern const int __ENOMEM; | |
37 | #define ENOMEM __ENOMEM | |
38 | extern const int __EINVAL; | |
39 | #define EINVAL __EINVAL | |
40 | ||
41 | /* Prefix dlmalloc's names with 'dl'. We wrap them with public names below. */ | |
42 | #define USE_DL_PREFIX 1 | |
43 | #define DLMALLOC_EXPORT static inline | |
44 | ||
320054e8 DG |
45 | /* This isn't declared with DLMALLOC_EXPORT so make it static explicitly. */ |
46 | static size_t dlmalloc_usable_size(void*); | |
47 | ||
dbfccac2 DG |
48 | /* Include the upstream dlmalloc's malloc.c. */ |
49 | #include "malloc.c" | |
50 | ||
51 | /* Export the public names. */ | |
52 | ||
53 | void *malloc(size_t size) { | |
54 | return dlmalloc(size); | |
55 | } | |
56 | ||
57 | void free(void *ptr) { | |
7ba6adfc | 58 | dlfree(ptr); |
dbfccac2 DG |
59 | } |
60 | ||
61 | void *calloc(size_t nmemb, size_t size) { | |
62 | return dlcalloc(nmemb, size); | |
63 | } | |
64 | ||
65 | void *realloc(void *ptr, size_t size) { | |
66 | return dlrealloc(ptr, size); | |
67 | } | |
68 | ||
69 | int posix_memalign(void **memptr, size_t alignment, size_t size) { | |
70 | return dlposix_memalign(memptr, alignment, size); | |
71 | } | |
320054e8 DG |
72 | |
73 | void* aligned_alloc(size_t alignment, size_t bytes) { | |
74 | return dlmemalign(alignment, bytes); | |
75 | } | |
76 | ||
77 | size_t malloc_usable_size(void *ptr) { | |
78 | return dlmalloc_usable_size(ptr); | |
79 | } |