HyperDbg Debugger
Loading...
Searching...
No Matches
ThreadHolder.h File Reference

User debugger's thread holder headers. More...

Go to the source code of this file.

Classes

struct  _USERMODE_DEBUGGING_THREAD_DETAILS
 Details of each thread in process. More...
struct  _USERMODE_DEBUGGING_THREAD_HOLDER
 The holder for detail of each thread in process. More...

Typedefs

typedef struct _USERMODE_DEBUGGING_THREAD_DETAILS USERMODE_DEBUGGING_THREAD_DETAILS
 Details of each thread in process.
typedef struct _USERMODE_DEBUGGING_THREAD_DETAILSPUSERMODE_DEBUGGING_THREAD_DETAILS
typedef struct _USERMODE_DEBUGGING_THREAD_HOLDER USERMODE_DEBUGGING_THREAD_HOLDER
 The holder for detail of each thread in process.
typedef struct _USERMODE_DEBUGGING_THREAD_HOLDERPUSERMODE_DEBUGGING_THREAD_HOLDER

Functions

VOID ThreadHolderAllocateThreadHoldingBuffers ()
 Pre allocate buffer for thread holder.
BOOLEAN ThreadHolderAssignThreadHolderToProcessDebuggingDetails (PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetail)
 Assign a thread holder to process debugging details.
BOOLEAN ThreadHolderIsAnyPausedThreadInProcess (PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetail)
 Check if there is any thread paused by checking process debugging details.
BOOLEAN ThreadHolderUnpauseAllThreadsInProcess (PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetail)
 Unpause all threads in the process debugging details.
PUSERMODE_DEBUGGING_THREAD_DETAILS ThreadHolderGetProcessThreadDetailsByProcessIdAndThreadId (UINT32 ProcessId, UINT32 ThreadId)
 Find the active threads of the process from process id.
PUSERMODE_DEBUGGING_THREAD_DETAILS ThreadHolderGetProcessFirstThreadDetailsByProcessId (UINT32 ProcessId)
 Find the first active threads of the process from process id.
PUSERMODE_DEBUGGING_PROCESS_DETAILS ThreadHolderGetProcessDebuggingDetailsByThreadId (UINT32 ThreadId)
 Find the active process debugging detail from the thread id.
PUSERMODE_DEBUGGING_THREAD_DETAILS ThreadHolderFindOrCreateThreadDebuggingDetail (UINT32 ThreadId, PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetail)
 Find or create user-mode debugging details for threads.
BOOLEAN ThreadHolderApplyActionToPausedThreads (PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetails, PDEBUGGER_UD_COMMAND_PACKET ActionRequest)
 Apply the action of the user debugger to a specific thread or all threads.
VOID ThreadHolderFreeHoldingStructures (PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetail)
 Free all of thread holder structures.
UINT32 ThreadHolderQueryCountOfActiveDebuggingThreadsAndProcesses ()
 Query count of active debugging threads and processes.
VOID ThreadHolderQueryDetailsOfActiveDebuggingThreadsAndProcesses (USERMODE_DEBUGGING_THREAD_OR_PROCESS_STATE_DETAILS *BufferToStoreDetails, UINT32 MaxCount)
 Query details of active debugging threads and processes.

Variables

volatile LONG VmxRootThreadHoldingLock
 Vmx-root lock for thread holding.

Detailed Description

User debugger's thread holder headers.

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.1
Date
2022-01-28

Typedef Documentation

◆ PUSERMODE_DEBUGGING_THREAD_DETAILS

◆ PUSERMODE_DEBUGGING_THREAD_HOLDER

◆ USERMODE_DEBUGGING_THREAD_DETAILS

Details of each thread in process.

◆ USERMODE_DEBUGGING_THREAD_HOLDER

The holder for detail of each thread in process.

Function Documentation

◆ ThreadHolderAllocateThreadHoldingBuffers()

VOID ThreadHolderAllocateThreadHoldingBuffers ( )

Pre allocate buffer for thread holder.

