From 152924c9e42dce9d82daccebc77ba357e6bb5726 Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Fri, 8 Sep 2023 12:33:22 +0100 Subject: [PATCH] ntdll: Store the codepage data addresses in both PEBs. Spotted by Jactry Zeng. --- dlls/ntdll/locale.c | 11 +++++++++++ dlls/ntdll/tests/wow64.c | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/dlls/ntdll/locale.c b/dlls/ntdll/locale.c index a5777117cfa..545cc628909 100644 --- a/dlls/ntdll/locale.c +++ b/dlls/ntdll/locale.c @@ -89,6 +89,13 @@ invalid: return STATUS_INVALID_PARAMETER; } +static PEB64 *get_peb64( void ) +{ + TEB64 *teb64 = NtCurrentTeb64(); + + if (!teb64) return NULL; + return (PEB64 *)(UINT_PTR)teb64->Peb; +} void locale_init(void) { @@ -101,6 +108,7 @@ void locale_init(void) void *ansi_ptr = utf8, *oem_ptr = utf8, *case_ptr; NTSTATUS status; const struct locale_nls_header *header; + PEB64 *peb64 = get_peb64(); status = RtlGetLocaleFileMappingAddress( (void **)&header, &system_lcid, &unused ); if (status) @@ -158,15 +166,18 @@ void locale_init(void) NtGetNlsSectionPtr( 10, 0, NULL, &case_ptr, &size ); NtCurrentTeb()->Peb->UnicodeCaseTableData = case_ptr; + if (peb64) peb64->UnicodeCaseTableData = PtrToUlong( case_ptr ); if (ansi_cp != CP_UTF8) { NtGetNlsSectionPtr( 11, ansi_cp, NULL, &ansi_ptr, &size ); NtCurrentTeb()->Peb->AnsiCodePageData = ansi_ptr; + if (peb64) peb64->AnsiCodePageData = PtrToUlong( ansi_ptr ); } if (oem_cp != CP_UTF8) { NtGetNlsSectionPtr( 11, oem_cp, NULL, &oem_ptr, &size ); NtCurrentTeb()->Peb->OemCodePageData = oem_ptr; + if (peb64) peb64->OemCodePageData = PtrToUlong( oem_ptr ); } RtlInitNlsTables( ansi_ptr, oem_ptr, case_ptr, &nls_info ); NlsAnsiCodePage = nls_info.AnsiTableInfo.CodePage; diff --git a/dlls/ntdll/tests/wow64.c b/dlls/ntdll/tests/wow64.c index 4e9107ded9d..12ad7329816 100644 --- a/dlls/ntdll/tests/wow64.c +++ b/dlls/ntdll/tests/wow64.c @@ -875,6 +875,15 @@ static void test_peb_teb(void) peb64->OSBuildNumber, NtCurrentTeb()->Peb->OSBuildNumber ); ok( peb64->OSPlatformId == NtCurrentTeb()->Peb->OSPlatformId, "wrong OSPlatformId %lx / %lx\n", peb64->OSPlatformId, NtCurrentTeb()->Peb->OSPlatformId ); + ok( peb64->AnsiCodePageData == PtrToUlong( NtCurrentTeb()->Peb->AnsiCodePageData ), + "wrong AnsiCodePageData %I64x / %p\n", + peb64->AnsiCodePageData, NtCurrentTeb()->Peb->AnsiCodePageData ); + ok( peb64->OemCodePageData == PtrToUlong( NtCurrentTeb()->Peb->OemCodePageData ), + "wrong OemCodePageData %I64x / %p\n", + peb64->OemCodePageData, NtCurrentTeb()->Peb->OemCodePageData ); + ok( peb64->UnicodeCaseTableData == PtrToUlong( NtCurrentTeb()->Peb->UnicodeCaseTableData ), + "wrong UnicodeCaseTableData %I64x / %p\n", + peb64->UnicodeCaseTableData, NtCurrentTeb()->Peb->UnicodeCaseTableData ); return; } #endif