This is the mail archive of the cygwin-patches mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Cygwin: Fix the address of myself

From: Corinna Vinschen <>

Introducing an independent Cygwin PID introduced a regression:

The expectation is that the myself pinfo pointer always points to a
specific address right in front of the loaded Cygwin DLL.

However, commit b5e1003722cb14235c4f166be72c09acdffc62ea "Cygwin:
processes: use dedicated Cygwin PID rather than Windows PID" and commit
88605243a19bbc2b6b9be36b99f513140b972e38 "Cygwin: fix child getting
another pid after spawnve" broke this.  To get myself at the right
address requires to call init with h0 set to INVALID_HANDLE_VALUE or an
existing address:

pinfo::init (pid_t n, DWORD flag, HANDLE h0)
  if (!h0 || myself.h)
      shloc = SH_MYSELF;
      if (h0 == INVALID_HANDLE_VALUE)       <-- !!!
        h0 = NULL;

That was not the case anymore after the above commits.  This patch makes
sure to set the handle to INVALID_HANDLE_VALUE again when creating a new
process, so init knows that myself has to be created in the right spot.

While at it, fix a potential uninitialized handle value in

Signed-off-by: Corinna Vinschen <>
 winsup/cygwin/ | 2 +-
 winsup/cygwin/ | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/winsup/cygwin/ b/winsup/cygwin/
index fb726a739ccf..86ab7256484c 100644
--- a/winsup/cygwin/
+++ b/winsup/cygwin/
@@ -652,7 +652,7 @@ void
 child_info_spawn::handle_spawn ()
   extern void fixup_lockf_after_exec (bool);
-  HANDLE h;
   if (!dynamically_loaded || get_parent_handle ())
 	cygheap_fixup_in_child (true);
diff --git a/winsup/cygwin/ b/winsup/cygwin/
index cdbd8bd7eaf3..b67d660ae04d 100644
--- a/winsup/cygwin/
+++ b/winsup/cygwin/
@@ -62,11 +62,10 @@ pinfo::thisproc (HANDLE h)
       cygheap->pid = create_cygwin_pid ();
       flags |= PID_NEW;
   /* spawnve'd process got pid in parent, cygheap->pid has been set in
      child_info_spawn::handle_spawn. */
-  else if (h == INVALID_HANDLE_VALUE)
-    h = NULL;
   init (cygheap->pid, flags, h);
   procinfo->process_state |= PID_IN_USE;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]