2014-09-15 22:05:21 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: GPL, see COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
|
|
|
* FILE: drivers/base/kddll/utils.c
|
|
|
|
* PURPOSE: Misc helper functions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "kdgdb.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We cannot use PsLookupProcessThreadByCid or alike as we could be running at any IRQL.
|
|
|
|
* So we have to loop over the process list.
|
|
|
|
*/
|
|
|
|
|
|
|
|
PEPROCESS
|
|
|
|
find_process(
|
|
|
|
_In_ UINT_PTR Pid)
|
|
|
|
{
|
|
|
|
HANDLE ProcessId = gdb_pid_to_handle(Pid);
|
|
|
|
LIST_ENTRY* ProcessEntry;
|
|
|
|
PEPROCESS Process;
|
|
|
|
|
|
|
|
/* Special case for idle process */
|
2016-08-01 22:16:58 +00:00
|
|
|
if (ProcessId == NULL)
|
2014-09-15 22:05:21 +00:00
|
|
|
return TheIdleProcess;
|
|
|
|
|
|
|
|
for (ProcessEntry = ProcessListHead->Flink;
|
|
|
|
ProcessEntry != ProcessListHead;
|
|
|
|
ProcessEntry = ProcessEntry->Flink)
|
|
|
|
{
|
|
|
|
Process = CONTAINING_RECORD(ProcessEntry, EPROCESS, ActiveProcessLinks);
|
|
|
|
|
|
|
|
if (Process->UniqueProcessId == ProcessId)
|
|
|
|
return Process;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PETHREAD
|
|
|
|
find_thread(
|
|
|
|
_In_ UINT_PTR Pid,
|
|
|
|
_In_ UINT_PTR Tid)
|
|
|
|
{
|
|
|
|
HANDLE ThreadId = gdb_tid_to_handle(Tid);
|
|
|
|
PETHREAD Thread;
|
|
|
|
PEPROCESS Process;
|
|
|
|
LIST_ENTRY* ThreadEntry;
|
2016-08-01 22:16:58 +00:00
|
|
|
#if MONOPROCESS
|
|
|
|
LIST_ENTRY* ProcessEntry;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (
|
|
|
|
#if !MONOPROCESS
|
|
|
|
(Pid == 0) &&
|
|
|
|
#endif
|
|
|
|
(Tid == 0))
|
|
|
|
{
|
|
|
|
/* Zero means any, so use the current one */
|
|
|
|
return (PETHREAD)(ULONG_PTR)CurrentStateChange.Thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if MONOPROCESS
|
2014-09-15 22:05:21 +00:00
|
|
|
|
|
|
|
/* Special case for the idle thread */
|
2016-08-01 22:16:58 +00:00
|
|
|
if (Tid == 1)
|
2014-09-15 22:05:21 +00:00
|
|
|
return TheIdleThread;
|
|
|
|
|
2016-08-01 22:16:58 +00:00
|
|
|
for (ProcessEntry = ProcessListHead->Flink;
|
|
|
|
ProcessEntry != ProcessListHead;
|
|
|
|
ProcessEntry = ProcessEntry->Flink)
|
|
|
|
{
|
|
|
|
Process = CONTAINING_RECORD(ProcessEntry, EPROCESS, ActiveProcessLinks);
|
|
|
|
#else
|
|
|
|
|
2014-09-15 22:05:21 +00:00
|
|
|
Process = find_process(Pid);
|
2016-08-01 22:16:58 +00:00
|
|
|
|
|
|
|
/* Special case for the idle thread */
|
|
|
|
if ((Process == TheIdleProcess) && (Tid == 1))
|
|
|
|
return TheIdleThread;
|
|
|
|
|
2014-09-15 22:05:21 +00:00
|
|
|
if (!Process)
|
|
|
|
return NULL;
|
|
|
|
|
2016-08-01 22:16:58 +00:00
|
|
|
#endif
|
|
|
|
|
2014-09-15 22:05:21 +00:00
|
|
|
for (ThreadEntry = Process->ThreadListHead.Flink;
|
|
|
|
ThreadEntry != &Process->ThreadListHead;
|
|
|
|
ThreadEntry = ThreadEntry->Flink)
|
|
|
|
{
|
|
|
|
Thread = CONTAINING_RECORD(ThreadEntry, ETHREAD, ThreadListEntry);
|
|
|
|
/* For GDB, Tid == 0 means any thread */
|
|
|
|
if ((Thread->Cid.UniqueThread == ThreadId) || (Tid == 0))
|
|
|
|
{
|
|
|
|
return Thread;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-01 22:16:58 +00:00
|
|
|
#if MONOPROCESS
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-09-15 22:05:21 +00:00
|
|
|
return NULL;
|
|
|
|
}
|