Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Unified Diff: src/trap-handler/trap-handler.h

Issue 2371833007: [wasm] Initial signal handler (Closed)
Patch Set: Make sure guard pages get set up when resizing from 0 to more than 0 Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/trap-handler/handler-shared.cc ('k') | src/trap-handler/trap-handler-internal.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/trap-handler/trap-handler.h
diff --git a/src/trap-handler/trap-handler.h b/src/trap-handler/trap-handler.h
index e6dd9bdca463c456af0b4fa75972e8facbc11cee..27830eab6c71e3d01443d397bbd9d91b99bcb40f 100644
--- a/src/trap-handler/trap-handler.h
+++ b/src/trap-handler/trap-handler.h
@@ -5,10 +5,29 @@
#ifndef V8_TRAP_HANDLER_H_
#define V8_TRAP_HANDLER_H_
+#include <signal.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include "src/base/build_config.h"
+#include "src/flags.h"
+#include "src/globals.h"
+
+#if V8_OS_LINUX
+#include <ucontext.h>
+#endif
+
namespace v8 {
namespace internal {
namespace trap_handler {
+// TODO(eholk): Support trap handlers on other platforms.
+#if V8_TARGET_ARCH_X64 && V8_OS_LINUX
+#define V8_TRAP_HANDLER_SUPPORTED 1
+#else
+#define V8_TRAP_HANDLER_SUPPORTED 0
+#endif
+
struct ProtectedInstructionData {
// The offset of this instruction from the start of its code object.
intptr_t instr_offset;
@@ -19,6 +38,56 @@ struct ProtectedInstructionData {
intptr_t landing_offset;
};
+/// Adjusts the base code pointer.
+void UpdateHandlerDataCodePointer(int index, void* base);
+
+/// Adds the handler data to the place where the signal handler will find it.
+///
+/// This returns a number that can be used to identify the handler data to
+/// UpdateHandlerDataCodePointer and ReleaseHandlerData, or -1 on failure.
+int RegisterHandlerData(void* base, size_t size,
+ size_t num_protected_instructions,
+ ProtectedInstructionData* protected_instructions);
+
+/// Removes the data from the master list and frees any memory, if necessary.
+void ReleaseHandlerData(int index);
+
+#if V8_OS_WIN
+#define THREAD_LOCAL __declspec(thread)
+#elif V8_OS_ANDROID
+// TODO(eholk): fix this before enabling for trap handlers for Android.
+#define THREAD_LOCAL
+#else
+#define THREAD_LOCAL __thread
+#endif
+
+inline bool UseTrapHandler() {
+ return FLAG_wasm_trap_handler && V8_TRAP_HANDLER_SUPPORTED;
+}
+
+extern THREAD_LOCAL bool g_thread_in_wasm_code;
+
+inline bool IsThreadInWasm() { return g_thread_in_wasm_code; }
+
+inline void SetThreadInWasm() {
+ if (UseTrapHandler()) {
+ DCHECK(!IsThreadInWasm());
+ g_thread_in_wasm_code = true;
+ }
+}
+inline void ClearThreadInWasm() {
+ if (UseTrapHandler()) {
+ DCHECK(IsThreadInWasm());
+ g_thread_in_wasm_code = false;
+ }
+}
+
+bool RegisterDefaultSignalHandler();
+
+#if V8_OS_LINUX
+bool TryHandleSignal(int signum, siginfo_t* info, ucontext_t* context);
+#endif // V8_OS_LINUX
+
} // namespace trap_handler
} // namespace internal
} // namespace v8
« no previous file with comments | « src/trap-handler/handler-shared.cc ('k') | src/trap-handler/trap-handler-internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698