public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: Fix the address of myself
@ 2019-07-25 13:31 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2019-07-25 13:31 UTC (permalink / raw)
  To: cygwin-cvs

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=3a72edc124e7a459ee8a62ebb74b82fe38b8073e

commit 3a72edc124e7a459ee8a62ebb74b82fe38b8073e
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Wed Jul 24 17:48:57 2019 +0200

    Cygwin: Fix the address of myself
    
    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, the independent Cygwin PID changes broke this.  To create
    myself at the right address requires to call init with h0 set to
    INVALID_HANDLE_VALUE or an existing address:
    
    void
    pinfo::init (pid_t n, DWORD flag, HANDLE h0)
    {
      [...]
      if (!h0 || myself.h)
        [...]
      else
        {
          shloc = SH_MYSELF;
          if (h0 == INVALID_HANDLE_VALUE)       <-- !!!
            h0 = NULL;
        }
    
    The aforementioned commits changed that so h0 was always NULL, this way
    creating myself at an arbitrary address.
    
    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 child_info_spawn::handle_spawn.
    
    Fixes: b5e1003722cb ("Cygwin: processes: use dedicated Cygwin PID rather than Windows PID")
    Fixes: 88605243a19b ("Cygwin: fix child getting another pid after spawnve")
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/dcrt0.cc | 2 +-
 winsup/cygwin/pinfo.cc | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index fb726a7..86ab725 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -652,7 +652,7 @@ void
 child_info_spawn::handle_spawn ()
 {
   extern void fixup_lockf_after_exec (bool);
-  HANDLE h;
+  HANDLE h = INVALID_HANDLE_VALUE;
   if (!dynamically_loaded || get_parent_handle ())
       {
 	cygheap_fixup_in_child (true);
diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc
index 123784e..ffd4c8c 100644
--- a/winsup/cygwin/pinfo.cc
+++ b/winsup/cygwin/pinfo.cc
@@ -62,11 +62,10 @@ pinfo::thisproc (HANDLE h)
     {
       cygheap->pid = create_cygwin_pid ();
       flags |= PID_NEW;
+      h = INVALID_HANDLE_VALUE;
     }
   /* 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;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-07-25 13:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-25 13:31 [newlib-cygwin] Cygwin: Fix the address of myself Corinna Vinschen

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).