gh-152433: Windows: fix ctypes error in UWP build - #154700
Conversation
|
Ping @zooba for review |
|
I've finally resolved all the issues related to ctype. The first error was due to loading kernel32 with The second error was a |
UWP does not allow allocating memory with code execution permissions.
chris-eibl
left a comment
There was a problem hiding this comment.
LGTM. This is sitting for a while now. If nobody objects, I'm gonna merge end of next week at the latest.
| item = (ITEM*)VirtualAllocFromApp(NULL, | ||
| count * sizeof(ITEM), | ||
| MEM_COMMIT | MEM_RESERVE, | ||
| PAGE_READWRITE); |
There was a problem hiding this comment.
If this works without EXECUTE, then do we need EXECUTE in the alternative VirtualAlloc call?
There was a problem hiding this comment.
More work is needed for ctypes to have full functionality in UWP.
The EXECUTE flag is required, but in UWP, it is not allowed alongside READWRITE. This PR addresses some of the issues that recently arose after adding this code:
cpython/Modules/_ctypes/_ctypes.c
Lines 6390 to 6397 in e5d4fa2
This causes errors immediately upon ctypes initialization (because reserves memory with execute permission).
But executing code in memory remains necessary for full ctypes functionality.
Let's say this PR only enables "limited" ctypes functionality on UWP but causes no harm on Windows Desktop.
Fix
ctypeserror in UWP build:In UWP is possible call
GetLastError()Win32 API but not like import from ctypes withLibraryLoader:The error produced is like this (in this case using Cryptodome):
Since GetLastError is available from_winapi, the workaround is import from _winapi and call directly.