1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
// Copyright (C) Microsoft Corporation. All rights reserved.
#pragma once
#include <wil/resource.h>
// #include <KMacros.h>
#ifdef _KERNEL_MODE
using ENL_START_ROUTINE = KSTART_ROUTINE;
using ENL_THREAD_ROUTINE_RETURN = VOID;
using ENL_THREAD = PKTHREAD;
// static const EC_THREAD EC_THREAD_INVALID = nullptr;
using ENL_THREAD_PRIORITY = LONG;
// #define EC_INVALID_THREAD_PRIORITY MAXLONG
using unique_zw_handle = wil::unique_any<HANDLE, decltype(&::ZwClose), &::ZwClose>;
using unique_pkthread = wil::unique_any<PKTHREAD, decltype(&ObfDereferenceObject), &ObfDereferenceObject>;
using unique_pkevent = wil::unique_any<PKEVENT, decltype(&ObfDereferenceObject), &ObfDereferenceObject>;
using unique_completionport = wil::unique_any<void *, decltype(&ObfDereferenceObject), &ObfDereferenceObject>;
struct unique_thread
{
unique_zw_handle
NtHandle;
unique_pkthread
ObHandle;
operator bool(
void
) const;
void reset(
);
};
#else
#ifndef NOTHING
#define NOTHING
#endif
#ifndef AFFINITY_MASK
#define AFFINITY_MASK(n) ((KAFFINITY)1 << (n))
#endif
typedef struct _NDTBUS_POWER_INTERFACE_STANDARD
{
} NDTBUS_POWER_INTERFACE_STANDARD;
_IRQL_requires_same_
typedef DWORD (WINAPI ENL_START_ROUTINE)(
LPVOID lpThreadParameter
);
using ENL_THREAD_ROUTINE_RETURN = DWORD;
using ENL_THREAD = DWORD;
// static const EC_THREAD EC_THREAD_INVALID = 0;
using ENL_THREAD_PRIORITY = int;
// #define EC_INVALID_THREAD_PRIORITY THREAD_PRIORITY_ERROR_RETURN
using unique_thread = wil::unique_handle;
#define KeGetProcessorIndexFromNumber(_processor) (_processor)->Number
#define KeMemoryBarrier() MemoryBarrier()
inline
NTSTATUS
KeGetProcessorNumberFromIndex (
_In_ ULONG ProcIndex,
_Out_ PPROCESSOR_NUMBER ProcNumber
)
{
ProcNumber->Number = static_cast<UCHAR>(ProcIndex);
ProcNumber->Group = 0;
ProcNumber->Reserved = 0;
return STATUS_SUCCESS;
}
inline
VOID
KeQueryNodeActiveAffinity (
__in USHORT NodeNumber,
__out_opt PGROUP_AFFINITY Affinity,
__out_opt PUSHORT Count
)
{
UNREFERENCED_PARAMETER(NodeNumber);
UNREFERENCED_PARAMETER(Count);
GetThreadGroupAffinity(GetCurrentThread(), Affinity);
}
#endif
ENL_THREAD
EnlGetCurrentThread(
void
);
NTSTATUS
EnlThreadCreate(
_In_ ENL_START_ROUTINE StartRoutine,
_In_opt_ void * Context,
_Out_ unique_thread & Thread
);
void
EnlThreadSetPriority(
_In_ unique_thread & Thread,
_In_ ENL_THREAD_PRIORITY Priority
);
void
EnlThreadSetAffinity(
_In_ PGROUP_AFFINITY GroupAffinity,
_Out_opt_ PGROUP_AFFINITY PreviousAffinity
);
void
EnlThreadWaitForTermination(
_In_ unique_thread & Thread
);
|