Browse Source

[coop] Protect copy_stack_data from GCC optimizations. (#3157)

[coop] Protect copy_stack_data from GCC optimizations.

GCC 5.3.1 (Debian sid/amd64) "optimizied" the previous incarnation of
`void *stackdata_end = return_stack_ptr ()` to
`void *stackdata_end = 0`.
Aleksey Kliger (λgeek) 9 years ago
parent
commit
fdfa5d8461
1 changed files with 9 additions and 5 deletions
  1. 9 5
      mono/utils/mono-threads-coop.c

+ 9 - 5
mono/utils/mono-threads-coop.c

@@ -145,11 +145,14 @@ mono_threads_state_poll_with_info (MonoThreadInfo *info)
 	}
 }
 
-static void *
-return_stack_ptr ()
+static volatile gpointer* dummy_global;
+
+static MONO_NEVER_INLINE
+void*
+return_stack_ptr (gpointer *i)
 {
-	gpointer i;
-	return &i;
+	dummy_global = i;
+	return i;
 }
 
 static void
@@ -157,7 +160,8 @@ copy_stack_data (MonoThreadInfo *info, gpointer *stackdata_begin)
 {
 	MonoThreadUnwindState *state;
 	int stackdata_size;
-	void* stackdata_end = return_stack_ptr ();
+	gpointer dummy;
+	void* stackdata_end = return_stack_ptr (&dummy);
 
 	SAVE_REGS_ON_STACK;