Implement Wasmtime's new API as designed by RFC 11. This is quite a large commit which has had lots of discussion externally, so for more information it's best to read the RFC thread and the PR thread.
35 lines
987 B
C
35 lines
987 B
C
#include <setjmp.h>
|
|
|
|
// Note that `sigsetjmp` and `siglongjmp` are used here where possible to
|
|
// explicitly pass a 0 argument to `sigsetjmp` that we don't need to preserve
|
|
// the process signal mask. This should make this call a bit faster b/c it
|
|
// doesn't need to touch the kernel signal handling routines.
|
|
#ifdef CFG_TARGET_OS_windows
|
|
#define platform_setjmp(buf) setjmp(buf)
|
|
#define platform_longjmp(buf, arg) longjmp(buf, arg)
|
|
#define platform_jmp_buf jmp_buf
|
|
#else
|
|
#define platform_setjmp(buf) sigsetjmp(buf, 0)
|
|
#define platform_longjmp(buf, arg) siglongjmp(buf, arg)
|
|
#define platform_jmp_buf sigjmp_buf
|
|
#endif
|
|
|
|
int RegisterSetjmp(
|
|
void **buf_storage,
|
|
void (*body)(void*, void*),
|
|
void *payload,
|
|
void *callee) {
|
|
platform_jmp_buf buf;
|
|
if (platform_setjmp(buf) != 0) {
|
|
return 0;
|
|
}
|
|
*buf_storage = &buf;
|
|
body(payload, callee);
|
|
return 1;
|
|
}
|
|
|
|
void Unwind(void *JmpBuf) {
|
|
platform_jmp_buf *buf = (platform_jmp_buf*) JmpBuf;
|
|
platform_longjmp(*buf, 1);
|
|
}
|