Skip to content

Commit 1018b15

Browse files
docs: Add docs for stack.h
This does not include documentation for `emscripten_stack_init()` as this appears to be for use internally within emscripten.
1 parent db51a47 commit 1018b15

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

site/source/docs/api_reference/index.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ high level it consists of:
4848
- :ref:`proxying-h`:
4949
API for synchronously or asynchronously proxying work to a target pthread.
5050

51+
- :ref:`stack-h`:
52+
Inspecting the WebAssembly data stack.
53+
5154
- :ref:`api-reference-advanced-apis`:
5255
APIs for advanced users/core developers.
5356

@@ -66,6 +69,7 @@ high level it consists of:
6669
trace.h
6770
fiber.h
6871
proxying.h
72+
stack.h
6973
wasm_workers
7074
wasm_audio_worklets
7175
advanced-apis
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.. _stack-h:
2+
3+
=======
4+
stack.h
5+
=======
6+
7+
The functions defined in `<emscripten/stack.h>` allow inspecting
8+
information about the WebAssembly data stack (sometimes called the
9+
"user stack" or the "C stack"). This data stack is the data contained
10+
within the linear memory (as opposed to the trusted call stack that
11+
is managed by the VM, and which is not visible to the running program).
12+
13+
.. c:function:: uintptr_t emscripten_stack_get_base(void)
14+
15+
Returns the starting address of the stack. This is the address
16+
that the stack pointer would point to when no bytes are in use on the
17+
stack.
18+
19+
.. c:function:: uintptr_t emscripten_stack_get_end(void)
20+
21+
Returns the end address of the stack. This is the address that
22+
the stack pointer would point to when the whole stack is in use. (The
23+
address pointed to by the end is not part of the stack itself). Note
24+
that the stack grows down so the address returned by
25+
`emscripten_stack_get_end()` is smaller than
26+
:c:func:`emscripten_stack_get_base()`.
27+
28+
.. c:function:: void emscripten_stack_set_limits(void* base, void* end)
29+
30+
Sets the internal values reported by :c:func:`emscripten_stack_get_base()`
31+
and :c:func:`emscripten_stack_get_end()`. This should only used by low
32+
level libraries such as asyncify fibers.
33+
34+
.. c:function:: uintptr_t emscripten_stack_get_current(void)
35+
36+
Returns the current stack pointer.
37+
38+
.. c:function:: size_t emscripten_stack_get_free(void)
39+
40+
Returns the number of free bytes left on the stack. This is required
41+
to be fast so that it can be called frequently.

system/include/emscripten/stack.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@
1616
extern "C" {
1717
#endif
1818

19-
// Returns the starting address of the wasm stack. This is the address
19+
// Returns the starting address of the stack. This is the address
2020
// that the stack pointer would point to when no bytes are in use on the stack.
2121
uintptr_t emscripten_stack_get_base(void);
2222

23-
// Returns the end address of the wasm stack. This is the address that the stack
23+
// Returns the end address of the stack. This is the address that the stack
2424
// pointer would point to when the whole stack is in use. (the address pointed
2525
// to by the end is not part of the stack itself). Note that the stack grows
2626
// down so the address returned by emscripten_stack_get_end() is smaller than
2727
// emscripten_stack_get_base().
2828
uintptr_t emscripten_stack_get_end(void);
2929

3030
// Setup internal base/end values based on the initial values that were either
31-
// set at compile time (in static linking) or instantiations time (for dynamic
31+
// set at compile time (in static linking) or instantiation time (for dynamic
3232
// linking).
3333
void emscripten_stack_init(void);
3434

35-
// Sets the internal values reported by emscripten_stack_get_base and
36-
// emscripten_stack_get_end. This should only used by low level libraries
37-
// such as asyncify fibres.
35+
// Sets the internal values reported by emscripten_stack_get_base() and
36+
// emscripten_stack_get_end(). This should only used by low level libraries
37+
// such as asyncify fibers.
3838
void emscripten_stack_set_limits(void* base, void* end);
3939

4040
// Returns the current stack pointer.

0 commit comments

Comments
 (0)