-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtlskip.h
237 lines (211 loc) · 5.52 KB
/
rtlskip.h
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
//
// rtlskip.h
//
// Native NT implementation of a skip list - O(log n).
//
// This is free and unencumbered software released into the public domain.
//
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
// binary, for any purpose, commercial or non - commercial, and by any
// means.
//
// In jurisdictions that recognize copyright laws, the author or authors
// of this software dedicate any and all copyright interest in the
// software to the public domain. We make this dedication for the benefit
// of the public at large and to the detriment of our heirs and
// successors. We intend this dedication to be an overt act of
// relinquishment in perpetuity of all present and future rights to this
// software under copyright law.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// For more information, please refer to <http://unlicense.org/>
//
#if !defined (_RTL_SKIPLIST_H)
#define _RTL_SKIPLIST_H
#include <ntddk.h>
#define RTL_SKIPLIST_MAX_LEVEL 32
// Build options.
#define RTL_SKIPLIST_INCLUDE_BACKWARD_LINK
// #define RTL_SKIPLIST_USE_RANDOMEX
// Forwarder for the function pointers.
typedef struct _RTL_SKIPLIST_TABLE RTL_SKIPLIST_TABLE, *PRTL_SKIPLIST_TABLE;
typedef
_IRQL_requires_same_
_Function_class_(RTL_SKIPLIST_COMPARE_ROUTINE)
RTL_GENERIC_COMPARE_RESULTS
NTAPI
RTL_SKIPLIST_COMPARE_ROUTINE
(
_In_ struct _RTL_SKIPLIST_TABLE *Table,
_In_ PVOID FirstStruct,
_In_ PVOID SecondStruct
);
typedef RTL_SKIPLIST_COMPARE_ROUTINE *PRTL_SKIPLIST_COMPARE_ROUTINE;
typedef
_IRQL_requires_same_
_Function_class_(RTL_SKIPLIST_ALLOCATE_ROUTINE)
__drv_allocatesMem(Mem)
PVOID
NTAPI
RTL_SKIPLIST_ALLOCATE_ROUTINE
(
_In_ struct _RTL_SKIPLIST_TABLE *Table,
_In_ CLONG ByteSize
);
typedef RTL_SKIPLIST_ALLOCATE_ROUTINE *PRTL_SKIPLIST_ALLOCATE_ROUTINE;
typedef
_IRQL_requires_same_
_Function_class_(RTL_SKIPLIST_FREE_ROUTINE)
VOID
NTAPI
RTL_SKIPLIST_FREE_ROUTINE
(
_In_ struct _RTL_SKIPLIST_TABLE *Table,
_In_ __drv_freesMem(Mem) _Post_invalid_ PVOID Buffer
);
typedef RTL_SKIPLIST_FREE_ROUTINE *PRTL_SKIPLIST_FREE_ROUTINE;
typedef struct _RTL_SKIPLIST_NODE {
PVOID Data;
#if defined (RTL_SKIPLIST_INCLUDE_BACKWARD_LINK)
struct _RTL_SKIPLIST_NODE *Backward;
#endif
struct _RTL_SKIPLIST_NODE *Forward[1];
} RTL_SKIPLIST_NODE, *PRTL_SKIPLIST_NODE;
typedef struct _RTL_SKIPLIST_TABLE {
struct _RTL_SKIPLIST_NODE *Head;
LONG Level;
ULONG Size;
#if defined (RTL_SKIPLIST_USE_RANDOMEX)
ULONG Seed;
#else
struct
{
ULONG x;
ULONG y;
ULONG z;
ULONG c;
} KissState;
#endif
PVOID Context;
PRTL_SKIPLIST_COMPARE_ROUTINE CompareRoutine;
PRTL_SKIPLIST_ALLOCATE_ROUTINE AllocateRoutine;
PRTL_SKIPLIST_FREE_ROUTINE FreeRoutine;
} RTL_SKIPLIST_TABLE, *PRTL_SKIPLIST_TABLE;
typedef struct _RTL_SKIPLIST_ITOR {
struct _RTL_SLIPLIST_TABLE *Table;
struct _RTL_SKIPLIST_NODE *Node;
} RTL_SKIPLIST_ITOR, *PRTL_SKIPLIST_ITOR;
PVOID
NTAPI
RtlInsertElementGenericTableSkiplist
(
_In_ PRTL_SKIPLIST_TABLE Table,
_In_reads_bytes_(BufferSize) PVOID Buffer,
_In_ CLONG BufferSize,
_Out_opt_ PBOOLEAN NewElement
);
BOOLEAN
NTAPI
RtlDeleteElementGenericTableSkiplist
(
_In_ PRTL_SKIPLIST_TABLE Table,
_In_ PVOID Buffer
);
_Must_inspect_result_
PVOID
NTAPI
RtlLookupElementGenericTableSkiplist
(
_In_ PRTL_SKIPLIST_TABLE Table,
_In_ PVOID Buffer
);
BOOLEAN
NTAPI
RtlIsGenericTableEmptySkiplist
(
_In_ PRTL_SKIPLIST_TABLE Table
);
LONGLONG
NTAPI
RtlNumberGenericTableElementsSkiplist
(
_In_ PRTL_SKIPLIST_TABLE Table
);
PVOID
NTAPI
RtlEnumerateGenericTableSkiplist
(
_In_ PRTL_SKIPLIST_TABLE Table,
_In_ PVOID *RestartKey
);
PVOID
NTAPI
RtlEnumerateGenericTableWithoutSplayingSkiplist
(
_In_ PRTL_SKIPLIST_TABLE Table,
_In_ PVOID *RestartKey
);
BOOLEAN
NTAPI
RtlInitializeGenericTableSkiplist
(
_Out_ PRTL_SKIPLIST_TABLE Table,
_In_ PRTL_SKIPLIST_COMPARE_ROUTINE CompareRoutine,
_In_ PRTL_SKIPLIST_ALLOCATE_ROUTINE AllocateRoutine,
_In_ PRTL_SKIPLIST_FREE_ROUTINE FreeRoutine,
_In_opt_ PVOID TableContext
);
// The follwoing functions still need implementing to round out
// interface parity with the WDK generic table interface.
//
PVOID
NTAPI
RtlInsertElementGenericTableFullSkiplist
(
_In_ PRTL_SKIPLIST_TABLE Table,
_In_reads_bytes_(BufferSize) PVOID Buffer,
_In_ CLONG BufferSize,
_Out_opt_ PBOOLEAN NewElement,
_In_ PVOID NodeOrParent,
_In_ TABLE_SEARCH_RESULT SearchResult
);
VOID
NTAPI
RtlDeleteElementGenericTableSkiplistEx
(
_In_ PRTL_SKIPLIST_TABLE Table,
_In_ PVOID NodeOrParent
);
PVOID
NTAPI
RtlLookupElementGenericTableFullSkiplist
(
_In_ PRTL_SKIPLIST_TABLE Table,
_In_ PVOID Buffer,
_Out_ PVOID *NodeOrParent,
_Out_ TABLE_SEARCH_RESULT *SearchResult
);
PVOID
NTAPI
RtlLookupFirstMatchingElementGenericTableSkiplist
(
_In_ PRTL_SKIPLIST_TABLE Table,
_In_ PVOID Buffer,
_Out_ PVOID *RestartKey
);
PVOID
NTAPI
RtlGetElementGenericTableSkiplist
(
_In_ PRTL_SKIPLIST_TABLE Table,
_In_ ULONG I
);
#endif