forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime_init_memory.js
More file actions
93 lines (86 loc) · 2.59 KB
/
runtime_init_memory.js
File metadata and controls
93 lines (86 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* @license
* Copyright 2019 The Emscripten Authors
* SPDX-License-Identifier: MIT
*/
// Create the main memory. (Note: this isn't used in STANDALONE_WASM mode since the wasm
// memory is created in the wasm, not in JS.)
#if USE_PTHREADS
if (ENVIRONMENT_IS_PTHREAD) {
wasmMemory = Module['wasmMemory'];
buffer = Module['buffer'];
} else {
#endif // USE_PTHREADS
#if WASM
#if expectToReceiveOnModule('wasmMemory')
if (Module['wasmMemory']) {
wasmMemory = Module['wasmMemory'];
} else
#endif
{
wasmMemory = new WebAssembly.Memory({
'initial': INITIAL_INITIAL_MEMORY / WASM_PAGE_SIZE
#if ALLOW_MEMORY_GROWTH
#if MAXIMUM_MEMORY != -1
,
'maximum': {{{ MAXIMUM_MEMORY }}} / WASM_PAGE_SIZE
#endif
#else
,
'maximum': INITIAL_INITIAL_MEMORY / WASM_PAGE_SIZE
#endif // ALLOW_MEMORY_GROWTH
#if USE_PTHREADS
,
'shared': true
#endif
});
#if USE_PTHREADS
if (!(wasmMemory.buffer instanceof SharedArrayBuffer)) {
err('requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag');
if (ENVIRONMENT_IS_NODE) {
console.log('(on node you may need: --experimental-wasm-threads --experimental-wasm-bulk-memory and also use a recent version)');
}
throw Error('bad memory');
}
#endif
}
#else // WASM
if (Module['buffer']) {
buffer = Module['buffer'];
}
#ifdef USE_PTHREADS
else if (typeof SharedArrayBuffer !== 'undefined') {
buffer = new SharedArrayBuffer(INITIAL_INITIAL_MEMORY);
}
#endif
else {
buffer = new ArrayBuffer(INITIAL_INITIAL_MEMORY);
}
#endif // WASM
#if USE_PTHREADS
}
#endif
#if WASM
if (wasmMemory) {
buffer = wasmMemory.buffer;
}
#endif
// If the user provides an incorrect length, just use that length instead rather than providing the user to
// specifically provide the memory length with Module['INITIAL_MEMORY'].
INITIAL_INITIAL_MEMORY = buffer.byteLength;
#ifdef ASSERTIONS && WASM
assert(INITIAL_INITIAL_MEMORY % WASM_PAGE_SIZE === 0);
#ifdef ALLOW_MEMORY_GROWTH && MAXIMUM_MEMORY != -1
assert({{{ WASM_PAGE_SIZE }}} % WASM_PAGE_SIZE === 0);
#endif
#endif
updateGlobalBufferAndViews(buffer);
#if USE_PTHREADS
if (!ENVIRONMENT_IS_PTHREAD) { // Pthreads have already initialized these variables in src/worker.js, where they were passed to the thread worker at startup time
#endif
#if !STANDALONE_WASM // in standalone mode the value is in the wasm
HEAP32[DYNAMICTOP_PTR>>2] = DYNAMIC_BASE;
#endif // !STANDALONE_WASM
#if USE_PTHREADS
}
#endif