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

udbgk.c File Reference

#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>
#include <ntdbg.h>

Go to the source code of this file.

Functions

NTSTATUS ThreadThatExits (IN PVOID ThreadParameter)
ULONG foo (PULONG l)
NTSTATUS ThreadThatExcepts (IN PVOID ThreadParameter)
NTSTATUS ThreadThatSpins (IN PVOID ThreadParameter)
 UdbgTest1 ()
 UdbgTest2 ()
 main ()

Variables

HANDLE DebugPort


Function Documentation

ULONG foo PULONG  l  ) 
 

Definition at line 38 of file udbgk.c.

Referenced by SLEditWndProc().

00039 { 00040 //ULONG x; 00041 //x = *l; 00042 //return x + 1; 00043 00044 return *l; 00045 00046 }

main  ) 
 

Definition at line 453 of file udbgk.c.

References ASSERT, DebugPort, L, NT_SUCCESS, NtCreatePort(), NTSTATUS(), NULL, UdbgTest1(), and UdbgTest2().

00454 { 00455 NTSTATUS st; 00456 OBJECT_ATTRIBUTES Obja; 00457 00458 InitializeObjectAttributes(&Obja, NULL, 0, NULL, NULL); 00459 00460 st = NtCreatePort( 00461 &DebugPort, 00462 &Obja, 00463 0L, 00464 256, 00465 256 * 16 00466 ); 00467 ASSERT(NT_SUCCESS(st)); 00468 00469 UdbgTest2(); 00470 UdbgTest1(); 00471 00472 }

NTSTATUS ThreadThatExcepts IN PVOID  ThreadParameter  ) 
 

Definition at line 49 of file udbgk.c.

References foo(), NTSTATUS(), and NtTerminateThread().

Referenced by UdbgTest2().

00052 { 00053 foo((PULONG)0x00000001); 00054 NtTerminateThread(NtCurrentThread(),(NTSTATUS) ThreadParameter ); 00055 }

NTSTATUS ThreadThatExits IN PVOID  ThreadParameter  ) 
 

Definition at line 30 of file udbgk.c.

References NTSTATUS(), and NtTerminateThread().

Referenced by UdbgTest1().

00033 { 00034 NtTerminateThread(NtCurrentThread(),(NTSTATUS) ThreadParameter ); 00035 }

NTSTATUS ThreadThatSpins IN PVOID  ThreadParameter  ) 
 

Definition at line 60 of file udbgk.c.

References NtTerminateThread().

Referenced by UdbgTest1().

00063 { 00064 for(;;); 00065 NtTerminateThread(NtCurrentThread(),STATUS_SUCCESS); 00066 }

UdbgTest1  ) 
 

Definition at line 69 of file udbgk.c.

References ASSERT, DbgPrint, DebugPort, FALSE, L, NT_SUCCESS, NtClose(), NtCreateProcess(), NtReplyPort(), NtReplyWaitReceivePort(), NtResumeThread(), NTSTATUS(), NtSuspendThread(), NtTerminateProcess(), NtWaitForSingleObject(), NULL, RtlCreateUserThread(), ThreadThatExits(), ThreadThatSpins(), and TRUE.

Referenced by main().

