summaryrefslogtreecommitdiffstats
path: root/o3d
diff options
context:
space:
mode:
authorfbarchard@chromium.org <fbarchard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-21 20:25:23 +0000
committerfbarchard@chromium.org <fbarchard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-21 20:25:23 +0000
commit1f1a34a5bb59ae0050a90af84435f8e8d6542ef0 (patch)
tree98064232a72bf18c4134d3394d60eadcbed82136 /o3d
parentfb642f1b5d638c367c6a7c2bc7d060c17ddc1f1d (diff)
downloadchromium_src-1f1a34a5bb59ae0050a90af84435f8e8d6542ef0.zip
chromium_src-1f1a34a5bb59ae0050a90af84435f8e8d6542ef0.tar.gz
chromium_src-1f1a34a5bb59ae0050a90af84435f8e8d6542ef0.tar.bz2
Detect SSE2 and return if not present to avoid a crash.
BUG=none TEST=run o3d on Pentium3. Voice and Settings page should work. Review URL: http://codereview.chromium.org/6708057 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78916 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r--o3d/plugin/cross/main.cc41
1 files changed, 41 insertions, 0 deletions
diff --git a/o3d/plugin/cross/main.cc b/o3d/plugin/cross/main.cc
index e17ba64..c6a2b43 100644
--- a/o3d/plugin/cross/main.cc
+++ b/o3d/plugin/cross/main.cc
@@ -40,6 +40,7 @@
#include "plugin/cross/whitelist.h"
#ifdef OS_WIN
#include "breakpad/win/bluescreen_detector.h"
+#include <intrin.h>
#endif
using glue::_o3d::PluginObject;
@@ -300,12 +301,52 @@ namespace o3d {
extern "C" {
#endif
+// Detect CPU has SSE2
+#if defined(__pic__) && defined(__i386__)
+void __cpuid(int cpu_info[4], int info_type) {
+ __asm__ volatile (
+ "mov %%ebx, %%edi\n"
+ "cpuid\n"
+ "xchg %%edi, %%ebx\n"
+ : "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3])
+ : "a"(info_type)
+ );
+}
+#elif defined(__i386__) || defined(__x86_64__)
+void __cpuid(int cpu_info[4], int info_type) {
+ __asm__ volatile (
+ "cpuid\n"
+ : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3])
+ : "a"(info_type)
+ );
+}
+#endif
+
+#if defined(__x86_64__) || defined(_M_X64) || \
+ defined(__i386__) || defined(_M_IX86)
+bool CpuHasSSE2() {
+ int cpu_info[4];
+ __cpuid(cpu_info, 1);
+ return (cpu_info[3] & 0x04000000) != 0;
+}
+#endif
+
NPError EXPORT_SYMBOL OSCALL NP_Initialize(NPNetscapeFuncs *browserFuncs
#ifdef OS_LINUX
,
NPPluginFuncs *pluginFuncs
#endif
) {
+
+// On x86, detect lack of SSE2 and quit before a crash occurs.
+// TODO(fbarchard): Remove this when -msse2 is removed or SSE2 is required.
+#if defined(__x86_64__) || defined(_M_X64) || \
+ defined(__i386__) || defined(_M_IX86)
+ if (!CpuHasSSE2()) {
+ return NPERR_MODULE_LOAD_FAILED_ERROR;
+ }
+#endif
+
HANDLE_CRASHES;
NPError err = InitializeNPNApi(browserFuncs);
if (err != NPERR_NO_ERROR) {