ReactOS 0.4.15-dev-7924-g5949c20
utils.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: GPL, see COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: drivers/base/kddll/utils.c
5 * PURPOSE: Misc helper functions.
6 */
7
8#include "kdgdb.h"
9
10/*
11 * We cannot use PsLookupProcessThreadByCid or alike as we could be running at any IRQL.
12 * So we have to loop over the process list.
13 */
14
17 _In_ UINT_PTR Pid)
18{
20 LIST_ENTRY* ProcessEntry;
22
23 /* Special case for idle process */
24 if (ProcessId == NULL)
25 return TheIdleProcess;
26
27 for (ProcessEntry = ProcessListHead->Flink;
28 ProcessEntry != ProcessListHead;
29 ProcessEntry = ProcessEntry->Flink)
30 {
31 Process = CONTAINING_RECORD(ProcessEntry, EPROCESS, ActiveProcessLinks);
32
33 if (Process->UniqueProcessId == ProcessId)
34 return Process;
35 }
36
37 return NULL;
38}
39
42 _In_ UINT_PTR Pid,
43 _In_ UINT_PTR Tid)
44{
45 HANDLE ThreadId = gdb_tid_to_handle(Tid);
49#if MONOPROCESS
50 LIST_ENTRY* ProcessEntry;
51#endif
52
53 if (
54#if !MONOPROCESS
55 (Pid == 0) &&
56#endif
57 (Tid == 0))
58 {
59 /* Zero means any, so use the current one */
61 }
62
63#if MONOPROCESS
64
65 /* Special case for the idle thread */
66 if (Tid == 1)
67 return TheIdleThread;
68
69 for (ProcessEntry = ProcessListHead->Flink;
70 ProcessEntry != ProcessListHead;
71 ProcessEntry = ProcessEntry->Flink)
72 {
73 Process = CONTAINING_RECORD(ProcessEntry, EPROCESS, ActiveProcessLinks);
74#else
75
76 Process = find_process(Pid);
77
78 /* Special case for the idle thread */
79 if ((Process == TheIdleProcess) && (Tid == 1))
80 return TheIdleThread;
81
82 if (!Process)
83 return NULL;
84
85#endif
86
87 for (ThreadEntry = Process->ThreadListHead.Flink;
88 ThreadEntry != &Process->ThreadListHead;
89 ThreadEntry = ThreadEntry->Flink)
90 {
91 Thread = CONTAINING_RECORD(ThreadEntry, ETHREAD, ThreadListEntry);
92 /* For GDB, Tid == 0 means any thread */
93 if ((Thread->Cid.UniqueThread == ThreadId) || (Tid == 0))
94 {
95 return Thread;
96 }
97 }
98
99#if MONOPROCESS
100 }
101#endif
102
103 return NULL;
104}
#define NULL
Definition: types.h:112
PEPROCESS find_process(_In_ UINT_PTR Pid)
Definition: utils.c:16
PETHREAD find_thread(_In_ UINT_PTR Pid, _In_ UINT_PTR Tid)
Definition: utils.c:41
#define ULONG_PTR
Definition: config.h:101
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2711
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
#define gdb_pid_to_handle
Definition: kdgdb.h:39
PEPROCESS TheIdleProcess
Definition: kdpacket.c:30
PETHREAD TheIdleThread
Definition: kdpacket.c:31
DBGKD_ANY_WAIT_STATE_CHANGE CurrentStateChange
Definition: kdpacket.c:28
FORCEINLINE HANDLE gdb_tid_to_handle(UINT_PTR Tid)
Definition: kdgdb.h:35
LIST_ENTRY * ProcessListHead
Definition: kdpacket.c:22
#define MONOPROCESS
Definition: kdgdb.h:25
#define _In_
Definition: ms_sal.h:308
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
HANDLE UniqueThread
Definition: compat.h:826
CLIENT_ID Cid
Definition: pstypes.h:1128
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
DWORD WINAPI ThreadEntry(LPVOID parameter)
Definition: thread.cpp:16
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260