From 6c74e69d12b7d6e55f74f7a330e658cd589752bb Mon Sep 17 00:00:00 2001 From: Katayama Hirofumi MZ Date: Tue, 9 Jul 2024 04:22:14 +0900 Subject: [PATCH] [NTUSER][USER32] Populate dwExpWinVer (#7095) This value is needed for SetWindowPlacement and IMM. JIRA issue: CORE-19675 JIRA issue: CORE-19268 - Add RtlGetExpWinVer function into win32ss/user/rtl/image.c. - Add RtlGetExpWinVer prototype into win32ss/include/ntuser.h. - Delete RtlGetExpWinVer definition in win32ss/user/user32/windows/window.c. - Populate THREADINFO.dwExpWinVer and CLIENTINFO.dwExpWinVer by using RtlGetExpWinVer in InitThreadCallback function. --- win32ss/CMakeLists.txt | 1 + win32ss/include/ntuser.h | 3 ++ win32ss/user/ntuser/main.c | 8 ++++- win32ss/user/rtl/image.c | 46 ++++++++++++++++++++++++++++ win32ss/user/user32/CMakeLists.txt | 1 + win32ss/user/user32/windows/window.c | 28 ----------------- 6 files changed, 58 insertions(+), 29 deletions(-) create mode 100644 win32ss/user/rtl/image.c diff --git a/win32ss/CMakeLists.txt b/win32ss/CMakeLists.txt index afe4b35627b..ebf0084dcad 100644 --- a/win32ss/CMakeLists.txt +++ b/win32ss/CMakeLists.txt @@ -164,6 +164,7 @@ list(APPEND SOURCE user/ntuser/winpos.c user/ntuser/winsta.c user/ntuser/object.c + user/rtl/image.c user/rtl/text.c gdi/ntgdi/arc.c gdi/ntgdi/bezier.c diff --git a/win32ss/include/ntuser.h b/win32ss/include/ntuser.h index 2148546a980..9803eb1bce3 100644 --- a/win32ss/include/ntuser.h +++ b/win32ss/include/ntuser.h @@ -3628,6 +3628,9 @@ NtUserSetScrollBarInfo( LONG idObject, SETSCROLLBARINFO *info); +ULONG +RtlGetExpWinVer(_In_ PVOID BaseAddress); + #endif /* __WIN32K_NTUSER_H */ /* EOF */ diff --git a/win32ss/user/ntuser/main.c b/win32ss/user/ntuser/main.c index 4bfd95c93c7..84881a8831e 100644 --- a/win32ss/user/ntuser/main.c +++ b/win32ss/user/ntuser/main.c @@ -451,7 +451,6 @@ UserThreadDestroy(PETHREAD Thread) return STATUS_SUCCESS; } -/* Win: xxxCreateThreadInfo */ NTSTATUS NTAPI InitThreadCallback(PETHREAD Thread) { @@ -556,6 +555,13 @@ InitThreadCallback(PETHREAD Thread) pci->CodePage = pDefKL->CodePage; } + /* Populate dwExpWinVer */ + if (Process->Peb) + ptiCurrent->dwExpWinVer = RtlGetExpWinVer(Process->SectionBaseAddress); + else + ptiCurrent->dwExpWinVer = WINVER_WINNT4; + pci->dwExpWinVer = ptiCurrent->dwExpWinVer; + /* Need to pass the user Startup Information to the current process. */ if ( ProcessParams ) { diff --git a/win32ss/user/rtl/image.c b/win32ss/user/rtl/image.c new file mode 100644 index 00000000000..7ec9cce35cd --- /dev/null +++ b/win32ss/user/rtl/image.c @@ -0,0 +1,46 @@ +/* + * PROJECT: ReactOS user32.dll and win32k.sys + * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later) + * PURPOSE: RtlGetExpWinVer function + * COPYRIGHT: Copyright 2019 James Tabor + * Copyright 2024 Katayama Hirofumi MZ + */ + +#ifdef _WIN32K_ +#include +DBG_DEFAULT_CHANNEL(UserMisc); +#else +#include +#include +WINE_DEFAULT_DEBUG_CHANNEL(user32); +#endif + +/* Get the expected OS version from the application module */ +ULONG +RtlGetExpWinVer(_In_ PVOID BaseAddress) +{ + ULONG dwMajorVersion = 3, dwMinorVersion = 10; /* Set default to Windows 3.10 (WINVER_WIN31) */ + PIMAGE_NT_HEADERS pNTHeader; + ULONG_PTR AlignedAddress = (ULONG_PTR)BaseAddress; + + TRACE("(%p)\n", BaseAddress); + + /* Remove the magic flag for non-mapped images */ + if (AlignedAddress & 1) + AlignedAddress = (AlignedAddress & ~1); + + if (AlignedAddress && !LOWORD(AlignedAddress)) + { + pNTHeader = RtlImageNtHeader((PVOID)AlignedAddress); + if (pNTHeader) + { + dwMajorVersion = pNTHeader->OptionalHeader.MajorSubsystemVersion; + if (dwMajorVersion == 1) + dwMajorVersion = 3; + else + dwMinorVersion = pNTHeader->OptionalHeader.MinorSubsystemVersion; + } + } + + return MAKEWORD(dwMinorVersion, dwMajorVersion); +} diff --git a/win32ss/user/user32/CMakeLists.txt b/win32ss/user/user32/CMakeLists.txt index 66bbe21f9b8..ca2f2a143e2 100644 --- a/win32ss/user/user32/CMakeLists.txt +++ b/win32ss/user/user32/CMakeLists.txt @@ -62,6 +62,7 @@ list(APPEND SOURCE windows/text.c windows/window.c windows/winpos.c + ${REACTOS_SOURCE_DIR}/win32ss/user/rtl/image.c ${REACTOS_SOURCE_DIR}/win32ss/user/rtl/text.c ${CMAKE_CURRENT_BINARY_DIR}/user32_stubs.c include/user32.h) diff --git a/win32ss/user/user32/windows/window.c b/win32ss/user/user32/windows/window.c index a0efdfab2b2..dfe06a349c5 100644 --- a/win32ss/user/user32/windows/window.c +++ b/win32ss/user/user32/windows/window.c @@ -148,34 +148,6 @@ RtlFreeLargeString( } } -DWORD -FASTCALL -RtlGetExpWinVer(HMODULE hModule) -{ - DWORD dwMajorVersion = 3; // Set default to Windows 3.10. - DWORD dwMinorVersion = 10; - PIMAGE_NT_HEADERS pinth; - - if (hModule && !LOWORD((ULONG_PTR)hModule)) - { - pinth = RtlImageNtHeader(hModule); - if (pinth) - { - dwMajorVersion = pinth->OptionalHeader.MajorSubsystemVersion; - - if (dwMajorVersion == 1) - { - dwMajorVersion = 3; - } - else - { - dwMinorVersion = pinth->OptionalHeader.MinorSubsystemVersion; - } - } - } - return MAKELONG(MAKEWORD(dwMinorVersion, dwMajorVersion), 0); -} - HWND WINAPI User32CreateWindowEx(DWORD dwExStyle, LPCSTR lpClassName,