ReactOS  0.4.14-dev-342-gdc047f9
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 }
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2697
FORCEINLINE HANDLE gdb_tid_to_handle(UINT_PTR Tid)
Definition: kdgdb.h:35
DBGKD_ANY_WAIT_STATE_CHANGE CurrentStateChange
Definition: kdpacket.c:28
PETHREAD TheIdleThread
Definition: kdpacket.c:31
smooth NULL
Definition: ftsmooth.c:416
PEPROCESS TheIdleProcess
Definition: kdpacket.c:30
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
CLIENT_ID Cid
Definition: pstypes.h:1059
PEPROCESS find_process(_In_ UINT_PTR Pid)
Definition: utils.c:16
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define MONOPROCESS
Definition: kdgdb.h:25
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
HANDLE UniqueThread
Definition: compat.h:483
Definition: typedefs.h:117
#define _In_
Definition: no_sal2.h:204
LIST_ENTRY * ProcessListHead
Definition: kdpacket.c:22
DWORD WINAPI ThreadEntry(LPVOID parameter)
Definition: thread.cpp:16
PETHREAD find_thread(_In_ UINT_PTR Pid, _In_ UINT_PTR Tid)
Definition: utils.c:41
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define ULONG_PTR
Definition: config.h:101
#define gdb_pid_to_handle
Definition: kdgdb.h:39