Implement wasm trap handlers. (#27)
* Implement wasm trap handlers. This adds signal handlers based on SpiderMonkey's signal-handler code. The functionality for looking up the trap code and wasm bytecode offset isn't yet implemented, but this is a start. I considered rewriting this code in Rust, but decided against it for now as C++ allows us to talk to the relevant OS APIs more directly. Fixes #15. * Compile with -std=c++11. * Refactor InstallState initialization. * Compile with -fPIC. * Factor out the code for calling a wasm function with a given index. * Fix unclear wording in a comment.
This commit is contained in:
55
lib/execute/signalhandlers/SignalHandlers.h
Normal file
55
lib/execute/signalhandlers/SignalHandlers.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#ifndef signal_handlers_h
|
||||
#define signal_handlers_h
|
||||
|
||||
#include <stdint.h>
|
||||
#include <setjmp.h>
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct CodeSegment;
|
||||
|
||||
// Record the Trap code and wasm bytecode offset in TLS somewhere
|
||||
void RecordTrap(const uint8_t* pc, const struct CodeSegment* codeSegment);
|
||||
|
||||
// Initiate an unwind.
|
||||
void Unwind(void);
|
||||
|
||||
// Return the CodeSegment containing the given pc, if any exist in the process.
|
||||
// This method does not take a lock.
|
||||
const struct CodeSegment*
|
||||
LookupCodeSegment(const void* pc);
|
||||
|
||||
// Trap initialization state.
|
||||
struct TrapContext {
|
||||
bool triedToInstallSignalHandlers;
|
||||
bool haveSignalHandlers;
|
||||
};
|
||||
|
||||
// This function performs the low-overhead signal handler initialization that we
|
||||
// want to do eagerly to ensure a more-deterministic global process state. This
|
||||
// is especially relevant for signal handlers since handler ordering depends on
|
||||
// installation order: the wasm signal handler must run *before* the other crash
|
||||
// handlers and since POSIX signal handlers work LIFO, this function needs to be
|
||||
// called at the end of the startup process, after other handlers have been
|
||||
// installed. This function can thus be called multiple times, having no effect
|
||||
// after the first call.
|
||||
bool
|
||||
EnsureEagerSignalHandlers(void);
|
||||
|
||||
// Assuming EnsureEagerProcessSignalHandlers() has already been called,
|
||||
// this function performs the full installation of signal handlers which must
|
||||
// be performed per-thread. This operation may incur some overhead and
|
||||
// so should be done only when needed to use wasm.
|
||||
bool
|
||||
EnsureDarwinMachPorts(struct TrapContext* cx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // signal_handlers_h
|
||||
Reference in New Issue
Block a user