00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
#include "dbgkp.h"
00023 
00024 
#ifdef ALLOC_PRAGMA
00025 
#pragma alloc_text(PAGE, DbgkpSendApiMessage)
00026 
#pragma alloc_text(PAGE, DbgkForwardException)
00027 
#endif
00028 
00029 
00030 
NTSTATUS
00031 DbgkpSendApiMessage(
00032     IN OUT PDBGKM_APIMSG ApiMsg,
00033     IN PVOID Port,
00034     IN BOOLEAN SuspendProcess
00035     )
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 
00058 
00059 
00060 
00061 
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 }
00095 
00096 LARGE_INTEGER 
DbgkpCalibrationTime;
00097 
00098 BOOLEAN
00099 DbgkForwardException(
00100     IN PEXCEPTION_RECORD ExceptionRecord,
00101     IN BOOLEAN DebugException,
00102     IN BOOLEAN SecondChance
00103     )
00104 
00105 
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123 
00124 
00125 
00126 
00127 
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     
00144     
00145 
00146     DBGKM_FORMAT_API_MSG(m,DbgKmExceptionApi,
sizeof(*args));
00147 
00148     
00149     
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     
00163     
00164 
00165     
if (Port == 
NULL) {
00166         
return FALSE;
00167     }
00168 
00169     
00170     
00171     
00172 
00173     args->ExceptionRecord = *ExceptionRecord;
00174     args->FirstChance = !SecondChance;
00175 
00176     
00177     
00178     
00179 
00180     st = 
DbgkpSendApiMessage(&m,Port,DebugException);
00181 
00182     
00183     
00184     
00185     
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 }