()
| 7 | #if STACK_OVERFLOW_CHECK |
| 8 | // Initializes the stack cookie. Called at the startup of main and at the startup of each thread in pthreads mode. |
| 9 | function writeStackCookie() { |
| 10 | var max = _emscripten_stack_get_end(); |
| 11 | #if RUNTIME_DEBUG |
| 12 | dbg(`writeStackCookie: ${ptrToString(max)}`); |
| 13 | #endif |
| 14 | #if ASSERTIONS |
| 15 | assert((max & 3) == 0); |
| 16 | #endif |
| 17 | // If the stack ends at address zero we write our cookies 4 bytes into the |
| 18 | // stack. This prevents interference with SAFE_HEAP and ASAN which also |
| 19 | // monitor writes to address zero. |
| 20 | if (max == 0) { |
| 21 | max += 4; |
| 22 | } |
| 23 | // The stack grow downwards towards _emscripten_stack_get_end. |
| 24 | // We write cookies to the final two words in the stack and detect if they are |
| 25 | // ever overwritten. |
| 26 | {{{ makeSetValue('max', 0, '0x02135467', 'u32') }}}; |
| 27 | {{{ makeSetValue('max', 4, '0x89BACDFE', 'u32') }}}; |
| 28 | #if CHECK_NULL_WRITES |
| 29 | // Also test the global address 0 for integrity. |
| 30 | {{{ makeSetValue(0, 0, 0x63736d65 /* 'emsc' */, 'u32') }}}; |
| 31 | #endif |
| 32 | } |
| 33 | |
| 34 | function checkStackCookie() { |
| 35 | #if !MINIMAL_RUNTIME |
no test coverage detected