Skip to content

Commit

Permalink
Use correct thread stack limits in jl_init_stack_limits (#54639)
Browse files Browse the repository at this point in the history
Actually these do not really seem to matter much in practice (as
explained to me by @vtjnash on Slack, thank you). The one thing that did
cause me some grief here, though, was that stack_hi was the low address
and stack_lo the high address.

A smaller change to achieve that "hi means high, lo means low" would be
to just reverse `stack_hi` and `stack_lo`.
  • Loading branch information
fingolfin authored Jun 12, 2024
1 parent 1cd47c3 commit f1c601d
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,17 @@ void jl_init_stack_limits(int ismaster, void **stack_lo, void **stack_hi)
size_t stacksize;
pthread_attr_getstack(&attr, &stackaddr, &stacksize);
pthread_attr_destroy(&attr);
*stack_lo = (void*)stackaddr;
#pragma GCC diagnostic push
#if defined(_COMPILER_GCC_) && __GNUC__ >= 12
#pragma GCC diagnostic ignored "-Wdangling-pointer"
#endif
*stack_hi = (void*)__builtin_frame_address(0);
#pragma GCC diagnostic pop
*stack_hi = stackaddr;
*stack_lo = (char*)stackaddr - stacksize;
return;
# elif defined(_OS_DARWIN_)
extern void *pthread_get_stackaddr_np(pthread_t thread);
extern size_t pthread_get_stacksize_np(pthread_t thread);
pthread_t thread = pthread_self();
void *stackaddr = pthread_get_stackaddr_np(thread);
*stack_lo = (void*)stackaddr;
*stack_hi = (void*)__builtin_frame_address(0);
size_t stacksize = pthread_get_stacksize_np(thread);
*stack_hi = stackaddr;
*stack_lo = (char*)stackaddr - stacksize;
return;
# elif defined(_OS_FREEBSD_)
pthread_attr_t attr;
Expand All @@ -95,8 +91,8 @@ void jl_init_stack_limits(int ismaster, void **stack_lo, void **stack_hi)
size_t stacksize;
pthread_attr_getstack(&attr, &stackaddr, &stacksize);
pthread_attr_destroy(&attr);
*stack_lo = (void*)stackaddr;
*stack_hi = (void*)__builtin_frame_address(0);
*stack_hi = stackaddr;
*stack_lo = (char*)stackaddr - stacksize;
return;
# else
# warning "Getting precise stack size for thread is not supported."
Expand Down

0 comments on commit f1c601d

Please sign in to comment.