2006-06-28 17:02:37 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Win32 Base API
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: dll/win32/kernel32/debug/debugger.c
|
|
|
|
* PURPOSE: Wrappers for the NT Debug Implementation
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
2003-03-31 22:28:59 +00:00
|
|
|
*/
|
|
|
|
|
2006-06-28 17:02:37 +00:00
|
|
|
/* INCLUDES *****************************************************************/
|
2003-03-31 22:28:59 +00:00
|
|
|
|
|
|
|
#include <k32.h>
|
2006-06-28 17:02:37 +00:00
|
|
|
#define NDEBUG
|
2007-09-02 19:42:22 +00:00
|
|
|
#include <debug.h>
|
2006-06-28 17:02:37 +00:00
|
|
|
|
2006-10-22 23:28:33 +00:00
|
|
|
typedef struct _DBGSS_THREAD_DATA
|
|
|
|
{
|
|
|
|
struct _DBGSS_THREAD_DATA *Next;
|
|
|
|
HANDLE ThreadHandle;
|
|
|
|
HANDLE ProcessHandle;
|
|
|
|
DWORD ProcessId;
|
|
|
|
DWORD ThreadId;
|
|
|
|
BOOLEAN HandleMarked;
|
|
|
|
} DBGSS_THREAD_DATA, *PDBGSS_THREAD_DATA;
|
|
|
|
|
|
|
|
#define DbgSsSetThreadData(d) \
|
|
|
|
NtCurrentTeb()->DbgSsReserved[0] = d
|
|
|
|
|
|
|
|
#define DbgSsGetThreadData() \
|
|
|
|
((PDBGSS_THREAD_DATA)NtCurrentTeb()->DbgSsReserved[0])
|
|
|
|
|
|
|
|
/* PRIVATE FUNCTIONS *********************************************************/
|
|
|
|
|
|
|
|
VOID
|
|
|
|
WINAPI
|
|
|
|
SaveThreadHandle(IN DWORD dwProcessId,
|
|
|
|
IN DWORD dwThreadId,
|
|
|
|
IN HANDLE hThread)
|
|
|
|
{
|
|
|
|
PDBGSS_THREAD_DATA ThreadData;
|
|
|
|
|
|
|
|
/* Allocate a thread structure */
|
|
|
|
ThreadData = RtlAllocateHeap(RtlGetProcessHeap(),
|
|
|
|
0,
|
|
|
|
sizeof(DBGSS_THREAD_DATA));
|
|
|
|
if (!ThreadData) return;
|
|
|
|
|
|
|
|
/* Fill it out */
|
|
|
|
ThreadData->ThreadHandle = hThread;
|
|
|
|
ThreadData->ProcessId = dwProcessId;
|
|
|
|
ThreadData->ThreadId = dwThreadId;
|
|
|
|
ThreadData->ProcessHandle = NULL;
|
|
|
|
ThreadData->HandleMarked = FALSE;
|
|
|
|
|
|
|
|
/* Link it */
|
|
|
|
ThreadData->Next = DbgSsGetThreadData();
|
|
|
|
DbgSsSetThreadData(ThreadData);
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
WINAPI
|
|
|
|
SaveProcessHandle(IN DWORD dwProcessId,
|
|
|
|
IN HANDLE hProcess)
|
|
|
|
{
|
|
|
|
PDBGSS_THREAD_DATA ThreadData;
|
|
|
|
|
|
|
|
/* Allocate a thread structure */
|
|
|
|
ThreadData = RtlAllocateHeap(RtlGetProcessHeap(),
|
|
|
|
0,
|
|
|
|
sizeof(DBGSS_THREAD_DATA));
|
|
|
|
if (!ThreadData) return;
|
|
|
|
|
|
|
|
/* Fill it out */
|
|
|
|
ThreadData->ProcessHandle = hProcess;
|
|
|
|
ThreadData->ProcessId = dwProcessId;
|
|
|
|
ThreadData->ThreadId = 0;
|
|
|
|
ThreadData->ThreadHandle = NULL;
|
|
|
|
ThreadData->HandleMarked = FALSE;
|
|
|
|
|
|
|
|
/* Link it */
|
|
|
|
ThreadData->Next = DbgSsGetThreadData();
|
|
|
|
DbgSsSetThreadData(ThreadData);
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
WINAPI
|
|
|
|
MarkThreadHandle(IN DWORD dwThreadId)
|
|
|
|
{
|
|
|
|
PDBGSS_THREAD_DATA ThreadData;
|
|
|
|
|
|
|
|
/* Loop all thread data events */
|
|
|
|
ThreadData = DbgSsGetThreadData();
|
|
|
|
while (ThreadData)
|
|
|
|
{
|
|
|
|
/* Check if this one matches */
|
|
|
|
if (ThreadData->ThreadId == dwThreadId)
|
|
|
|
{
|
|
|
|
/* Mark the structure and break out */
|
|
|
|
ThreadData->HandleMarked = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move to the next one */
|
|
|
|
ThreadData = ThreadData->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
WINAPI
|
|
|
|
MarkProcessHandle(IN DWORD dwProcessId)
|
|
|
|
{
|
|
|
|
PDBGSS_THREAD_DATA ThreadData;
|
|
|
|
|
|
|
|
/* Loop all thread data events */
|
|
|
|
ThreadData = DbgSsGetThreadData();
|
|
|
|
while (ThreadData)
|
|
|
|
{
|
|
|
|
/* Check if this one matches */
|
|
|
|
if (ThreadData->ProcessId == dwProcessId)
|
|
|
|
{
|
|
|
|
/* Make sure the thread ID is empty */
|
|
|
|
if (!ThreadData->ThreadId)
|
|
|
|
{
|
|
|
|
/* Mark the structure and break out */
|
|
|
|
ThreadData->HandleMarked = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move to the next one */
|
|
|
|
ThreadData = ThreadData->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
WINAPI
|
|
|
|
RemoveHandles(IN DWORD dwProcessId,
|
|
|
|
IN DWORD dwThreadId)
|
|
|
|
{
|
|
|
|
PDBGSS_THREAD_DATA ThreadData;
|
|
|
|
|
|
|
|
/* Loop all thread data events */
|
|
|
|
ThreadData = DbgSsGetThreadData();
|
|
|
|
while (ThreadData)
|
|
|
|
{
|
|
|
|
/* Check if this one matches */
|
|
|
|
if (ThreadData->ProcessId == dwProcessId)
|
|
|
|
{
|
|
|
|
/* Make sure the thread ID matches too */
|
|
|
|
if (ThreadData->ThreadId == dwThreadId)
|
|
|
|
{
|
|
|
|
/* Check if we have a thread handle */
|
|
|
|
if (ThreadData->ThreadHandle)
|
|
|
|
{
|
|
|
|
/* Close it */
|
|
|
|
CloseHandle(ThreadData->ThreadHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we have a process handle */
|
|
|
|
if (ThreadData->ProcessHandle)
|
|
|
|
{
|
|
|
|
/* Close it */
|
|
|
|
CloseHandle(ThreadData->ProcessHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unlink the thread data */
|
|
|
|
DbgSsSetThreadData(ThreadData->Next);
|
|
|
|
|
|
|
|
/* Free it*/
|
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, ThreadData);
|
|
|
|
|
|
|
|
/* Move to the next structure */
|
|
|
|
ThreadData = DbgSsGetThreadData();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move to the next one */
|
|
|
|
ThreadData = ThreadData->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
WINAPI
|
|
|
|
CloseAllProcessHandles(IN DWORD dwProcessId)
|
|
|
|
{
|
|
|
|
PDBGSS_THREAD_DATA ThreadData;
|
|
|
|
|
|
|
|
/* Loop all thread data events */
|
|
|
|
ThreadData = DbgSsGetThreadData();
|
|
|
|
while (ThreadData)
|
|
|
|
{
|
|
|
|
/* Check if this one matches */
|
|
|
|
if (ThreadData->ProcessId == dwProcessId)
|
|
|
|
{
|
|
|
|
/* Check if we have a thread handle */
|
|
|
|
if (ThreadData->ThreadHandle)
|
|
|
|
{
|
|
|
|
/* Close it */
|
|
|
|
CloseHandle(ThreadData->ThreadHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we have a process handle */
|
|
|
|
if (ThreadData->ProcessHandle)
|
|
|
|
{
|
|
|
|
/* Close it */
|
|
|
|
CloseHandle(ThreadData->ProcessHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unlink the thread data */
|
|
|
|
DbgSsSetThreadData(ThreadData->Next);
|
|
|
|
|
|
|
|
/* Free it*/
|
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, ThreadData);
|
|
|
|
|
|
|
|
/* Move to the next structure */
|
|
|
|
ThreadData = DbgSsGetThreadData();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move to the next one */
|
|
|
|
ThreadData = ThreadData->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE
|
|
|
|
WINAPI
|
|
|
|
ProcessIdToHandle(IN DWORD dwProcessId)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
HANDLE Handle;
|
|
|
|
CLIENT_ID ClientId;
|
|
|
|
|
|
|
|
/* If we don't have a PID, look it up */
|
[KERNEL32]
Merge r34770, r36475, r36990, r37019, r43852, r43952, r43954, r43979, r43981, r46868 from amd64 branch:
- Multiple ULONG / SIZE_T fixes
- Use UlongToHandle / HandleToUlong to convert between DWORD ProcessId and ClientId.UniqueProcess
- implement amd64 version of _dump_context
- Make IsConsoleHandle 64bit safe
- Update kernel32.pspec with a lot of Win7 (commented out) and some amd64 specific exports, add some more comments and fix sorting
- Implement amd64 version of BaseThreadStartupThunk and BaseProcessStartThunk
- Stub amd64 version of SwitchToFiber
- Implement amd64 version of BasepInitializeContext
svn path=/trunk/; revision=48119
2010-07-19 18:52:18 +00:00
|
|
|
if (dwProcessId == MAXDWORD) dwProcessId = (DWORD_PTR)CsrGetProcessId();
|
2006-10-22 23:28:33 +00:00
|
|
|
|
|
|
|
/* Open a handle to the process */
|
2006-11-30 19:38:04 +00:00
|
|
|
ClientId.UniqueThread = NULL;
|
[KERNEL32]
Merge r34770, r36475, r36990, r37019, r43852, r43952, r43954, r43979, r43981, r46868 from amd64 branch:
- Multiple ULONG / SIZE_T fixes
- Use UlongToHandle / HandleToUlong to convert between DWORD ProcessId and ClientId.UniqueProcess
- implement amd64 version of _dump_context
- Make IsConsoleHandle 64bit safe
- Update kernel32.pspec with a lot of Win7 (commented out) and some amd64 specific exports, add some more comments and fix sorting
- Implement amd64 version of BaseThreadStartupThunk and BaseProcessStartThunk
- Stub amd64 version of SwitchToFiber
- Implement amd64 version of BasepInitializeContext
svn path=/trunk/; revision=48119
2010-07-19 18:52:18 +00:00
|
|
|
ClientId.UniqueProcess = UlongToHandle(dwProcessId);
|
2006-10-22 23:28:33 +00:00
|
|
|
InitializeObjectAttributes(&ObjectAttributes, NULL, 0, NULL, NULL);
|
|
|
|
Status = NtOpenProcess(&Handle,
|
|
|
|
PROCESS_ALL_ACCESS,
|
|
|
|
&ObjectAttributes,
|
|
|
|
&ClientId);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
SetLastErrorByStatus(Status);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the handle */
|
|
|
|
return Handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PUBLIC FUNCTIONS **********************************************************/
|
2003-03-31 22:28:59 +00:00
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
2004-12-09 19:03:33 +00:00
|
|
|
* @implemented
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2006-06-28 17:02:37 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
CheckRemoteDebuggerPresent(IN HANDLE hProcess,
|
|
|
|
OUT PBOOL pbDebuggerPresent)
|
2003-03-31 22:28:59 +00:00
|
|
|
{
|
2006-06-28 17:02:37 +00:00
|
|
|
HANDLE DebugPort;
|
|
|
|
NTSTATUS Status;
|
2005-01-18 13:59:14 +00:00
|
|
|
|
2006-06-28 17:02:37 +00:00
|
|
|
/* Make sure we have an output and process*/
|
|
|
|
if (!(pbDebuggerPresent) || !(hProcess))
|
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-01-18 13:59:14 +00:00
|
|
|
|
2006-06-28 17:02:37 +00:00
|
|
|
/* Check if the process has a debug object/port */
|
|
|
|
Status = NtQueryInformationProcess(hProcess,
|
|
|
|
ProcessDebugPort,
|
|
|
|
(PVOID)&DebugPort,
|
|
|
|
sizeof(HANDLE),
|
|
|
|
NULL);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Return the current state */
|
|
|
|
*pbDebuggerPresent = (DebugPort) ? TRUE : FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-03-31 22:28:59 +00:00
|
|
|
|
2006-06-28 17:02:37 +00:00
|
|
|
/* Otherwise, fail */
|
|
|
|
SetLastErrorByStatus(Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2006-06-28 17:02:37 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
ContinueDebugEvent(IN DWORD dwProcessId,
|
|
|
|
IN DWORD dwThreadId,
|
|
|
|
IN DWORD dwContinueStatus)
|
2003-03-31 22:28:59 +00:00
|
|
|
{
|
2006-06-28 17:02:37 +00:00
|
|
|
CLIENT_ID ClientId;
|
|
|
|
NTSTATUS Status;
|
2003-03-31 22:28:59 +00:00
|
|
|
|
2006-06-28 17:02:37 +00:00
|
|
|
/* Set the Client ID */
|
|
|
|
ClientId.UniqueProcess = (HANDLE)dwProcessId;
|
|
|
|
ClientId.UniqueThread = (HANDLE)dwThreadId;
|
2003-03-31 22:28:59 +00:00
|
|
|
|
2006-06-28 17:02:37 +00:00
|
|
|
/* Continue debugging */
|
|
|
|
Status = DbgUiContinue(&ClientId, dwContinueStatus);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
SetLastErrorByStatus(Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-03-31 22:28:59 +00:00
|
|
|
|
2006-10-22 23:28:33 +00:00
|
|
|
/* Remove the process/thread handles */
|
|
|
|
RemoveHandles(dwProcessId, dwThreadId);
|
2006-06-28 17:02:37 +00:00
|
|
|
|
2006-10-22 23:28:33 +00:00
|
|
|
/* Success */
|
|
|
|
return TRUE;
|
2006-06-28 17:02:37 +00:00
|
|
|
}
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
2006-06-28 17:02:37 +00:00
|
|
|
* @implemented
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2005-01-18 14:16:01 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2006-06-28 17:02:37 +00:00
|
|
|
DebugActiveProcess(IN DWORD dwProcessId)
|
2003-03-31 22:28:59 +00:00
|
|
|
{
|
2006-06-28 17:02:37 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
HANDLE Handle;
|
|
|
|
|
|
|
|
/* Connect to the debugger */
|
|
|
|
Status = DbgUiConnectToDbg();
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
SetLastErrorByStatus(Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-03-31 22:28:59 +00:00
|
|
|
|
2006-06-28 17:02:37 +00:00
|
|
|
/* Get the process handle */
|
|
|
|
Handle = ProcessIdToHandle(dwProcessId);
|
|
|
|
if (!Handle) return FALSE;
|
|
|
|
|
|
|
|
/* Now debug the process */
|
|
|
|
Status = DbgUiDebugActiveProcess(Handle);
|
2006-10-22 23:28:33 +00:00
|
|
|
NtClose(Handle);
|
|
|
|
|
|
|
|
/* Check if debugging worked */
|
2006-06-28 17:02:37 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
SetLastErrorByStatus(Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Success */
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
2006-06-28 17:02:37 +00:00
|
|
|
* @implemented
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2004-12-09 19:03:33 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2006-06-28 17:02:37 +00:00
|
|
|
DebugActiveProcessStop(IN DWORD dwProcessId)
|
2003-03-31 22:28:59 +00:00
|
|
|
{
|
2006-06-28 17:02:37 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
HANDLE Handle;
|
|
|
|
|
|
|
|
/* Get the process handle */
|
|
|
|
Handle = ProcessIdToHandle(dwProcessId);
|
|
|
|
if (!Handle) return FALSE;
|
|
|
|
|
2006-10-22 23:28:33 +00:00
|
|
|
/* Close all the process handles */
|
|
|
|
CloseAllProcessHandles(dwProcessId);
|
|
|
|
|
2006-06-28 17:02:37 +00:00
|
|
|
/* Now stop debgging the process */
|
|
|
|
Status = DbgUiStopDebugging(Handle);
|
|
|
|
NtClose(Handle);
|
|
|
|
|
|
|
|
/* Check for failure */
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
SetLastError(ERROR_ACCESS_DENIED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-03-31 22:28:59 +00:00
|
|
|
|
2006-06-28 17:02:37 +00:00
|
|
|
/* Success */
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
2006-06-28 17:02:37 +00:00
|
|
|
* @implemented
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2004-12-09 19:03:33 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2006-06-28 17:02:37 +00:00
|
|
|
DebugBreakProcess(IN HANDLE Process)
|
2003-03-31 22:28:59 +00:00
|
|
|
{
|
2006-06-28 17:02:37 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
/* Send the breakin request */
|
|
|
|
Status = DbgUiIssueRemoteBreakin(Process);
|
|
|
|
if(!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Failure */
|
|
|
|
SetLastErrorByStatus(Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Success */
|
|
|
|
return TRUE;
|
2003-03-31 22:28:59 +00:00
|
|
|
}
|
|
|
|
|
2006-06-28 17:02:37 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
DebugSetProcessKillOnExit(IN BOOL KillOnExit)
|
|
|
|
{
|
|
|
|
HANDLE Handle;
|
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG State;
|
|
|
|
|
|
|
|
/* Get the debug object */
|
|
|
|
Handle = DbgUiGetThreadDebugObject();
|
|
|
|
if (!Handle)
|
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
SetLastErrorByStatus(STATUS_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now set the kill-on-exit state */
|
|
|
|
State = KillOnExit;
|
|
|
|
Status = NtSetInformationDebugObject(Handle,
|
|
|
|
DebugObjectKillProcessOnExitInformation,
|
|
|
|
&State,
|
|
|
|
sizeof(State),
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Fail */
|
2009-01-06 19:58:53 +00:00
|
|
|
SetLastErrorByStatus(Status);
|
2006-06-28 17:02:37 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Success */
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2004-12-09 19:03:33 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2006-10-22 23:28:33 +00:00
|
|
|
IsDebuggerPresent(VOID)
|
2003-03-31 22:28:59 +00:00
|
|
|
{
|
2006-06-28 17:02:37 +00:00
|
|
|
return (BOOL)NtCurrentPeb()->BeingDebugged;
|
2003-03-31 22:28:59 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
2006-10-22 23:47:12 +00:00
|
|
|
* @implemented
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2004-12-09 19:03:33 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2006-06-28 17:02:37 +00:00
|
|
|
WaitForDebugEvent(IN LPDEBUG_EVENT lpDebugEvent,
|
2006-10-22 23:28:33 +00:00
|
|
|
IN DWORD dwMilliseconds)
|
2003-03-31 22:28:59 +00:00
|
|
|
{
|
2006-10-22 23:47:12 +00:00
|
|
|
LARGE_INTEGER WaitTime;
|
|
|
|
PLARGE_INTEGER Timeout;
|
|
|
|
DBGUI_WAIT_STATE_CHANGE WaitStateChange;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
/* Check if this is an infinite wait */
|
|
|
|
if (dwMilliseconds == INFINITE)
|
|
|
|
{
|
|
|
|
/* Under NT, this means no timer argument */
|
|
|
|
Timeout = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Otherwise, convert the time to NT Format */
|
|
|
|
WaitTime.QuadPart = UInt32x32To64(-10000, dwMilliseconds);
|
|
|
|
Timeout = &WaitTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Loop while we keep getting interrupted */
|
2007-10-19 23:21:45 +00:00
|
|
|
do
|
2006-10-22 23:47:12 +00:00
|
|
|
{
|
|
|
|
/* Call the native API */
|
|
|
|
Status = DbgUiWaitStateChange(&WaitStateChange, Timeout);
|
|
|
|
} while ((Status == STATUS_ALERTED) || (Status == STATUS_USER_APC));
|
|
|
|
|
|
|
|
/* Check if the wait failed */
|
2006-11-30 19:38:04 +00:00
|
|
|
if (!(NT_SUCCESS(Status)) || (Status == DBG_UNABLE_TO_PROVIDE_HANDLE))
|
2006-10-22 23:47:12 +00:00
|
|
|
{
|
|
|
|
/* Set the error code and quit */
|
|
|
|
SetLastErrorByStatus(Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we timed out */
|
|
|
|
if (Status == STATUS_TIMEOUT)
|
|
|
|
{
|
|
|
|
/* Fail with a timeout error */
|
|
|
|
SetLastError(ERROR_SEM_TIMEOUT);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert the structure */
|
|
|
|
Status = DbgUiConvertStateChangeStructure(&WaitStateChange, lpDebugEvent);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Set the error code and quit */
|
|
|
|
SetLastErrorByStatus(Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check what kind of event this was */
|
|
|
|
switch (lpDebugEvent->dwDebugEventCode)
|
|
|
|
{
|
|
|
|
/* New thread was created */
|
|
|
|
case CREATE_THREAD_DEBUG_EVENT:
|
|
|
|
|
|
|
|
/* Setup the thread data */
|
|
|
|
SaveThreadHandle(lpDebugEvent->dwProcessId,
|
|
|
|
lpDebugEvent->dwThreadId,
|
|
|
|
lpDebugEvent->u.CreateThread.hThread);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* New process was created */
|
|
|
|
case CREATE_PROCESS_DEBUG_EVENT:
|
|
|
|
|
|
|
|
/* Setup the process data */
|
|
|
|
SaveProcessHandle(lpDebugEvent->dwProcessId,
|
|
|
|
lpDebugEvent->u.CreateProcessInfo.hProcess);
|
|
|
|
|
|
|
|
/* Setup the thread data */
|
|
|
|
SaveThreadHandle(lpDebugEvent->dwProcessId,
|
|
|
|
lpDebugEvent->dwThreadId,
|
|
|
|
lpDebugEvent->u.CreateThread.hThread);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Process was exited */
|
|
|
|
case EXIT_PROCESS_DEBUG_EVENT:
|
|
|
|
|
|
|
|
/* Mark the thread data as such */
|
|
|
|
MarkProcessHandle(lpDebugEvent->dwProcessId);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Thread was exited */
|
|
|
|
case EXIT_THREAD_DEBUG_EVENT:
|
|
|
|
|
|
|
|
/* Mark the thread data */
|
|
|
|
MarkThreadHandle(lpDebugEvent->dwThreadId);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Nothing to do for anything else */
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return success */
|
|
|
|
return TRUE;
|
2003-03-31 22:28:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|