MCPcopy Create free account
hub / github.com/HoShiMin/Kernel-Bridge / CallInSystemContext

Function CallInSystemContext

Kernel-Bridge/API/Callable.cpp:11–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9namespace Callable
10{
11 bool CallInSystemContext(bool(*Callback)(void* Arg), void* Arg, bool Wait)
12 {
13 HANDLE hThread = NULL;
14
15 struct PARAMS {
16 bool(*Callback)(PVOID Arg);
17 PVOID Arg;
18 bool Result;
19 } Params = {};
20 Params.Callback = Callback;
21 Params.Arg = Arg;
22
23 OBJECT_ATTRIBUTES ObjectAttributes;
24 InitializeObjectAttributes(&ObjectAttributes, NULL, OBJ_KERNEL_HANDLE, NULL, NULL);
25 NTSTATUS Status = PsCreateSystemThread(
26 &hThread,
27 GENERIC_ALL,
28 &ObjectAttributes,
29 NULL,
30 NULL,
31 [](PVOID Arg)
32 {
33 PARAMS* Params = reinterpret_cast<PARAMS*>(Arg);
34 Params->Result = Params->Callback(Params->Arg);
35 PsTerminateSystemThread(STATUS_SUCCESS);
36 },
37 &Params
38 );
39
40 if (NT_SUCCESS(Status))
41 {
42 if (Wait)
43 {
44 ZwWaitForSingleObject(hThread, FALSE, NULL);
45 ZwClose(hThread);
46 return Params.Result;
47 }
48 else
49 {
50 ZwClose(hThread);
51 return true;
52 }
53 }
54
55 return false;
56 }
57
58 bool ForEachCpu(bool(*Callback)(void* Arg, unsigned int ProcessorNumber), void* Arg)
59 {

Callers 1

VirtualizeAllProcessorsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected