]>
git.proxmox.com Git - wasi-libc.git/blob - dlmalloc/src/dlmalloc.c
cb9cc81270403668d9ce569c8e1fecfa5ec138a5
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.
9 /* Define configuration macros for dlmalloc. */
11 /* WebAssembly doesn't have mmap-style memory allocation. */
14 /* WebAssembly doesn't support shrinking linear memory. */
15 #define MORECORE_CANNOT_TRIM 1
17 /* Disable sanity checks to reduce code size. */
18 #define ABORT __builtin_unreachable()
20 /* If threads are enabled, enable support for threads. */
25 /* Make malloc deterministic. */
26 #define LACKS_TIME_H 1
28 /* Disable malloc statistics generation to reduce code size. */
30 #define NO_MALLOC_STATS 1
32 /* Align malloc regions to 16, to avoid unaligned SIMD accesses. */
33 #define MALLOC_ALIGNMENT 16
36 * Declare errno values used by dlmalloc. We define them like this to avoid
37 * putting specific errno values in the ABI.
39 extern const int __ENOMEM
;
40 #define ENOMEM __ENOMEM
41 extern const int __EINVAL
;
42 #define EINVAL __EINVAL
44 /* Prefix dlmalloc's names with 'dl'. We wrap them with public names below. */
45 #define USE_DL_PREFIX 1
46 #define DLMALLOC_EXPORT static inline
48 /* This isn't declared with DLMALLOC_EXPORT so make it static explicitly. */
49 static size_t dlmalloc_usable_size(void*);
51 /* Include the upstream dlmalloc's malloc.c. */
54 /* Export the public names. */
56 void *malloc(size_t size
) {
57 return dlmalloc(size
);
60 void free(void *ptr
) {
64 void *calloc(size_t nmemb
, size_t size
) {
65 return dlcalloc(nmemb
, size
);
68 void *realloc(void *ptr
, size_t size
) {
69 return dlrealloc(ptr
, size
);
72 int posix_memalign(void **memptr
, size_t alignment
, size_t size
) {
73 return dlposix_memalign(memptr
, alignment
, size
);
76 void* aligned_alloc(size_t alignment
, size_t bytes
) {
77 return dlmemalign(alignment
, bytes
);
80 size_t malloc_usable_size(void *ptr
) {
81 return dlmalloc_usable_size(ptr
);