Returns
VOID
22{
23 //
24 // Request to allocate two buffer for holder of threads
25 //
27
28 //
29 // As it might be called from an attaching request and never find a
30 // a chance to allocate it, we allocate it here as it's safe at PASSIVE_LEVEL
31 //
33}
BOOLEAN PoolManagerCheckAndPerformAllocationAndDeallocation()
This function performs allocations from VMX non-root based on g_RequestNewAllocation.
Definition PoolManager.c:320
BOOLEAN PoolManagerRequestAllocation(SIZE_T Size, UINT32 Count, POOL_ALLOCATION_INTENTION Intention)
Request to allocate new buffers.
Definition PoolManager.c:436
struct _USERMODE_DEBUGGING_THREAD_HOLDER USERMODE_DEBUGGING_THREAD_HOLDER
The holder for detail of each thread in process.
@ PROCESS_THREAD_HOLDER
Definition DataTypes.h:79

◆ ThreadHolderApplyActionToPausedThreads()

BOOLEAN ThreadHolderApplyActionToPausedThreads ( PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetails,
PDEBUGGER_UD_COMMAND_PACKET ActionRequest )

Apply the action of the user debugger to a specific thread or all threads.

Parameters
ProcessDebuggingDetails
ActionRequest
Returns
BOOLEAN Shows whether the command is applied or not
402{
403 PUSERMODE_DEBUGGING_THREAD_DETAILS ThreadDebuggingDetails;
404 BOOLEAN CommandApplied = FALSE;
405
406 if (!ActionRequest->ApplyToAllPausedThreads)
407 {
408 //
409 // *** only the active thread ***
410 //
411
412 ThreadDebuggingDetails = ThreadHolderGetProcessThreadDetailsByProcessIdAndThreadId(ProcessDebuggingDetails->ProcessId,
413 ActionRequest->TargetThreadId);
414
415 //
416 // Apply the command
417 //
418 for (SIZE_T i = 0; i < MAX_USER_ACTIONS_FOR_THREADS; i++)
419 {
420 if (ThreadDebuggingDetails->UdAction[i].ActionType == DEBUGGER_UD_COMMAND_ACTION_TYPE_NONE)
421 {
422 //
423 // Set the action
424 //
425 ThreadDebuggingDetails->UdAction[i].OptionalParam1 = ActionRequest->UdAction.OptionalParam1;
426 ThreadDebuggingDetails->UdAction[i].OptionalParam2 = ActionRequest->UdAction.OptionalParam2;
427 ThreadDebuggingDetails->UdAction[i].OptionalParam3 = ActionRequest->UdAction.OptionalParam3;
428 ThreadDebuggingDetails->UdAction[i].OptionalParam4 = ActionRequest->UdAction.OptionalParam4;
429
430 //
431 // At last we set the action type to make it valid
432 //
433 ThreadDebuggingDetails->UdAction[i].ActionType = ActionRequest->UdAction.ActionType;
434
435 //
436 // Command is applied
437 //
438 return TRUE;
439 }
440 }
441 }
442 else
443 {
444 //
445 // *** apply to all paused threads ***
446 //
447 PLIST_ENTRY TempList = 0;
448
449 TempList = &ProcessDebuggingDetails->ThreadsListHead;
450
451 while (&ProcessDebuggingDetails->ThreadsListHead != TempList->Flink)
452 {
453 TempList = TempList->Flink;
455 CONTAINING_RECORD(TempList, USERMODE_DEBUGGING_THREAD_HOLDER, ThreadHolderList);
456
457 for (SIZE_T i = 0; i < MAX_THREADS_IN_A_PROCESS_HOLDER; i++)
458 {
459 if (ThreadHolder->Threads[i].ThreadId != NULL_ZERO &&
460 ThreadHolder->Threads[i].IsPaused)
461 {
462 for (SIZE_T j = 0; j < MAX_USER_ACTIONS_FOR_THREADS; j++)
463 {
465 {
466 //
467 // Set the action
468 //
469 ThreadHolder->Threads[i].UdAction[j].OptionalParam1 = ActionRequest->UdAction.OptionalParam1;
470 ThreadHolder->Threads[i].UdAction[j].OptionalParam2 = ActionRequest->UdAction.OptionalParam2;
471 ThreadHolder->Threads[i].UdAction[j].OptionalParam3 = ActionRequest->UdAction.OptionalParam3;
472 ThreadHolder->Threads[i].UdAction[j].OptionalParam4 = ActionRequest->UdAction.OptionalParam4;
473
474 //
475 // At last we set the action type to make it valid
476 //
477 ThreadHolder->Threads[i].UdAction[j].ActionType = ActionRequest->UdAction.ActionType;
478
479 CommandApplied = TRUE;
480 break;
481 }
482 }
483 }
484 }
485 }
486 }
487
488 //
489 // Return the result of applying the command
490 //
491 return CommandApplied;
492}
#define MAX_THREADS_IN_A_PROCESS_HOLDER
Maximum threads that a process thread holder might have.
Definition Attaching.h:28
#define MAX_USER_ACTIONS_FOR_THREADS
Maximum actions in paused threads storage.
Definition Attaching.h:22
PUSERMODE_DEBUGGING_THREAD_DETAILS ThreadHolderGetProcessThreadDetailsByProcessIdAndThreadId(UINT32 ProcessId, UINT32 ThreadId)
Find the active threads of the process from process id.
Definition ThreadHolder.c:145
struct _USERMODE_DEBUGGING_THREAD_HOLDER * PUSERMODE_DEBUGGING_THREAD_HOLDER
struct _USERMODE_DEBUGGING_THREAD_DETAILS * PUSERMODE_DEBUGGING_THREAD_DETAILS
UCHAR BOOLEAN
Definition BasicTypes.h:35
#define NULL_ZERO
Definition BasicTypes.h:110
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113
@ DEBUGGER_UD_COMMAND_ACTION_TYPE_NONE
Definition RequestStructures.h:920
#define CONTAINING_RECORD(address, type, field)
Definition nt-list.h:36
DEBUGGER_UD_COMMAND_ACTION_TYPE ActionType
Definition RequestStructures.h:934
UINT64 OptionalParam1
Definition RequestStructures.h:935
UINT64 OptionalParam3
Definition RequestStructures.h:937
UINT64 OptionalParam4
Definition RequestStructures.h:938
UINT64 OptionalParam2
Definition RequestStructures.h:936
DEBUGGER_UD_COMMAND_ACTION UdAction
Definition RequestStructures.h:948
UINT32 TargetThreadId
Definition RequestStructures.h:950
BOOLEAN ApplyToAllPausedThreads
Definition RequestStructures.h:951
LIST_ENTRY ThreadsListHead
Definition Ud.h:40
UINT32 ProcessId
Definition Ud.h:35
UINT32 ThreadId
Definition ThreadHolder.h:34
DEBUGGER_UD_COMMAND_ACTION UdAction[MAX_USER_ACTIONS_FOR_THREADS]
Definition ThreadHolder.h:40
BOOLEAN IsPaused
Definition ThreadHolder.h:36
USERMODE_DEBUGGING_THREAD_DETAILS Threads[MAX_THREADS_IN_A_PROCESS_HOLDER]
Definition ThreadHolder.h:51

◆ ThreadHolderAssignThreadHolderToProcessDebuggingDetails()

BOOLEAN ThreadHolderAssignThreadHolderToProcessDebuggingDetails ( PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetail)

Assign a thread holder to process debugging details.

Parameters
ProcessDebuggingDetail
Returns
BOOLEAN
43{
45
46 //
47 // Initialize the list entry of threads
48 //
49 InitializeListHead(&ProcessDebuggingDetail->ThreadsListHead);
50
51 //
52 // Add a thread holder here
53 //
54 ThreadHolder = (USERMODE_DEBUGGING_THREAD_HOLDER *)
56
57 if (!ThreadHolder)
58 {
59 return FALSE;
60 }
61
62 //
63 // Add it to thread holder of the structure
64 //
65 InsertHeadList(&ProcessDebuggingDetail->ThreadsListHead, &(ThreadHolder->ThreadHolderList));
66
67 return TRUE;
68}
UINT64 PoolManagerRequestPool(POOL_ALLOCATION_INTENTION Intention, BOOLEAN RequestNewPool, UINT32 Size)
This function should be called from vmx-root in order to get a pool from the list.
Definition PoolManager.c:230
LIST_ENTRY ThreadHolderList
Definition ThreadHolder.h:50

◆ ThreadHolderFindOrCreateThreadDebuggingDetail()

PUSERMODE_DEBUGGING_THREAD_DETAILS ThreadHolderFindOrCreateThreadDebuggingDetail ( UINT32 ThreadId,
PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetail )

Find or create user-mode debugging details for threads.

