public inbox for cygwin-cvs@sourceware.org help / color / mirror / Atom feed
From: Jon TURNEY <jturney@sourceware.org> To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: Use documented QueryWorkingSetEx() in dumper Date: Fri, 7 Aug 2020 14:09:03 +0000 (GMT) [thread overview] Message-ID: <20200807140903.645893857C45@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=1be41b802ae151f0dbc4e67fd3fd1cc563978643 commit 1be41b802ae151f0dbc4e67fd3fd1cc563978643 Author: Jon Turney <jon.turney@dronecode.org.uk> Date: Wed Jul 29 15:19:13 2020 +0100 Cygwin: Use documented QueryWorkingSetEx() in dumper In dumper, use the documented QueryWorkingSetEx(), rather than the undocumented NtQueryVirtualMemory() with MemoryWorkingSetExInformation. Diff: --- winsup/utils/dumper.cc | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/winsup/utils/dumper.cc b/winsup/utils/dumper.cc index 25fd080c8..f21c93bf7 100644 --- a/winsup/utils/dumper.cc +++ b/winsup/utils/dumper.cc @@ -34,6 +34,7 @@ #include <unistd.h> #include <sys/param.h> #include <windows.h> +#include <psapi.h> #include "dumper.h" @@ -267,43 +268,20 @@ void protect_dump(DWORD protect, char *buf) strcat (buf, pt[i]); } -typedef enum _MEMORY_INFORMATION_CLASS -{ - MemoryWorkingSetExInformation = 4, // MEMORY_WORKING_SET_EX_INFORMATION -} MEMORY_INFORMATION_CLASS; - -extern "C" -NTSTATUS NTAPI -NtQueryVirtualMemory(HANDLE ProcessHandle, - LPVOID BaseAddress, - MEMORY_INFORMATION_CLASS MemoryInformationClass, - LPVOID MemoryInformation, - SIZE_T MemoryInformationLength, - SIZE_T *ReturnLength); - -typedef struct _MEMORY_WORKING_SET_EX_INFORMATION -{ - LPVOID VirtualAddress; - ULONG_PTR Long; -} MEMORY_WORKING_SET_EX_INFORMATION; - -#define MWSEI_ATTRIB_SHARED (0x1 << 15) +#define PSWSEI_ATTRIB_SHARED (0x1 << 15) static BOOL getRegionAttributes(HANDLE hProcess, LPVOID address, DWORD &attribs) { - MEMORY_WORKING_SET_EX_INFORMATION mwsei = { address }; - NTSTATUS status = NtQueryVirtualMemory(hProcess, 0, - MemoryWorkingSetExInformation, - &mwsei, sizeof(mwsei), 0); + PSAPI_WORKING_SET_EX_INFORMATION pswsei = { address }; - if (!status) + if (QueryWorkingSetEx(hProcess, &pswsei, sizeof(pswsei))) { - attribs = mwsei.Long; + attribs = pswsei.VirtualAttributes.Flags; return TRUE; } - deb_printf("MemoryWorkingSetExInformation failed status %08x\n", status); + deb_printf("QueryWorkingSetEx failed status %08x\n", GetLastError()); return FALSE; } @@ -338,7 +316,7 @@ dumper::collect_memory_sections () DWORD attribs = 0; if (getRegionAttributes(hProcess, current_page_address, attribs)) { - if (attribs & MWSEI_ATTRIB_SHARED) + if (attribs & PSWSEI_ATTRIB_SHARED) { skip_region_p = 1; disposition = "skipped due to shared MEM_IMAGE";
reply other threads:[~2020-08-07 14:09 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200807140903.645893857C45@sourceware.org \ --to=jturney@sourceware.org \ --cc=cygwin-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).