unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Quang Kien Nguyen <kien.n.quang@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org, pipcet@protonmail.com
Subject: Re: MPS: Win64 testers?
Date: Wed, 7 Aug 2024 11:32:23 -0700	[thread overview]
Message-ID: <CAL7sU5hCK=GOBkVhYsxCyCU6NkYC6YcV=jxv0ad347YroK4+sw@mail.gmail.com> (raw)
In-Reply-To: <86ed70o90k.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1386 bytes --]

> This is not what I think we need.  First, there's no need to change
> anything in the MSVCRT build, because AFAIK the current code "just
> works" in such a build, both in 32-bit builds and in 64-bit builds.
> The problem happens only in UCRT builds.

Okay, put a new patch.
By the way, the code of using `pfn_SetHandleInformation` has been using by
`init_winsock` as well for the same purpose of making the handle not
inheritable.  So I think we should be pretty safe with this change.

> To test that, one would need to demonstrate that the parent Emacs
> process can do something with its standard handles without affecting
> the same handles of the child process.  For example, moving the file
> pointer in one process doesn't move it in the other.  As another
> example, if Emacs's standard output is redirected to a file, and
> writing to stdout in the child process writes to that same file, then
> the standard output handle _was_ inherited.  Yet another possibility
> is to use a tool such as ProcessExplorer to show the target of each
> handle, in both parent Emacs and its child sub-process, and verify the
> target is different.

I'm not sure how to redirect Emacs output in Windows.  And using
ProcExp64, I can
confirm that the standard handles (\Device\ConDrv\Input ...) is not refereed by
its child processes.  Let me know if you want me test other scenarios.

---
Kien

[-- Attachment #2: 0001-Use-SetHandleInformation-to-set-NOINHERIT-in-UCRT64.patch --]
[-- Type: application/octet-stream, Size: 1527 bytes --]

From fa1ecbf4c33589c4d753e1af380fa2902d2f672f Mon Sep 17 00:00:00 2001
From: Kien Nguyen <kien.n.quang@gmail.com>
Date: Wed, 7 Aug 2024 10:39:38 -0700
Subject: [PATCH] Use SetHandleInformation to set NOINHERIT in UCRT64

    * init_ntproc: Use SetHandleInformation to set NOINHERIT in UCRT64 

---
 src/w32.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/w32.c b/src/w32.c
index 31ffa301c..0c1291f10 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -10480,6 +10480,16 @@ init_ntproc (int dumping)
   /* Initial preparation for subprocess support: replace our standard
      handles with non-inheritable versions. */
   {
+
+#ifdef _UCRT
+    /* For UCRT, the _fdopen will try to find free stream from
+       _IOB_ENTRIES (= 3), thus we can't reopen the standard handles
+       with it. Using SetHandleInformation to make the handle not
+       inheritable to child process is a better way. */
+    SetHandleInformation (GetStdHandle(STD_INPUT_HANDLE), HANDLE_FLAG_INHERIT, 0);
+    SetHandleInformation (GetStdHandle(STD_OUTPUT_HANDLE), HANDLE_FLAG_INHERIT, 0);
+    SetHandleInformation (GetStdHandle(STD_ERROR_HANDLE), HANDLE_FLAG_INHERIT, 0);
+#else
     HANDLE parent;
     HANDLE stdin_save =  INVALID_HANDLE_VALUE;
     HANDLE stdout_save = INVALID_HANDLE_VALUE;
@@ -10534,6 +10544,7 @@ init_ntproc (int dumping)
     else
       _open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY);
     _fdopen (2, "w");
+#endif
   }
 
   /* unfortunately, atexit depends on implementation of malloc */
-- 
2.45.2.vfs.0.1


  reply	other threads:[~2024-08-07 18:32 UTC|newest]

