all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* SIGTRAP in kill emulation on Windows
@ 2016-08-25 15:08 Alain Schneble
  2016-08-25 16:18 ` Eli Zaretskii
  0 siblings, 1 reply; 12+ messages in thread
From: Alain Schneble @ 2016-08-25 15:08 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 323 bytes --]

Hello

The following patch provides support for SIGTRAP in the kill emulation
on Windows.  It implements mapping SIGTRAP to a call to
DebugBreakProcess in C code.  Patches that implement the discussed use
cases in LISP will be submitted separately as this change is useful on
its own, e.g. (signal-process PROCESS 'TRAP).


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: SIGTRAP in kill emulation on Windows --]
[-- Type: text/x-patch, Size: 2331 bytes --]

From fca0f7d3969ee3ad68046e3a0a2d4ccfef738692 Mon Sep 17 00:00:00 2001
From: Alain Schneble <a.s@realize.ch>
Date: Thu, 25 Aug 2016 15:19:09 +0200
Subject: [PATCH] Support SIGTRAP in kill emulation on Windows

* src/w32proc.c (sys_kill): Translate SIGTRAP signal into a call to
  DebugBreakProcess to cause a breakpoint exception to occur in the
  specified process. Windows versions prior to Windows XP that do not
  support DebugBreakProcess return -1 and errno set to EINVAL as before.
---
 src/w32proc.c | 37 ++++++++++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/src/w32proc.c b/src/w32proc.c
index 11a121f..ab2a667 100644
--- a/src/w32proc.c
+++ b/src/w32proc.c
@@ -2507,9 +2507,9 @@ sys_kill (pid_t pid, int sig)
   if (pid < 0)
     pid = -pid;
 
-  /* Only handle signals that will result in the process dying */
+  /* Only handle signals that can be mapped to a similar behavior on Windows */
   if (sig != 0
-      && sig != SIGINT && sig != SIGKILL && sig != SIGQUIT && sig != SIGHUP)
+      && sig != SIGINT && sig != SIGKILL && sig != SIGQUIT && sig != SIGHUP && sig != SIGTRAP)
     {
       errno = EINVAL;
       return -1;
@@ -2552,7 +2552,11 @@ sys_kill (pid_t pid, int sig)
 	 close the selected frame, which does not necessarily
 	 terminates Emacs.  But then we are not supposed to call
 	 sys_kill with our own PID.  */
-      proc_hand = OpenProcess (PROCESS_TERMINATE, 0, pid);
+
+      DWORD desiredAccess =
+	(sig == SIGTRAP) ? PROCESS_ALL_ACCESS : PROCESS_TERMINATE;
+
+      proc_hand = OpenProcess (desiredAccess, 0, pid);
       if (proc_hand == NULL)
         {
 	  errno = EPERM;
@@ -2648,6 +2652,33 @@ sys_kill (pid_t pid, int sig)
 	  rc = -1;
 	}
     }
+  else if (sig == SIGTRAP)
+    {
+#if _WIN32_WINNT >= _WIN32_WINNT_WINXP
+      if (!DebugBreakProcess (proc_hand))
+	{
+	  DWORD err = GetLastError ();
+
+	  DebPrint (("sys_kill.DebugBreakProcess return %d "
+		     "for pid %lu\n", err, pid));
+
+	  switch (err)
+	    {
+	    case ERROR_ACCESS_DENIED:
+	      errno = EPERM;
+	      break;
+	    default:
+	      errno = EINVAL;
+	      break;
+	    }
+
+	  rc = -1;
+	}
+#else
+      errno = EINVAL;
+      rc = -1;
+#endif
+    }
   else
     {
       if (NILP (Vw32_start_process_share_console) && cp && cp->hwnd)
-- 
2.8.1.windows.1


[-- Attachment #3: Type: text/plain, Size: 54 bytes --]


Many thanks for considering and reviewing it.
Alain


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-10-08 14:36 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-25 15:08 SIGTRAP in kill emulation on Windows Alain Schneble
2016-08-25 16:18 ` Eli Zaretskii
2016-08-25 20:02   ` Alain Schneble
2016-08-25 20:09     ` Alain Schneble
2016-08-26  8:24     ` Eli Zaretskii
2016-08-26  8:58       ` Alain Schneble
2016-08-26  9:13         ` Eli Zaretskii
2016-08-26  9:31           ` Eli Zaretskii
2016-08-26  9:47           ` Alain Schneble
2016-08-26 10:19             ` Alain Schneble
2016-10-08 13:54               ` Eli Zaretskii
2016-10-08 14:36                 ` Alain Schneble

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.