From 7ff92dc60b7576c40015add3576d3a7020bc6fbb Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Sat, 21 Jul 2012 00:36:34 +0400 Subject: [PATCH] Fix stop_info.stack_ptr assignment in GC_suspend_all for OpenBSD * 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 | 3 ++- pthread_stop_world.c | 19 ++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/os_dep.c b/os_dep.c index 30452e35..84ea1ca6 100644 --- 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; } diff --git a/pthread_stop_world.c b/pthread_stop_world.c index 52573dbd..11f7573c 100644 --- a/pthread_stop_world.c +++ b/pthread_stop_world.c @@ -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); -- 2.40.0