From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: SIGTRAP in kill emulation on Windows Date: Thu, 25 Aug 2016 19:18:20 +0300 Message-ID: <83bn0gesab.fsf@gnu.org> References: <86d1kwj37g.fsf@realize.ch> Reply-To: Eli Zaretskii NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1472142109 24130 195.159.176.226 (25 Aug 2016 16:21:49 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 25 Aug 2016 16:21:49 +0000 (UTC) Cc: emacs-devel@gnu.org To: Alain Schneble Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Aug 25 18:21:43 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 1bcxPS-0005ea-Of for ged-emacs-devel@m.gmane.org; Thu, 25 Aug 2016 18:21:42 +0200 Original-Received: from localhost ([::1]:57119 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcxPQ-0000KQ-3Y for ged-emacs-devel@m.gmane.org; Thu, 25 Aug 2016 12:21:40 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57826) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcxLy-0006a7-NM for emacs-devel@gnu.org; Thu, 25 Aug 2016 12:18:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bcxLt-0007Q7-HB for emacs-devel@gnu.org; Thu, 25 Aug 2016 12:18:05 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:40023) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcxLt-0007Q3-DH; Thu, 25 Aug 2016 12:18:01 -0400 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:4621 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1bcxLs-0007cZ-Li; Thu, 25 Aug 2016 12:18:01 -0400 In-reply-to: <86d1kwj37g.fsf@realize.ch> (message from Alain Schneble on Thu, 25 Aug 2016 17:08:51 +0200) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e 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:206802 Archived-At: > From: Alain Schneble > Date: Thu, 25 Aug 2016 17:08:51 +0200 > > 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). Thanks. I think this needs an entry in NEWS. > + else if (sig == SIGTRAP) > + { > +#if _WIN32_WINNT >= _WIN32_WINNT_WINXP > + if (!DebugBreakProcess (proc_hand)) We don't put in Emacs sources compile-time conditionals that depend on the version of the OS on which Emacs is built: that would preclude the (very popular on Windows) practice of building Emacs on one system, and then using it on many others, possibly running other versions of the OS. Instead, functions that might be unavailable at run time are called through a function pointer, which is assigned the value when it is first needed, by looking up the function address in the corresponding DLL (and loading the DLL if needed, which is not the case here). Please see an example of how that is done in w32proc.c:w32_compare_strings (and in many places in w32.c). > + { > + 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; When the function is not available, you should assign ENOTSUP to errno, not EINVAL, to make the error message more accurate. Please test what this functionality does when PID specifies a child process of Emacs (which is tracked via the child_procs[] array), and also when it specifies the calling Emacs process itself. If any of these use cases cause any kind of trouble, we may wish to disallow such usage, to prevent users from shooting themselves in the foot.