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

Side by Side Diff: chrome/plugin/plugin_main_linux.cc

Issue 517031: linux: work around LAHF bug in Flash (Closed)
Patch Set: comment Created 10 years, 11 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 unified diff | Download patch
« no previous file with comments | « chrome/plugin/plugin_main.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #define _POSIX_SOURCE
6 #include <signal.h>
7 #include <string.h>
8
9 #include "build/build_config.h"
10
11 // This whole file is only useful on 64-bit architectures.
12 #if defined(ARCH_CPU_64_BITS)
13
14 namespace {
15
16 // Signal handler for SIGILL; see WorkaroundFlashLAHF().
17 void SignalHandler(int signal, siginfo_t* info, void* void_context) {
18 const char kLAHFInstruction = 0x9f;
19 if (signal != SIGILL ||
20 *reinterpret_cast<char*>(info->si_addr) != kLAHFInstruction) {
21 raise(signal);
agl 2010/01/04 23:02:43 This may overflow the stack.
22 return; // raise() should have killed us, but just in case...
23 }
24
25 ucontext_t* context = static_cast<ucontext_t*>(void_context);
26 greg_t* regs = context->uc_mcontext.gregs;
27 // LAHF moves the low byte of the EFLAGS register to AH. Emulate that.
28 reinterpret_cast<char*>(&regs[REG_RAX])[1] =
29 reinterpret_cast<char*>(&regs[REG_EFL])[0];
30 // And advance the instruction pointer past the (one-byte) instruction.
31 ++regs[REG_RIP];
32 }
33
34 } // namespace
35
36 // 64-bit Flash sometimes uses the LAHF instruction which isn't
37 // available on some CPUs. We can work around it by catching SIGILL
38 // (illegal instruction), checking if the signal was caused by this
39 // particular circumstance, emulating the instruction, and resuming.
40 // This function registers the signal handler.
41 void WorkaroundFlashLAHF() {
42 struct sigaction action;
43 memset(&action, 0, sizeof(action));
44 action.sa_flags = SA_SIGINFO;
45 action.sa_sigaction = &SignalHandler;
46
47 sigaction(SIGILL, &action, NULL);
48 }
49
50 #endif // defined(ARCH_CPU_64_BITS)
OLDNEW
« no previous file with comments | « chrome/plugin/plugin_main.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698