]> CyberLeo.Net >> Repos - CDN/portage-cdn.git/blob - www-plugins/adobe-flash/files/flashplugin-lahf-fix.c
www-plugins/adobe-flash: import 11.0.1.98-b2-20110808
[CDN/portage-cdn.git] / www-plugins / adobe-flash / files / flashplugin-lahf-fix.c
1 /* Simple work-around for running the 64-bit Adobe Flash plug-in version 10
2    on Athlon64 processors without support for the lahf instruction.
3
4 Compile with:
5 cc -fPIC -shared -nostdlib -lc -oflashplugin-lahf-fix.so flashplugin-lahf-fix.c
6 Then place the .so file in the plug-in directory (e.g. $HOME/.mozilla/plugins)
7 or use LD_PRELOAD to force Firefox to load the library.
8
9    - Maks Verver <maksverver@geocities.com> July 2009 */
10
11 #define _GNU_SOURCE
12 #include <stdlib.h>
13 #include <signal.h>
14 #include <ucontext.h>
15
16 static void sig_handler(int signal, siginfo_t *info, void *context) {
17         if (signal != SIGILL) return;
18         if (*(char*)info->si_addr != (char)0x9f) abort();
19         greg_t *regs = ((ucontext_t*)context)->uc_mcontext.gregs;
20         ((char*)&regs[REG_RAX])[1] = ((char*)&regs[REG_EFL])[0];
21         regs[REG_RIP]++;
22 }
23
24 static struct sigaction old_sa, new_sa = {
25         .sa_flags     = SA_SIGINFO,
26         .sa_sigaction = &sig_handler };
27
28 int _init() { sigaction(SIGILL, &new_sa, &old_sa); return 0; }
29 int _fini() { sigaction(SIGILL, &old_sa, &new_sa); return 0; }