diff mbox series

[Ada] Fix __gnat_kill on Windows

Message ID 20220107162716.GA948658@adacore.com
State New
Headers show
Series [Ada] Fix __gnat_kill on Windows | expand

Commit Message

Pierre-Marie de Rodat Jan. 7, 2022, 4:27 p.m. UTC
Terminate process only on terminating signals.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* adaint.c (__gnat_kill): Terminate process only in case of
	SIGKILL, SIGINT, SIGBREAK, SIGTERM, SIGABRT.  Do not call
	OpenProcess if not going to terminate process.
diff mbox series

Patch

diff --git a/gcc/ada/adaint.c b/gcc/ada/adaint.c
--- a/gcc/ada/adaint.c
+++ b/gcc/ada/adaint.c
@@ -3559,13 +3559,21 @@  void
 __gnat_kill (int pid, int sig, int close ATTRIBUTE_UNUSED)
 {
 #if defined(_WIN32)
-  HANDLE h = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid);
-  if (h == NULL)
-    return;
+  HANDLE h;
 
-  TerminateProcess (h, sig);
+  switch (sig) {
+    case 9: // SIGKILL is not declared in Windows headers
+    case SIGINT:
+    case SIGBREAK:
+    case SIGTERM:
+    case SIGABRT:
+      h = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid);
+      if (h != NULL) {
+        TerminateProcess (h, sig);
+        CloseHandle (h);
+      }
+  }
 
-  CloseHandle (h);
 #elif defined (__vxworks)
   /* Not implemented */
 #else