[Gc] [PATCH] OS X MACHINE_THREAD_STATE patch for i386

Allan Hsu allan at counterpop.net
Wed Oct 25 20:54:45 PDT 2006


Attached is a slightly cleaner version of Renaud Blanch's patch for
OS X that introduces a new #define called GC_MACH_THREAD_STATE_FLAVOR in
gc_priv.h and replaces all uses of MACHINE_THREAD_STATE with
GC_MACH_THREAD_STATE_FLAVOR. The patch is against libgc6.8. I haven't
tested all uses that are changed (most notably the mprotect exception
handling), but it is almost gauranteed that the current
MACHINE_THREAD_STATE usage in libgc6.8 is broken under the new 10.4u SDK
headers.

Also, what is the state of the darwin_stop_world.c patch I submitted a
few weeks ago? I haven't heard back on whether or not is was accepted
into the tree.

-Allan
-- 
Allan Hsu <allan at counterpop dot net>
1E64 E20F 34D9 CBA7 1300 1457 AC37 CBBB 0E92 C779
-------------- next part --------------
diff -ur gc6.8/darwin_stop_world.c gc6.8-fixed/darwin_stop_world.c
--- gc6.8/darwin_stop_world.c	2006-06-28 15:38:42.000000000 -0700
+++ gc6.8-fixed/darwin_stop_world.c	2006-10-25 20:42:28.000000000 -0700
@@ -77,12 +77,14 @@
   ptr_t lo, hi;
 #if defined(POWERPC)
   ppc_thread_state_t state;
+  mach_msg_type_number_t thread_state_count = PPC_THREAD_STATE_COUNT;
 #elif defined(I386)
   i386_thread_state_t state;
+  mach_msg_type_number_t thread_state_count = i386_THREAD_STATE_COUNT;
 #else
 # error FIXME for non-x86 || ppc architectures
-#endif
   mach_msg_type_number_t thread_state_count = MACHINE_THREAD_STATE_COUNT;
+#endif
   
   me = pthread_self();
   if (!GC_thr_initialized) GC_thr_init();
@@ -96,7 +98,7 @@
 	/* Get the thread state (registers, etc) */
 	r = thread_get_state(
 			     p->stop_info.mach_thread,
-			     MACHINE_THREAD_STATE,
+			     GC_MACH_THREAD_STATE_FLAVOR,
 			     (natural_t*)&state,
 			     &thread_state_count);
 	if(r != KERN_SUCCESS) ABORT("thread_get_state failed");
@@ -195,7 +197,7 @@
 	ppc_thread_state64_t info;
 #      endif
 	mach_msg_type_number_t outCount = THREAD_STATE_MAX;
-	r = thread_get_state(thread, MACHINE_THREAD_STATE,
+	r = thread_get_state(thread, GC_MACH_THREAD_STATE_FLAVOR,
 			     (natural_t *)&info, &outCount);
 	if(r != KERN_SUCCESS) ABORT("task_get_state failed");
 
@@ -238,7 +240,7 @@
 	WARN("This is completely untested and likely will not work\n", 0);
 	i386_thread_state_t info;
 	mach_msg_type_number_t outCount = THREAD_STATE_MAX;
-	r = thread_get_state(thread, MACHINE_THREAD_STATE,
+	r = thread_get_state(thread, GC_MACH_THREAD_STATE_FLAVOR,
 			     (natural_t *)&info, &outCount);
 	if(r != KERN_SUCCESS) ABORT("task_get_state failed");
 
diff -ur gc6.8/include/private/gc_priv.h gc6.8-fixed/include/private/gc_priv.h
--- gc6.8/include/private/gc_priv.h	2006-02-10 11:38:40.000000000 -0800
+++ gc6.8-fixed/include/private/gc_priv.h	2006-10-25 20:42:28.000000000 -0700
@@ -365,6 +365,16 @@
 #   define BZERO(x,n) bzero((char *)(x),(int)(n))
 # endif
 
+#if defined(DARWIN)
+#	if defined(POWERPC)
+#		define GC_MACH_THREAD_STATE_FLAVOR PPC_THREAD_STATE
+#	elif defined(I386)
+#		define GC_MACH_THREAD_STATE_FLAVOR i386_THREAD_STATE
+#	else
+#		define GC_MACH_THREAD_STATE_FLAVOR MACHINE_THREAD_STATE
+#	endif
+#endif
+
 /* Delay any interrupts or signals that may abort this thread.  Data	*/
 /* structures are in a consistent state outside this pair of calls.	*/
 /* ANSI C allows both to be empty (though the standard isn't very	*/
diff -ur gc6.8/os_dep.c gc6.8-fixed/os_dep.c
--- gc6.8/os_dep.c	2006-04-21 16:26:47.000000000 -0700
+++ gc6.8-fixed/os_dep.c	2006-10-25 20:42:28.000000000 -0700
@@ -3690,7 +3690,7 @@
         mask,
         GC_ports.exception,
         EXCEPTION_DEFAULT,
-        MACHINE_THREAD_STATE
+        GC_MACH_THREAD_STATE_FLAVOR
     );
     if(r != KERN_SUCCESS) ABORT("task_set_exception_ports failed");
 


More information about the Gc mailing list