summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorTony Roberts <tony@pyxll.com>2019-02-02 17:16:42 (GMT)
committerSteve Dower <steve.dower@microsoft.com>2019-02-02 17:16:42 (GMT)
commit4860f01ac0f07cdc8fc0cc27c33f5a64e5cfec9f (patch)
tree18e9232f27d8bee1c9a8139937b69ec013a19abf /Modules/posixmodule.c
parent2de576e16d42ce43698d384d0dd46ba6cf165424 (diff)
downloadcpython-4860f01ac0f07cdc8fc0cc27c33f5a64e5cfec9f.zip
cpython-4860f01ac0f07cdc8fc0cc27c33f5a64e5cfec9f.tar.gz
cpython-4860f01ac0f07cdc8fc0cc27c33f5a64e5cfec9f.tar.bz2
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.
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 0f6bd14..931c0d3 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -7749,9 +7749,13 @@ check_CreateSymbolicLink(void)
/* only recheck */
if (Py_CreateSymbolicLinkW)
return 1;
+
+ Py_BEGIN_ALLOW_THREADS
hKernel32 = GetModuleHandleW(L"KERNEL32");
*(FARPROC*)&Py_CreateSymbolicLinkW = GetProcAddress(hKernel32,
"CreateSymbolicLinkW");
+ Py_END_ALLOW_THREADS
+
return Py_CreateSymbolicLinkW != NULL;
}
@@ -11288,7 +11292,6 @@ check_ShellExecute()
the system SHELL32.DLL, even if there is another SHELL32.DLL
in the DLL search path. */
hShell32 = LoadLibraryW(L"SHELL32");
- Py_END_ALLOW_THREADS
if (hShell32) {
*(FARPROC*)&Py_ShellExecuteW = GetProcAddress(hShell32,
"ShellExecuteW");
@@ -11296,6 +11299,7 @@ check_ShellExecute()
} else {
has_ShellExecute = 0;
}
+ Py_END_ALLOW_THREADS
}
return has_ShellExecute;
}
@@ -11909,11 +11913,12 @@ os_cpu_count_impl(PyObject *module)
/* Vista is supported and the GetMaximumProcessorCount API is Win7+
Need to fallback to Vista behavior if this call isn't present */
HINSTANCE hKernel32;
- hKernel32 = GetModuleHandleW(L"KERNEL32");
-
static DWORD(CALLBACK *_GetMaximumProcessorCount)(WORD) = NULL;
+ Py_BEGIN_ALLOW_THREADS
+ hKernel32 = GetModuleHandleW(L"KERNEL32");
*(FARPROC*)&_GetMaximumProcessorCount = GetProcAddress(hKernel32,
"GetMaximumProcessorCount");
+ Py_END_ALLOW_THREADS
if (_GetMaximumProcessorCount != NULL) {
ncpu = _GetMaximumProcessorCount(ALL_PROCESSOR_GROUPS);
}