https://git.reactos.org/?p=reactos.git;a=commitdiff;h=be9a788f8bb2c75974ca2…
commit be9a788f8bb2c75974ca219502d861c499cac439
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Mon Sep 27 09:31:16 2021 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Mon Sep 27 09:31:16 2021 +0900
[IMM32] Improve Imm32CleanupContext and ImmLockClientImc (#3974)
- Improve Imm32CleanupContext and ImmLockClientImc functions.
- Add ValidateHandleNoErr and Imm32CheckImcProcess helper functions.
CORE-11700
---
dll/win32/imm32/imm.c | 27 ++++++++++++---------------
dll/win32/imm32/precomp.h | 2 ++
dll/win32/imm32/utils.c | 39 ++++++++++++++++++++++++++++-----------
3 files changed, 42 insertions(+), 26 deletions(-)
diff --git a/dll/win32/imm32/imm.c b/dll/win32/imm32/imm.c
index 3297fa085e9..9fecb94c183 100644
--- a/dll/win32/imm32/imm.c
+++ b/dll/win32/imm32/imm.c
@@ -336,23 +336,21 @@ static VOID APIENTRY Imm32CleanupContextExtra(LPINPUTCONTEXT pIC)
FIXME("We have to do something do here");
}
-static PCLIENTIMC APIENTRY Imm32FindClientImc(HIMC hIMC)
-{
- // FIXME
- return NULL;
-}
-
BOOL APIENTRY Imm32CleanupContext(HIMC hIMC, HKL hKL, BOOL bKeep)
{
PIMEDPI pImeDpi;
LPINPUTCONTEXT pIC;
PCLIENTIMC pClientImc;
+ PIMC pIMC;
if (!Imm32IsImmMode() || hIMC == NULL)
return FALSE;
- FIXME("We have do something to do here\n");
- pClientImc = Imm32FindClientImc(hIMC);
+ pIMC = ValidateHandleNoErr(hIMC, TYPE_INPUTCONTEXT);
+ if (!pIMC || pIMC->head.pti != NtCurrentTeb()->Win32ThreadInfo)
+ return FALSE;
+
+ pClientImc = (PCLIENTIMC)pIMC->dwClientImcData;
if (!pClientImc)
return FALSE;
@@ -430,17 +428,12 @@ BOOL WINAPI ImmDestroyContext(HIMC hIMC)
return Imm32CleanupContext(hIMC, hKL, FALSE);
}
-static PCLIENTIMC APIENTRY Imm32GetClientImcCache(void)
-{
- // FIXME: Do something properly here
- return NULL;
-}
-
/***********************************************************************
* ImmLockClientImc (IMM32.@)
*/
PCLIENTIMC WINAPI ImmLockClientImc(HIMC hImc)
{
+ PIMC pIMC;
PCLIENTIMC pClientImc;
TRACE("(%p)\n", hImc);
@@ -448,7 +441,11 @@ PCLIENTIMC WINAPI ImmLockClientImc(HIMC hImc)
if (hImc == NULL)
return NULL;
- pClientImc = Imm32GetClientImcCache();
+ pIMC = ValidateHandleNoErr(hImc, TYPE_INPUTCONTEXT);
+ if (pIMC == NULL || !Imm32CheckImcProcess(pIMC))
+ return NULL;
+
+ pClientImc = (PCLIENTIMC)pIMC->dwClientImcData;
if (!pClientImc)
{
pClientImc = Imm32HeapAlloc(HEAP_ZERO_MEMORY, sizeof(CLIENTIMC));
diff --git a/dll/win32/imm32/precomp.h b/dll/win32/imm32/precomp.h
index b914f8f625a..7bab3b95031 100644
--- a/dll/win32/imm32/precomp.h
+++ b/dll/win32/imm32/precomp.h
@@ -72,6 +72,8 @@ BOOL Imm32GetSystemLibraryPath(LPWSTR pszPath, DWORD cchPath, LPCWSTR
pszFileNam
VOID APIENTRY LogFontAnsiToWide(const LOGFONTA *plfA, LPLOGFONTW plfW);
VOID APIENTRY LogFontWideToAnsi(const LOGFONTW *plfW, LPLOGFONTA plfA);
PWND FASTCALL ValidateHwndNoErr(HWND hwnd);
+LPVOID FASTCALL ValidateHandleNoErr(HANDLE hObject, UINT uType);
+BOOL APIENTRY Imm32CheckImcProcess(PIMC pIMC);
LPVOID APIENTRY Imm32HeapAlloc(DWORD dwFlags, DWORD dwBytes);
#define Imm32HeapFree(lpData) HeapFree(g_hImm32Heap, 0, (lpData))
diff --git a/dll/win32/imm32/utils.c b/dll/win32/imm32/utils.c
index 2289ea895e0..17a7efb5179 100644
--- a/dll/win32/imm32/utils.c
+++ b/dll/win32/imm32/utils.c
@@ -72,19 +72,14 @@ VOID APIENTRY LogFontWideToAnsi(const LOGFONTW *plfW, LPLOGFONTA
plfA)
plfA->lfFaceName[cch] = 0;
}
-PWND FASTCALL ValidateHwndNoErr(HWND hwnd)
+LPVOID FASTCALL ValidateHandleNoErr(HANDLE hObject, UINT uType)
{
- PCLIENTINFO ClientInfo = GetWin32ClientInfo();
INT index;
PUSER_HANDLE_TABLE ht;
PUSER_HANDLE_ENTRY he;
WORD generation;
- /* See if the window is cached */
- if (hwnd == ClientInfo->CallbackWnd.hWnd)
- return ClientInfo->CallbackWnd.pWnd;
-
- if (!NtUserValidateHandleSecure(hwnd))
+ if (!NtUserValidateHandleSecure(hObject))
return NULL;
ht = g_SharedInfo.aheList; /* handle table */
@@ -93,15 +88,37 @@ PWND FASTCALL ValidateHwndNoErr(HWND hwnd)
ASSERT(g_SharedInfo.ulSharedDelta != 0);
he = (PUSER_HANDLE_ENTRY)((ULONG_PTR)ht->handles - g_SharedInfo.ulSharedDelta);
- index = (LOWORD(hwnd) - FIRST_USER_HANDLE) >> 1;
- if (index < 0 || index >= ht->nb_handles || he[index].type != TYPE_WINDOW)
+ index = (LOWORD(hObject) - FIRST_USER_HANDLE) >> 1;
+ if (index < 0 || ht->nb_handles <= index || he[index].type != uType)
return NULL;
- generation = HIWORD(hwnd);
+ generation = HIWORD(hObject);
if (generation != he[index].generation && generation && generation !=
0xFFFF)
return NULL;
- return (PWND)&he[index];
+ return &he[index];
+}
+
+PWND FASTCALL ValidateHwndNoErr(HWND hwnd)
+{
+ /* See if the window is cached */
+ PCLIENTINFO ClientInfo = GetWin32ClientInfo();
+ if (hwnd == ClientInfo->CallbackWnd.hWnd)
+ return ClientInfo->CallbackWnd.pWnd;
+
+ return ValidateHandleNoErr(hwnd, TYPE_WINDOW);
+}
+
+BOOL APIENTRY Imm32CheckImcProcess(PIMC pIMC)
+{
+ HIMC hIMC;
+ DWORD dwProcessID;
+ if (pIMC->head.pti == NtCurrentTeb()->Win32ThreadInfo)
+ return TRUE;
+
+ hIMC = pIMC->head.h;
+ dwProcessID = NtUserQueryInputContext(hIMC, 0);
+ return dwProcessID == (DWORD_PTR)NtCurrentTeb()->ClientId.UniqueProcess;
}
LPVOID APIENTRY Imm32HeapAlloc(DWORD dwFlags, DWORD dwBytes)