gst/gstcpu.c: Add a temporary

Original commit message from CVS:
* gst/gstcpu.c: (illegal_instruction_handler),
(cpu_fault_check_enable), (cpu_fault_check_try),
(cpu_fault_check_disable), (gst_cpuid_i386), (test_cpuid),
(gst_cpuid_test), (_gst_cpu_initialize_i386): Add a temporary
SIGILL handler to check for the existence of cpuid before
using it.  (fixes #166696)
This commit is contained in:
David Schleef 2005-03-26 00:13:34 +00:00
parent 41b7a94969
commit c1ce267dd1
2 changed files with 97 additions and 16 deletions

View file

@ -1,3 +1,12 @@
2005-03-25 David Schleef <ds@schleef.org>
* gst/gstcpu.c: (illegal_instruction_handler),
(cpu_fault_check_enable), (cpu_fault_check_try),
(cpu_fault_check_disable), (gst_cpuid_i386), (test_cpuid),
(gst_cpuid_test), (_gst_cpu_initialize_i386): Add a temporary
SIGILL handler to check for the existence of cpuid before
using it. (fixes #166696)
2005-03-25 Ronald S. Bultje <rbultje@ronald.bitfreak.net> 2005-03-25 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
* gst/elements/gsttypefindelement.c: * gst/elements/gsttypefindelement.c:

View file

@ -27,6 +27,8 @@
#include "gstcpu.h" #include "gstcpu.h"
#include "gstinfo.h" #include "gstinfo.h"
#include <setjmp.h>
#include <signal.h>
static guint32 _gst_cpu_flags = 0; static guint32 _gst_cpu_flags = 0;
@ -63,32 +65,102 @@ _gst_cpu_initialize_none (gulong * flags, GString * featurelist)
} }
#if defined(HAVE_CPU_I386) && defined(__GNUC__) #if defined(HAVE_CPU_I386) && defined(__GNUC__)
static void
gst_cpuid_i386 (int x, unsigned long *eax, unsigned long *ebx,
unsigned long *ecx, unsigned long *edx)
{
unsigned long regs[4];
/* From liboil */
static jmp_buf jump_env;
static struct sigaction action;
static struct sigaction oldaction;
static int in_try_block;
static void
illegal_instruction_handler (int num)
{
if (in_try_block) {
longjmp (jump_env, 1);
} else {
abort ();
}
}
void
cpu_fault_check_enable (void)
{
memset (&action, 0, sizeof (action));
action.sa_handler = &illegal_instruction_handler;
sigaction (SIGILL, &action, &oldaction);
in_try_block = 0;
}
int
cpu_fault_check_try (void (*func) (void *), void *priv)
{
int ret;
in_try_block = 1;
ret = setjmp (jump_env);
if (!ret) {
func (priv);
}
in_try_block = 0;
return (ret == 0);
}
void
cpu_fault_check_disable (void)
{
sigaction (SIGILL, &oldaction, NULL);
}
/* end of code from liboil */
static void
gst_cpuid_i386 (int x, unsigned int *eax, unsigned int *ebx,
unsigned int *ecx, unsigned int *edx)
{
/* *INDENT-OFF* */
asm ( asm (
/* GCC-3.2 (and possibly others) don't clobber ebx properly, /* GCC-3.2 (and possibly others) don't clobber ebx properly,
* so we save/restore it directly. */ * so we save/restore it directly. */
" movl %%ebx, %%esi\n" " cpuid\n" " movl %%eax, %0\n" " movl %%ebx, %1\n" " movl %%ecx, %2\n" " movl %%edx, %3\n" " movl %%esi, %%ebx\n":"=o" (regs[0]), "=o" (regs[1]), "=o" (regs[2]), " pushl %%ebx\n"
"=o" (regs " cpuid\n"
[3]) " mov %%ebx, %%esi\n"
: "a" (x) " popl %%ebx\n"
: "ecx", "edx", "esi"); : "=a" (*eax), "=S" (*ebx), "=c" (*ecx), "=d" (*edx)
: "0" (x));
/* *INDENT-ON* */
}
*eax = regs[0]; static void
*ebx = regs[1]; test_cpuid (void *ignore)
*ecx = regs[2]; {
*edx = regs[3]; unsigned int eax, ebx, ecx, edx;
gst_cpuid_i386 (0, &eax, &ebx, &ecx, &edx);
}
static gboolean
gst_cpuid_test (void)
{
int ret;
cpu_fault_check_enable ();
ret = cpu_fault_check_try (test_cpuid, NULL);
cpu_fault_check_disable ();
return ret;
} }
gboolean gboolean
_gst_cpu_initialize_i386 (gulong * flags, GString * featurelist) _gst_cpu_initialize_i386 (gulong * flags, GString * featurelist)
{ {
gboolean AMD; gboolean AMD;
gulong eax = 0, ebx = 0, ecx = 0, edx = 0; guint eax = 0, ebx = 0, ecx = 0, edx = 0;
if (!gst_cpuid_test ()) {
return FALSE;
}
gst_cpuid_i386 (0, &eax, &ebx, &ecx, &edx); gst_cpuid_i386 (0, &eax, &ebx, &ecx, &edx);
@ -122,7 +194,7 @@ _gst_cpu_initialize_i386 (gulong * flags, GString * featurelist)
} }
} }
} }
*flags = eax; *flags = _gst_cpu_flags;
if (_gst_cpu_flags) if (_gst_cpu_flags)
return TRUE; return TRUE;
return FALSE; return FALSE;