https://github.com/python/cpython/commit/0f00aef285f57231c5b9eb1cb52c6b2697bb5a8c
commit: 0f00aef285f57231c5b9eb1cb52c6b2697bb5a8c
branch: main
author: thexai <[email protected]>
committer: zooba <[email protected]>
date: 2026-09-17T17:47:45Z
summary:
gh-152433: Fix ctypes import error on Windows UWP builds (GH-154700)
This defers a closure-related limitation to time of use, rather than import
time.
Further work is necessary to offer full functionality on UWP builds.
files:
M Modules/_ctypes/malloc_closure.c
diff --git a/Modules/_ctypes/malloc_closure.c b/Modules/_ctypes/malloc_closure.c
index 62c7aa5d6affbfb..3abab8873acbd01 100644
--- a/Modules/_ctypes/malloc_closure.c
+++ b/Modules/_ctypes/malloc_closure.c
@@ -68,10 +68,25 @@ static void more_core(void)
/* allocate a memory block */
#ifdef MS_WIN32
+#ifdef MS_WINDOWS_DESKTOP
item = (ITEM *)VirtualAlloc(NULL,
count * sizeof(ITEM),
MEM_COMMIT,
PAGE_EXECUTE_READWRITE);
+#else // UWP
+ /* Due security restrictions, UWP not allows request Read-Write-Execute
permissions at once.
+ The correct flow in UWP for execute dynamic code in memmory is:
+ 1. Alloate as Read-Write (PAGE_READWRITE) and write dynamic code to
memmory.
+ 2. Change to Executable (PAGE_EXECUTE_READ) with
'VirtualProtectFromApp'.
+ 3. Flush cache with 'FlushInstructionCache' to ensure CPU instruction
cache coherency
+ before executing the generated code.
+ TODO: Implement 2 and 3 in the appropriate places. For now, this defers
+ the error from import time to time of use (or never, if an app avoids
it). */
+ item = (ITEM*)VirtualAllocFromApp(NULL,
+ count * sizeof(ITEM),
+ MEM_COMMIT | MEM_RESERVE,
+ PAGE_READWRITE);
+#endif // !MS_WINDOWS_DESKTOP
if (item == NULL)
return;
#else
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]