Skip to content

Commit 062dbd3

Browse files
committed
Wait for binaryen side [ci skip] #9039 (comment)
1 parent c3d82f6 commit 062dbd3

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

tests/stack_overflow.cpp

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,30 @@
99

1010
void __attribute__((noinline)) InteropString(char *staticBuffer)
1111
{
12-
char *string = (char*)EM_ASM_INT({
13-
var str = "hello, this is a string! ";
14-
for(var i = 0; i < 15; ++i)
15-
str = str + str;
16-
var stringOnTheStack = allocate(intArrayFromString(str), 'i8', ALLOC_STACK);
17-
return stringOnTheStack;
18-
});
19-
20-
int stringLength = strlen(string);
21-
printf("Got string: %s\n", string);
22-
printf("Received a string of length %d.\n", stringLength);
23-
strcpy(staticBuffer, string);
12+
char *string = (char*)EM_ASM_INT({
13+
var str = "hello, this is a string! ";
14+
#if ONE_BIG_STRING
15+
// double it until it is bigger than the stack
16+
for (var i = 0; i < 15; ++i) {
17+
str = str + str;
18+
}
19+
allocate(intArrayFromString(str), "i8", ALLOC_STACK);
20+
#else
21+
// allocate as many times as we need to overflow
22+
for (var i = 0; i < 1024 * 1024; i++) {
23+
allocate(intArrayFromString(str), "i8", ALLOC_STACK);
24+
}
25+
abort("we should never get here!");
26+
#endif
27+
});
2428
}
2529

2630
int main()
2731
{
28-
char staticBuffer[512288] = {}; // Make asm.js side consume a large portion of the stack, before bumping the rest with C++<->JS interop.
29-
InteropString(staticBuffer);
30-
int stringLength = strlen(staticBuffer);
31-
printf("Got string: %s\n", staticBuffer);
32-
printf("Received a string of length %d.\n", stringLength);
32+
// Make C side consume a large portion of the stack, before bumping the rest with C++<->JS interop.
33+
char staticBuffer[512288] = {};
34+
InteropString(staticBuffer);
35+
int stringLength = strlen(staticBuffer);
36+
printf("Got string: %s\n", staticBuffer);
37+
printf("Received a string of length %d.\n", stringLength);
3338
}

tests/test_core.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7811,15 +7811,13 @@ def test_fs_dict_none(self):
78117811
self.do_run('int main() { return 0; }', expected)
78127812

78137813
@sync
7814-
@no_wasm_backend("https://github.com/emscripten-core/emscripten/issues/9039")
78157814
def test_stack_overflow_check(self):
7816-
args = self.emcc_args + ['-s', 'TOTAL_STACK=1048576']
7817-
7818-
self.emcc_args = args + ['-s', 'STACK_OVERFLOW_CHECK=2', '-s', 'ASSERTIONS=0']
7819-
self.do_runf(path_from_root('tests', 'stack_overflow.cpp'), 'Stack overflow! Attempted to allocate', assert_returncode=NON_ZERO)
7815+
self.set_setting('TOTAL_STACK', 1048576)
7816+
self.set_setting('STACK_OVERFLOW_CHECK', 2)
7817+
self.do_runf(path_from_root('tests', 'stack_overflow.cpp'), 'stack overflow', assert_returncode=NON_ZERO)
78207818

7821-
self.emcc_args = args + ['-s', 'ASSERTIONS=1']
7822-
self.do_runf(path_from_root('tests', 'stack_overflow.cpp'), 'Stack overflow! Attempted to allocate', assert_returncode=NON_ZERO)
7819+
self.emcc_args += ['-DONE_BIG_STRING']
7820+
self.do_runf(path_from_root('tests', 'stack_overflow.cpp'), 'stack overflow', assert_returncode=NON_ZERO)
78237821

78247822
@node_pthreads
78257823
def test_binaryen_2170_emscripten_atomic_cas_u8(self):

0 commit comments

Comments
 (0)