[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SIGTRAP in kill emulation on Windows
From: |
Alain Schneble |
Subject: |
SIGTRAP in kill emulation on Windows |
Date: |
Thu, 25 Aug 2016 17:08:51 +0200 |
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).
>From fca0f7d3969ee3ad68046e3a0a2d4ccfef738692 Mon Sep 17 00:00:00 2001
From: Alain Schneble <address@hidden>
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
Many thanks for considering and reviewing it.
Alain
- SIGTRAP in kill emulation on Windows,
Alain Schneble <=
- Re: SIGTRAP in kill emulation on Windows, Eli Zaretskii, 2016/08/25
- Re: SIGTRAP in kill emulation on Windows, Alain Schneble, 2016/08/25
- Re: SIGTRAP in kill emulation on Windows, Alain Schneble, 2016/08/25
- Re: SIGTRAP in kill emulation on Windows, Eli Zaretskii, 2016/08/26
- Re: SIGTRAP in kill emulation on Windows, Alain Schneble, 2016/08/26
- Re: SIGTRAP in kill emulation on Windows, Eli Zaretskii, 2016/08/26
- Re: SIGTRAP in kill emulation on Windows, Eli Zaretskii, 2016/08/26
- Re: SIGTRAP in kill emulation on Windows, Alain Schneble, 2016/08/26
- Re: SIGTRAP in kill emulation on Windows, Alain Schneble, 2016/08/26