[PATCH] enumerate process in reverse
Marcus Meissner
marcus at jet.franken.de
Sun Jan 13 14:55:29 CST 2008
Hi,
This is an update of the enumerate process in reverse
patch.
Reason is Last Chaos USA of Aeria Games, which does
Process32First(...);
while (Process32Next(...)) {
/* check for child */
}
and does not check the Process32First() return for the childs
process name (but expects it).
Ciao, Marcus
---
dlls/kernel32/tests/toolhelp.c | 7 ++++++-
server/snapshot.c | 10 ++++++----
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/dlls/kernel32/tests/toolhelp.c b/dlls/kernel32/tests/toolhelp.c
index 3ae7540..3249379 100644
--- a/dlls/kernel32/tests/toolhelp.c
+++ b/dlls/kernel32/tests/toolhelp.c
@@ -106,6 +106,7 @@ static void test_process(DWORD curr_pid, DWORD sub_pcs_pid)
MODULEENTRY32 me;
unsigned found = 0;
int num = 0;
+ int childpos = -1;
hSnapshot = pCreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
ok(hSnapshot != NULL, "Cannot create snapshot\n");
@@ -117,7 +118,7 @@ static void test_process(DWORD curr_pid, DWORD sub_pcs_pid)
do
{
if (pe.th32ProcessID == curr_pid) found++;
- if (pe.th32ProcessID == sub_pcs_pid) found++;
+ if (pe.th32ProcessID == sub_pcs_pid) { childpos = num; found++; }
trace("PID=%x %s\n", pe.th32ProcessID, pe.szExeFile);
num++;
} while (pProcess32Next( hSnapshot, &pe ));
@@ -139,6 +140,10 @@ static void test_process(DWORD curr_pid, DWORD sub_pcs_pid)
ok(found == 2, "couldn't find self and/or sub-process in process list\n");
ok(!num, "mismatch in counting\n");
+ /* one broken program does Process32First() and does not expect anything
+ * interesting to be there, especially not the just forked off child */
+ ok (childpos !=0, "child is not expected to be at position 0.\n");
+
te.dwSize = sizeof(te);
ok(!pThread32First( hSnapshot, &te ), "shouldn't return a thread\n");
diff --git a/server/snapshot.c b/server/snapshot.c
index 57c9fac..25847b5 100644
--- a/server/snapshot.c
+++ b/server/snapshot.c
@@ -101,8 +101,10 @@ static struct snapshot *create_snapshot( process_id_t pid, int flags )
snapshot->process_pos = 0;
snapshot->process_count = 0;
- if (flags & SNAP_PROCESS)
+ if (flags & SNAP_PROCESS) {
snapshot->processes = process_snap( &snapshot->process_count );
+ snapshot->process_pos = snapshot->process_count-1;
+ }
snapshot->thread_pos = 0;
snapshot->thread_count = 0;
@@ -128,12 +130,12 @@ static int snapshot_next_process( struct snapshot *snapshot, struct next_process
set_error( STATUS_INVALID_PARAMETER ); /* FIXME */
return 0;
}
- if (snapshot->process_pos >= snapshot->process_count)
+ if (snapshot->process_pos < 0)
{
set_error( STATUS_NO_MORE_FILES );
return 0;
}
- ptr = &snapshot->processes[snapshot->process_pos++];
+ ptr = &snapshot->processes[snapshot->process_pos--];
reply->count = ptr->count;
reply->pid = get_process_id( ptr->process );
reply->ppid = ptr->process->parent ? get_process_id( ptr->process->parent ) : 0;
@@ -256,7 +258,7 @@ DECL_HANDLER(next_process)
if ((snapshot = (struct snapshot *)get_handle_obj( current->process, req->handle,
0, &snapshot_ops )))
{
- if (req->reset) snapshot->process_pos = 0;
+ if (req->reset) snapshot->process_pos = snapshot->process_count-1;
snapshot_next_process( snapshot, reply );
release_object( snapshot );
}
--
1.5.2.4
More information about the wine-patches
mailing list