| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <signal.h> | 5 #include <signal.h> |
| 6 #include <string.h> | 6 #include <string.h> |
| 7 #include <sys/types.h> | 7 #include <sys/types.h> |
| 8 #include <syscall.h> | 8 #include <syscall.h> |
| 9 #include <unistd.h> | 9 #include <unistd.h> |
| 10 | 10 |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 | 12 |
| 13 // This whole file is only useful on 64-bit architectures. | 13 // This whole file is only useful on 64-bit architectures. |
| 14 #if defined(ARCH_CPU_64_BITS) | 14 #if defined(ARCH_CPU_64_BITS) |
| 15 | 15 |
| 16 namespace content { |
| 17 |
| 16 namespace { | 18 namespace { |
| 17 | 19 |
| 18 // Signal handler for SIGILL; see WorkaroundFlashLAHF(). | 20 // Signal handler for SIGILL; see WorkaroundFlashLAHF(). |
| 19 void SignalHandler(int signum, siginfo_t* info, void* void_context) { | 21 void SignalHandler(int signum, siginfo_t* info, void* void_context) { |
| 20 const char kLAHFInstruction = 0x9f; | 22 const char kLAHFInstruction = 0x9f; |
| 21 ucontext_t* context = static_cast<ucontext_t*>(void_context); | 23 ucontext_t* context = static_cast<ucontext_t*>(void_context); |
| 22 greg_t* regs = context->uc_mcontext.gregs; | 24 greg_t* regs = context->uc_mcontext.gregs; |
| 23 char instruction = *reinterpret_cast<char*>(regs[REG_RIP]); | 25 char instruction = *reinterpret_cast<char*>(regs[REG_RIP]); |
| 24 | 26 |
| 25 // Check whether this is the kind of SIGILL we care about. | 27 // Check whether this is the kind of SIGILL we care about. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 // particular circumstance, emulating the instruction, and resuming. | 62 // particular circumstance, emulating the instruction, and resuming. |
| 61 // This function registers the signal handler. | 63 // This function registers the signal handler. |
| 62 void WorkaroundFlashLAHF() { | 64 void WorkaroundFlashLAHF() { |
| 63 struct sigaction action = { { NULL } }; | 65 struct sigaction action = { { NULL } }; |
| 64 action.sa_flags = SA_SIGINFO; | 66 action.sa_flags = SA_SIGINFO; |
| 65 action.sa_sigaction = &SignalHandler; | 67 action.sa_sigaction = &SignalHandler; |
| 66 | 68 |
| 67 sigaction(SIGILL, &action, NULL); | 69 sigaction(SIGILL, &action, NULL); |
| 68 } | 70 } |
| 69 | 71 |
| 72 } // namespace content |
| 73 |
| 70 #endif // defined(ARCH_CPU_64_BITS) | 74 #endif // defined(ARCH_CPU_64_BITS) |
| OLD | NEW |