Here is a patch that makes mysql run on my 486 without disabling use of
MMX, and such on other systems.

It isn't great yet, since it should really have some ifdef's for linux
only since it requires the linux specific /proc/cpuinfo, which of course
implies it requires /proc to be mounted.  On the other hand it is a much
safer (and thread safe too) way to check for cpuid presence before using
it.  This make php and proftpd run fine with mysql enabled on my 486.
The original way of handling cpuid missing is not thread safe, and since
mysql is supposed to be thread safe it just isn't a valid solution.  I
am not sure how one would do signal handling safely with threads.  If I
can figure that out, then that would probably be better than using
/proc/cpuinfo but at least there is potential for a solution.

Of course I imagine the same code that I am patching is used on bsd and
various other systems too, which I would have no clude how to fix.  But
at least with a little more work this could becaome a way to at least
maintain support for 486's on linux while still allowing the use of
newer instruction sets on most machines.

Some error checking on the file open and such might also be nice.  I may
see if I can clean it up a bit tomorrow.

--- mysql.ori/extra/yassl/taocrypt/src/misc.cpp 2007-02-20 12:49:38.000000000 
-0500
+++ mysql/extra/yassl/taocrypt/src/misc.cpp     2007-04-04 22:43:51.000000000 
-0400
@@ -21,7 +21,8 @@
 
 #include "runtime.hpp"
 #include "misc.hpp"
-
+#include <stdio.h>
+#include <string.h>
 
 #ifdef __GNUC__
     #include <signal.h>
@@ -174,6 +175,7 @@
     }
 #endif
 
+static bool have_cpu_id = false;
 
 bool HaveCpuId()
 {
@@ -192,27 +194,30 @@
     }
     return true;
 #else
-    typedef void (*SigHandler)(int);
-
-    SigHandler oldHandler = signal(SIGILL, SigIllHandler);
-    if (oldHandler == SIG_ERR)
-        return false;
+    // Cache value to avoid doing this crap each call
+    if(have_cpu_id) return true;
 
-    bool result = true;
-    if (setjmp(s_env))
-        result = false;
-    else 
-        __asm__ __volatile
-        (
-            // save ebx in case -fPIC is being used
-            "push %%ebx; mov $0, %%eax; cpuid; pop %%ebx"
-            : 
-            :
-            : "%eax", "%ecx", "%edx" 
-        );
-
-    signal(SIGILL, oldHandler);
-    return result;
+    FILE *input;
+    char *line = NULL;
+    size_t linelength;
+
+    input = fopen("/proc/cpuinfo","r");
+    while(getline(&line, &linelength, input) > -1) {
+       if(0 == strncmp(line,"cpuid level",11)) {
+           char *tmp = line;
+           tmp = strstr(tmp,":");
+           tmp++;
+           tmp++;
+           // cpuid level -1 means not supported.
+           if(*tmp == '-') {
+               have_cpu_id = false;
+           } else {
+               have_cpu_id = true;
+           }
+           return have_cpu_id;
+       }
+    }
+    return have_cpu_id;
 #endif
 }
 

--
Len Sorensen


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to