| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 greg_t* regs = context->uc_mcontext.gregs; | 22 greg_t* regs = context->uc_mcontext.gregs; |
| 23 char instruction = *reinterpret_cast<char*>(regs[REG_RIP]); | 23 char instruction = *reinterpret_cast<char*>(regs[REG_RIP]); |
| 24 | 24 |
| 25 // Check whether this is the kind of SIGILL we care about. | 25 // Check whether this is the kind of SIGILL we care about. |
| 26 // (info->si_addr can be NULL when we get a SIGILL via other means, | 26 // (info->si_addr can be NULL when we get a SIGILL via other means, |
| 27 // like with kill.) | 27 // like with kill.) |
| 28 if (signum != SIGILL || instruction != kLAHFInstruction) { | 28 if (signum != SIGILL || instruction != kLAHFInstruction) { |
| 29 // Not the problem we're interested in. Reraise the signal. We | 29 // Not the problem we're interested in. Reraise the signal. We |
| 30 // need to be careful to handle threads etc. properly. | 30 // need to be careful to handle threads etc. properly. |
| 31 | 31 |
| 32 struct sigaction sa; | 32 struct sigaction sa = { { NULL } }; |
| 33 sa.sa_flags = 0; | |
| 34 sigemptyset(&sa.sa_mask); | 33 sigemptyset(&sa.sa_mask); |
| 35 sa.sa_handler = SIG_DFL; | 34 sa.sa_handler = SIG_DFL; |
| 36 sigaction(signum, &sa, NULL); | 35 sigaction(signum, &sa, NULL); |
| 37 | 36 |
| 38 // block the current signal | 37 // block the current signal |
| 39 sigset_t block_set; | 38 sigset_t block_set; |
| 40 sigemptyset(&block_set); | 39 sigemptyset(&block_set); |
| 41 sigaddset(&block_set, signum); | 40 sigaddset(&block_set, signum); |
| 42 sigprocmask(SIG_BLOCK, &block_set, NULL); | 41 sigprocmask(SIG_BLOCK, &block_set, NULL); |
| 43 | 42 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 54 } | 53 } |
| 55 | 54 |
| 56 } // namespace | 55 } // namespace |
| 57 | 56 |
| 58 // 64-bit Flash sometimes uses the LAHF instruction which isn't | 57 // 64-bit Flash sometimes uses the LAHF instruction which isn't |
| 59 // available on some CPUs. We can work around it by catching SIGILL | 58 // available on some CPUs. We can work around it by catching SIGILL |
| 60 // (illegal instruction), checking if the signal was caused by this | 59 // (illegal instruction), checking if the signal was caused by this |
| 61 // particular circumstance, emulating the instruction, and resuming. | 60 // particular circumstance, emulating the instruction, and resuming. |
| 62 // This function registers the signal handler. | 61 // This function registers the signal handler. |
| 63 void WorkaroundFlashLAHF() { | 62 void WorkaroundFlashLAHF() { |
| 64 struct sigaction action; | 63 struct sigaction action = { { NULL } }; |
| 65 memset(&action, 0, sizeof(action)); | |
| 66 action.sa_flags = SA_SIGINFO; | 64 action.sa_flags = SA_SIGINFO; |
| 67 action.sa_sigaction = &SignalHandler; | 65 action.sa_sigaction = &SignalHandler; |
| 68 | 66 |
| 69 sigaction(SIGILL, &action, NULL); | 67 sigaction(SIGILL, &action, NULL); |
| 70 } | 68 } |
| 71 | 69 |
| 72 #endif // defined(ARCH_CPU_64_BITS) | 70 #endif // defined(ARCH_CPU_64_BITS) |
| OLD | NEW |