From: Alain Schneble <a.s@realize.ch>
To: <emacs-devel@gnu.org>
Subject: SIGTRAP in kill emulation on Windows
Date: Thu, 25 Aug 2016 17:08:51 +0200 [thread overview]
Message-ID: <86d1kwj37g.fsf@realize.ch> (raw)
[-- 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
next reply other threads:[~2016-08-25 15:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-25 15:08 Alain Schneble [this message]
2016-08-25 16:18 ` SIGTRAP in kill emulation on Windows 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86d1kwj37g.fsf@realize.ch \
--to=a.s@realize.ch \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).