13typedef VOID(NTAPI*
PS_APC_ROUTINE_t)(PVOID ApcArgument1, PVOID ApcArgument2, PVOID ApcArgument3);
15 PVOID ApcArgument1, PVOID ApcArgument2, PVOID ApcArgument3);
17 ULONG ApcFlags,
PS_APC_ROUTINE_t ApcRoutine, PVOID ApcArgument1, PVOID ApcArgument2, PVOID ApcArgument3);
19#define TEST_SPECIAL_USER_APC 0x1
21static VOID NTAPI NtApc(PVOID, PVOID, PVOID) {}
22static VOID CALLBACK UserApc(ULONG_PTR) {}
24static void QueueNt(HANDLE thread) {
28static NTSTATUS QueueNtEx2(HANDLE thread, ULONG flags) {
31 fprintf(stderr,
" NtQueueApcThreadEx2 is not exported by this ntdll\n");
32 return (NTSTATUS)0xC0000002;
34 return queue(thread, NULL, flags, NtApc, NULL, NULL, NULL);
38static void DrainApcs() {
43static const std::vector<HookTestCase> g_Cases = {
47 "APC queued to a remote thread",
49 QueueNt(context.RemoteThread());
51 {
"NtQueueApcThread: APC queued to a thread in the remote process, routine *, flags 0x0" },
54 "APC queued to the current thread (pseudo-handle) is not reported",
56 QueueNt(GetCurrentThread());
62 "APC queued through a real handle to the current thread is not reported",
64 HANDLE thread = OpenThread(THREAD_SET_CONTEXT | THREAD_QUERY_LIMITED_INFORMATION, FALSE, GetCurrentThreadId());
74 "APC queued through a local thread handle without query access is not reported",
76 HANDLE thread = OpenThread(THREAD_SET_CONTEXT, FALSE, GetCurrentThreadId());
84 "APC queued through a remote thread handle without query access is reported",
86 HANDLE thread = OpenThread(THREAD_SET_CONTEXT, FALSE, GetThreadId(context.RemoteThread()));
90 {
"NtQueueApcThread: APC queued to a thread in the remote process, routine *, flags 0x0" },
93 "Failed APC queue to a remote thread is not reported",
96 HANDLE thread = OpenThread(THREAD_QUERY_LIMITED_INFORMATION, FALSE, GetThreadId(context.RemoteThread()));
106 "Ex2: APC queued to a remote thread",
108 QueueNtEx2(context.RemoteThread(), 0);
110 {
"NtQueueApcThreadEx2: APC queued to a thread in the remote process, routine *, flags 0x0" },
115 "Ex2: special user APC queued to a remote thread",
119 {
"NtQueueApcThreadEx2: APC queued to a thread in the remote process, routine *, flags 0x1" },
125 "Ex2: special user APC to a 32-bit remote thread fails and is not reported",
128 if (status != (NTSTATUS)0xC00000BB) {
129 fprintf(stderr,
" expected STATUS_NOT_SUPPORTED, got 0x%08lx\n", (
unsigned long)status);
136 "Ex2: APC queued to the current thread is not reported",
138 QueueNtEx2(GetCurrentThread(), 0);
144 "Ex2: failed APC queue to a remote thread is not reported",
146 HANDLE thread = OpenThread(THREAD_QUERY_LIMITED_INFORMATION, FALSE, GetThreadId(context.RemoteThread()));
147 QueueNtEx2(thread, 0);
156 "QueueUserAPC to a remote thread",
158 if (!QueueUserAPC(UserApc, context.RemoteThread(), 0)) {
159 fprintf(stderr,
" QueueUserAPC failed (error %lu)\n", GetLastError());
162 {
"NtQueueApcThreadEx2: APC queued to a thread in the remote process, routine *, flags 0x0" },
165 "QueueUserAPC to the current thread is not reported",
167 QueueUserAPC(UserApc, GetCurrentThread(), 0);
174int main(
int argc,
char** argv) {
175 return RunHookTests(argc, argv,
"NtQueueApcThread", g_Cases);
VOID(NTAPI * PS_APC_ROUTINE_t)(PVOID ApcArgument1, PVOID ApcArgument2, PVOID ApcArgument3)
#define TEST_SPECIAL_USER_APC
NTSTATUS(NTAPI * NtQueueApcThread_t)(HANDLE ThreadHandle, PS_APC_ROUTINE_t ApcRoutine, PVOID ApcArgument1, PVOID ApcArgument2, PVOID ApcArgument3)
NTSTATUS(NTAPI * NtQueueApcThreadEx2_t)(HANDLE ThreadHandle, HANDLE ReserveHandle, ULONG ApcFlags, PS_APC_ROUTINE_t ApcRoutine, PVOID ApcArgument1, PVOID ApcArgument2, PVOID ApcArgument3)
int main()
Loads the hook DLL for this architecture from bin/<config>, one directory above the tests folder this...
Resources shared by the cases of one test run, created in the child process. The remote processes are...
T NtdllFunction(const char *name)
Looks up an ntdll export. Calls through the result go through the hooks, because the hooks patch the ...
int RunHookTests(int argc, char **argv, const char *apiName, const std::vector< HookTestCase > &cases)
Runs the cases and prints a PASS/FAIL line for each. Call from main.