| #if STACK_OVERFLOW_CHECK |
| // Initializes the stack cookie. Called at the startup of main and at the startup of each thread in pthreads mode. |
| function writeStackCookie() { |
| assert((STACK_MAX & 3) == 0); |
| HEAPU32[(STACK_MAX >> 2)-1] = 0x02135467; |
| HEAPU32[(STACK_MAX >> 2)-2] = 0x89BACDFE; |
| } |
| |
| function checkStackCookie() { |
| if (HEAPU32[(STACK_MAX >> 2)-1] != 0x02135467 || HEAPU32[(STACK_MAX >> 2)-2] != 0x89BACDFE) { |
| abort('Stack overflow! Stack cookie has been overwritten, expected hex dwords 0x89BACDFE and 0x02135467, but received 0x' + HEAPU32[(STACK_MAX >> 2)-2].toString(16) + ' ' + HEAPU32[(STACK_MAX >> 2)-1].toString(16)); |
| } |
| // Also test the global address 0 for integrity. |
| if (HEAP32[0] !== 0x63736d65 /* 'emsc' */) throw 'Runtime error: The application has corrupted its heap memory area (address zero)!'; |
| } |
| |
| #if !MINIMAL_RUNTIME // MINIMAL_RUNTIME moves this to a JS library function |
| function abortStackOverflow(allocSize) { |
| abort('Stack overflow! Attempted to allocate ' + allocSize + ' bytes on the stack, but stack has only ' + (STACK_MAX - stackSave() + allocSize) + ' bytes available!'); |
| } |
| #endif |
| |
| #endif |
| |
| #if STACK_OVERFLOW_CHECK |
| #if USE_PTHREADS |
| if (!ENVIRONMENT_IS_PTHREAD) { |
| #endif |
| HEAP32[0] = 0x63736d65; /* 'emsc' */ |
| #if USE_PTHREADS |
| } else { |
| if (HEAP32[0] !== 0x63736d65) throw 'Runtime error: The application has corrupted its heap memory area (address zero)!'; |
| } |
| #endif // USE_PTHREADS |
| #endif // STACK_OVERFLOW_CHECK |