00070 { 00071 NTSTATUS st; 00072 HANDLE ExitThread, SpinThread, DebugProcess; 00073 CLIENT_ID ExitClientId, SpinClientId; 00074 DBGKM_APIMSG m; 00075 PDBGKM_CREATE_THREAD CreateThreadArgs; 00076 PDBGKM_CREATE_PROCESS CreateProcessArgs; 00077 PDBGKM_EXIT_THREAD ExitThreadArgs; 00078 PDBGKM_EXIT_PROCESS ExitProcessArgs; 00079 ULONG Psp; 00080 00081 DbgPrint("UdbgTest1: (1)...\n"); 00082 00083 // 00084 // Verify that a process can be created with a debug 00085 // port. 00086 // 00087 00088 st = NtCreateProcess( 00089 &DebugProcess, 00090 PROCESS_ALL_ACCESS, 00091 NULL, 00092 NtCurrentProcess(), 00093 FALSE, 00094 NULL, 00095 DebugPort, 00096 NULL 00097 ); 00098 ASSERT(NT_SUCCESS(st)); 00099 00100 st = RtlCreateUserThread( 00101 DebugProcess, 00102 NULL, 00103 TRUE, 00104 0L, 00105 0L, 00106 0L, 00107 ThreadThatExits, 00108 (PVOID) STATUS_ABANDONED, 00109 &ExitThread, 00110 &ExitClientId 00111 ); 00112 ASSERT(NT_SUCCESS(st)); 00113 00114 st = RtlCreateUserThread( 00115 DebugProcess, 00116 NULL, 00117 TRUE, 00118 0L, 00119 0L, 00120 0L, 00121 ThreadThatSpins, 00122 NULL, 00123 &SpinThread, 00124 &SpinClientId 00125 ); 00126 ASSERT(NT_SUCCESS(st)); 00127 00128 DbgPrint("UdbgTest1: (2)...\n"); 00129 00130 // 00131 // Verify that CreateProcess Messages Arrive, and that 00132 // they are correct 00133 // 00134 00135 st = NtResumeThread(SpinThread,NULL); 00136 ASSERT(NT_SUCCESS(st)); 00137 00138 st = NtReplyWaitReceivePort( 00139 DebugPort, 00140 NULL, 00141 NULL, 00142 (PPORT_MESSAGE)&m 00143 ); 00144 ASSERT(NT_SUCCESS(st)); 00145 ASSERT(m.ApiNumber == DbgKmCreateProcessApi); 00146 00147 CreateThreadArgs = &m.u.CreateProcess.InitialThread; 00148 CreateProcessArgs = &m.u.CreateProcess; 00149 ASSERT( CreateThreadArgs->SubSystemKey == 0 && CreateThreadArgs->StartAddress == (PVOID)ThreadThatSpins ); 00150 ASSERT( CreateProcessArgs->SubSystemKey == 0); 00151 00152 DbgPrint("UdbgTest1: (3)...\n"); 00153 00154 // 00155 // Verify that other threads in the process are properly suspended 00156 // 00157 00158 st = NtSuspendThread(ExitThread,&Psp); 00159 ASSERT(NT_SUCCESS(st) && Psp == 2); 00160 00161 st = NtResumeThread(ExitThread,&Psp); 00162 ASSERT(NT_SUCCESS(st) && Psp == 3); 00163 00164 st = NtReplyPort(DebugPort,(PPORT_MESSAGE)&m); 00165 ASSERT(NT_SUCCESS(st)); 00166 00167 00168 DbgPrint("UdbgTest1: (4)...\n"); 00169 00170 // 00171 // Verify that CreateThread Messages Arrive, and that 00172 // they are correct 00173 // 00174 00175 st = NtResumeThread(ExitThread,&Psp); 00176 ASSERT(NT_SUCCESS(st)); 00177 00178 st = NtReplyWaitReceivePort( 00179 DebugPort, 00180 NULL, 00181 NULL, 00182 (PPORT_MESSAGE)&m 00183 ); 00184 ASSERT(NT_SUCCESS(st)); 00185 ASSERT(m.ApiNumber == DbgKmCreateThreadApi); 00186 00187 CreateThreadArgs = &m.u.CreateThread; 00188 ASSERT( CreateThreadArgs->SubSystemKey == 0 && CreateThreadArgs->StartAddress == (PVOID)ThreadThatExits ); 00189 00190 st = NtReplyPort(DebugPort,(PPORT_MESSAGE)&m); 00191 ASSERT(NT_SUCCESS(st)); 00192 00193 DbgPrint("UdbgTest1: (5)...\n"); 00194 00195 // 00196 // Verify that ExitThread Messages Arrive, and that 00197 // they are correct 00198 // 00199 00200 st = NtReplyWaitReceivePort( 00201 DebugPort, 00202 NULL, 00203 NULL, 00204 (PPORT_MESSAGE)&m 00205 ); 00206 ASSERT(NT_SUCCESS(st)); 00207 ASSERT(m.ApiNumber == DbgKmExitThreadApi); 00208 00209 ExitThreadArgs = &m.u.ExitThread; 00210 ASSERT( ExitThreadArgs->ExitStatus == STATUS_ABANDONED ); 00211 00212 st = NtReplyPort(DebugPort,(PPORT_MESSAGE)&m); 00213 ASSERT(NT_SUCCESS(st)); 00214 00215 st = NtWaitForSingleObject(ExitThread,FALSE,NULL); 00216 ASSERT(NT_SUCCESS(st)); 00217 00218 DbgPrint("UdbgTest1: (6)...\n"); 00219 00220 // 00221 // Verify that ExitThread Messages Arrive, and that 00222 // they are correct 00223 // 00224 00225 st = NtTerminateProcess(DebugProcess,STATUS_REPARSE); 00226 ASSERT(NT_SUCCESS(st)); 00227 00228 st = NtReplyWaitReceivePort( 00229 DebugPort, 00230 NULL, 00231 NULL, 00232 (PPORT_MESSAGE)&m 00233 ); 00234 ASSERT(NT_SUCCESS(st)); 00235 ASSERT(m.ApiNumber == DbgKmExitThreadApi); 00236 00237 ExitThreadArgs = &m.u.ExitThread; 00238 ASSERT( ExitThreadArgs->ExitStatus == STATUS_REPARSE ); 00239 00240 st = NtReplyPort(DebugPort,(PPORT_MESSAGE)&m); 00241 ASSERT(NT_SUCCESS(st)); 00242 00243 DbgPrint("UdbgTest1: (7)...\n"); 00244 00245 // 00246 // Verify that ExitProcess Messages Arrive, and that 00247 // they are correct 00248 // 00249 00250 st = NtReplyWaitReceivePort( 00251 DebugPort, 00252 NULL, 00253 NULL, 00254 (PPORT_MESSAGE)&m 00255 ); 00256 ASSERT(NT_SUCCESS(st)); 00257 ASSERT(m.ApiNumber == DbgKmExitProcessApi); 00258 00259 ExitProcessArgs = &m.u.ExitProcess; 00260 ASSERT( ExitProcessArgs->ExitStatus == STATUS_REPARSE ); 00261 00262 st = NtReplyPort(DebugPort,(PPORT_MESSAGE)&m); 00263 ASSERT(NT_SUCCESS(st)); 00264 00265 00266 st = NtWaitForSingleObject(ExitThread,FALSE,NULL); 00267 ASSERT(NT_SUCCESS(st)); 00268 00269 st = NtWaitForSingleObject(DebugProcess,FALSE,NULL); 00270 ASSERT(NT_SUCCESS(st)); 00271 00272 NtClose(ExitThread); 00273 NtClose(SpinThread); 00274 NtClose(DebugProcess); 00275 00276 DbgPrint("UdbgTest1: END OF TEST ***\n"); 00277 00278 }

UdbgTest2  ) 
 

