emscripten-core / emscripten-core/emscripten

Add a 4GB debug validation mode?

Open
#15,382 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

I would like to have a build mode `-s DEBUG_4GB_SAFETY=1` where Emscripten would immediately at startup grow the heap to 2GB+ size, consume all that memory, and then place the program global data section, stack and all malloc results to >= 2GB memory area.

I prototyped such a support for emmalloc() to sbrk() in and consume 2GB at startup, but that does not cover the stack and global data sections, so that is a partial test. Then realized that both LLVM and Binaryen would need to be updated for such a support to take place?

I am aware that the Wasm spec does not allow initial memories larger than 2GB (or wasm-embedded global data sections larger than 2GB?), so such a build mode would need to run with the memory init file option (which btw looks like has regressed: running `emcc tests/hello_world.c -o a.html --memory-init-file 1` no longer produces a `a.mem` file, but the option gets silently ignored)

Would it be possible to add support for this kind of debug build mode? That would help developers reliably test out in practice that all JS code they write will be 4GB compliant? This will be very important for both Unity internal developers, but also for Unity game developers who also need a way to audit their own JS code to work properly.

Currently there is no good way to be sure that one has written 4GB safe code, and faulty code will not produce a runtime crash, but can result to silent failures and runtime corruption.

Under a `-s DEBUG_4GB_SAFETY=1` mode, one could also pair the `-s SAFE_HEAP=1` check to verify that no memory accesses are done to the lower 2GB half, to ensure that there is no code that would erroneously access the wrong memory area.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.