Skip to content

Question: Preventing stack overflows / increasing effective stack size #13043

@hoodmane

Description

@hoodmane

I am using Pyodide and running into difficulties with recursion errors, particularly in Chrome. I am wondering whether there are any ways to increase the effective size of the wasm stack.

The compilation variable TOTAL_STACK looks potentially relevant. However, the RangeError is presumably a result of overflowing the VM stack. I found the following quote describing TOTAL_STACK:

The stack defined by TOTAL_STACK etc. is the "C stack", which is just for variables whose address is taken etc., otherwise the call stack and local variables and so forth are handled by the VM automatically. So the size of the stack emscripten allocates can usually be much smaller than the stack a native program would.

If I know that the program is likely to overflow the VM stack, is it possible to encourage Emscripten to allocate things on the "C stack" defensively in order to conserve the limited VM stack? Is it possible to allocate stack traces on the "C stack" or only stack-allocated variables?

If only variables can be on the "C stack", is there any way to instrument a build to audit what is taking up space on the VM stack when there is a stack overflow? If most of the VM stack is occupied by the call stack and cannot be moved to the "C stack" then this strategy wouldn't work very well...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions