win32 patching shouldn't use as much stack (Was: Stack overflow caused by PatchAllModules() function) · Issue #1365 · gperftools/gperftools · GitHub
More Web Proxy on the site http://driver.im/
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
is using 65732 bytes of stack, which already triggers an MSVC warning on its own. I had increased the stack reserve size, but it did not help in my case, one user has been getting crash while a GPU driver was being loaded regardless. Doing ?? int(@$teb->NtTib.StackBase) - int(@$teb->NtTib.StackLimit) in WinDbg showed that the stack size is 61440, and the stack overflow crash trace fragment is:
I tried moving the variables hModules (seems to be main culprit), modules and currently_loaded_modules into globals to have them located at the heap (replacing declaration with clearing instructions in case of the vector and set inside of the function), and that seems to have fixed the issue.
I would have created a PR, but I'm not familiar enough with the codebase to gauge whether these should be converted to static globals or allocated dynamically...
Edit: While default stack reserve size is over 1 MB, some reverse engineering of the Nvidia driver's DLL reveals that they supply the dwStackSize parameter to CreateThread with a value of 0x10000 (65536, so more than PatchAllModules() itself used!) for some threads. One of those happens to be a thread that loads Windows API DLLs, and as such runs into this issue.
The text was updated successfully, but these errors were encountered:
I think allocating those arrays via tc_malloc/tc_free should work. So go ahead and contribute. If tcmalloc_minimal_unittest passes, then it works. Thanks for reporting it.
alk
changed the title
Stack overflow caused by PatchAllModules() function
win32 patching shouldn't use as much stack (Was: Stack overflow caused by PatchAllModules() function)
Jul 3, 2023
The function PatchAllModules() located at:
gperftools/src/windows/patch_functions.cc
Line 696 in f7c6fb6
is using 65732 bytes of stack, which already triggers an MSVC warning on its own. I had increased the stack reserve size, but it did not help in my case, one user has been getting crash while a GPU driver was being loaded regardless. Doing
?? int(@$teb->NtTib.StackBase) - int(@$teb->NtTib.StackLimit)
in WinDbg showed that the stack size is 61440, and the stack overflow crash trace fragment is:I tried moving the variables
hModules
(seems to be main culprit),modules
andcurrently_loaded_modules
into globals to have them located at the heap (replacing declaration with clearing instructions in case of the vector and set inside of the function), and that seems to have fixed the issue.I would have created a PR, but I'm not familiar enough with the codebase to gauge whether these should be converted to static globals or allocated dynamically...
Edit: While default stack reserve size is over 1 MB, some reverse engineering of the Nvidia driver's DLL reveals that they supply the dwStackSize parameter to CreateThread with a value of 0x10000 (65536, so more than PatchAllModules() itself used!) for some threads. One of those happens to be a thread that loads Windows API DLLs, and as such runs into this issue.
The text was updated successfully, but these errors were encountered: