ReactOS
0.4.16-dev-336-gb667d82
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
15
PEPROCESS
16
find_process
(
17
_In_
UINT_PTR
Pid)
18
{
19
HANDLE
ProcessId
=
gdb_pid_to_handle
(Pid);
20
LIST_ENTRY
* ProcessEntry;
21
PEPROCESS
Process
;
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
40
PETHREAD
41
find_thread
(
42
_In_
UINT_PTR
Pid,
43
_In_
UINT_PTR
Tid)
44
{
45
HANDLE
ThreadId =
gdb_tid_to_handle
(Tid);
46
PETHREAD
Thread
;
47
PEPROCESS
Process
;
48
LIST_ENTRY
*
ThreadEntry
;
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 */
60
return
(
PETHREAD
)(
ULONG_PTR
)
CurrentStateChange
.
Thread
;
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
}
NULL
#define NULL
Definition:
types.h:112
find_process
PEPROCESS find_process(_In_ UINT_PTR Pid)
Definition:
utils.c:16
find_thread
PETHREAD find_thread(_In_ UINT_PTR Pid, _In_ UINT_PTR Tid)
Definition:
utils.c:41
ULONG_PTR
#define ULONG_PTR
Definition:
config.h:101
ProcessId
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition:
fatprocs.h:2712
Thread
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition:
fltkernel.h:2653
Process
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition:
fsrtlfuncs.h:223
void
Definition:
nsiface.idl:2307
kdgdb.h
gdb_pid_to_handle
#define gdb_pid_to_handle
Definition:
kdgdb.h:39
TheIdleProcess
PEPROCESS TheIdleProcess
Definition:
kdpacket.c:30
TheIdleThread
PETHREAD TheIdleThread
Definition:
kdpacket.c:31
CurrentStateChange
DBGKD_ANY_WAIT_STATE_CHANGE CurrentStateChange
Definition:
kdpacket.c:28
gdb_tid_to_handle
FORCEINLINE HANDLE gdb_tid_to_handle(UINT_PTR Tid)
Definition:
kdgdb.h:35
ProcessListHead
LIST_ENTRY * ProcessListHead
Definition:
kdpacket.c:22
MONOPROCESS
#define MONOPROCESS
Definition:
kdgdb.h:25
UINT_PTR
unsigned __int3264 UINT_PTR
Definition:
mstsclib_h.h:274
_In_
#define _In_
Definition:
no_sal2.h:158
_CLIENT_ID::UniqueThread
HANDLE UniqueThread
Definition:
compat.h:826
_DBGKD_ANY_WAIT_STATE_CHANGE::Thread
ULONG64 Thread
Definition:
windbgkd.h:504
_EPROCESS
Definition:
pstypes.h:1262
_ETHREAD
Definition:
pstypes.h:1103
_ETHREAD::Cid
CLIENT_ID Cid
Definition:
pstypes.h:1129
_LIST_ENTRY
Definition:
typedefs.h:120
_LIST_ENTRY::Flink
struct _LIST_ENTRY * Flink
Definition:
typedefs.h:121
ThreadEntry
DWORD WINAPI ThreadEntry(LPVOID parameter)
Definition:
thread.cpp:16
CONTAINING_RECORD
#define CONTAINING_RECORD(address, type, field)
Definition:
typedefs.h:260
drivers
base
kdgdb
utils.c
Generated on Tue Dec 10 2024 06:14:56 for ReactOS by
1.9.6