|
9 | 9 |
|
10 | 10 | void __attribute__((noinline)) InteropString(char *staticBuffer)
|
11 | 11 | {
|
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 | + }); |
24 | 28 | }
|
25 | 29 |
|
26 | 30 | int main()
|
27 | 31 | {
|
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); |
33 | 38 | }
|
0 commit comments