From 0f5776c47ca08c31c939f4b9faf6c105b61fa688 Mon Sep 17 00:00:00 2001 From: Michael Haubenwallner Date: Tue, 30 Apr 2019 16:14:55 +0200 Subject: [PATCH] Cygwin: dll_list: stat_real_file_once as dll method Make stat_real_file_once a method of struct dll, to be more flexible on where to use. Also, debug print memory section name queried for a dll. This is a preparation to query the file id when loading the dll. --- winsup/cygwin/dll_init.h | 1 + winsup/cygwin/forkable.cc | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/winsup/cygwin/dll_init.h b/winsup/cygwin/dll_init.h index 0a9749638..e4fbde867 100644 --- a/winsup/cygwin/dll_init.h +++ b/winsup/cygwin/dll_init.h @@ -65,6 +65,7 @@ struct dll void detach (); int init (); + bool stat_real_file_once (); void nominate_forkable (PCWCHAR); bool create_forkable (); void run_dtors () diff --git a/winsup/cygwin/forkable.cc b/winsup/cygwin/forkable.cc index 30833c406..912a9ac8c 100644 --- a/winsup/cygwin/forkable.cc +++ b/winsup/cygwin/forkable.cc @@ -155,10 +155,10 @@ rmdirs (WCHAR ntmaxpathbuf[NT_MAX_PATH]) file name, as GetModuleFileNameW () yields the as-loaded name. While we have the file handle open, also read the attributes. NOTE: Uses dll_list::nt_max_path_buf (). */ -static bool -stat_real_file_once (dll *d) +bool +dll::stat_real_file_once () { - if (d->fii.IndexNumber.QuadPart != -1LL) + if (fii.IndexNumber.QuadPart != -1LL) return true; tmp_pathbuf tp; @@ -171,35 +171,37 @@ stat_real_file_once (dll *d) RtlInitEmptyUnicodeString (&msi2.SectionFileName, tp.w_get (), 65535); /* Retry opening the real file name until that does not change any more. */ - status = NtQueryVirtualMemory (NtCurrentProcess (), d->handle, + status = NtQueryVirtualMemory (NtCurrentProcess (), handle, MemorySectionName, pmsi1, 65536, NULL); while (NT_SUCCESS (status) && !RtlEqualUnicodeString (&msi2.SectionFileName, &pmsi1->SectionFileName, FALSE)) { + debug_printf ("for %s at %p got memory section name '%W'", + ntname, handle, pmsi1->SectionFileName.Buffer); RtlCopyUnicodeString (&msi2.SectionFileName, &pmsi1->SectionFileName); if (fhandle != INVALID_HANDLE_VALUE) NtClose (fhandle); pmsi1->SectionFileName.Buffer[pmsi1->SectionFileName.Length] = L'\0'; fhandle = dll_list::ntopenfile (pmsi1->SectionFileName.Buffer, &fstatus); - status = NtQueryVirtualMemory (NtCurrentProcess (), d->handle, + status = NtQueryVirtualMemory (NtCurrentProcess (), handle, MemorySectionName, pmsi1, 65536, NULL); } if (!NT_SUCCESS (status)) system_printf ("WARNING: Unable (ntstatus %y) to query real file for %W", - status, d->ntname); + status, ntname); else if (fhandle == INVALID_HANDLE_VALUE) system_printf ("WARNING: Unable (ntstatus %y) to open real file for %W", - fstatus, d->ntname); + fstatus, ntname); if (fhandle == INVALID_HANDLE_VALUE) return false; - if (!dll_list::read_fii (fhandle, &d->fii)) + if (!dll_list::read_fii (fhandle, &fii)) system_printf ("WARNING: Unable to read real file attributes for %W", pmsi1->SectionFileName.Buffer); NtClose (fhandle); - return d->fii.IndexNumber.QuadPart != -1LL; + return fii.IndexNumber.QuadPart != -1LL; } /* easy use of NtOpenFile */ @@ -605,7 +607,7 @@ dll_list::prepare_forkables_nomination () { dll *d = &dlls.start; while ((d = d->next)) - stat_real_file_once (d); /* uses nt_max_path_buf () */ + d->stat_real_file_once (); /* uses nt_max_path_buf () */ PWCHAR pbuf = nt_max_path_buf (); -- 2.43.5