diff --git a/patches/ntdll-NtQueryInformationThread/0001-ntdll-Add-support-for-fs-to-NtQueryInformationThread.patch b/patches/ntdll-NtQueryInformationThread/0001-ntdll-Add-support-for-fs-to-NtQueryInformationThread.patch new file mode 100644 index 00000000..a65d1e47 --- /dev/null +++ b/patches/ntdll-NtQueryInformationThread/0001-ntdll-Add-support-for-fs-to-NtQueryInformationThread.patch @@ -0,0 +1,96 @@ +From 9aaa34a9cd1e72b82212933dffcbf07692d3fa64 Mon Sep 17 00:00:00 2001 +From: Dmitry Timoshkov +Date: Sat, 7 May 2016 11:56:17 +0800 +Subject: ntdll: Add support for fs to + NtQueryInformationThread(ThreadDescriptorTableEntry). + +This patch fixes one of the problems reported in the bug 40583. +--- + dlls/kernel32/tests/thread.c | 41 +++++++++++++++++++++++++++++++++++++++++ + dlls/ntdll/thread.c | 11 +++++++++++ + 2 files changed, 52 insertions(+) + +diff --git a/dlls/kernel32/tests/thread.c b/dlls/kernel32/tests/thread.c +index e0de3f9..67c5a37 100644 +--- a/dlls/kernel32/tests/thread.c ++++ b/dlls/kernel32/tests/thread.c +@@ -1100,6 +1100,46 @@ static void test_SetThreadContext(void) + CloseHandle( thread ); + } + ++static void test_GetThreadSelectorEntry(void) ++{ ++ TEB *teb = NtCurrentTeb(); ++ LDT_ENTRY entry; ++ CONTEXT ctx; ++ TEB *teb_fs; ++ DWORD ret; ++ ++ memset(&ctx, 0x11, sizeof(ctx)); ++ ctx.ContextFlags = CONTEXT_SEGMENTS | CONTEXT_CONTROL; ++ ret = GetThreadContext(GetCurrentThread(), &ctx); ++ ok(ret, "GetThreadContext error %u\n", GetLastError()); ++ ok(!HIWORD(ctx.SegCs) && !HIWORD(ctx.SegDs) && !HIWORD(ctx.SegEs) && !HIWORD(ctx.SegFs) && !HIWORD(ctx.SegGs), ++ "cs %08x, ds %08x, es %08x, fs %08x, gs %08x\n", ctx.SegCs, ctx.SegDs, ctx.SegEs, ctx.SegFs, ctx.SegGs); ++ ++ ret = GetThreadSelectorEntry(GetCurrentThread(), ctx.SegCs, &entry); ++ ok(ret, "GetThreadSelectorEntry(SegCs) error %u\n", GetLastError()); ++ ++ ret = GetThreadSelectorEntry(GetCurrentThread(), ctx.SegDs, &entry); ++ ok(ret, "GetThreadSelectorEntry(SegDs) error %u\n", GetLastError()); ++ ++ memset(&entry, 0x11, sizeof(entry)); ++ ret = GetThreadSelectorEntry(GetCurrentThread(), ctx.SegFs, &entry); ++ ok(ret, "GetThreadSelectorEntry(SegFs) error %u\n", GetLastError()); ++ ++ teb_fs = (TEB *)((entry.HighWord.Bits.BaseHi << 24) | (entry.HighWord.Bits.BaseMid << 16) | entry.BaseLow); ++ ok(teb_fs == teb, "teb_fs %p != teb %p\n", teb_fs, teb); ++ ++ ret = (entry.HighWord.Bits.LimitHi << 16) | entry.LimitLow; ++ ok(ret == 0x0fff || ret == 0x4000 /* testbot win7u */, "got %#x\n", ret); ++ ++ ok(entry.HighWord.Bits.Dpl == 3, "got %#x\n", entry.HighWord.Bits.Dpl); ++ ok(entry.HighWord.Bits.Sys == 0, "got %#x\n", entry.HighWord.Bits.Sys); ++ ok(entry.HighWord.Bits.Pres == 1, "got %#x\n", entry.HighWord.Bits.Pres); ++ ok(entry.HighWord.Bits.Granularity == 0, "got %#x\n", entry.HighWord.Bits.Granularity); ++ ok(entry.HighWord.Bits.Default_Big == 1, "got %#x\n", entry.HighWord.Bits.Default_Big); ++ ok(entry.HighWord.Bits.Type == 0x13, "got %#x\n", entry.HighWord.Bits.Type); ++ ok(entry.HighWord.Bits.Reserved_0 == 0, "got %#x\n", entry.HighWord.Bits.Reserved_0); ++} ++ + #endif /* __i386__ */ + + static HANDLE finish_event; +@@ -1965,6 +2005,7 @@ START_TEST(thread) + test_GetThreadExitCode(); + #ifdef __i386__ + test_SetThreadContext(); ++ test_GetThreadSelectorEntry(); + #endif + test_QueueUserWorkItem(); + test_RegisterWaitForSingleObject(); +diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c +index f6a5fbe..8465a26 100644 +--- a/dlls/ntdll/thread.c ++++ b/dlls/ntdll/thread.c +@@ -1051,6 +1051,17 @@ NTSTATUS WINAPI NtQueryInformationThread( HANDLE handle, THREADINFOCLASS class, + { + if (sel == (wine_get_cs() & ~3)) + tdi->Entry.HighWord.Bits.Type |= 8; /* code segment */ ++ else if (sel == (ntdll_get_thread_data()->fs & ~3)) ++ { ++ ULONG_PTR fs_base = (ULONG_PTR)NtCurrentTeb(); ++ tdi->Entry.BaseLow = fs_base & 0xffff; ++ tdi->Entry.HighWord.Bits.BaseMid = (fs_base >> 16) & 0xff; ++ tdi->Entry.HighWord.Bits.BaseHi = (fs_base >> 24) & 0xff; ++ tdi->Entry.LimitLow = 0x0fff; ++ tdi->Entry.HighWord.Bits.LimitHi = 0; ++ tdi->Entry.HighWord.Bits.Granularity = 0; ++ tdi->Entry.HighWord.Bits.Type = 0x13; ++ } + else status = STATUS_ACCESS_DENIED; + } + } +-- +2.8.0 + diff --git a/patches/ntdll-NtQueryInformationThread/definition b/patches/ntdll-NtQueryInformationThread/definition new file mode 100644 index 00000000..5bca14de --- /dev/null +++ b/patches/ntdll-NtQueryInformationThread/definition @@ -0,0 +1 @@ +Fixes: Implement support for fs segment in GetThreadSelectorEntry diff --git a/patches/ntdll-NtSetLdtEntries/0001-ntdll-Implement-NtSetLdtEntries.patch b/patches/ntdll-NtSetLdtEntries/0001-ntdll-Implement-NtSetLdtEntries.patch index e6b7eafd..f0adf5f7 100644 --- a/patches/ntdll-NtSetLdtEntries/0001-ntdll-Implement-NtSetLdtEntries.patch +++ b/patches/ntdll-NtSetLdtEntries/0001-ntdll-Implement-NtSetLdtEntries.patch @@ -1,4 +1,4 @@ -From 41b856b5d47d0d935daf5fdaf3f0fa22c4d1eaba Mon Sep 17 00:00:00 2001 +From 41ea9000f7791e23906af3ab936728c52a0ed7aa Mon Sep 17 00:00:00 2001 From: Dmitry Timoshkov Date: Thu, 28 Apr 2016 18:14:36 +0800 Subject: ntdll: Implement NtSetLdtEntries. @@ -9,7 +9,7 @@ Subject: ntdll: Implement NtSetLdtEntries. 2 files changed, 106 insertions(+), 1 deletion(-) diff --git a/dlls/kernel32/tests/thread.c b/dlls/kernel32/tests/thread.c -index e0de3f9..10a7979 100644 +index 67c5a37..5de114e 100644 --- a/dlls/kernel32/tests/thread.c +++ b/dlls/kernel32/tests/thread.c @@ -102,6 +102,7 @@ static NTSTATUS (WINAPI *pNtQueryInformationThread)(HANDLE,THREADINFOCLASS,PVOID @@ -20,8 +20,8 @@ index e0de3f9..10a7979 100644 static HANDLE create_target_process(const char *arg) { -@@ -1100,6 +1101,82 @@ static void test_SetThreadContext(void) - CloseHandle( thread ); +@@ -1140,6 +1141,82 @@ static void test_GetThreadSelectorEntry(void) + ok(entry.HighWord.Bits.Reserved_0 == 0, "got %#x\n", entry.HighWord.Bits.Reserved_0); } +static void test_NtSetLdtEntries(void) @@ -103,7 +103,7 @@ index e0de3f9..10a7979 100644 #endif /* __i386__ */ static HANDLE finish_event; -@@ -1913,6 +1990,7 @@ static void init_funcs(void) +@@ -1953,6 +2030,7 @@ static void init_funcs(void) X(NtQueryInformationThread); X(RtlGetThreadErrorMode); X(NtSetInformationThread); @@ -111,10 +111,10 @@ index e0de3f9..10a7979 100644 } #undef X } -@@ -1965,6 +2043,7 @@ START_TEST(thread) - test_GetThreadExitCode(); +@@ -2006,6 +2084,7 @@ START_TEST(thread) #ifdef __i386__ test_SetThreadContext(); + test_GetThreadSelectorEntry(); + test_NtSetLdtEntries(); #endif test_QueueUserWorkItem(); diff --git a/patches/ntdll-NtSetLdtEntries/definition b/patches/ntdll-NtSetLdtEntries/definition new file mode 100644 index 00000000..80139748 --- /dev/null +++ b/patches/ntdll-NtSetLdtEntries/definition @@ -0,0 +1 @@ +Depends: ntdll-NtQueryInformationThread diff --git a/patches/patchinstall.sh b/patches/patchinstall.sh index 0c84ab26..7e0a17ef 100755 --- a/patches/patchinstall.sh +++ b/patches/patchinstall.sh @@ -51,7 +51,7 @@ usage() # Get the upstream commit sha upstream_commit() { - echo "890312ccfd0f54ece6bd330355183cc84a3a97ec" + echo "e1970c8547aa7fed5a097faf172eadc282b3394e" } # Show version information @@ -213,6 +213,7 @@ patch_enable_all () enable_ntdll_Loader_Machine_Type="$1" enable_ntdll_NtAccessCheck="$1" enable_ntdll_NtQueryEaFile="$1" + enable_ntdll_NtQueryInformationThread="$1" enable_ntdll_NtQuerySection="$1" enable_ntdll_NtSetLdtEntries="$1" enable_ntdll_OSX_TEB_x86_64="$1" @@ -802,6 +803,9 @@ patch_enable () ntdll-NtQueryEaFile) enable_ntdll_NtQueryEaFile="$2" ;; + ntdll-NtQueryInformationThread) + enable_ntdll_NtQueryInformationThread="$2" + ;; ntdll-NtQuerySection) enable_ntdll_NtQuerySection="$2" ;; @@ -2115,6 +2119,13 @@ if test "$enable_ntdll_Purist_Mode" -eq 1; then enable_ntdll_DllRedirects=1 fi +if test "$enable_ntdll_NtSetLdtEntries" -eq 1; then + if test "$enable_ntdll_NtQueryInformationThread" -gt 1; then + abort "Patchset ntdll-NtQueryInformationThread disabled, but ntdll-NtSetLdtEntries depends on that." + fi + enable_ntdll_NtQueryInformationThread=1 +fi + if test "$enable_ntdll_Junction_Points" -eq 1; then if test "$enable_ntdll_NtQueryEaFile" -gt 1; then abort "Patchset ntdll-NtQueryEaFile disabled, but ntdll-Junction_Points depends on that." @@ -4747,6 +4758,18 @@ if test "$enable_ntdll_NtAccessCheck" -eq 1; then ) >> "$patchlist" fi +# Patchset ntdll-NtQueryInformationThread +# | +# | Modified files: +# | * dlls/kernel32/tests/thread.c, dlls/ntdll/thread.c +# | +if test "$enable_ntdll_NtQueryInformationThread" -eq 1; then + patch_apply ntdll-NtQueryInformationThread/0001-ntdll-Add-support-for-fs-to-NtQueryInformationThread.patch + ( + echo '+ { "Dmitry Timoshkov", "ntdll: Add support for fs to NtQueryInformationThread(ThreadDescriptorTableEntry).", 1 },'; + ) >> "$patchlist" +fi + # Patchset ntdll-NtQuerySection # | # | This patchset fixes the following Wine bugs: @@ -4771,6 +4794,9 @@ fi # Patchset ntdll-NtSetLdtEntries # | +# | This patchset has the following (direct or indirect) dependencies: +# | * ntdll-NtQueryInformationThread +# | # | Modified files: # | * dlls/kernel32/tests/thread.c, dlls/ntdll/nt.c, libs/wine/ldt.c # |