Alexandre Julliard : kernel32: Reimplement GetProcessVersion() in kernelbase.

Alexandre Julliard julliard at winehq.org
Tue May 26 17:17:06 CDT 2020


Module: wine
Branch: master
Commit: fc173ccca8734f6c6d54fcf56e763d4557e9eb48
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=fc173ccca8734f6c6d54fcf56e763d4557e9eb48

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue May 26 13:23:33 2020 +0200

kernel32: Reimplement GetProcessVersion() in kernelbase.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/kernel32/kernel32.spec     |  2 +-
 dlls/kernel32/process.c         | 55 -----------------------------------------
 dlls/kernelbase/kernelbase.spec |  2 +-
 dlls/kernelbase/process.c       | 23 +++++++++++++++++
 4 files changed, 25 insertions(+), 57 deletions(-)

diff --git a/dlls/kernel32/kernel32.spec b/dlls/kernel32/kernel32.spec
index a095a85e66..1a6fdbab01 100644
--- a/dlls/kernel32/kernel32.spec
+++ b/dlls/kernel32/kernel32.spec
@@ -793,7 +793,7 @@
 # @ stub GetProcessorSystemCycleTime
 @ stdcall -import GetProcessTimes(long ptr ptr ptr ptr)
 # @ stub GetProcessUserModeExceptionPolicy
-@ stdcall GetProcessVersion(long)
+@ stdcall -import GetProcessVersion(long)
 @ stdcall GetProcessWorkingSetSize(long ptr ptr)
 @ stdcall -import GetProcessWorkingSetSizeEx(long ptr ptr ptr)
 @ stdcall -import GetProductInfo(long long long long ptr)
diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c
index f628f96f36..1c3ed9938f 100644
--- a/dlls/kernel32/process.c
+++ b/dlls/kernel32/process.c
@@ -451,61 +451,6 @@ BOOL WINAPI GetProcessAffinityMask( HANDLE hProcess, PDWORD_PTR process_mask, PD
 }
 
 
-/***********************************************************************
- *           GetProcessVersion    (KERNEL32.@)
- */
-DWORD WINAPI GetProcessVersion( DWORD pid )
-{
-    HANDLE process;
-    NTSTATUS status;
-    PROCESS_BASIC_INFORMATION pbi;
-    SIZE_T count;
-    PEB peb;
-    IMAGE_DOS_HEADER dos;
-    IMAGE_NT_HEADERS nt;
-    DWORD ver = 0;
-
-    if (!pid || pid == GetCurrentProcessId())
-    {
-        IMAGE_NT_HEADERS *pnt;
-
-        if ((pnt = RtlImageNtHeader( NtCurrentTeb()->Peb->ImageBaseAddress )))
-            return ((pnt->OptionalHeader.MajorSubsystemVersion << 16) |
-                    pnt->OptionalHeader.MinorSubsystemVersion);
-        return 0;
-    }
-
-    process = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, FALSE, pid);
-    if (!process) return 0;
-
-    status = NtQueryInformationProcess(process, ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
-    if (status) goto err;
-
-    status = NtReadVirtualMemory(process, pbi.PebBaseAddress, &peb, sizeof(peb), &count);
-    if (status || count != sizeof(peb)) goto err;
-
-    memset(&dos, 0, sizeof(dos));
-    status = NtReadVirtualMemory(process, peb.ImageBaseAddress, &dos, sizeof(dos), &count);
-    if (status || count != sizeof(dos)) goto err;
-    if (dos.e_magic != IMAGE_DOS_SIGNATURE) goto err;
-
-    memset(&nt, 0, sizeof(nt));
-    status = NtReadVirtualMemory(process, (char *)peb.ImageBaseAddress + dos.e_lfanew, &nt, sizeof(nt), &count);
-    if (status || count != sizeof(nt)) goto err;
-    if (nt.Signature != IMAGE_NT_SIGNATURE) goto err;
-
-    ver = MAKELONG(nt.OptionalHeader.MinorSubsystemVersion, nt.OptionalHeader.MajorSubsystemVersion);
-
-err:
-    CloseHandle(process);
-
-    if (status != STATUS_SUCCESS)
-        SetLastError(RtlNtStatusToDosError(status));
-
-    return ver;
-}
-
-
 /***********************************************************************
  *		SetProcessWorkingSetSize	[KERNEL32.@]
  * Sets the min/max working set sizes for a specified process.
diff --git a/dlls/kernelbase/kernelbase.spec b/dlls/kernelbase/kernelbase.spec
index d85c36c6e5..986cd851ed 100644
--- a/dlls/kernelbase/kernelbase.spec
+++ b/dlls/kernelbase/kernelbase.spec
@@ -636,7 +636,7 @@
 @ stdcall GetProcessPriorityBoost(long ptr)
 @ stdcall GetProcessShutdownParameters(ptr ptr)
 @ stdcall GetProcessTimes(long ptr ptr ptr ptr)
-@ stdcall GetProcessVersion(long) kernel32.GetProcessVersion
+@ stdcall GetProcessVersion(long)
 @ stdcall GetProcessWorkingSetSizeEx(long ptr ptr ptr)
 # @ stub GetProcessorSystemCycleTime
 @ stdcall GetProductInfo(long long long long ptr)
diff --git a/dlls/kernelbase/process.c b/dlls/kernelbase/process.c
index 66e115ce69..a3b168543f 100644
--- a/dlls/kernelbase/process.c
+++ b/dlls/kernelbase/process.c
@@ -814,6 +814,29 @@ BOOL WINAPI DECLSPEC_HOTPATCH GetProcessTimes( HANDLE process, FILETIME *create,
 }
 
 
+/***********************************************************************
+ *           GetProcessVersion   (kernelbase.@)
+ */
+DWORD WINAPI DECLSPEC_HOTPATCH GetProcessVersion( DWORD pid )
+{
+    SECTION_IMAGE_INFORMATION info;
+    NTSTATUS status;
+    HANDLE process;
+
+    if (pid && pid != GetCurrentProcessId())
+    {
+        if (!(process = OpenProcess( PROCESS_QUERY_INFORMATION, FALSE, pid ))) return 0;
+        status = NtQueryInformationProcess( process, ProcessImageInformation, &info, sizeof(info), NULL );
+        CloseHandle( process );
+    }
+    else status = NtQueryInformationProcess( GetCurrentProcess(), ProcessImageInformation,
+                                             &info, sizeof(info), NULL );
+
+    if (!set_ntstatus( status )) return 0;
+    return MAKELONG( info.SubsystemVersionLow, info.SubsystemVersionHigh );
+}
+
+
 /***********************************************************************
  *           GetProcessWorkingSetSizeEx   (kernelbase.@)
  */




More information about the wine-cvs mailing list