]> sourceware.org Git - newlib-cygwin.git/commitdiff
Cygwin: /proc/<PID>/maps: print real shared region addresses
authorCorinna Vinschen <corinna@vinschen.de>
Tue, 17 Jan 2023 20:58:06 +0000 (21:58 +0100)
committerCorinna Vinschen <corinna@vinschen.de>
Tue, 17 Jan 2023 21:00:48 +0000 (22:00 +0100)
So far, the addresses printed for the shared regions of a process
were faked.  The assumption was that the shared regions are always
in the same place in all processes, so we just printed the addresses
of the current process.  This is no safe bet.  The only safe bet is
the address of the cygheap.  So keep track of the addresses in the
cygheap and read the addresses from the cygheap of the observed
processes.  Add output for the shared console.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
winsup/cygwin/fhandler/console.cc
winsup/cygwin/fhandler/process.cc
winsup/cygwin/local_includes/cygheap.h
winsup/cygwin/mm/shared.cc
winsup/cygwin/pinfo.cc

index 68ab43d81ea141c7965f6af8c47c1db44b70aa36..0cbfe4ea41f442eecd5f8262369da3f426748a1a 100644 (file)
@@ -219,6 +219,8 @@ fhandler_console::open_shared_console (HWND hw, HANDLE& h, bool& created)
   shared_locations m = created ? SH_SHARED_CONSOLE : SH_JUSTOPEN;
   console_state *res = (console_state *)
     open_shared (namebuf, 0, h, sizeof (console_state), m, created);
+  if (m == SH_SHARED_CONSOLE)
+    cygheap->shared_regions.console_shared_addr = res;
   return res;
 }
 
index b0aef2ebec00f3080f5f8d9acc4ec5d23d48352c..864e2f4d5009a802aeb8c3040f9fe07b1a3772ed 100644 (file)
@@ -860,8 +860,11 @@ format_process_maps (void *data, char *&destbuf)
   /* The heap info on the cygheap is also in the same spot in each process
      because the cygheap is located at the same address. */
   user_heap_info user_heap;
+  shared_region_info region_info;
   ReadProcessMemory (proc, &cygheap->user_heap, &user_heap,
                     sizeof user_heap, NULL);
+  ReadProcessMemory (proc, &cygheap->shared_regions, &region_info,
+                    sizeof region_info, NULL);
 
   off_t len = 0;
 
@@ -1060,12 +1063,14 @@ peb_teb_rinse_repeat:
                    strcpy (posix_modname, "[peb]");
                  else if (cur.abase == (char *) &SharedUserData)
                    strcpy (posix_modname, "[shared-user-data]");
-                 else if (cur.abase == (char *) cygwin_shared)
+                 else if (cur.abase == region_info.cygwin_shared_addr)
                    strcpy (posix_modname, "[cygwin-shared]");
-                 else if (cur.abase == (char *) user_shared)
+                 else if (cur.abase == region_info.user_shared_addr)
                    strcpy (posix_modname, "[cygwin-user-shared]");
-                 else if (cur.abase == (char *) *proc_pinfo)
+                 else if (cur.abase == region_info.myself_shared_addr)
                    strcpy (posix_modname, "[procinfo]");
+                 else if (cur.abase == region_info.console_shared_addr)
+                   strcpy (posix_modname, "[cygwin-shared-console]");
                  else if (cur.abase == (char *) cygheap)
                    strcpy (posix_modname, "[cygheap]");
                  else if (cur.abase == user_heap.base)
index ceff0fdcf0ba3fdfaa872c993f4b81479da47922..d885ca1230856c2d9a4a6310155d136656309463 100644 (file)
@@ -302,6 +302,15 @@ struct user_heap_info
   void init ();
 };
 
+/* This info is maintained for /proc/<PID>/maps ONLY! */
+struct shared_region_info
+{
+  void *cygwin_shared_addr;
+  void *user_shared_addr;
+  void *myself_shared_addr;
+  void *console_shared_addr;
+};
+
 class cygheap_domain_info
 {
   PWCHAR pdom_name;
@@ -503,6 +512,7 @@ struct init_cygheap: public mini_cygheap
   cygheap_ugid_cache ugid_cache;
   cygheap_user user;
   user_heap_info user_heap;
+  shared_region_info shared_regions;
   mode_t umask;
   LONG rlim_as_id;
   unsigned long rlim_core;
index d23cc8e0e510254136665e541b47d6dfdbfbd6c9..d7d6547ec3bb65d7d3226b2809267b954845c86f 100644 (file)
@@ -274,6 +274,7 @@ user_info::create (bool reinit)
   debug_printf ("user shared version %x", user_shared->version);
   if (reinit)
     user_shared->initialize ();
+  cygheap->shared_regions.user_shared_addr = user_shared;
 }
 
 void
@@ -315,6 +316,7 @@ shared_info::create ()
                                               SH_CYGWIN_SHARED,
                                               &sec_all_nih);
   cygwin_shared->initialize ();
+  cygheap->shared_regions.cygwin_shared_addr = cygwin_shared;
 }
 
 void
index c05cf2662cd711f097fac9b425eeef45145a5839..37770b643ef6b87d6d802514045b6594b3f511e5 100644 (file)
@@ -466,6 +466,8 @@ pinfo::init (pid_t n, DWORD flag, HANDLE h0)
       h = h0;
       _pinfo_release ();
     }
+  if (shloc == SH_MYSELF)
+    cygheap->shared_regions.myself_shared_addr = procinfo;
 }
 
 void
This page took 0.042165 seconds and 5 git commands to generate.