[Ada] Fix __gnat_kill on Windows
authorDmitriy Anisimkov <anisimko@adacore.com>
Mon, 20 Dec 2021 11:44:58 +0000 (17:44 +0600)
committerPierre-Marie de Rodat <derodat@adacore.com>
Fri, 7 Jan 2022 16:24:11 +0000 (16:24 +0000)
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.

gcc/ada/adaint.c

index 2db3528..68f187b 100644 (file)
@@ -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