Message->ReturnedStatus = STATUS_PENDING;
/* Set create process reported state */
- PsGetCurrentProcess()->CreateReported = TRUE;
+ PspSetProcessFlag(PsGetCurrentProcess(), PSF_CREATE_REPORTED_BIT);
/* Send the LPC command */
Status = LpcRequestWaitReplyPort(Port,
ApiMsg->ReturnedStatus = STATUS_PENDING;
/* Set create process reported state */
- PsGetCurrentProcess()->CreateReported = TRUE;
+ PspSetProcessFlag(PsGetCurrentProcess(), PSF_CREATE_REPORTED_BIT);
/* Send the LPC command */
Status = DbgkpQueueMessage(PsGetCurrentProcess(),
BOOLEAN DebugPortCleared = FALSE;
PLIST_ENTRY DebugEventList;
PDEBUG_EVENT DebugEvent;
+ PAGED_CODE();
DBGKTRACE(DBGK_OBJECT_DEBUG, "OwnerProcess: %p DebugObject: %p\n",
OwnerProcess, DebugObject);
else
{
/* Set the process flags */
- InterlockedOr((PLONG)&Process->Flags,
- PSF_NO_DEBUG_INHERIT_BIT | PSF_CREATE_REPORTED_BIT);
+ PspSetProcessFlag(Process,
+ PSF_NO_DEBUG_INHERIT_BIT |
+ PSF_CREATE_REPORTED_BIT);
/* Reference the debug object */
ObReferenceObject(DebugObject);
&hDebug);
if (NT_SUCCESS(Status))
{
+ /* Enter SEH to protect the write */
_SEH2_TRY
{
+ /* Return the handle */
*DebugHandle = hDebug;
}
- _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+ _SEH2_EXCEPT(ExSystemExceptionFilter())
{
+ /* Get the exception code */
Status = _SEH2_GetExceptionCode();
} _SEH2_END;
}
{
/* Wake it up and break out */
DebugEvent->Flags &= ~DEBUG_EVENT_INACTIVE;
- KeSetEvent(&DebugEvent->ContinueEvent,
+ KeSetEvent(&DebugObject->EventsPresent,
IO_NO_INCREMENT,
FALSE);
break;
if (NeedsWake)
{
/* Set the continue status */
- DebugEvent->ApiMsg.ReturnedStatus = ContinueStatus;
- DebugEvent->Status = STATUS_SUCCESS;
+ DebugEventToWake->ApiMsg.ReturnedStatus = ContinueStatus;
+ DebugEventToWake->Status = STATUS_SUCCESS;
/* Wake the target */
- DbgkpWakeTarget(DebugEvent);
+ DbgkpWakeTarget(DebugEventToWake);
}
else
{
{
PEPROCESS Process;
PDEBUG_OBJECT DebugObject;
- KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
+ KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
PETHREAD LastThread;
NTSTATUS Status;
PAGED_CODE();
NULL);
if (!NT_SUCCESS(Status)) return Status;
- /* Don't allow debugging the initial system process */
- if (Process == PsInitialSystemProcess)
+ /* Don't allow debugging the current process or the system process */
+ if ((Process == PsGetCurrentProcess()) ||
+ (Process == PsInitialSystemProcess))
{
/* Dereference and fail */
ObDereferenceObject(Process);
{
PEPROCESS Process;
PDEBUG_OBJECT DebugObject;
- KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
+ KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
NTSTATUS Status;
PAGED_CODE();
DBGKTRACE(DBGK_PROCESS_DEBUG, "Process: %p Handle: %p\n",
OUT PDBGUI_WAIT_STATE_CHANGE StateChange)
{
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
- LARGE_INTEGER SafeTimeOut;
+ LARGE_INTEGER LocalTimeOut;
PEPROCESS Process;
LARGE_INTEGER StartTime;
PETHREAD Thread;
PAGED_CODE();
DBGKTRACE(DBGK_OBJECT_DEBUG, "Handle: %p\n", DebugHandle);
- /* Clear the initial wait state change structure */
+ /* Clear the initial wait state change structure and the timeout */
RtlZeroMemory(&WaitStateChange, sizeof(WaitStateChange));
+ LocalTimeOut.QuadPart = 0;
- /* Protect probe in SEH */
- _SEH2_TRY
+ /* Check if we were called from user mode */
+ if (PreviousMode != KernelMode)
{
- /* Check if we came with a timeout */
- if (Timeout)
+ /* Protect probe in SEH */
+ _SEH2_TRY
{
- /* Check if the call was from user mode */
- if (PreviousMode != KernelMode)
+ /* Check if we came with a timeout */
+ if (Timeout)
{
/* Probe it */
ProbeForReadLargeInteger(Timeout);
- }
-
- /* Make a local copy */
- SafeTimeOut = *Timeout;
- Timeout = &SafeTimeOut;
- /* Query the current time */
- KeQuerySystemTime(&StartTime);
- }
+ /* Make a local copy */
+ LocalTimeOut = *Timeout;
+ Timeout = &LocalTimeOut;
+ }
- /* Check if the call was from user mode */
- if (PreviousMode != KernelMode)
- {
/* Probe the state change structure */
ProbeForWrite(StateChange, sizeof(*StateChange), sizeof(ULONG));
}
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+ {
+ /* Get the exception code */
+ Status = _SEH2_GetExceptionCode();
+ }
+ _SEH2_END;
+ if (!NT_SUCCESS(Status)) return Status;
}
- _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+ else
{
- /* Get the exception code */
- Status = _SEH2_GetExceptionCode();
+ /* Copy directly */
+ if (Timeout) LocalTimeOut = *Timeout;
}
- _SEH2_END;
- if (!NT_SUCCESS(Status)) return Status;
+
+ /* If we were passed a timeout, query the current time */
+ if (Timeout) KeQuerySystemTime(&StartTime);
/* Get the debug object */
Status = ObReferenceObjectByHandle(DebugHandle,
/* Wait on the debug object given to us */
while (TRUE)
{
- Status = KeWaitForSingleObject(DebugObject,
+ Status = KeWaitForSingleObject(&DebugObject->EventsPresent,
Executive,
PreviousMode,
Alertable,
if (!GotEvent)
{
/* Check if we can wait again */
- if (SafeTimeOut.QuadPart < 0)
+ if (LocalTimeOut.QuadPart < 0)
{
/* Query the new time */
KeQuerySystemTime(&NewTime);
/* Substract times */
- SafeTimeOut.QuadPart += (NewTime.QuadPart - StartTime.QuadPart);
+ LocalTimeOut.QuadPart += (NewTime.QuadPart - StartTime.QuadPart);
StartTime = NewTime;
/* Check if we've timed out */
- if (SafeTimeOut.QuadPart >= 0)
+ if (LocalTimeOut.QuadPart >= 0)
{
/* We have, break out of the loop */
Status = STATUS_TIMEOUT;
#define NDEBUG
#include <debug.h>
-extern ULONG DbgkpTraceLevel;
-
/* FUNCTIONS *****************************************************************/
HANDLE
VOID
NTAPI
-DbgkCreateThread(PVOID StartAddress)
+DbgkCreateThread(IN PETHREAD Thread,
+ IN PVOID StartAddress)
{
- PETHREAD Thread = PsGetCurrentThread();
PEPROCESS Process = PsGetCurrentProcess();
ULONG ProcessFlags;
IMAGE_INFO ImageInfo;
PTEB Teb;
PAGED_CODE();
+ /* Sanity check */
+ ASSERT(Thread == PsGetCurrentThread());
+
/* Try ORing in the create reported and image notify flags */
- ProcessFlags = InterlockedOr((PLONG)&Process->Flags,
- PSF_CREATE_REPORTED_BIT |
- PSF_IMAGE_NOTIFY_DONE_BIT);
+ ProcessFlags = PspSetProcessFlag(Process,
+ PSF_CREATE_REPORTED_BIT |
+ PSF_IMAGE_NOTIFY_DONE_BIT);
/* Check if we were the first to set them or if another thread raced us */
if (!(ProcessFlags & PSF_IMAGE_NOTIFY_DONE_BIT) && (PsImageNotifyEnabled))
{
/* Otherwise, do it just for the thread */
CreateThread->SubSystemKey = 0;
- CreateThread->StartAddress = NULL;
+ CreateThread->StartAddress = StartAddress;
/* Setup the API Message */
ApiMessage.h.u1.Length = sizeof(DBGKM_MSG) << 16 |
DBGKTRACE(DBGK_PROCESS_DEBUG,
"Section: %p. Base: %p\n", Section, BaseAddress);
- /* Check if this thread is hidden, doesn't have a debug port, or died */
- if ((Thread->HideFromDebugger) ||
- !(Process->DebugPort) ||
- (Thread->DeadThread) ||
- (KeGetPreviousMode() == KernelMode))
+ /* Check if this thread is kernel, hidden or doesn't have a debug port */
+ if ((ExGetPreviousMode() == KernelMode) ||
+ (Thread->HideFromDebugger) ||
+ !(Process->DebugPort))
{
/* Don't notify the debugger */
return;
PETHREAD Thread = PsGetCurrentThread();
PAGED_CODE();
- /* Check if this thread is hidden, doesn't have a debug port, or died */
- if ((Thread->HideFromDebugger) ||
- !(Process->DebugPort) ||
- (Thread->DeadThread) ||
- (KeGetPreviousMode() == KernelMode))
+ /* Check if this thread is kernel, hidden or doesn't have a debug port */
+ if ((ExGetPreviousMode() == KernelMode) ||
+ (Thread->HideFromDebugger) ||
+ !(Process->DebugPort))
{
/* Don't notify the debugger */
return;
/* Send the message */
DbgkpSendApiMessage(&ApiMessage, TRUE);
}
-
-/* EOF */