Parameters
ThreadId
ProcessDebuggingDetail
Returns
PUSERMODE_DEBUGGING_THREAD_DETAILS
294{
295 PLIST_ENTRY TempList = 0;
296
297 TempList = &ProcessDebuggingDetail->ThreadsListHead;
298
299 //
300 // Let's see if we can find the thread
301 //
302 while (&ProcessDebuggingDetail->ThreadsListHead != TempList->Flink)
303 {
304 TempList = TempList->Flink;
306 CONTAINING_RECORD(TempList, USERMODE_DEBUGGING_THREAD_HOLDER, ThreadHolderList);
307
308 for (SIZE_T i = 0; i < MAX_THREADS_IN_A_PROCESS_HOLDER; i++)
309 {
310 if (ThreadHolder->Threads[i].ThreadId == ThreadId)
311 {
312 //
313 // We find a thread, let's return it's structure
314 //
315 return &ThreadHolder->Threads[i];
316 }
317 }
318 }
319
320 //
321 // *** We're here, the thread is not found, let's create an entry for it ***
322 //
323
324 //
325 // Two threads should not simultaneously reach here
326 //
328
329 TempList = &ProcessDebuggingDetail->ThreadsListHead;
330
331 //
332 // Let's see if we can find the thread
333 //
334 while (&ProcessDebuggingDetail->ThreadsListHead != TempList->Flink)
335 {
336 TempList = TempList->Flink;
338 CONTAINING_RECORD(TempList, USERMODE_DEBUGGING_THREAD_HOLDER, ThreadHolderList);
339
340 for (SIZE_T i = 0; i < MAX_THREADS_IN_A_PROCESS_HOLDER; i++)
341 {
342 if (ThreadHolder->Threads[i].ThreadId == NULL_ZERO)
343 {
344 //
345 // We find a null thread place, let's return it's structure
346 //
347 ThreadHolder->Threads[i].ThreadId = ThreadId;
348
350 return &ThreadHolder->Threads[i];
351 }
352 }
353 }
354
355 //
356 // We didn't find an empty entry,
357 // let's use another structure and link it to the thread holder
358 //
361
362 if (NewThreadHolder == NULL)
363 {
364 LogError("Err, enable to find a place to save the threads data, "
365 "please use 'prealloc' command to allocate more pre-allocated "
366 "buffer for the thread holder");
367
369 return NULL;
370 }
371
372 //
373 // Add the current thread as the first entry of the holder
374 //
375 NewThreadHolder->Threads[0].ThreadId = ThreadId;
376
377 //
378 // Link to the thread holding structure
379 //
380 InsertHeadList(&ProcessDebuggingDetail->ThreadsListHead, &(NewThreadHolder->ThreadHolderList));
381
382 //
383 // Other threads are now allowed to use the thread listing mechanism
384 //
386
387 return &NewThreadHolder->Threads[0];
388}
VOID SpinlockLock(volatile LONG *Lock)
Tries to get the lock and won't return until successfully get the lock.
Definition Spinlock.c:53
VOID SpinlockUnlock(volatile LONG *Lock)
Release the lock.
Definition Spinlock.c:162
volatile LONG VmxRootThreadHoldingLock
Vmx-root lock for thread holding.
Definition ThreadHolder.h:22
#define LogError(format,...)
Log in the case of error.
Definition HyperDbgHyperLogIntrinsics.h:113
NULL()
Definition test-case-generator.py:530

◆ ThreadHolderFreeHoldingStructures()

VOID ThreadHolderFreeHoldingStructures ( PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetail)

Free all of thread holder structures.

Parameters
ProcessDebuggingDetail
Returns
VOID
502{
503 PLIST_ENTRY TempList = 0;
504
505 TempList = &ProcessDebuggingDetail->ThreadsListHead;
506
507 while (&ProcessDebuggingDetail->ThreadsListHead != TempList->Flink)
508 {
509 TempList = TempList->Flink;
511 CONTAINING_RECORD(TempList, USERMODE_DEBUGGING_THREAD_HOLDER, ThreadHolderList);
512
513 //
514 // The thread is allocated from the pool management, so we'll
515 // free it from there
516 //
517 PoolManagerFreePool((UINT64)ThreadHolder);
518 }
519}
BOOLEAN PoolManagerFreePool(UINT64 AddressToFree)
This function set a pool flag to be freed, and it will be freed on the next IOCTL when it's safe to r...
Definition PoolManager.c:154

◆ ThreadHolderGetProcessDebuggingDetailsByThreadId()

PUSERMODE_DEBUGGING_PROCESS_DETAILS ThreadHolderGetProcessDebuggingDetailsByThreadId ( UINT32 ThreadId)

Find the active process debugging detail from the thread id.

Parameters
ThreadId
Returns
PUSERMODE_DEBUGGING_PROCESS_DETAILS
242{
243 PLIST_ENTRY TempList = 0;
244 PLIST_ENTRY TempList2 = 0;
245
247
248 while (&g_ProcessDebuggingDetailsListHead != TempList->Flink)
249 {
250 TempList = TempList->Flink;
251 PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetails =
252 CONTAINING_RECORD(TempList, USERMODE_DEBUGGING_PROCESS_DETAILS, AttachedProcessList);
253
254 //
255 // Search through all the active threads of this process
256 //
257 TempList2 = &ProcessDebuggingDetails->ThreadsListHead;
258
259 while (&ProcessDebuggingDetails->ThreadsListHead != TempList2->Flink)
260 {
261 TempList2 = TempList2->Flink;
263 CONTAINING_RECORD(TempList2, USERMODE_DEBUGGING_THREAD_HOLDER, ThreadHolderList);
264
265 for (SIZE_T i = 0; i < MAX_THREADS_IN_A_PROCESS_HOLDER; i++)
266 {
267 if (ThreadHolder->Threads[i].ThreadId == ThreadId)
268 {
269 //
270 // The target thread is found, not let's return the process debugging
271 // details of this process
272 //
273 return ProcessDebuggingDetails;
274 }
275 }
276 }
277 }
278
279 //
280 // Active thread not found
281 //
282 return NULL;
283}
LIST_ENTRY g_ProcessDebuggingDetailsListHead
List header of thread debugging details.
Definition Global.h:200
struct _USERMODE_DEBUGGING_PROCESS_DETAILS * PUSERMODE_DEBUGGING_PROCESS_DETAILS
struct _USERMODE_DEBUGGING_PROCESS_DETAILS USERMODE_DEBUGGING_PROCESS_DETAILS
Description of each active thread in user-mode attaching mechanism.

◆ ThreadHolderGetProcessFirstThreadDetailsByProcessId()

PUSERMODE_DEBUGGING_THREAD_DETAILS ThreadHolderGetProcessFirstThreadDetailsByProcessId ( UINT32 ProcessId)

Find the first active threads of the process from process id.

Parameters
ProcessId
Returns
PUSERMODE_DEBUGGING_THREAD_DETAILS
194{
195 PLIST_ENTRY TempList = 0;
196 PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetail;
197
198 //
199 // First, find the process details
200 //
201 ProcessDebuggingDetail = AttachingFindProcessDebuggingDetailsByProcessId(ProcessId);
202
203 if (ProcessDebuggingDetail == NULL)
204 {
205 return NULL;
206 }
207
208 TempList = &ProcessDebuggingDetail->ThreadsListHead;
209
210 while (&ProcessDebuggingDetail->ThreadsListHead != TempList->Flink)
211 {
212 TempList = TempList->Flink;
214 CONTAINING_RECORD(TempList, USERMODE_DEBUGGING_THREAD_HOLDER, ThreadHolderList);
215
216 for (SIZE_T i = 0; i < MAX_THREADS_IN_A_PROCESS_HOLDER; i++)
217 {
218 if (ThreadHolder->Threads[i].ThreadId != NULL_ZERO)
219 {
220 //
221 // The active thread's structure is found
222 //
223 return &ThreadHolder->Threads[i];
224 }
225 }
226 }
227
228 //
229 // Active thread not found
230 //
231 return NULL;
232}
PUSERMODE_DEBUGGING_PROCESS_DETAILS AttachingFindProcessDebuggingDetailsByProcessId(UINT32 ProcessId)
Find user-mode debugging details for threads by process Id.
Definition Attaching.c:184

◆ ThreadHolderGetProcessThreadDetailsByProcessIdAndThreadId()

PUSERMODE_DEBUGGING_THREAD_DETAILS ThreadHolderGetProcessThreadDetailsByProcessIdAndThreadId ( UINT32 ProcessId,
UINT32 ThreadId )

Find the active threads of the process from process id.

Parameters
ProcessId
ThreadId
Returns
PUSERMODE_DEBUGGING_THREAD_DETAILS
146{
147 PLIST_ENTRY TempList = 0;
148 PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetail;
149
150 //
151 // First, find the process details
152 //
153 ProcessDebuggingDetail = AttachingFindProcessDebuggingDetailsByProcessId(ProcessId);
154
155 if (ProcessDebuggingDetail == NULL)
156 {
157 return NULL;
158 }
159
160 TempList = &ProcessDebuggingDetail->ThreadsListHead;
161
162 while (&ProcessDebuggingDetail->ThreadsListHead != TempList->Flink)
163 {
164 TempList = TempList->Flink;
166 CONTAINING_RECORD(TempList, USERMODE_DEBUGGING_THREAD_HOLDER, ThreadHolderList);
167
168 for (SIZE_T i = 0; i < MAX_THREADS_IN_A_PROCESS_HOLDER; i++)
169 {
170 if (ThreadHolder->Threads[i].ThreadId == ThreadId)
171 {
172 //
173 // The active thread's structure is found
174 //
175 return &ThreadHolder->Threads[i];
176 }
177 }
178 }
179
180 //
181 // Active thread not found
182 //
183 return NULL;
184}

◆ ThreadHolderIsAnyPausedThreadInProcess()

BOOLEAN ThreadHolderIsAnyPausedThreadInProcess ( PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetail)

Check if there is any thread paused by checking process debugging details.

Parameters
ProcessDebuggingDetail
Returns
BOOLEAN
78{
79 PLIST_ENTRY TempList = 0;
80
81 TempList = &ProcessDebuggingDetail->ThreadsListHead;
82
83 while (&ProcessDebuggingDetail->ThreadsListHead != TempList->Flink)
84 {
85 TempList = TempList->Flink;
87 CONTAINING_RECORD(TempList, USERMODE_DEBUGGING_THREAD_HOLDER, ThreadHolderList);
88
89 for (SIZE_T i = 0; i < MAX_THREADS_IN_A_PROCESS_HOLDER; i++)
90 {
91 if (ThreadHolder->Threads[i].ThreadId != NULL_ZERO && ThreadHolder->Threads[i].IsPaused)
92 {
93 return TRUE;
94 }
95 }
96 }
97
98 return FALSE;
99}

◆ ThreadHolderQueryCountOfActiveDebuggingThreadsAndProcesses()

UINT32 ThreadHolderQueryCountOfActiveDebuggingThreadsAndProcesses ( )

Query count of active debugging threads and processes.

Returns
UINT32
528{
529 PLIST_ENTRY TempList = 0;
530 PLIST_ENTRY TempList2 = 0;
531 UINT32 CountOfThreadsAndProcesses = 0;
532
534
535 while (&g_ProcessDebuggingDetailsListHead != TempList->Flink)
536 {
537 TempList = TempList->Flink;
538 PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetails =
539 CONTAINING_RECORD(TempList, USERMODE_DEBUGGING_PROCESS_DETAILS, AttachedProcessList);
540
541 //
542 // Each process is also counted (no matter if it has active paused thread or not)
543 //
544 CountOfThreadsAndProcesses++;
545
546 //
547 // Search through all the active threads of this process
548 //
549 TempList2 = &ProcessDebuggingDetails->ThreadsListHead;
550
551 while (&ProcessDebuggingDetails->ThreadsListHead != TempList2->Flink)
552 {
553 TempList2 = TempList2->Flink;
555 CONTAINING_RECORD(TempList2, USERMODE_DEBUGGING_THREAD_HOLDER, ThreadHolderList);
556
557 for (SIZE_T i = 0; i < MAX_THREADS_IN_A_PROCESS_HOLDER; i++)
558 {
559 if (ThreadHolder->Threads[i].IsPaused)
560 {
561 //
562 // A paused thread should be counted
563 //
564 CountOfThreadsAndProcesses++;
565 }
566 }
567 }
568 }
569
570 //
571 // Return count of active threads and processes
572 //
573 return CountOfThreadsAndProcesses;
574}
unsigned int UINT32
Definition BasicTypes.h:54

◆ ThreadHolderQueryDetailsOfActiveDebuggingThreadsAndProcesses()

VOID ThreadHolderQueryDetailsOfActiveDebuggingThreadsAndProcesses ( USERMODE_DEBUGGING_THREAD_OR_PROCESS_STATE_DETAILS * BufferToStoreDetails,
UINT32 MaxCount )

Query details of active debugging threads and processes.

Parameters
BufferToStoreDetails
MaxCount
Returns
VOID
588{
589 PLIST_ENTRY TempList = 0;
590 PLIST_ENTRY TempList2 = 0;
591 UINT32 CurrentIndex = 0;
592
593 if (MaxCount == 0)
594 {
595 //
596 // Invalid query, storage is empty
597 //
598 return;
599 }
600
602
603 while (&g_ProcessDebuggingDetailsListHead != TempList->Flink)
604 {
605 TempList = TempList->Flink;
606 PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetails =
607 CONTAINING_RECORD(TempList, USERMODE_DEBUGGING_PROCESS_DETAILS, AttachedProcessList);
608
609 //
610 // Each process is also save (no matter if it has active paused thread or not)
611 //
612 BufferToStoreDetails[CurrentIndex].IsProcess = TRUE;
613 BufferToStoreDetails[CurrentIndex].ProcessId = ProcessDebuggingDetails->ProcessId;
614 CurrentIndex++;
615 if (MaxCount == CurrentIndex)
616 {
617 //
618 // Storage is full
619 //
620 return;
621 }
622
623 //
624 // Search through all the active threads of this process
625 //
626 TempList2 = &ProcessDebuggingDetails->ThreadsListHead;
627
628 while (&ProcessDebuggingDetails->ThreadsListHead != TempList2->Flink)
629 {
630 TempList2 = TempList2->Flink;
632 CONTAINING_RECORD(TempList2, USERMODE_DEBUGGING_THREAD_HOLDER, ThreadHolderList);
633
634 for (SIZE_T i = 0; i < MAX_THREADS_IN_A_PROCESS_HOLDER; i++)
635 {
636 if (ThreadHolder->Threads[i].IsPaused)
637 {
638 //
639 // A paused thread should be saved
640 //
641 BufferToStoreDetails[CurrentIndex].IsProcess = FALSE;
642 BufferToStoreDetails[CurrentIndex].ProcessId = ProcessDebuggingDetails->ProcessId;
643 BufferToStoreDetails[CurrentIndex].ThreadId = ThreadHolder->Threads[i].ThreadId;
644 BufferToStoreDetails[CurrentIndex].NumberOfBlockedContextSwitches = ThreadHolder->Threads[i].NumberOfBlockedContextSwitches;
645
646 CurrentIndex++;
647 if (MaxCount == CurrentIndex)
648 {
649 //
650 // Storage is full
651 //
652 return;
653 }
654 }
655 }
656 }
657 }
658}
UINT64 NumberOfBlockedContextSwitches
Definition ThreadHolder.h:39
UINT64 NumberOfBlockedContextSwitches
Definition RequestStructures.h:867
BOOLEAN IsProcess
Definition RequestStructures.h:868
UINT32 ThreadId
Definition RequestStructures.h:866
UINT32 ProcessId
Definition RequestStructures.h:865

◆ ThreadHolderUnpauseAllThreadsInProcess()

BOOLEAN ThreadHolderUnpauseAllThreadsInProcess ( PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetail)

Unpause all threads in the process debugging details.

Parameters
ProcessDebuggingDetail
Returns
BOOLEAN
109{
110 PLIST_ENTRY TempList = 0;
111 BOOLEAN AtLeastOneThreadUnpaused = FALSE;
112
113 TempList = &ProcessDebuggingDetail->ThreadsListHead;
114
115 while (&ProcessDebuggingDetail->ThreadsListHead != TempList->Flink)
116 {
117 TempList = TempList->Flink;
119 CONTAINING_RECORD(TempList, USERMODE_DEBUGGING_THREAD_HOLDER, ThreadHolderList);
120
121 for (SIZE_T i = 0; i < MAX_THREADS_IN_A_PROCESS_HOLDER; i++)
122 {
123 if (ThreadHolder->Threads[i].ThreadId != NULL_ZERO && ThreadHolder->Threads[i].IsPaused)
124 {
125 //
126 // At least one thread is paused, let's unpause it
127 //
128 ThreadHolder->Threads[i].IsPaused = FALSE;
129 AtLeastOneThreadUnpaused = TRUE;
130 }
131 }
132 }
133
134 return AtLeastOneThreadUnpaused;
135}

Variable Documentation

◆ VmxRootThreadHoldingLock

volatile LONG VmxRootThreadHoldingLock

Vmx-root lock for thread holding.