mirror of
https://github.com/python/cpython.git
synced 2025-07-15 23:35:23 +00:00
bpo-33895: Relase GIL while calling functions that acquire Windows loader lock (GH-7789)
LoadLibrary, GetProcAddress, FreeLibrary and GetModuleHandle acquire the system loader lock. Calling these while holding the GIL will cause a deadlock on the rare occasion that another thread is detaching and needs to destroy its thread state at the same time.
This commit is contained in:
parent
2de576e16d
commit
4860f01ac0
8 changed files with 48 additions and 6 deletions
|
@ -218,8 +218,10 @@ dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix,
|
|||
/* We use LoadLibraryEx so Windows looks for dependent DLLs
|
||||
in directory of pathname first. */
|
||||
/* XXX This call doesn't exist in Windows CE */
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
hDLL = LoadLibraryExW(wpathname, NULL,
|
||||
LOAD_WITH_ALTERED_SEARCH_PATH);
|
||||
Py_END_ALLOW_THREADS
|
||||
#if HAVE_SXS
|
||||
_Py_DeactivateActCtx(cookie);
|
||||
#endif
|
||||
|
@ -298,11 +300,15 @@ dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix,
|
|||
"Module use of %.150s conflicts "
|
||||
"with this version of Python.",
|
||||
import_python);
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
FreeLibrary(hDLL);
|
||||
Py_END_ALLOW_THREADS
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
p = GetProcAddress(hDLL, funcname);
|
||||
Py_END_ALLOW_THREADS
|
||||
}
|
||||
|
||||
return p;
|
||||
|
|
|
@ -1159,7 +1159,9 @@ sys_getwindowsversion_impl(PyObject *module)
|
|||
// We need to read the version info from a system file resource
|
||||
// to accurately identify the OS version. If we fail for any reason,
|
||||
// just return whatever GetVersion said.
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
hKernel32 = GetModuleHandleW(L"kernel32.dll");
|
||||
Py_END_ALLOW_THREADS
|
||||
if (hKernel32 && GetModuleFileNameW(hKernel32, kernel32_path, MAX_PATH) &&
|
||||
(verblock_size = GetFileVersionInfoSizeW(kernel32_path, NULL)) &&
|
||||
(verblock = PyMem_RawMalloc(verblock_size))) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue