| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef RUNTIME_VM_SIGNAL_HANDLER_H_ | 5 #ifndef RUNTIME_VM_SIGNAL_HANDLER_H_ |
| 6 #define RUNTIME_VM_SIGNAL_HANDLER_H_ | 6 #define RUNTIME_VM_SIGNAL_HANDLER_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
| 10 | 10 |
| 11 #if defined(TARGET_OS_LINUX) | 11 #if defined(TARGET_OS_LINUX) |
| 12 #include <signal.h> // NOLINT | 12 #include <signal.h> // NOLINT |
| 13 #include <ucontext.h> // NOLINT | 13 #include <ucontext.h> // NOLINT |
| 14 #elif defined(TARGET_OS_ANDROID) | 14 #elif defined(TARGET_OS_ANDROID) |
| 15 #include <signal.h> // NOLINT | 15 #include <signal.h> // NOLINT |
| 16 #if !defined(__BIONIC_HAVE_UCONTEXT_T) | 16 #if !defined(__BIONIC_HAVE_UCONTEXT_T) |
| 17 #include <asm/sigcontext.h> // NOLINT | 17 #include <asm/sigcontext.h> // NOLINT |
| 18 // If ucontext_t is not defined on Android, define it here. | 18 // If ucontext_t is not defined on Android, define it here. |
| 19 typedef struct sigcontext mcontext_t; | 19 typedef struct sigcontext mcontext_t; |
| 20 typedef struct ucontext { | 20 typedef struct ucontext { |
| 21 uint32_t uc_flags; | 21 uint32_t uc_flags; |
| 22 struct ucontext *uc_link; | 22 struct ucontext* uc_link; |
| 23 stack_t uc_stack; | 23 stack_t uc_stack; |
| 24 struct sigcontext uc_mcontext; | 24 struct sigcontext uc_mcontext; |
| 25 uint32_t uc_sigmask; | 25 uint32_t uc_sigmask; |
| 26 } ucontext_t; | 26 } ucontext_t; |
| 27 #endif // !defined(__BIONIC_HAVE_UCONTEXT_T) | 27 #endif // !defined(__BIONIC_HAVE_UCONTEXT_T) |
| 28 #elif defined(TARGET_OS_MACOS) | 28 #elif defined(TARGET_OS_MACOS) |
| 29 #include <signal.h> // NOLINT | 29 #include <signal.h> // NOLINT |
| 30 #include <sys/ucontext.h> // NOLINT | 30 #include <sys/ucontext.h> // NOLINT |
| 31 #elif defined(TARGET_OS_WINDOWS) | 31 #elif defined(TARGET_OS_WINDOWS) |
| 32 // Stub out for windows. | 32 // Stub out for windows. |
| 33 struct siginfo_t; | 33 struct siginfo_t; |
| 34 struct mcontext_t; | 34 struct mcontext_t; |
| 35 struct sigset_t { | 35 struct sigset_t {}; |
| 36 }; | |
| 37 #elif defined(TARGET_OS_FUCHSIA) | 36 #elif defined(TARGET_OS_FUCHSIA) |
| 38 #include <signal.h> // NOLINT | 37 #include <signal.h> // NOLINT |
| 39 #include <ucontext.h> // NOLINT | 38 #include <ucontext.h> // NOLINT |
| 40 #endif | 39 #endif |
| 41 | 40 |
| 42 | 41 |
| 43 // Old linux kernels on ARM might require a trampoline to | 42 // Old linux kernels on ARM might require a trampoline to |
| 44 // work around incorrect Thumb -> ARM transitions. See SignalHandlerTrampoline | 43 // work around incorrect Thumb -> ARM transitions. See SignalHandlerTrampoline |
| 45 // below for more details. | 44 // below for more details. |
| 46 #if defined(HOST_ARCH_ARM) && \ | 45 #if defined(HOST_ARCH_ARM) && \ |
| 47 (defined(TARGET_OS_LINUX) || defined(TARGET_OS_ANDROID)) && \ | 46 (defined(TARGET_OS_LINUX) || defined(TARGET_OS_ANDROID)) && \ |
| 48 !defined(__thumb__) | 47 !defined(__thumb__) |
| 49 #define USE_SIGNAL_HANDLER_TRAMPOLINE | 48 #define USE_SIGNAL_HANDLER_TRAMPOLINE |
| 50 #endif | 49 #endif |
| 51 | 50 |
| 52 | 51 |
| 53 namespace dart { | 52 namespace dart { |
| 54 | 53 |
| 55 typedef void (*SignalAction)(int signal, siginfo_t* info, | 54 typedef void (*SignalAction)(int signal, siginfo_t* info, void* context); |
| 56 void* context); | |
| 57 | 55 |
| 58 class SignalHandler : public AllStatic { | 56 class SignalHandler : public AllStatic { |
| 59 public: | 57 public: |
| 60 template<SignalAction action> | 58 template <SignalAction action> |
| 61 static void Install() { | 59 static void Install() { |
| 62 #if defined(USE_SIGNAL_HANDLER_TRAMPOLINE) | 60 #if defined(USE_SIGNAL_HANDLER_TRAMPOLINE) |
| 63 InstallImpl(SignalHandlerTrampoline<action>); | 61 InstallImpl(SignalHandlerTrampoline<action>); |
| 64 #else | 62 #else |
| 65 InstallImpl(action); | 63 InstallImpl(action); |
| 66 #endif // defined(USE_SIGNAL_HANDLER_TRAMPOLINE) | 64 #endif // defined(USE_SIGNAL_HANDLER_TRAMPOLINE) |
| 67 } | 65 } |
| 68 static void Remove(); | 66 static void Remove(); |
| 69 static uintptr_t GetProgramCounter(const mcontext_t& mcontext); | 67 static uintptr_t GetProgramCounter(const mcontext_t& mcontext); |
| 70 static uintptr_t GetFramePointer(const mcontext_t& mcontext); | 68 static uintptr_t GetFramePointer(const mcontext_t& mcontext); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 101 asm volatile("nop; nop; nop; nop" : : : "memory"); | 99 asm volatile("nop; nop; nop; nop" : : : "memory"); |
| 102 | 100 |
| 103 // Tail-call into the actual signal handler. | 101 // Tail-call into the actual signal handler. |
| 104 // Note: this code is split into a separate inline assembly block because | 102 // Note: this code is split into a separate inline assembly block because |
| 105 // any code that compiler generates to satisfy register constraints must | 103 // any code that compiler generates to satisfy register constraints must |
| 106 // be generated after four NOPs. | 104 // be generated after four NOPs. |
| 107 register int arg0 asm("r0") = signal; | 105 register int arg0 asm("r0") = signal; |
| 108 register siginfo_t* arg1 asm("r1") = info; | 106 register siginfo_t* arg1 asm("r1") = info; |
| 109 register void* arg2 asm("r2") = context_; | 107 register void* arg2 asm("r2") = context_; |
| 110 asm volatile("bx %3" | 108 asm volatile("bx %3" |
| 111 : | 109 : |
| 112 : "r"(arg0), "r"(arg1), "r"(arg2), | 110 : "r"(arg0), "r"(arg1), "r"(arg2), "r"(action) |
| 113 "r"(action) | 111 : "memory"); |
| 114 : "memory"); | |
| 115 } | 112 } |
| 116 #endif // defined(USE_SIGNAL_HANDLER_TRAMPOLINE) | 113 #endif // defined(USE_SIGNAL_HANDLER_TRAMPOLINE) |
| 117 }; | 114 }; |
| 118 | 115 |
| 119 | 116 |
| 120 #undef USE_SIGNAL_HANDLER_TRAMPOLINE | 117 #undef USE_SIGNAL_HANDLER_TRAMPOLINE |
| 121 | 118 |
| 122 | 119 |
| 123 } // namespace dart | 120 } // namespace dart |
| 124 | 121 |
| 125 #endif // RUNTIME_VM_SIGNAL_HANDLER_H_ | 122 #endif // RUNTIME_VM_SIGNAL_HANDLER_H_ |
| OLD | NEW |