Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 59 lines 2.5 kB view raw
1diff --git a/pthread_stop_world.c b/pthread_stop_world.c 2index 2b45489..0e6d8ef 100644 3--- a/pthread_stop_world.c 4+++ b/pthread_stop_world.c 5@@ -776,6 +776,8 @@ 6 /* world is stopped. Should not fail if it isn't. */ 7 GC_INNER void GC_push_all_stacks(void) 8 { 9+ size_t stack_limit; 10+ pthread_attr_t pattr; 11 GC_bool found_me = FALSE; 12 size_t nthreads = 0; 13 int i; 14@@ -868,6 +870,45 @@ 15 hi = p->altstack + p->altstack_size; 16 # endif 17 /* FIXME: Need to scan the normal stack too, but how ? */ 18+ } else { 19+ #if defined(HAVE_PTHREAD_ATTR_GET_NP) 20+ if (pthread_attr_init(&pattr) != 0) { 21+ ABORT("GC_push_all_stacks: pthread_attr_init failed!"); 22+ } 23+ if (pthread_attr_get_np(p->id, &pattr) != 0) { 24+ ABORT("GC_push_all_stacks: pthread_attr_get_np failed!"); 25+ } 26+ #elif defined(HAVE_PTHREAD_GETATTR_NP) 27+ if (pthread_getattr_np(p->id, &pattr)) { 28+ ABORT("GC_push_all_stacks: pthread_getattr_np failed!"); 29+ } 30+ #else 31+ /* assume default */ 32+ if (pthread_attr_init(&pattr) != 0) { 33+ ABORT("GC_push_all_stacks: pthread_attr_init failed!"); 34+ } 35+ #endif 36+ if (pthread_attr_getstacksize(&pattr, &stack_limit)) { 37+ ABORT("GC_push_all_stacks: pthread_attr_getstacksize failed!"); 38+ } 39+ if (pthread_attr_destroy(&pattr)) { 40+ ABORT("GC_push_all_stacks: pthread_attr_destroy failed!"); 41+ } 42+ // When a thread goes into a coroutine, we lose its original sp until 43+ // control flow returns to the thread. 44+ // While in the coroutine, the sp points outside the thread stack, 45+ // so we can detect this and push the entire thread stack instead, 46+ // as an approximation. 47+ // We assume that the coroutine has similarly added its entire stack. 48+ // This could be made accurate by cooperating with the application 49+ // via new functions and/or callbacks. 50+ #ifndef STACK_GROWS_UP 51+ if (lo >= hi || lo < hi - stack_limit) { // sp outside stack 52+ lo = hi - stack_limit; 53+ } 54+ #else 55+ #error "STACK_GROWS_UP not supported in boost_coroutine2 (as of june 2021), so we don't support it in Nix." 56+ #endif 57 } 58 # ifdef STACKPTR_CORRECTOR_AVAILABLE 59 if (GC_sp_corrector != 0)