forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary_stack.js
68 lines (62 loc) · 1.76 KB
/
library_stack.js
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
/**
* @license
* Copyright 2015 The Emscripten Authors
* SPDX-License-Identifier: MIT
*/
mergeInto(LibraryManager.library, {
emscripten_stack_get_base: function() {
return STACK_BASE;
},
emscripten_stack_get_end: function() {
// TODO(sbc): rename STACK_MAX -> STACK_END?
return STACK_MAX;
},
#if !WASM_BACKEND
$abortStackOverflow__deps: ['$stackSave'],
#endif
$abortStackOverflow__import: true,
$abortStackOverflow: function(allocSize) {
abort('Stack overflow! Attempted to allocate ' + allocSize + ' bytes on the stack, but stack has only ' + (STACK_MAX - stackSave() + allocSize) + ' bytes available!');
},
#if !WASM_BACKEND
$stackAlloc__asm: true,
$stackAlloc__sig: 'ii',
#if ASSERTIONS || STACK_OVERFLOW_CHECK >= 2
$stackAlloc__deps: ['$abortStackOverflow'],
#endif
$stackAlloc: function(size) {
size = size|0;
var ret = 0;
ret = STACKTOP;
STACKTOP = (STACKTOP + size)|0;
STACKTOP = (STACKTOP + 15)&-16;
#if ASSERTIONS || STACK_OVERFLOW_CHECK >= 2
if ((STACKTOP|0) >= (STACK_MAX|0)) abortStackOverflow(size|0);
#endif
return ret|0;
},
$stackSave__asm: true,
$stackSave__sig: 'i',
$stackSave: function() {
return STACKTOP|0;
},
$stackRestore__asm: true,
$stackRestore__sig: 'vi',
$stackRestore: function(top) {
top = top|0;
STACKTOP = top;
},
// With the wasm backend, these functions are implemented as native
// functions in compiler-rt/stack_ops.s
emscripten_stack_get_current__asm: true,
emscripten_stack_get_current__sig: 'i',
emscripten_stack_get_current: function() {
return STACKTOP|0;
},
emscripten_stack_get_free__asm: true,
emscripten_stack_get_free__sig: 'i',
emscripten_stack_get_free: function() {
return (STACK_MAX|0) - (STACKTOP|0);
}
#endif
});