MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / writeStackCookie

Function writeStackCookie

src/runtime_stack_check.js:9–32  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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.
9function 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
34function checkStackCookie() {
35#if !MINIMAL_RUNTIME

Callers 4

libpthread.jsFile · 0.50
libasync.jsFile · 0.50
libwasm_worker.jsFile · 0.50

Calls 4

ptrToStringFunction · 0.85
makeSetValueFunction · 0.85
assertFunction · 0.70
dbgFunction · 0.50

Tested by

no test coverage detected