- DBGKD_WAIT_STATE_CHANGE64 is used in KD protocol 5, not number 6 that we use. Proto...
[reactos.git] / reactos / lib / cmlib / cmlib.h
1 /*
2 * PROJECT: registry manipulation library
3 * LICENSE: GPL - See COPYING in the top level directory
4 * COPYRIGHT: Copyright 2005 Filip Navara <navaraf@reactos.org>
5 * Copyright 2001 - 2005 Eric Kohl
6 */
7
8 #ifndef CMLIB_H
9 #define CMLIB_H
10
11 //
12 // Debug support switch
13 //
14 #define _CMLIB_DEBUG_ 1
15
16 #ifdef CMLIB_HOST
17 #include <host/typedefs.h>
18 #include <stdio.h>
19 #include <string.h>
20
21 // Definitions copied from <ntstatus.h>
22 // We only want to include host headers, so we define them manually
23 #define STATUS_SUCCESS ((NTSTATUS)0x00000000)
24 #define STATUS_NOT_IMPLEMENTED ((NTSTATUS)0xC0000002)
25 #define STATUS_NO_MEMORY ((NTSTATUS)0xC0000017)
26 #define STATUS_INSUFFICIENT_RESOURCES ((NTSTATUS)0xC000009A)
27 #define STATUS_REGISTRY_CORRUPT ((NTSTATUS)0xC000014C)
28 #define STATUS_NOT_REGISTRY_FILE ((NTSTATUS)0xC000015C)
29 #define STATUS_REGISTRY_RECOVERED ((NTSTATUS)0x40000009)
30
31 #define REG_OPTION_VOLATILE 1
32 #define OBJ_CASE_INSENSITIVE 0x00000040L
33 #define USHORT_MAX USHRT_MAX
34
35 VOID NTAPI
36 KeQuerySystemTime(
37 OUT PLARGE_INTEGER CurrentTime);
38
39 VOID NTAPI
40 RtlInitializeBitMap(
41 IN PRTL_BITMAP BitMapHeader,
42 IN PULONG BitMapBuffer,
43 IN ULONG SizeOfBitMap);
44
45 ULONG NTAPI
46 RtlFindSetBits(
47 IN PRTL_BITMAP BitMapHeader,
48 IN ULONG NumberToFind,
49 IN ULONG HintIndex);
50
51 VOID NTAPI
52 RtlSetBits(
53 IN PRTL_BITMAP BitMapHeader,
54 IN ULONG StartingIndex,
55 IN ULONG NumberToSet);
56
57 VOID NTAPI
58 RtlClearAllBits(
59 IN PRTL_BITMAP BitMapHeader);
60
61 #define RtlCheckBit(BMH,BP) (((((PLONG)(BMH)->Buffer)[(BP) / 32]) >> ((BP) % 32)) & 0x1)
62 #define UNREFERENCED_PARAMETER(P) {(P)=(P);}
63
64 #define PKTHREAD PVOID
65 #define PKGUARDED_MUTEX PVOID
66 #define PERESOURCE PVOID
67 #define PFILE_OBJECT PVOID
68 #define PKEVENT PVOID
69 #define PWORK_QUEUE_ITEM PVOID
70 #define EX_PUSH_LOCK PULONG_PTR
71
72 /* For <host/wcsfuncs.h> */
73 #define USE_HOST_WCSFUNCS
74
75 #define CMLTRACE(x, ...)
76 #else
77 //
78 // Debug/Tracing support
79 //
80 #if _CMLIB_DEBUG_
81 #ifdef NEW_DEBUG_SYSTEM_IMPLEMENTED // enable when Debug Filters are implemented
82 #define CMLTRACE DbgPrintEx
83 #else
84 #define CMLTRACE(x, ...) \
85 if (x & CmlibTraceLevel) DbgPrint(__VA_ARGS__)
86 #endif
87 #else
88 #define CMLTRACE(x, ...) DPRINT(__VA_ARGS__)
89 #endif
90
91 #include <ntdef.h>
92 #undef DECLSPEC_IMPORT
93 #define DECLSPEC_IMPORT
94 #include <ntddk.h>
95 #endif
96
97 #include <host/wcsfuncs.h>
98
99 //
100 // These define the Debug Masks Supported
101 //
102 #define CMLIB_HCELL_DEBUG 0x01
103
104 #ifndef ROUND_UP
105 #define ROUND_UP(a,b) ((((a)+(b)-1)/(b))*(b))
106 #define ROUND_DOWN(a,b) (((a)/(b))*(b))
107 #endif
108
109 //
110 // PAGE_SIZE definition
111 //
112 #ifndef PAGE_SIZE
113 #if defined(TARGET_i386) || defined(TARGET_amd64) || defined(TARGET_arm)
114 #define PAGE_SIZE 0x1000
115 #else
116 #error Local PAGE_SIZE definition required when built as host
117 #endif
118 #endif
119
120 #define TAG_CM 0x68742020
121
122 #define CMAPI NTAPI
123
124 #include <wchar.h>
125 #include "hivedata.h"
126 #include "cmdata.h"
127
128 #if defined(_TYPEDEFS_HOST_H) || defined(__FREELDR_H)
129
130 #define PCM_KEY_SECURITY_CACHE_ENTRY PVOID
131 #define PCM_KEY_CONTROL_BLOCK PVOID
132 #define CMP_SECURITY_HASH_LISTS 64
133 #define PCM_CELL_REMAP_BLOCK PVOID
134
135 //
136 // Use Count Log and Entry
137 //
138 typedef struct _CM_USE_COUNT_LOG_ENTRY
139 {
140 HCELL_INDEX Cell;
141 PVOID Stack[7];
142 } CM_USE_COUNT_LOG_ENTRY, *PCM_USE_COUNT_LOG_ENTRY;
143
144 typedef struct _CM_USE_COUNT_LOG
145 {
146 USHORT Next;
147 USHORT Size;
148 CM_USE_COUNT_LOG_ENTRY Log[32];
149 } CM_USE_COUNT_LOG, *PCM_USE_COUNT_LOG;
150
151 //
152 // Configuration Manager Hive Structure
153 //
154 typedef struct _CMHIVE
155 {
156 HHIVE Hive;
157 HANDLE FileHandles[3];
158 LIST_ENTRY NotifyList;
159 LIST_ENTRY HiveList;
160 EX_PUSH_LOCK HiveLock;
161 PKTHREAD HiveLockOwner;
162 PKGUARDED_MUTEX ViewLock;
163 PKTHREAD ViewLockOwner;
164 EX_PUSH_LOCK WriterLock;
165 PKTHREAD WriterLockOwner;
166 PERESOURCE FlusherLock;
167 EX_PUSH_LOCK SecurityLock;
168 PKTHREAD HiveSecurityLockOwner;
169 LIST_ENTRY LRUViewListHead;
170 LIST_ENTRY PinViewListHead;
171 PFILE_OBJECT FileObject;
172 UNICODE_STRING FileFullPath;
173 UNICODE_STRING FileUserName;
174 USHORT MappedViews;
175 USHORT PinnedViews;
176 ULONG UseCount;
177 ULONG SecurityCount;
178 ULONG SecurityCacheSize;
179 LONG SecurityHitHint;
180 PCM_KEY_SECURITY_CACHE_ENTRY SecurityCache;
181 LIST_ENTRY SecurityHash[CMP_SECURITY_HASH_LISTS];
182 PKEVENT UnloadEvent;
183 PCM_KEY_CONTROL_BLOCK RootKcb;
184 BOOLEAN Frozen;
185 PWORK_QUEUE_ITEM UnloadWorkItem;
186 BOOLEAN GrowOnlyMode;
187 ULONG GrowOffset;
188 LIST_ENTRY KcbConvertListHead;
189 LIST_ENTRY KnodeConvertListHead;
190 PCM_CELL_REMAP_BLOCK CellRemapArray;
191 CM_USE_COUNT_LOG UseCountLog;
192 CM_USE_COUNT_LOG LockHiveLog;
193 ULONG Flags;
194 LIST_ENTRY TrustClassEntry;
195 ULONG FlushCount;
196 BOOLEAN HiveIsLoading;
197 PKTHREAD CreatorOwner;
198 } CMHIVE, *PCMHIVE;
199
200 #endif
201
202 extern ULONG CmlibTraceLevel;
203
204 /*
205 * Public functions.
206 */
207 NTSTATUS CMAPI
208 HvInitialize(
209 PHHIVE RegistryHive,
210 ULONG Operation,
211 ULONG HiveType,
212 ULONG HiveFlags,
213 PVOID HiveData OPTIONAL,
214 PALLOCATE_ROUTINE Allocate,
215 PFREE_ROUTINE Free,
216 PFILE_SET_SIZE_ROUTINE FileSetSize,
217 PFILE_WRITE_ROUTINE FileWrite,
218 PFILE_READ_ROUTINE FileRead,
219 PFILE_FLUSH_ROUTINE FileFlush,
220 ULONG Cluster OPTIONAL,
221 PUNICODE_STRING FileName);
222
223 VOID CMAPI
224 HvFree(
225 PHHIVE RegistryHive);
226
227 PVOID CMAPI
228 HvGetCell(
229 PHHIVE RegistryHive,
230 HCELL_INDEX CellOffset);
231
232 #define HvReleaseCell(h, c) \
233 if (h->ReleaseCellRoutine) h->ReleaseCellRoutine(h, c)
234
235 LONG CMAPI
236 HvGetCellSize(
237 PHHIVE RegistryHive,
238 PVOID Cell);
239
240 HCELL_INDEX CMAPI
241 HvAllocateCell(
242 PHHIVE RegistryHive,
243 SIZE_T Size,
244 HSTORAGE_TYPE Storage,
245 IN HCELL_INDEX Vicinity);
246
247 BOOLEAN CMAPI
248 HvIsCellAllocated(
249 IN PHHIVE RegistryHive,
250 IN HCELL_INDEX CellIndex
251 );
252
253 HCELL_INDEX CMAPI
254 HvReallocateCell(
255 PHHIVE RegistryHive,
256 HCELL_INDEX CellOffset,
257 ULONG Size);
258
259 VOID CMAPI
260 HvFreeCell(
261 PHHIVE RegistryHive,
262 HCELL_INDEX CellOffset);
263
264 BOOLEAN CMAPI
265 HvMarkCellDirty(
266 PHHIVE RegistryHive,
267 HCELL_INDEX CellOffset,
268 BOOLEAN HoldingLock);
269
270 BOOLEAN CMAPI
271 HvIsCellDirty(
272 IN PHHIVE Hive,
273 IN HCELL_INDEX Cell
274 );
275
276 BOOLEAN CMAPI
277 HvSyncHive(
278 PHHIVE RegistryHive);
279
280 BOOLEAN CMAPI
281 HvWriteHive(
282 PHHIVE RegistryHive);
283
284 BOOLEAN CMAPI
285 CmCreateRootNode(
286 PHHIVE Hive,
287 PCWSTR Name);
288
289 VOID CMAPI
290 CmPrepareHive(
291 PHHIVE RegistryHive);
292
293 /*
294 * Private functions.
295 */
296
297 PHBIN CMAPI
298 HvpAddBin(
299 PHHIVE RegistryHive,
300 ULONG Size,
301 HSTORAGE_TYPE Storage);
302
303 NTSTATUS CMAPI
304 HvpCreateHiveFreeCellList(
305 PHHIVE Hive);
306
307 ULONG CMAPI
308 HvpHiveHeaderChecksum(
309 PHBASE_BLOCK HiveHeader);
310
311 #endif /* CMLIB_H */