Description
Based on feedback from the discussion at the CG meeting, @fgmccabe and I would like to propose adding stack-walking primitives to WebAssembly based on the primer in WebAssembly/exception-handling#105. For those new to the topic, the following is a high-level description of the proposal.
Many high-level languages keep the stack as an abstract entity that is heavily used for implementing the language but which the programmer rarely directly manipulates. This proposal is for a small suite of primitives that enable language implementers to provide specific functionalities that depend on access to the stack but without compromising the security guarantees provided by WebAssembly. Examples of enabled functionalities include better support for language-provided garbage collection, better support for debugging, better support for exception handling, support for stack-allocated closures, support for simple yield and resume computations, and, in contemplated future extensions, support for stack switching and coroutining.
The core of the stack-walking functionality is centered around two features. The first feature is executable stack marks, which associate stack frames with executable code. This executable code can, for example, indicate what line of source code the stack frame corresponds to, can inform which 32-bit integers on the stack frame correspond to addresses that should not be collected as garbage, and can display the source-code-relevant contents of the current stack frame and even update the contents of the stack frame. The second feature is a framework for stack walking, which enables WebAssembly code to walk up the stack to find and execute these stack marks.
The stack-walking functionality imagined does not permit arbitrary inspection of stack frames nor of arbitrary locations on the stack. Rather, the regions of the stack that are intended to be inspected are declared as part of the stack-mark primitives. This is so that stack walking can be done in a safe manner within WebAssembly, keeping in line with WebAssembly’s existing security considerations, and furthermore can be designed independently of features such as memory-managed references, maintaining compatibility with low-resource engines.
We propose establishing a new activity to clarify and specify these primitives and to construct a formal proposal for adoption by the WebAssembly community.