From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alain Schneble Newsgroups: gmane.emacs.devel Subject: SIGTRAP in kill emulation on Windows Date: Thu, 25 Aug 2016 17:08:51 +0200 Message-ID: <86d1kwj37g.fsf@realize.ch> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1472137879 19710 195.159.176.226 (25 Aug 2016 15:11:19 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 25 Aug 2016 15:11:19 +0000 (UTC) To: Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Aug 25 17:11:07 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bcwJ8-0004EM-42 for ged-emacs-devel@m.gmane.org; Thu, 25 Aug 2016 17:11:06 +0200 Original-Received: from localhost ([::1]:56754 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcwJ5-0006ve-G5 for ged-emacs-devel@m.gmane.org; Thu, 25 Aug 2016 11:11:03 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41502) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcwHf-0006Gn-36 for emacs-devel@gnu.org; Thu, 25 Aug 2016 11:09:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bcwHa-0003bB-Hk for emacs-devel@gnu.org; Thu, 25 Aug 2016 11:09:34 -0400 Original-Received: from clientmail.realize.ch ([46.140.89.53]:2091) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1bcwHa-0003aJ-5h for emacs-devel@gnu.org; Thu, 25 Aug 2016 11:09:30 -0400 Original-Received: from rintintin.hq.realize.ch.lan.rit ([192.168.0.105]) by clientmail.realize.ch ; Thu, 25 Aug 2016 17:09:25 +0200 Original-Received: from MYNGB (192.168.66.65) by rintintin.hq.realize.ch.lan.rit (192.168.0.105) with Microsoft SMTP Server (TLS) id 15.0.516.32; Thu, 25 Aug 2016 17:08:59 +0200 X-ClientProxiedBy: rintintin.hq.realize.ch.lan.rit (192.168.0.105) To rintintin.hq.realize.ch.lan.rit (192.168.0.105) X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] X-Received-From: 46.140.89.53 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:206801 Archived-At: --=-=-= Content-Type: text/plain 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). --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename="0001-Support-SIGTRAP-in-kill-emulation-on-Windows.patch" Content-Description: SIGTRAP in kill emulation on Windows >From fca0f7d3969ee3ad68046e3a0a2d4ccfef738692 Mon Sep 17 00:00:00 2001 From: Alain Schneble 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 --=-=-= Content-Type: text/plain Many thanks for considering and reviewing it. Alain --=-=-=--