all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Alain Schneble <a.s@realize.ch>
Cc: emacs-devel@gnu.org
Subject: Re: SIGTRAP in kill emulation on Windows
Date: Thu, 25 Aug 2016 19:18:20 +0300	[thread overview]
Message-ID: <83bn0gesab.fsf@gnu.org> (raw)
In-Reply-To: <86d1kwj37g.fsf@realize.ch> (message from Alain Schneble on Thu,  25 Aug 2016 17:08:51 +0200)

> From: Alain Schneble <a.s@realize.ch>
> 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.



  reply	other threads:[~2016-08-25 16:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-25 15:08 SIGTRAP in kill emulation on Windows Alain Schneble
2016-08-25 16:18 ` Eli Zaretskii [this message]
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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83bn0gesab.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=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 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.