dotnet / runtimelab

This repo is for experimentation and exploring new ideas that may or may not make it into the main dotnet/runtime repo.
MIT License
1.4k stars 197 forks source link

[NativeAOT-LLVM] Support emulated unwinding for WASI #2387

Closed SingleAccretion closed 1 year ago

SingleAccretion commented 1 year ago

The idea here is very simple. It rests on two premises: 1) We can "unwind" using early returns conditioned on a global "exception thrown" variable. 2) We will only need to "unwind" through managed code.

It turns out, crucially, that 2 is true: all native runtime code has the constraint that it will only tail-call managed code. On native platforms this is due to the lack of unwind information for this native code, for us it means we don't need to modify anything upstream for things to "just work". We do still need to ensure our own "manually managed" code such as the helpers generated in pure LLVM and allocators work in alignment with the tail-calling assumption.

The end result is that we now support all exception handling features except stack traces on non-WasmEH-enabled non-browser platforms with only ~200 lines of code changed.

SingleAccretion commented 1 year ago

@dotnet/nativeaot-llvm

jkotas commented 1 year ago

Thank you!