Prefer th->ec for stack base/size. (#13101)

This commit is contained in:
Samuel Williams 2025-04-17 22:21:51 +09:00 committed by GitHub
parent 6062c904ae
commit c4ae6cb500
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
Notes: git 2025-04-17 13:22:09 +00:00
Merged-By: ioquatix <samuel@codeotaku.com>
4 changed files with 86 additions and 6 deletions

View file

@ -3149,8 +3149,12 @@ ruby_stack_overflowed_p(const rb_thread_t *th, const void *addr)
const size_t water_mark = 1024 * 1024;
STACK_GROW_DIR_DETECTION;
if (th) {
size = th->ec->machine.stack_maxsize;
base = (char *)th->ec->machine.stack_start - STACK_DIR_UPPER(0, size);
}
#ifdef STACKADDR_AVAILABLE
if (get_stack(&base, &size) == 0) {
else if (get_stack(&base, &size) == 0) {
# ifdef __APPLE__
if (pthread_equal(th->nt->thread_id, native_main_thread.id)) {
struct rlimit rlim;
@ -3161,15 +3165,11 @@ ruby_stack_overflowed_p(const rb_thread_t *th, const void *addr)
# endif
base = (char *)base + STACK_DIR_UPPER(+size, -size);
}
else
#endif
if (th) {
size = th->ec->machine.stack_maxsize;
base = (char *)th->ec->machine.stack_start - STACK_DIR_UPPER(0, size);
}
else {
return 0;
}
size /= RUBY_STACK_SPACE_RATIO;
if (size > water_mark) size = water_mark;
if (IS_STACK_DIR_UPPER()) {