Skip to content

Commit 5627123

Browse files
authored
Always use size_t in dlmalloc's mallinfo (#23368)
For some reason emscripten was overriding `MALLINFO_FIELD_TYPE` to be `int` even though this defaults `size_t` and `size_t` is what linux uses, and `size_t` allows for correct reporting of numbers larger than 2^32. What is worse, the `MALLINFO_FIELD_TYPE` override was only applied when `DLMALLOC_DEBUG` was defined which meant that `MALLINFO_FIELD_TYPE` varied between `-sASSERTIONS=1` and `-sASSERTIONS=2` builds of dlmalloc! This means that `-sMEMORY64 + -sASSERTIONS=2` builds of dlmalloc were simply broken WRT `mallinfo` since the public definition of mallinfo disagreed with the dlmalloc-internal version. I verified that the follow tests fails without this change: `EMCC_CFLAGS=-sASSERTIONS=2 ./test/runner wasm64.test_mallinfo` I'm not updating the actual test code here since test coverage will be coming in #23330. This change was spit out from #23330.
1 parent 7dc74dc commit 5627123

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ See docs/process.md for more on how version tagging works.
6464
- JavaScript libraries can now be specified via `-lfoo.js`. This works like the
6565
existing `--js-library` flag but will search the library path (all paths
6666
specified with `-L`) for `libfoo.js`. (#23338)
67+
- The `mallinfo` struct members are now defined as `size_t` which makes them
68+
compatible with larger memories, and is also how linux defines them. (#23368)
6769

6870
3.1.74 - 12/14/24
6971
-----------------

system/include/compat/malloc.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ extern "C" {
1111
system/lib/dlmalloc.c. */
1212

1313
struct mallinfo {
14-
int arena; /* total space allocated from system */
15-
int ordblks; /* number of non-inuse chunks */
16-
int smblks; /* unused -- always zero */
17-
int hblks; /* number of mmapped regions */
18-
int hblkhd; /* total space in mmapped regions */
19-
int usmblks; /* unused -- always zero */
20-
int fsmblks; /* unused -- always zero */
21-
int uordblks; /* total allocated space */
22-
int fordblks; /* total non-inuse space */
23-
int keepcost; /* top-most, releasable (via malloc_trim) space */
14+
size_t arena; /* total space allocated from system */
15+
size_t ordblks; /* number of non-inuse chunks */
16+
size_t smblks; /* unused -- always zero */
17+
size_t hblks; /* number of mmapped regions */
18+
size_t hblkhd; /* total space in mmapped regions */
19+
size_t usmblks; /* unused -- always zero */
20+
size_t fsmblks; /* unused -- always zero */
21+
size_t uordblks; /* total allocated space */
22+
size_t fordblks; /* total non-inuse space */
23+
size_t keepcost; /* top-most, releasable (via malloc_trim) space */
2424
};
2525

2626
/* The routines. */

system/lib/dlmalloc.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#define ABORT __builtin_unreachable()
1717
/* allow malloc stats only in debug builds, which brings in stdio code. */
1818
#define NO_MALLOC_STATS 1
19-
#define MALLINFO_FIELD_TYPE int
2019
#endif
2120
/* XXX Emscripten Tracing API. This defines away the code if tracing is disabled. */
2221
#include <emscripten/trace.h>

test/core/test_setjmp_noleak.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void luaWork(int d){
1616

1717
void dump() {
1818
struct mallinfo m = mallinfo();
19-
emscripten_outf("dump: %d , %d", m.arena, m.uordblks);
19+
emscripten_outf("dump: %zu , %zu", m.arena, m.uordblks);
2020
}
2121

2222
void work(int n) {

0 commit comments

Comments
 (0)