This source file includes following definitions.
- SignalHandler
- WorkaroundFlashLAHF
#include <signal.h>
#include <string.h>
#include <sys/types.h>
#include <syscall.h>
#include <unistd.h>
#include "build/build_config.h"
#if defined(ARCH_CPU_64_BITS)
namespace content {
namespace {
void SignalHandler(int signum, siginfo_t* info, void* void_context) {
const char kLAHFInstruction = 0x9f;
ucontext_t* context = static_cast<ucontext_t*>(void_context);
greg_t* regs = context->uc_mcontext.gregs;
char instruction = *reinterpret_cast<char*>(regs[REG_RIP]);
if (signum != SIGILL || instruction != kLAHFInstruction) {
struct sigaction sa = { { NULL } };
sigemptyset(&sa.sa_mask);
sa.sa_handler = SIG_DFL;
sigaction(signum, &sa, NULL);
sigset_t block_set;
sigemptyset(&block_set);
sigaddset(&block_set, signum);
sigprocmask(SIG_BLOCK, &block_set, NULL);
syscall(SYS_tkill, syscall(SYS_gettid), signum);
return;
}
reinterpret_cast<char*>(®s[REG_RAX])[1] =
reinterpret_cast<char*>(®s[REG_EFL])[0];
++regs[REG_RIP];
}
}
void WorkaroundFlashLAHF() {
struct sigaction action = { { NULL } };
action.sa_flags = SA_SIGINFO;
action.sa_sigaction = &SignalHandler;
sigaction(SIGILL, &action, NULL);
}
}
#endif