-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
teach MINGW Ctrl+C handling about arm processes #47
teach MINGW Ctrl+C handling about arm processes #47
Conversation
2b90e8c
to
d7b4753
Compare
Jsut FYI, IsWow64Process2 is available from Win10 only. |
Yes, specifically 1511 |
40d491c
to
2db43c9
Compare
I've tested this on 20H2 Win10 arm64, against arm32 arm64 and i686 native processes, and it works as expected (quickly terminating the arm processes, and launching getprocaddr32 for i686). I still need to test on the insider preview with x86_64 processes. |
Depending on prevailing opinion, I can either drop a1431aa or squash it before merging. Unfortunately I am not seriously considering actually building arm32/arm64 executables, as that would require mingw-w64-cross-clang, and among other concerns mingw-w64-cross-clang-crt/headers conflict with their gcc cousins. For the curious, here are the binaries I built with mingw-w64-cross-clang: |
Unfortunately arm32 and arm64 say "Could not get symbol info" for CtrlRoutine, but they can ExitProcess ok |
Poked around with windbg. CtrlRoutine is there, but it's just not finding it for whatever reason...
|
Oddly enough, this hack seems to work: diff --git a/winsup/utils/getprocaddr.c b/winsup/utils/getprocaddr.c
index 80b399c..beafc10 100644
--- a/winsup/utils/getprocaddr.c
+++ b/winsup/utils/getprocaddr.c
@@ -164,9 +164,9 @@ main (int argc, char **argv)
* because here because that symbol isn't exported.
*/
- if (strcmp (argv[1], "CtrlRoutine"))
+ if (TRUE || strcmp (argv[1], "CtrlRoutine"))
{
- HINSTANCE kernel32 = GetModuleHandle ("kernel32");
+ HINSTANCE kernel32 = GetModuleHandle (strcmp(argv[1], "CtrlRoutine") ? "kernel32" : "kernelbase");
if (!kernel32)
return 1;
void *address = (void *)GetProcAddress (kernel32, argv[1]); Maybe it could look in |
The CtrlHandler stuff is not working on the insider preview arm64 at all, 32/64/arm32/arm64. |
Aargh, hopefully this is a bug in the insider preview, but IsWow64Process2 from x86_64 process to x86_64 process on ARM64 is returning TRUE, process_arch = It appears to be the same from i686 process querying x86_64 process. 🤯 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am in favor of integrating this as-is, even if it is unclear so far how we could get the ARM versions of getprocaddr
to compile and to work.
I was too, until the behavior on the insider preview build of arm64 with x86_64 processes completely blew up my assumptions about IsWow64Process2. @dscho do you happen to know the proper way to ask a question about an API of Microsoft, where you might get a response from somebody who knows how it works? |
a1431aa
to
4bcbe11
Compare
How so? |
I figured it would return
basically that's the only case I know of that doesn't work (From https://discord.com/channels/792780131906617355/797787562706075659/856948456437448715) |
I don't think I'm going to get a reasonable answer on the MS Q&A site... I did a deep dive, On the insider preview build on arm64, there is also a Should we just ignore the insider preview, assuming it is buggy, and go ahead with this as it works perfectly in released versions of Windows? |
Please join the discussion here msys2/MINGW-packages#8991 |
fa77b9c
to
1f06c46
Compare
1f06c46
to
31546e6
Compare
I have tested this (before squashing) on the ARM64 Insider Preview in both i686 and x86_64 msys, against mingw32 mingw64 and clangarm64 pythons interrupting |
31546e6
to
908f52e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made an attempt at conforming to style, with a couple of cases where I wasn't sure exactly.
This comment has been minimized.
This comment has been minimized.
908f52e
to
3cd6b50
Compare
Risk should be minimal because I used |
kill doesn't appear to have the cygwin autoload stuff, so use GetProcAddress manually Unfortunately, IsWow64Process2 doesn't consider x86_64 processes on ARM64 to be Wow64, and returns exactly the same information as it does for native ARM64 processes. Use GetProcessInformation/ProcessMachineTypeInfo to further refine the answer in that case, when available (see #8991) add exe names for arm, but they are not built as the tooling for targeting arm is complicated.
0f53070
to
085e129
Compare
I just got the "Windows 11" update on my insider preview arm64 vm. This all continues to work there for all 4 arches. I think this may be ready to merge. |
Hearing no objection, the motion is adopted. |
That's because there is, in fact, no "Windows-on-Windows" going on. Windows 11 has the classic WOW (WOW6432Node, for 32 bits x86) and WOWA (WowAA32Node, for 32 bits ARM). Btw, |
From https://github.com/msys2/msys2-runtime/pull/31/files#r637592143
Calling GetNativeSystemInfo on arm/arm64 lies. To get accurate information about native arch and process's emulated arch, use
IsWow64Process2
where available. Otherwise, fall back to the GetNativeSystemInfo/IsWow64Process logic.Unfortunately,
IsWow64Process2
doesn't consider x86_64 processes on ARM64 to be Wow64, and returns exactly the same information as it does for native ARM64 processes. UseGetProcessInformation
/ProcessMachineTypeInfo
to further refine theanswer in that case, when available (see msys2/MINGW-packages#8991)
Because there are more cases than just 32 or 64 bit, change out
bitness
out param forIMAGE_FILE_MACHINE_*
constants like IsWow64Process2 uses, and assume I386/AMD64 to be 32/64 bit in the old case.While cygwin already 'knows' how to autoload☹️
IsWow64Process2
, and will make it return FALSE/ERROR_PROC_NOT_FOUND if it isn't present, this magic does not seem to be present inkill.exe
so go back to manualGetModuleHandle
/GetProcAddress
.