test: dbgkport.c File Reference

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# dbgkport.c File Reference

`#include "dbgkp.h"`

Go to the source code of this file.

## Functions

NTSTATUS | DbgkpSendApiMessage (IN OUT PDBGKM_APIMSG ApiMsg, IN PVOID Port, IN BOOLEAN SuspendProcess)
BOOLEAN | DbgkForwardException (IN PEXCEPTION_RECORD ExceptionRecord, IN BOOLEAN DebugException, IN BOOLEAN SecondChance)

## Variables

LARGE_INTEGER | DbgkpCalibrationTime

## Function Documentation

BOOLEAN DbgkForwardException | ( | IN PEXCEPTION_RECORD | ExceptionRecord,
|  | IN BOOLEAN | DebugException,
|  | IN BOOLEAN | SecondChance
| ) |

Definition at line 99 of file dbgkport.c.

References DbgkpSendApiMessage(), _EPROCESS::DebugPort, _EPROCESS::ExceptionPort, FALSE, NT_SUCCESS, NTSTATUS(), NULL, PAGED_CODE, PsGetCurrentProcess, PsGetCurrentThread, and TRUE.

Referenced by KiDispatchException().

    00107                    :
    00108
    00109     This function is called forward an exception to the calling process's
    00110     debug or subsystem exception port.
    00111
    00112 Arguments:
    00113
    00114     ExceptionRecord - Supplies a pointer to an exception record.
    00115
    00116     DebugException - Supplies a boolean variable that specifies whether
    00117         this exception is to be forwarded to the process's
    00118         DebugPort(TRUE), or to its ExceptionPort(FALSE).
    00119
    00120 Return Value:
    00121
    00122     TRUE - The process has a DebugPort or an ExceptionPort, and the reply
    00123         received from the port indicated that the exception was handled.
    00124
    00125     FALSE - The process either does not have a DebugPort or
    00126         ExceptionPort, or the process has a port, but the reply received
    00127         from the port indicated that the exception was not handled.
    00128
    00129 --*/
    00130
    00131 {
    00132     PEPROCESS Process;
    00133     PVOID Port;
    00134     DBGKM_APIMSG m;
    00135     PDBGKM_EXCEPTION args;
    00136     NTSTATUS st;
    00137
    00138     PAGED_CODE();
    00139
    00140     args = &m.u.Exception;
    00141
    00142     //
    00143     // Initialize the debug LPC message with default infomaation.
    00144     //
    00145
    00146     DBGKM_FORMAT_API_MSG(m,DbgKmExceptionApi,sizeof(*args));
    00147
    00148     //
    00149     // Get the address of the destination LPC port.
    00150     //
    00151
    00152     Process = PsGetCurrentProcess();
    00153     if (DebugException) {
    00154         Port = PsGetCurrentThread()->HideFromDebugger ? NULL : Process->DebugPort;
    00155
    00156     } else {
    00157         Port = Process->ExceptionPort;
    00158         m.h.u2.ZeroInit = LPC_EXCEPTION;
    00159     }
    00160
    00161     //
    00162     // If the destination LPC port address is NULL, then return FALSE.
    00163     //
    00164
    00165     if (Port == NULL) {
    00166         return FALSE;
    00167     }
    00168
    00169     //
    00170     // Fill in the remainder of the debug LPC message.
    00171     //
    00172
    00173     args->ExceptionRecord = *ExceptionRecord;
    00174     args->FirstChance = !SecondChance;
    00175
    00176     //
    00177     // Send the debug message to the destination LPC port.
    00178     //
    00179
    00180     st = DbgkpSendApiMessage(&m,Port,DebugException);
    00181
    00182     //
    00183     // If the send was not successful, then return a FALSE indicating that
    00184     // the port did not handle the exception. Otherwise, if the debug port
    00185     // is specified, then look at the return status in the message.
    00186     //
    00187
    00188     if (!NT_SUCCESS(st) ||
    00189         ((DebugException) &&
    00190         (m.ReturnedStatus == DBG_EXCEPTION_NOT_HANDLED || !NT_SUCCESS(m.ReturnedStatus)))) {
    00191         return FALSE;
    00192
    00193     } else {
    00194         return TRUE;
    00195     }
    00196 }
    }

NTSTATUS DbgkpSendApiMessage | ( | IN OUT PDBGKM_APIMSG | ApiMsg,
|  | IN PVOID | Port,
|  | IN BOOLEAN | SuspendProcess
| ) |

Definition at line 31 of file dbgkport.c.

References DbgkpResumeProcess(), DbgkpSuspendProcess(), FALSE, LpcRequestWaitReplyPort(), NT_SUCCESS, NTSTATUS(), NULL, PAGED_CODE, PsGetCurrentProcess, and TRUE.

Referenced by DbgkCreateThread(), DbgkExitProcess(), DbgkExitThread(), DbgkForwardException(), DbgkMapViewOfSection(), and DbgkUnMapViewOfSection().

    00039                    :
    00040
    00041     This function sends the specified API message over the specified
    00042     port. It is the callers responsibility to format the API message
    00043     prior to calling this function.
    00044
    00045     If the SuspendProcess flag is supplied, then all threads in the
    00046     calling process are first suspended. Upon receipt of the reply
    00047     message, the threads are resumed.
    00048
    00049 Arguments:
    00050
    00051     ApiMsg - Supplies the API message to send.
    00052
    00053     Port - Supplies the address of a port to send the api message.
    00054
    00055     SuspendProcess - A flag that if set to true, causes all of the
    00056         threads in the process to be suspended prior to the call,
    00057         and resumed upon receipt of a reply.
    00058
    00059 Return Value:
    00060
    00061     TBD
    00062
    00063 --*/
    00064
    00065 {
    00066     NTSTATUS st;
    00067     ULONG_PTR MessageBuffer[PORT_MAXIMUM_MESSAGE_LENGTH/sizeof(ULONG_PTR)];
    00068
    00069     PAGED_CODE();
    00070
    00071     if ( SuspendProcess ) {
    00072         DbgkpSuspendProcess(FALSE);
    00073     }
    00074
    00075     ApiMsg->ReturnedStatus = STATUS_PENDING;
    00076
    00077     PsGetCurrentProcess()->CreateProcessReported = TRUE;
    00078
    00079     st = LpcRequestWaitReplyPort(
    00080             Port,
    00081             (PPORT_MESSAGE) ApiMsg,
    00082             (PPORT_MESSAGE) &MessageBuffer[0]
    00083             );
    00084
    00085     ZwFlushInstructionCache(NtCurrentProcess(), NULL, 0);
    00086     if ( NT_SUCCESS(st) ) {
    00087         RtlMoveMemory(ApiMsg,MessageBuffer,sizeof(*ApiMsg));
    00088         }
    00089     if ( SuspendProcess ) {
    00090         DbgkpResumeProcess(FALSE);
    00091     }
    00092
    00093     return st;
    00094 }

## Variable Documentation

LARGE_INTEGER DbgkpCalibrationTime

| Definition at line 96 of file dbgkport.c.