base16-schemes: unstable-2024-06-21 -> unstable-2024-11-12 (#356361)
[NixPkgs.git] / pkgs / tools / package-management / nix / patches / boehmgc-coroutine-sp-fallback.patch
bloba53b7f1f52f492b08ad45771a07c6684d87a85c6
1 diff --git a/pthread_stop_world.c b/pthread_stop_world.c
2 index 2b45489..0e6d8ef 100644
3 --- a/pthread_stop_world.c
4 +++ b/pthread_stop_world.c
5 @@ -776,6 +776,8 @@ STATIC void GC_restart_handler(int sig)
6 /* world is stopped. Should not fail if it isn't. */
7 GC_INNER void GC_push_all_stacks(void)
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,40 @@ GC_INNER void GC_push_all_stacks(void)
15 hi = p->altstack + p->altstack_size;
16 # endif
17 /* FIXME: Need to scan the normal stack too, but how ? */
18 + } else {
19 + #ifdef 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 + #else
27 + if (pthread_getattr_np(p->id, &pattr)) {
28 + ABORT("GC_push_all_stacks: pthread_getattr_np failed!");
29 + }
30 + #endif
31 + if (pthread_attr_getstacksize(&pattr, &stack_limit)) {
32 + ABORT("GC_push_all_stacks: pthread_attr_getstacksize failed!");
33 + }
34 + if (pthread_attr_destroy(&pattr)) {
35 + ABORT("GC_push_all_stacks: pthread_attr_destroy failed!");
36 + }
37 + // When a thread goes into a coroutine, we lose its original sp until
38 + // control flow returns to the thread.
39 + // While in the coroutine, the sp points outside the thread stack,
40 + // so we can detect this and push the entire thread stack instead,
41 + // as an approximation.
42 + // We assume that the coroutine has similarly added its entire stack.
43 + // This could be made accurate by cooperating with the application
44 + // via new functions and/or callbacks.
45 + #ifndef STACK_GROWS_UP
46 + if (lo >= hi || lo < hi - stack_limit) { // sp outside stack
47 + lo = hi - stack_limit;
48 + }
49 + #else
50 + #error "STACK_GROWS_UP not supported in boost_coroutine2 (as of june 2021), so we don't support it in Nix."
51 + #endif
53 # ifdef STACKPTR_CORRECTOR_AVAILABLE
54 if (GC_sp_corrector != 0)