|
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 | | - */ |
| 1 | +// This file is a wrapper around malloc.c, which is the upstream source file. |
| 2 | +// It sets configuration flags and controls which symbols are exported. |
5 | 3 |
|
6 | 4 | #include <stddef.h> |
7 | 5 | #include <malloc.h> |
8 | 6 |
|
9 | | -/* Define configuration macros for dlmalloc. */ |
| 7 | +// Define configuration macros for dlmalloc. |
10 | 8 |
|
11 | | -/* WebAssembly doesn't have mmap-style memory allocation. */ |
| 9 | +// WebAssembly doesn't have mmap-style memory allocation. |
12 | 10 | #define HAVE_MMAP 0 |
13 | 11 |
|
14 | | -/* WebAssembly doesn't support shrinking linear memory. */ |
| 12 | +// WebAssembly doesn't support shrinking linear memory. |
15 | 13 | #define MORECORE_CANNOT_TRIM 1 |
16 | 14 |
|
17 | | -/* Disable sanity checks to reduce code size. */ |
| 15 | +// Disable sanity checks to reduce code size. |
18 | 16 | #define ABORT __builtin_unreachable() |
19 | 17 |
|
20 | | -/* If threads are enabled, enable support for threads. */ |
| 18 | +// If threads are enabled, enable support for threads. |
21 | 19 | #ifdef _REENTRANT |
22 | 20 | #define USE_LOCKS 1 |
23 | 21 | #endif |
24 | 22 |
|
25 | | -/* Make malloc deterministic. */ |
| 23 | +// Make malloc deterministic. |
26 | 24 | #define LACKS_TIME_H 1 |
27 | 25 |
|
28 | | -/* Disable malloc statistics generation to reduce code size. */ |
| 26 | +// Disable malloc statistics generation to reduce code size. |
29 | 27 | #define NO_MALLINFO 1 |
30 | 28 | #define NO_MALLOC_STATS 1 |
31 | 29 |
|
32 | | -/* Align malloc regions to 16, to avoid unaligned SIMD accesses. */ |
| 30 | +// Align malloc regions to 16, to avoid unaligned SIMD accesses. |
33 | 31 | #define MALLOC_ALIGNMENT 16 |
34 | 32 |
|
35 | | -/* |
36 | | - * Declare errno values used by dlmalloc. We define them like this to avoid |
37 | | - * putting specific errno values in the ABI. |
38 | | - */ |
| 33 | +// Declare errno values used by dlmalloc. We define them like this to avoid |
| 34 | +// putting specific errno values in the ABI. |
39 | 35 | extern const int __ENOMEM; |
40 | 36 | #define ENOMEM __ENOMEM |
41 | 37 | extern const int __EINVAL; |
42 | 38 | #define EINVAL __EINVAL |
43 | 39 |
|
44 | | -/* |
45 | | - * Define USE_DL_PREFIX so that we leave dlmalloc's names prefixed with 'dl'. |
46 | | - * We define them as "static", and we wrap them with public names below. This |
47 | | - * serves two purposes: |
48 | | - * |
49 | | - * One is to make it easy to control which symbols are exported; dlmalloc |
50 | | - * defines several non-standard functions and we wish to explicitly control |
51 | | - * which functions are part of our public-facing interface. |
52 | | - * |
53 | | - * The other is to protect against compilers optimizing based on the assumption |
54 | | - * that they know what functions with names like "malloc" do. Code in the |
55 | | - * implementation will call functions like "dlmalloc" and assume it can use |
56 | | - * the resulting pointers to access the metadata outside of the nominally |
57 | | - * allocated objects. However, if the function were named "malloc", compilers |
58 | | - * might see code like that and assume it has undefined behavior and can be |
59 | | - * optimized away. By using "dlmalloc" in the implementation, we don't need |
60 | | - * -fno-builtin to avoid this problem. |
61 | | - */ |
| 40 | +// Define USE_DL_PREFIX so that we leave dlmalloc's names prefixed with 'dl'. |
| 41 | +// We define them as "static", and we wrap them with public names below. This |
| 42 | +// serves two purposes: |
| 43 | +// |
| 44 | +// One is to make it easy to control which symbols are exported; dlmalloc |
| 45 | +// defines several non-standard functions and we wish to explicitly control |
| 46 | +// which functions are part of our public-facing interface. |
| 47 | +// |
| 48 | +// The other is to protect against compilers optimizing based on the assumption |
| 49 | +// that they know what functions with names like "malloc" do. Code in the |
| 50 | +// implementation will call functions like "dlmalloc" and assume it can use |
| 51 | +// the resulting pointers to access the metadata outside of the nominally |
| 52 | +// allocated objects. However, if the function were named "malloc", compilers |
| 53 | +// might see code like that and assume it has undefined behavior and can be |
| 54 | +// optimized away. By using "dlmalloc" in the implementation, we don't need |
| 55 | +// -fno-builtin to avoid this problem. |
62 | 56 | #define USE_DL_PREFIX 1 |
63 | 57 | #define DLMALLOC_EXPORT static inline |
64 | 58 |
|
65 | | -/* This isn't declared with DLMALLOC_EXPORT so make it static explicitly. */ |
| 59 | +// This isn't declared with DLMALLOC_EXPORT so make it static explicitly. |
66 | 60 | static size_t dlmalloc_usable_size(void*); |
67 | 61 |
|
68 | | -/* Include the upstream dlmalloc's malloc.c. */ |
| 62 | +// Include the upstream dlmalloc's malloc.c. |
69 | 63 | #include "malloc.c" |
70 | 64 |
|
71 | | -/* Export the public names. */ |
| 65 | +// Export the public names. |
72 | 66 |
|
73 | 67 | void *malloc(size_t size) { |
74 | 68 | return dlmalloc(size); |
|
0 commit comments