-
-
Notifications
You must be signed in to change notification settings - Fork 24.1k
Use real stack limits instead of hardcoded call depth limit when checking for GDScript stack overflow. #115338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
5f760a2 to
73eca08
Compare
…king for GDScript stack overflow.
|
If the stack size is platform dependent, is there a danger that we are introducing something that could result in exports failing on some platforms but not others? |
I do not think it will introduce any new potential issues, previously it would crash on overflow, now script will fail with error. Adjusting stack size for the threads will require to make platform specific |
|
I'm wondering if we should hardcode instead the min stack size from all our supported platforms. Using platform-specific limits sounds like it could lead in situations where a script works fine on Linux, but fails on Windows or macOS. In such case it would be better IMO to enforce a lower limit on Linux to take into account cross-platform constraints (most Godot projects are intended to be cross-platform). |
|
It's not mutually exclusive, adjusting stack size on all platforms makes sense, but it's non-trivial to determine what size we need for each build config, so runtime check should still be safer. And, as I already mention, custom |
|
Yeah it makes sense to add a way to retrieve the real stack size for sure. I wasn't advocating for a custom Thread implementation, but more a GDScript only limit like: But I haven't looked into this much so maybe this wouldn't be sufficient or would be too limiting. |
|
In some debug build configs, the real limit is around So making the limit higher (either with custom |
| err_func = p_instance->script->local_name.operator String() + "." + err_func; | ||
|
|
||
| ++call_depth; | ||
| #if defined(SANITIZERS_ENABLED) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| #if defined(SANITIZERS_ENABLED) | |
| #ifdef SANITIZERS_ENABLED |
| bool has_overflow = false; | ||
| if (Thread::get_stack_limits(&bottom, &top, &frame)) { | ||
| uint64_t alloc_size = sizeof(Variant *) * FIXED_ADDRESSES_MAX + sizeof(Variant *) * _instruction_args_size + sizeof(Variant) * _stack_size; | ||
| #if defined(SANITIZERS_ENABLED) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| #if defined(SANITIZERS_ENABLED) | |
| #ifdef SANITIZERS_ENABLED |
Fixes #115311
Instead of using arbitrary 2K limit, which is only valid for main thread on release builds, use real stack limits for the check.
Depending on platform and build config, real call depth limits varies from ~100 to 7000.
Tested on macOS, Windows and Linux.