]> granicus.if.org Git - gc/commitdiff
Fix stop_info.stack_ptr assignment in GC_suspend_all for OpenBSD
authorIvan Maidanski <ivmai@mail.ru>
Fri, 20 Jul 2012 20:36:34 +0000 (00:36 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 20 Jul 2012 20:36:34 +0000 (00:36 +0400)
* os_dep.c (GC_get_stack_base): Abort if pthread_stackseg_np fails
(if GC_OPENBSD_THREADS).
* pthread_stop_world.c (GC_suspend_all): Get correct stack_ptr by
calling pthread_stackseg_np (subtracting ss_size from ss_sp) instead
of retrieving it from OpenBSD pthread implementation-dependent context
(if GC_OPENBSD_THREADS); remove test of stack_ptr and comment.

os_dep.c
pthread_stop_world.c

index 30452e350ed0c51c0ed483379294511fbdada3c8..84ea1ca6013e3fca5e76449f9d18a9177e5f4e0e 100644 (file)
--- a/os_dep.c
+++ b/os_dep.c
@@ -1321,7 +1321,8 @@ GC_INNER word GC_page_size = 0;
   GC_API int GC_CALL GC_get_stack_base(struct GC_stack_base *sb)
   {
     stack_t stack;
-    pthread_stackseg_np(pthread_self(), &stack);
+    if (pthread_stackseg_np(pthread_self(), &stack))
+      ABORT("pthread_stackseg_np(self) failed");
     sb->mem_base = stack.ss_sp;
     return GC_SUCCESS;
   }
index 52573dbdac129d7d1fa8f6a20b3dacf80e6a1007..11f7573c001913f083a9ae4dc02cabe829beffd5 100644 (file)
@@ -475,17 +475,14 @@ STATIC int GC_suspend_all(void)
 #           endif
 
 #           ifdef GC_OPENBSD_THREADS
-              if (pthread_suspend_np(p -> id) != 0)
-                ABORT("pthread_suspend_np failed");
-              /* FIXME: This will only work for userland pthreads.      */
-              /* It will fail badly on rthreads.  Perhaps we should     */
-              /* consider pthread_sp_np() that returns the stack        */
-              /* pointer for a suspended thread and implement in both   */
-              /* pthreads and rthreads.                                 */
-              p -> stop_info.stack_ptr =
-                        *(ptr_t *)((char *)p -> id + UTHREAD_SP_OFFSET);
-              if (p -> stop_info.stack_ptr == NULL)
-                ABORT("NULL pointer at pthread_context UTHREAD_SP_OFFSET");
+              {
+                stack_t stack;
+                if (pthread_suspend_np(p -> id) != 0)
+                  ABORT("pthread_suspend_np failed");
+                if (pthread_stackseg_np(p->id, &stack))
+                  ABORT("pthread_stackseg_np failed");
+                p -> stop_info.stack_ptr = (ptr_t)stack.ss_sp - stack.ss_size;
+              }
 #           else
 #             ifndef PLATFORM_ANDROID
                 result = pthread_kill(p -> id, GC_sig_suspend);