Thread overview: 120+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-06  3:04 MPS: Win64 testers? Quang Kien Nguyen
2024-08-06  7:03 ` Quang Kien Nguyen
2024-08-06 11:40 ` Eli Zaretskii
2024-08-06 17:39   ` Quang Kien Nguyen
2024-08-06 18:32     ` Eli Zaretskii
2024-08-06 20:52       ` Quang Kien Nguyen
2024-08-07 11:41         ` Eli Zaretskii
2024-08-07 18:32           ` Quang Kien Nguyen [this message]
2024-08-08  5:46             ` Eli Zaretskii
2024-08-08 23:44               ` Quang Kien Nguyen
2024-08-09  6:00                 ` Eli Zaretskii
2024-08-09  6:10                   ` Eli Zaretskii
2024-08-09  9:19                     ` Quang Kien Nguyen
2024-08-09 11:03                       ` Eli Zaretskii
2024-08-13 12:12                         ` Quang Kien Nguyen
2024-08-13 12:37                           ` Eli Zaretskii
2024-08-13 15:51                             ` Pip Cet
2024-08-13 18:26                               ` Quang Kien Nguyen
2024-08-13 19:19                                 ` Eli Zaretskii
2024-08-13 20:22                                   ` Quang Kien Nguyen
2024-08-14 13:11                                     ` Sebastián Monía
2024-08-14 17:24                                       ` Quang Kien Nguyen
2024-08-16 20:09                                         ` Sebastián Monía
2024-08-17 11:37                                           ` Sebastián Monía
2024-08-17 12:54                                             ` Eli Zaretskii
2024-08-17 13:24                                               ` Sebastián Monía
2024-08-19 14:34                                                 ` Sebastián Monía
2024-08-19 14:55                                                   ` Eli Zaretskii
2024-08-19 15:12                                                     ` Pip Cet
2024-08-19 15:23                                                     ` Sebastián Monía
2024-08-19 15:31                                                       ` Quang Kien Nguyen
2024-08-19 16:23                                                         ` Quang Kien Nguyen
2024-08-21 18:14                                                           ` Sebastián Monía
2024-08-21 18:20                                                             ` Pip Cet
2024-08-21 19:46                                                               ` Sebastián Monía
2024-08-21 18:22                                                             ` Ihor Radchenko
2024-08-21 19:48                                                               ` Sebastián Monía
2024-08-22 17:34                                                             ` Sebastián Monía
2024-08-22 17:51                                                               ` Pip Cet
2024-08-22 18:34                                                                 ` Eli Zaretskii
2024-08-22 19:12                                                                   ` Quang Kien Nguyen
2024-08-23  5:32                                                                     ` Eli Zaretskii
2024-08-22 19:14                                                                   ` Pip Cet
2024-08-23  5:38                                                                     ` Eli Zaretskii
2024-08-23  7:59                                                                       ` Pip Cet
2024-08-23 13:08                                                                         ` Eli Zaretskii
2024-08-23 13:42                                                                           ` Quang Kien Nguyen
2024-08-23 13:48                                                                             ` Pip Cet
2024-08-23 14:35                                                                               ` Eli Zaretskii
2024-08-23 14:54                                                                                 ` Quang Kien Nguyen
2024-08-23 16:08                                                                                   ` Eli Zaretskii
     [not found]                                                                                     ` <CAL7sU5g7BrbrPL-B120NtVKkpnMuqmyuwDd_Kp50F1p8Gc3N0g@mail.gmail.com>
     [not found]                                                                                       ` <86ikvrp2hz.fsf@gnu.org>
