From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 07B033858D28; Tue, 17 Jan 2023 21:47:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 07B033858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673992039; bh=+gY5VzB2uVuOdCVe8oLu23miICOh0P1gViAHJh9u2oE=; h=From:To:Subject:Date:From; b=xRrvIwIHh90NYtShWIwtHuk50U681+1x0f/aMeFLY3qnKiGMAUX3GM39Vu06Ovpw3 DNhp9RIPLmllvpomfqgFjW2UhUtD+uesp9RX+z4BHfqkrj+sXbwV8sOkCEpnvzpwEt FnogQveU4cwgDulMRlxWldk8BB9QnKVyhFoXCLZ4= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/main] Cygwin: /proc//maps: print real shared region addresses X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/main X-Git-Oldrev: 8d318bf142f7d740172099bfa23b6983eb8379ae X-Git-Newrev: 9ddd48ee1b8d736ebbd0b0bdf146ecf96774cd8a Message-Id: <20230117214719.07B033858D28@sourceware.org> Date: Tue, 17 Jan 2023 21:47:19 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D9ddd48ee1b8= d736ebbd0b0bdf146ecf96774cd8a commit 9ddd48ee1b8d736ebbd0b0bdf146ecf96774cd8a Author: Corinna Vinschen AuthorDate: Tue Jan 17 21:58:06 2023 +0100 Commit: Corinna Vinschen CommitDate: Tue Jan 17 22:00:48 2023 +0100 Cygwin: /proc//maps: print real shared region addresses =20 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. =20 Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/fhandler/console.cc | 2 ++ winsup/cygwin/fhandler/process.cc | 11 ++++++++--- winsup/cygwin/local_includes/cygheap.h | 10 ++++++++++ winsup/cygwin/mm/shared.cc | 2 ++ winsup/cygwin/pinfo.cc | 2 ++ 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/con= sole.cc index 68ab43d81ea1..0cbfe4ea41f4 100644 --- a/winsup/cygwin/fhandler/console.cc +++ b/winsup/cygwin/fhandler/console.cc @@ -219,6 +219,8 @@ fhandler_console::open_shared_console (HWND hw, HANDLE&= h, bool& created) shared_locations m =3D created ? SH_SHARED_CONSOLE : SH_JUSTOPEN; console_state *res =3D (console_state *) open_shared (namebuf, 0, h, sizeof (console_state), m, created); + if (m =3D=3D SH_SHARED_CONSOLE) + cygheap->shared_regions.console_shared_addr =3D res; return res; } =20 diff --git a/winsup/cygwin/fhandler/process.cc b/winsup/cygwin/fhandler/pro= cess.cc index b0aef2ebec00..864e2f4d5009 100644 --- a/winsup/cygwin/fhandler/process.cc +++ b/winsup/cygwin/fhandler/process.cc @@ -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, ®ion_info, + sizeof region_info, NULL); =20 off_t len =3D 0; =20 @@ -1060,12 +1063,14 @@ peb_teb_rinse_repeat: strcpy (posix_modname, "[peb]"); else if (cur.abase =3D=3D (char *) &SharedUserData) strcpy (posix_modname, "[shared-user-data]"); - else if (cur.abase =3D=3D (char *) cygwin_shared) + else if (cur.abase =3D=3D region_info.cygwin_shared_addr) strcpy (posix_modname, "[cygwin-shared]"); - else if (cur.abase =3D=3D (char *) user_shared) + else if (cur.abase =3D=3D region_info.user_shared_addr) strcpy (posix_modname, "[cygwin-user-shared]"); - else if (cur.abase =3D=3D (char *) *proc_pinfo) + else if (cur.abase =3D=3D region_info.myself_shared_addr) strcpy (posix_modname, "[procinfo]"); + else if (cur.abase =3D=3D region_info.console_shared_addr) + strcpy (posix_modname, "[cygwin-shared-console]"); else if (cur.abase =3D=3D (char *) cygheap) strcpy (posix_modname, "[cygheap]"); else if (cur.abase =3D=3D user_heap.base) diff --git a/winsup/cygwin/local_includes/cygheap.h b/winsup/cygwin/local_i= ncludes/cygheap.h index ceff0fdcf0ba..d885ca123085 100644 --- a/winsup/cygwin/local_includes/cygheap.h +++ b/winsup/cygwin/local_includes/cygheap.h @@ -302,6 +302,15 @@ struct user_heap_info void init (); }; =20 +/* This info is maintained for /proc//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; diff --git a/winsup/cygwin/mm/shared.cc b/winsup/cygwin/mm/shared.cc index d23cc8e0e510..d7d6547ec3bb 100644 --- a/winsup/cygwin/mm/shared.cc +++ b/winsup/cygwin/mm/shared.cc @@ -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 =3D user_shared; } =20 void @@ -315,6 +316,7 @@ shared_info::create () SH_CYGWIN_SHARED, &sec_all_nih); cygwin_shared->initialize (); + cygheap->shared_regions.cygwin_shared_addr =3D cygwin_shared; } =20 void diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index c05cf2662cd7..37770b643ef6 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -466,6 +466,8 @@ pinfo::init (pid_t n, DWORD flag, HANDLE h0) h =3D h0; _pinfo_release (); } + if (shloc =3D=3D SH_MYSELF) + cygheap->shared_regions.myself_shared_addr =3D procinfo; } =20 void