[PATCH v4 2/2] kernel32: Adjust toolhelp thread return order.

Changping Yu dead.ash at hotmail.com
Wed Jun 24 04:22:12 CDT 2020


-------------- next part --------------
>From 1bd4433d831c8c7e980a9af8312e5527ddf00876 Mon Sep 17 00:00:00 2001
From: Changping Yu <dead.ash at hotmail.com>
Date: Wed, 24 Jun 2020 17:19:26 +0800
Subject: [PATCH v4 2/2] kernel32: Adjust toolhelp thread return order.

Some software incorrectly uses the way to get the main thread id.
Coincidentally, the threads of wine and windows return differently.
The list of threads returned by flipping can be consistent with windows.

Signed-off-by: Changping Yu <dead.ash at hotmail.com>
---
 dlls/kernel32/tests/toolhelp.c | 3 ---
 dlls/kernel32/toolhelp.c       | 6 +++---
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/dlls/kernel32/tests/toolhelp.c b/dlls/kernel32/tests/toolhelp.c
index 36d0d6beab..3fe2fdc6f0 100644
--- a/dlls/kernel32/tests/toolhelp.c
+++ b/dlls/kernel32/tests/toolhelp.c
@@ -216,7 +216,6 @@ static DWORD WINAPI get_id_thread(void* curr_pid)
         }
     }
 
-    todo_wine
     ok(found==FALSE, "The thread order is not strictly consistent\n");
 
     SetEvent(ev);
@@ -236,7 +235,6 @@ static void test_main_thread(DWORD curr_pid, DWORD main_tid)
 
     /* check that the main thread id is first one in this thread. */
     first_tid = get_id_thread((void *)curr_pid);
-    todo_wine
     ok(first_tid == main_tid, "check main thread is error, main is %d, %d\n", main_tid, first_tid);
 
     /* check that the main thread id is first one in other thread. */
@@ -245,7 +243,6 @@ static void test_main_thread(DWORD curr_pid, DWORD main_tid)
     ok(error == WAIT_OBJECT_0, "Thread did not complete within timelimit\n");
 
     ok(GetExitCodeThread(thread, &first_tid), "Could not retrieve ext code\n");
-    todo_wine
     ok(first_tid == main_tid, "check main thread is error, main is %d, %d\n", main_tid, first_tid);
 }
 
diff --git a/dlls/kernel32/toolhelp.c b/dlls/kernel32/toolhelp.c
index d55e8185f2..26a8258e0a 100644
--- a/dlls/kernel32/toolhelp.c
+++ b/dlls/kernel32/toolhelp.c
@@ -359,11 +359,11 @@ static BOOL next_thread( HANDLE hSnapShot, LPTHREADENTRY32 lpte, BOOL first )
     }
     if ((snap = MapViewOfFile( hSnapShot, FILE_MAP_ALL_ACCESS, 0, 0, 0 )))
     {
-        if (first) snap->thread_pos = 0;
-        if (snap->thread_pos < snap->thread_count)
+        if (first) snap->thread_pos = snap->thread_count - 1;
+        if (snap->thread_pos >= 0)
         {
             LPTHREADENTRY32 te = (THREADENTRY32*)&snap->data[snap->thread_offset];
-            *lpte = te[snap->thread_pos++];
+            *lpte = te[snap->thread_pos--];
             ret = TRUE;
         }
         else SetLastError( ERROR_NO_MORE_FILES );
-- 
2.27.0.windows.1



More information about the wine-devel mailing list