2024-08-23 17:45                                                                                         ` Windows low-level keyboard hook Quang Kien Nguyen
2024-08-23 18:23                                                                                   ` MPS: Win64 testers? Sebastián Monía
2024-08-23 13:44                                                                           ` Pip Cet
2024-08-23 14:32                                                                             ` Eli Zaretskii
2024-08-23 15:51                                                                               ` Pip Cet
2024-08-23 16:17                                                                                 ` Eli Zaretskii
2024-08-23 18:57                                                                                   ` Pip Cet
2024-08-23 19:28                                                                                     ` Eli Zaretskii
2024-08-24 17:31                                                                         ` Pip Cet
2024-08-25  3:17                                                                           ` Quang Kien Nguyen
2024-08-30 19:59                                                                             ` Sebastián Monía
2024-09-01  8:21                                                                               ` Kien Nguyen
2024-09-01  8:43                                                                                 ` Eli Zaretskii
2024-09-01  9:36                                                                                   ` Kien Nguyen
2024-09-01 10:28                                                                                     ` Eli Zaretskii
2024-09-01 11:59                                                                                       ` Eli Zaretskii
2024-09-01 18:54                                                                                         ` Kien Nguyen
2024-09-01 19:27                                                                                           ` Eli Zaretskii
2024-09-01 19:44                                                                                           ` Pip Cet
2024-09-01 21:42                                                                                             ` Kien Nguyen
2024-09-02 11:08                                                                                             ` Eli Zaretskii
2024-09-03  4:12                                                                                               ` Kien Nguyen
2024-09-03 10:37                                                                                                 ` Pip Cet
2024-09-03 16:50                                                                                                   ` Kien Nguyen
2024-09-03 17:48                                                                                                     ` Pip Cet
2024-09-07  8:19                                                                                           ` Eli Zaretskii
2024-09-01 10:49                                                                                 ` Pip Cet
2024-09-01 12:15                                                                                   ` Kien Nguyen
2024-08-22 18:11                                                               ` Eli Zaretskii
2024-08-22 19:17                                                                 ` Sebastián Monía
2024-08-23  5:45                                                                   ` Eli Zaretskii
2024-08-07 19:50           ` Pip Cet
2024-08-07 23:14             ` Quang Kien Nguyen
2024-08-08  5:15             ` Eli Zaretskii
2024-08-06 14:18 ` Pip Cet
2024-08-07 11:03   ` Eli Zaretskii
  -- strict thread matches above, loose matches on Subject: below --
2024-07-25  9:45 Angelo Graziosi
2024-07-25 10:02 ` Stefan Kangas
2024-07-25 11:35 ` Eli Zaretskii
2024-07-27 14:22   ` Angelo Graziosi
2024-07-24 15:45 Pip Cet
2024-07-25  7:16 ` Eli Zaretskii
2024-07-25 15:39   ` Pip Cet
2024-07-27  8:02     ` Eli Zaretskii
2024-07-27 10:42       ` Pip Cet
2024-07-27 12:14         ` Eli Zaretskii
2024-07-27 15:49           ` Pip Cet
2024-07-27 16:10             ` Eli Zaretskii
2024-07-27 16:56               ` Eli Zaretskii
2024-07-27 18:27                 ` Pip Cet
2024-07-27 18:50                   ` Eli Zaretskii
2024-07-27 20:22                     ` Pip Cet
2024-07-28  5:25                       ` Eli Zaretskii
2024-07-28 13:00                         ` Pip Cet
2024-07-28 14:20                           ` Eli Zaretskii
2024-07-28 15:00                             ` Pip Cet
2024-07-28 15:20                               ` Eli Zaretskii
2024-07-28 20:22                                 ` Pip Cet
2024-07-29 11:25                                   ` Eli Zaretskii
2024-07-31  6:18                                     ` Pip Cet
2024-07-31 14:02                                       ` Eli Zaretskii
2024-07-31 19:04                                         ` Sebastián Monía
2024-08-01  5:00                                           ` Eli Zaretskii
2024-08-03  7:50                                         ` pipcet
2024-08-03  9:23                                           ` Eli Zaretskii
2024-08-03 15:17                                             ` pipcet
2024-08-03 16:07                                               ` Eli Zaretskii
2024-07-27 16:09         ` Michael Albinus
2024-07-28 13:22           ` Pip Cet

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='CAL7sU5hCK=GOBkVhYsxCyCU6NkYC6YcV=jxv0ad347YroK4+sw@mail.gmail.com' \
    --to=kien.n.quang@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=pipcet@protonmail.com \
    /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).