Definition at line 280 of file udbgk.c.

References ASSERT, DbgPrint, DebugPort, FALSE, L, NT_SUCCESS, NtClose(), NtCreateProcess(), NtReplyPort(), NtReplyWaitReceivePort(), NtResumeThread(), NTSTATUS(), NtTerminateProcess(), NtWaitForSingleObject(), NULL, RtlCreateUserThread(), ThreadThatExcepts(), and TRUE.

Referenced by main().

00281 { 00282 NTSTATUS st; 00283 HANDLE ExceptionThread, DebugProcess; 00284 DBGKM_APIMSG m; 00285 PDBGKM_CREATE_THREAD CreateThreadArgs; 00286 PDBGKM_CREATE_PROCESS CreateProcessArgs; 00287 PDBGKM_EXIT_THREAD ExitThreadArgs; 00288 PDBGKM_EXIT_PROCESS ExitProcessArgs; 00289 PDBGKM_EXCEPTION ExceptionArgs; 00290 ULONG Psp; 00291 00292 DbgPrint("UdbgTest2: (1)...\n"); 00293 00294 // 00295 // Verify that a process can be created with a debug 00296 // port. 00297 // 00298 00299 st = NtCreateProcess( 00300 &DebugProcess, 00301 PROCESS_ALL_ACCESS, 00302 NULL, 00303 NtCurrentProcess(), 00304 FALSE, 00305 NULL, 00306 DebugPort, 00307 NULL 00308 ); 00309 ASSERT(NT_SUCCESS(st)); 00310 00311 st = RtlCreateUserThread( 00312 DebugProcess, 00313 NULL, 00314 TRUE, 00315 0L, 00316 0L, 00317 0L, 00318 ThreadThatExcepts, 00319 (PVOID) STATUS_ABANDONED, 00320 &ExceptionThread, 00321 NULL 00322 ); 00323 ASSERT(NT_SUCCESS(st)); 00324 00325 DbgPrint("UdbgTest2: (2)...\n"); 00326 00327 // 00328 // Verify that CreateThread Messages Arrive, and that 00329 // they are correct 00330 // 00331 00332 st = NtResumeThread(ExceptionThread,NULL); 00333 ASSERT(NT_SUCCESS(st)); 00334 00335 st = NtReplyWaitReceivePort( 00336 DebugPort, 00337 NULL, 00338 NULL, 00339 (PPORT_MESSAGE)&m 00340 ); 00341 ASSERT(NT_SUCCESS(st)); 00342 ASSERT(m.ApiNumber == DbgKmCreateProcessApi); 00343 00344 CreateThreadArgs = &m.u.CreateProcess.InitialThread; 00345 CreateProcessArgs = &m.u.CreateProcess; 00346 ASSERT( CreateThreadArgs->SubSystemKey == 0 && CreateThreadArgs->StartAddress == (PVOID)ThreadThatExcepts ); 00347 ASSERT( CreateProcessArgs->SubSystemKey == 0); 00348 00349 st = NtReplyPort(DebugPort,(PPORT_MESSAGE)&m); 00350 ASSERT(NT_SUCCESS(st)); 00351 00352 DbgPrint("UdbgTest2: (3)...\n"); 00353 00354 // 00355 // Verify that First Chance Exception Messages Arrive, and that 00356 // they are correct 00357 // 00358 00359 st = NtReplyWaitReceivePort( 00360 DebugPort, 00361 NULL, 00362 NULL, 00363 (PPORT_MESSAGE)&m 00364 ); 00365 ASSERT(NT_SUCCESS(st)); 00366 ASSERT(m.ApiNumber == DbgKmExceptionApi); 00367 00368 ExceptionArgs = &m.u.Exception; 00369 ASSERT( ExceptionArgs->FirstChance == TRUE ); 00370 00371 m.ReturnedStatus = DBG_EXCEPTION_NOT_HANDLED; 00372 00373 st = NtReplyPort(DebugPort,(PPORT_MESSAGE)&m); 00374 ASSERT(NT_SUCCESS(st)); 00375 00376 DbgPrint("UdbgTest2: (4)...\n"); 00377 00378 // 00379 // Verify that First Chance Exception Messages Arrive, and that 00380 // they are correct 00381 // 00382 00383 st = NtReplyWaitReceivePort( 00384 DebugPort, 00385 NULL, 00386 NULL, 00387 (PPORT_MESSAGE)&m 00388 ); 00389 ASSERT(NT_SUCCESS(st)); 00390 ASSERT(m.ApiNumber == DbgKmExceptionApi); 00391 00392 ExceptionArgs = &m.u.Exception; 00393 ASSERT( ExceptionArgs->FirstChance == FALSE ); 00394 00395 m.ReturnedStatus = DBG_EXCEPTION_HANDLED; 00396 skip4: 00397 st = NtTerminateProcess(DebugProcess,STATUS_REPARSE); 00398 ASSERT(NT_SUCCESS(st)); 00399 00400 st = NtReplyPort(DebugPort,(PPORT_MESSAGE)&m); 00401 ASSERT(NT_SUCCESS(st)); 00402 00403 st = NtReplyWaitReceivePort( 00404 DebugPort, 00405 NULL, 00406 NULL, 00407 (PPORT_MESSAGE)&m 00408 ); 00409 ASSERT(NT_SUCCESS(st)); 00410 ASSERT(m.ApiNumber == DbgKmExitThreadApi); 00411 00412 ExitThreadArgs = &m.u.ExitThread; 00413 ASSERT( ExitThreadArgs->ExitStatus == STATUS_REPARSE ); 00414 00415 st = NtReplyPort(DebugPort,(PPORT_MESSAGE)&m); 00416 ASSERT(NT_SUCCESS(st)); 00417 00418 DbgPrint("UdbgTest2: (5)...\n"); 00419 00420 // 00421 // Verify that ExitProcess Messages Arrive, and that 00422 // they are correct 00423 // 00424 00425 st = NtReplyWaitReceivePort( 00426 DebugPort, 00427 NULL, 00428 NULL, 00429 (PPORT_MESSAGE)&m 00430 ); 00431 ASSERT(NT_SUCCESS(st)); 00432 ASSERT(m.ApiNumber == DbgKmExitProcessApi); 00433 00434 ExitProcessArgs = &m.u.ExitProcess; 00435 ASSERT( ExitProcessArgs->ExitStatus == STATUS_REPARSE ); 00436 00437 st = NtReplyPort(DebugPort,(PPORT_MESSAGE)&m); 00438 ASSERT(NT_SUCCESS(st)); 00439 00440 00441 st = NtWaitForSingleObject(ExceptionThread,FALSE,NULL); 00442 ASSERT(NT_SUCCESS(st)); 00443 00444 st = NtWaitForSingleObject(DebugProcess,FALSE,NULL); 00445 ASSERT(NT_SUCCESS(st)); 00446 00447 NtClose(ExceptionThread); 00448 NtClose(DebugProcess); 00449 00450 DbgPrint("UdbgTest2: END OF TEST ***\n"); 00451 }


Variable Documentation

HANDLE DebugPort
 

Definition at line 26 of file udbgk.c.

Referenced by _EndTask(), CreateCtrlThread(), main(), NtCreateProcess(), NtQueryInformationProcess(), NtSetInformationProcess(), PspCreateProcess(), RtlCreateUserProcess(), UdbgTest1(), UdbgTest2(), and UserClientShutdown().


Generated on Sat May 15 19:45:50 2004 for test by doxygen 1.3.7