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
00085
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
00132
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
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
00172
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
00197
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
00222
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
00247
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 }