Skip to content

Commit

Permalink
Add test case for sbrk race Wasm Workers crash
Browse files Browse the repository at this point in the history
  • Loading branch information
juj committed Nov 9, 2022
1 parent bdaaac3 commit 3391972
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/wasm_worker/sbrk_race.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Build with e.g.
em++ -O3 -g3 -sWASM_WORKERS=1 -sASSERTIONS=1 -sINITIAL_MEMORY=64KB -sALLOW_MEMORY_GROWTH=1 -sSAFE_HEAP=2
-sDISABLE_EXCEPTION_CATCHING=0 -sNO_FILESYSTEM -sEXIT_RUNTIME=0 -sMALLOC=emmalloc-verbose
-sSTACK_SIZE=16KB -sMEMORY_GROWTH_LINEAR_STEP=64KB
test/wasm_worker/sbrk_race.cpp -o a.html
*/

#include <emscripten/emscripten.h>
#include <emscripten/wasm_worker.h>

#include <stdlib.h>

void done()
{
EM_ASM(document.body.innerHTML = 'Test finished without crashing');
}

void worker() {
for(int i = 0; i < 60000; ++i)
EM_ASM({}, malloc(i)); // Allocate 60k*(60k-1)/2 == 1.8 GB of memory
emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, done);
}

int main() {
emscripten_wasm_worker_post_function_v(emscripten_malloc_wasm_worker(1024), &worker);
emscripten_set_main_loop([](){}, 0, 1);
}

0 comments on commit 3391972

Please sign in to comment.