Improved workaround for the annoying glibc global register mangling bug
authorblueswir1 <blueswir1@c046a42c-6fe2-441c-8c8c-71466251a162>
Sat, 17 May 2008 07:38:10 +0000 (07:38 +0000)
committerblueswir1 <blueswir1@c046a42c-6fe2-441c-8c8c-71466251a162>
Sat, 17 May 2008 07:38:10 +0000 (07:38 +0000)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4465 c046a42c-6fe2-441c-8c8c-71466251a162

cpu-exec.c

index 5fd9cad..49b4995 100644 (file)
 #include <sys/ucontext.h>
 #endif
 
+#if defined(__sparc__) && !defined(HOST_SOLARIS)
+// Work around ugly bugs in glibc that mangle global register contents
+#undef env
+#define env cpu_single_env
+#endif
+
 int tb_invalidated_flag;
 static unsigned long next_tb;
 
 //#define DEBUG_EXEC
 //#define DEBUG_SIGNAL
 
-#define SAVE_GLOBALS()
-#define RESTORE_GLOBALS()
-
-#if defined(__sparc__) && !defined(HOST_SOLARIS)
-#include <features.h>
-#if defined(__GLIBC__) && ((__GLIBC__ < 2) || \
-                           ((__GLIBC__ == 2) && (__GLIBC_MINOR__ <= 90)))
-// Work around ugly bugs in glibc that mangle global register contents
-
-static volatile void *saved_env;
-#undef SAVE_GLOBALS
-#define SAVE_GLOBALS() do {                                     \
-        saved_env = env;                                        \
-    } while(0)
-
-#undef RESTORE_GLOBALS
-#define RESTORE_GLOBALS() do {                                  \
-        env = (void *)saved_env;                                \
-    } while(0)
-
-static int sparc_setjmp(jmp_buf buf)
-{
-    int ret;
-
-    SAVE_GLOBALS();
-    ret = setjmp(buf);
-    RESTORE_GLOBALS();
-    return ret;
-}
-#undef setjmp
-#define setjmp(jmp_buf) sparc_setjmp(jmp_buf)
-
-static void sparc_longjmp(jmp_buf buf, int val)
-{
-    SAVE_GLOBALS();
-    longjmp(buf, val);
-}
-#define longjmp(jmp_buf, val) sparc_longjmp(jmp_buf, val)
-#endif
-#endif
-
 void cpu_loop_exit(void)
 {
     /* NOTE: the register at this point must be saved by hand because
@@ -176,9 +141,7 @@ static TranslationBlock *tb_find_slow(target_ulong pc,
     tb->tc_ptr = tc_ptr;
     tb->cs_base = cs_base;
     tb->flags = flags;
-    SAVE_GLOBALS();
     cpu_gen_code(env, tb, &code_gen_size);
-    RESTORE_GLOBALS();
     code_gen_ptr = (void *)(((unsigned long)code_gen_ptr + code_gen_size + CODE_GEN_ALIGN - 1) & ~(CODE_GEN_ALIGN - 1));
 
     /* check next page if needed */
@@ -302,7 +265,6 @@ int cpu_exec(CPUState *env1)
 #define SAVE_HOST_REGS 1
 #include "hostregs_helper.h"
     env = env1;
-    SAVE_GLOBALS();
 
     env_to_regs();
 #if defined(TARGET_I386)
@@ -414,7 +376,6 @@ int cpu_exec(CPUState *env1)
 
             next_tb = 0; /* force lookup of first TB */
             for(;;) {
-                SAVE_GLOBALS();
                 interrupt_request = env->interrupt_request;
                 if (__builtin_expect(interrupt_request, 0)
 #if defined(TARGET_I386)
@@ -633,7 +594,6 @@ int cpu_exec(CPUState *env1)
                             lookup_symbol(tb->pc));
                 }
 #endif
-                RESTORE_GLOBALS();
                 /* see if we can patch the calling TB. When the TB
                    spans two pages, we cannot safely do a direct
                    jump. */
@@ -651,6 +611,11 @@ int cpu_exec(CPUState *env1)
                 tc_ptr = tb->tc_ptr;
                 env->current_tb = tb;
                 /* execute the generated code */
+#if defined(__sparc__) && !defined(HOST_SOLARIS)
+#undef env
+                env = cpu_single_env;
+#define env cpu_single_env
+#endif
                 next_tb = tcg_qemu_tb_exec(tc_ptr);
                 env->current_tb = NULL;
                 /* reset soft MMU for next block (it can currently
@@ -701,7 +666,6 @@ int cpu_exec(CPUState *env1)
 #endif
 
     /* restore global registers */
-    RESTORE_GLOBALS();
 #include "hostregs_helper.h"
 
     /* fail safe : never use cpu_single_env outside cpu_exec() */