]> 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>
Sat, 21 Jul 2012 08:14:25 +0000 (12:14 +0400)
(commit '7ff92dc' from master branch)

* 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 comment.

os_dep.c
pthread_stop_world.c

index 333421d4b8a4e78205ca8421455f67fe26650be4..d9d8fdaebde107869ed024bc9ec3b773256a12ef 100644 (file)
--- a/os_dep.c
+++ b/os_dep.c
@@ -1304,7 +1304,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 811cfb5a86697721c5b347a786b31d5924e52897..20f54f97c024eba5af29a1a2a7b0b797764e145a 100644 (file)
@@ -446,15 +446,14 @@ STATIC int GC_suspend_all(void)
 #           endif
 
 #           ifdef GC_OPENBSD_THREADS
-              if (pthread_suspend_np(p -> id) != 0)
-                ABORT("pthread_suspend_np failed");
-              /* This will only work for userland pthreads.  It will    */
-              /* fail badly on rthreads.  Perhaps we should consider    */
-              /* a pthread_sp_np() function 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);
+              {
+                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, SIG_SUSPEND);