Skip to content

Option to check for stack overflows in threads #4478

Open
@ashivaram23

Description

@ashivaram23

Motivation

Currently wasm-bindgen allocates a stack on the heap in __wbindgen_start for each additional thread, and the new thread's stack pointer will usually end up somewhere close to the main thread's stack (e.g. if the main stack goes from 0-1 MiB, the second thread's stack may go from 2 to 4 MiB). If a program reaches a large enough stack depth or allocates a large value, it could silently overflow the stack and access data belonging to the main thread's stack, another thread's stack, or heap objects. This can break Rust's safety guarantees without any runtime or compile time indication.

Proposed Solution

Even though this may be unfixable without a significant effect on performance, I wonder if there could be a cli flag adding a check to every function that throws an error if the stack frame is out of bounds. That way people could check a typical run for stack overflows during development without sacrificing release performance. This would only be necessary when using threads, because going out of bounds in the main thread will just cause a runtime error due to a negative index.

Alternatives

A warning could be documented somewhere like the wasm-bindgen guide.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions