98fad41acb53340029cc0cd51dc85265987875b0
[reactos.git] / reactos / ntoskrnl / include / internal / cc.h
1 #pragma once
2
3 //
4 // Define this if you want debugging support
5 //
6 #define _CC_DEBUG_ 0x00
7
8 //
9 // These define the Debug Masks Supported
10 //
11 #define CC_API_DEBUG 0x01
12
13 //
14 // Debug/Tracing support
15 //
16 #if _CC_DEBUG_
17 #ifdef NEW_DEBUG_SYSTEM_IMPLEMENTED // enable when Debug Filters are implemented
18 #define CCTRACE(x, ...) \
19 { \
20 DbgPrintEx("%s [%.16s] - ", \
21 __FUNCTION__, \
22 PsGetCurrentProcess()->ImageFileName); \
23 DbgPrintEx(__VA_ARGS__); \
24 }
25 #else
26 #define CCTRACE(x, ...) \
27 if (x & CcRosTraceLevel) \
28 { \
29 DbgPrint("%s [%.16s] - ", \
30 __FUNCTION__, \
31 PsGetCurrentProcess()->ImageFileName); \
32 DbgPrint(__VA_ARGS__); \
33 }
34 #endif
35 #else
36 #define CCTRACE(x, fmt, ...) DPRINT(fmt, ##__VA_ARGS__)
37 #endif
38
39 //
40 // Global Cc Data
41 //
42 extern ULONG CcRosTraceLevel;
43
44 typedef struct _PF_SCENARIO_ID
45 {
46 WCHAR ScenName[30];
47 ULONG HashId;
48 } PF_SCENARIO_ID, *PPF_SCENARIO_ID;
49
50 typedef struct _PF_LOG_ENTRY
51 {
52 ULONG FileOffset:30;
53 ULONG Type:2;
54 union
55 {
56 ULONG FileKey;
57 ULONG FileSequenceNumber;
58 };
59 } PF_LOG_ENTRY, *PPF_LOG_ENTRY;
60
61 typedef struct _PFSN_LOG_ENTRIES
62 {
63 LIST_ENTRY TraceBuffersLink;
64 LONG NumEntries;
65 LONG MaxEntries;
66 PF_LOG_ENTRY Entries[ANYSIZE_ARRAY];
67 } PFSN_LOG_ENTRIES, *PPFSN_LOG_ENTRIES;
68
69 typedef struct _PF_SECTION_INFO
70 {
71 ULONG FileKey;
72 ULONG FileSequenceNumber;
73 ULONG FileIdLow;
74 ULONG FileIdHigh;
75 } PF_SECTION_INFO, *PPF_SECTION_INFO;
76
77 typedef struct _PF_TRACE_HEADER
78 {
79 ULONG Version;
80 ULONG MagicNumber;
81 ULONG Size;
82 PF_SCENARIO_ID ScenarioId;
83 ULONG ScenarioType; // PF_SCENARIO_TYPE
84 ULONG EventEntryIdxs[8];
85 ULONG NumEventEntryIdxs;
86 ULONG TraceBufferOffset;
87 ULONG NumEntries;
88 ULONG SectionInfoOffset;
89 ULONG NumSections;
90 ULONG FaultsPerPeriod[10];
91 LARGE_INTEGER LaunchTime;
92 ULONGLONG Reserved[5];
93 } PF_TRACE_HEADER, *PPF_TRACE_HEADER;
94
95 typedef struct _PFSN_TRACE_DUMP
96 {
97 LIST_ENTRY CompletedTracesLink;
98 PF_TRACE_HEADER Trace;
99 } PFSN_TRACE_DUMP, *PPFSN_TRACE_DUMP;
100
101 typedef struct _PFSN_TRACE_HEADER
102 {
103 ULONG Magic;
104 LIST_ENTRY ActiveTracesLink;
105 PF_SCENARIO_ID ScenarioId;
106 ULONG ScenarioType; // PF_SCENARIO_TYPE
107 ULONG EventEntryIdxs[8];
108 ULONG NumEventEntryIdxs;
109 PPFSN_LOG_ENTRIES CurrentTraceBuffer;
110 LIST_ENTRY TraceBuffersList;
111 ULONG NumTraceBuffers;
112 KSPIN_LOCK TraceBufferSpinLock;
113 KTIMER TraceTimer;
114 LARGE_INTEGER TraceTimerPeriod;
115 KDPC TraceTimerDpc;
116 KSPIN_LOCK TraceTimerSpinLock;
117 ULONG FaultsPerPeriod[10];
118 LONG LastNumFaults;
119 LONG CurPeriod;
120 LONG NumFaults;
121 LONG MaxFaults;
122 PEPROCESS Process;
123 EX_RUNDOWN_REF RefCount;
124 WORK_QUEUE_ITEM EndTraceWorkItem;
125 LONG EndTraceCalled;
126 PPFSN_TRACE_DUMP TraceDump;
127 NTSTATUS TraceDumpStatus;
128 LARGE_INTEGER LaunchTime;
129 PPF_SECTION_INFO SectionInfo;
130 ULONG SectionInfoCount;
131 } PFSN_TRACE_HEADER, *PPFSN_TRACE_HEADER;
132
133 typedef struct _PFSN_PREFETCHER_GLOBALS
134 {
135 LIST_ENTRY ActiveTraces;
136 KSPIN_LOCK ActiveTracesLock;
137 PPFSN_TRACE_HEADER SystemWideTrace;
138 LIST_ENTRY CompletedTraces;
139 FAST_MUTEX CompletedTracesLock;
140 LONG NumCompletedTraces;
141 PKEVENT CompletedTracesEvent;
142 LONG ActivePrefetches;
143 } PFSN_PREFETCHER_GLOBALS, *PPFSN_PREFETCHER_GLOBALS;
144
145 typedef struct _ROS_SHARED_CACHE_MAP
146 {
147 LIST_ENTRY CacheMapVacbListHead;
148 ULONG TimeStamp;
149 PFILE_OBJECT FileObject;
150 LARGE_INTEGER SectionSize;
151 LARGE_INTEGER FileSize;
152 BOOLEAN PinAccess;
153 PCACHE_MANAGER_CALLBACKS Callbacks;
154 PVOID LazyWriteContext;
155 KSPIN_LOCK CacheMapLock;
156 ULONG RefCount;
157 #if DBG
158 BOOLEAN Trace; /* enable extra trace output for this cache map and it's VACBs */
159 #endif
160 } ROS_SHARED_CACHE_MAP, *PROS_SHARED_CACHE_MAP;
161
162 typedef struct _ROS_VACB
163 {
164 /* Base address of the region where the view's data is mapped. */
165 PVOID BaseAddress;
166 /* Memory area representing the region where the view's data is mapped. */
167 struct _MEMORY_AREA* MemoryArea;
168 /* Lock */
169 ERESOURCE Lock;
170 /* Are the contents of the view valid. */
171 BOOLEAN Valid;
172 /* Are the contents of the view newer than those on disk. */
173 BOOLEAN Dirty;
174 /* Page out in progress */
175 BOOLEAN PageOut;
176 ULONG MappedCount;
177 /* Entry in the list of VACBs for this shared cache map. */
178 LIST_ENTRY CacheMapVacbListEntry;
179 /* Entry in the list of VACBs which are dirty. */
180 LIST_ENTRY DirtyVacbListEntry;
181 /* Entry in the list of VACBs. */
182 LIST_ENTRY VacbLruListEntry;
183 /* Offset in the file which this view maps. */
184 LARGE_INTEGER FileOffset;
185 /* Number of references. */
186 ULONG ReferenceCount;
187 /* Pointer to the shared cache map for the file which this view maps data for. */
188 PROS_SHARED_CACHE_MAP SharedCacheMap;
189 /* Pointer to the next VACB in a chain. */
190 } ROS_VACB, *PROS_VACB;
191
192 typedef struct _INTERNAL_BCB
193 {
194 PUBLIC_BCB PFCB;
195 PROS_VACB Vacb;
196 BOOLEAN Dirty;
197 CSHORT RefCount; /* (At offset 0x34 on WinNT4) */
198 PVOID OwnerPointer;
199 } INTERNAL_BCB, *PINTERNAL_BCB;
200
201 VOID
202 NTAPI
203 CcPfInitializePrefetcher(
204 VOID
205 );
206
207 VOID
208 NTAPI
209 CcMdlReadComplete2(
210 IN PFILE_OBJECT FileObject,
211 IN PMDL MemoryDescriptorList
212 );
213
214 VOID
215 NTAPI
216 CcMdlWriteComplete2(
217 IN PFILE_OBJECT FileObject,
218 IN PLARGE_INTEGER FileOffset,
219 IN PMDL MdlChain
220 );
221
222 NTSTATUS
223 NTAPI
224 CcRosFlushVacb(PROS_VACB Vacb);
225
226 NTSTATUS
227 NTAPI
228 CcRosGetVacb(
229 PROS_SHARED_CACHE_MAP SharedCacheMap,
230 LONGLONG FileOffset,
231 PLONGLONG BaseOffset,
232 PVOID *BaseAddress,
233 PBOOLEAN UptoDate,
234 PROS_VACB *Vacb
235 );
236
237 VOID
238 NTAPI
239 CcInitView(VOID);
240
241 NTSTATUS
242 NTAPI
243 CcReadVirtualAddress(PROS_VACB Vacb);
244
245 NTSTATUS
246 NTAPI
247 CcWriteVirtualAddress(PROS_VACB Vacb);
248
249 BOOLEAN
250 NTAPI
251 CcInitializeCacheManager(VOID);
252
253 NTSTATUS
254 NTAPI
255 CcRosUnmapVacb(
256 PROS_SHARED_CACHE_MAP SharedCacheMap,
257 LONGLONG FileOffset,
258 BOOLEAN NowDirty
259 );
260
261 PROS_VACB
262 NTAPI
263 CcRosLookupVacb(
264 PROS_SHARED_CACHE_MAP SharedCacheMap,
265 LONGLONG FileOffset
266 );
267
268 VOID
269 NTAPI
270 CcInitCacheZeroPage(VOID);
271
272 NTSTATUS
273 NTAPI
274 CcRosMarkDirtyVacb(
275 PROS_SHARED_CACHE_MAP SharedCacheMap,
276 LONGLONG FileOffset
277 );
278
279 NTSTATUS
280 NTAPI
281 CcRosFlushDirtyPages(
282 ULONG Target,
283 PULONG Count,
284 BOOLEAN Wait
285 );
286
287 VOID
288 NTAPI
289 CcRosDereferenceCache(PFILE_OBJECT FileObject);
290
291 VOID
292 NTAPI
293 CcRosReferenceCache(PFILE_OBJECT FileObject);
294
295 VOID
296 NTAPI
297 CcRosRemoveIfClosed(PSECTION_OBJECT_POINTERS SectionObjectPointer);
298
299 NTSTATUS
300 NTAPI
301 CcRosReleaseVacb(
302 PROS_SHARED_CACHE_MAP SharedCacheMap,
303 PROS_VACB Vacb,
304 BOOLEAN Valid,
305 BOOLEAN Dirty,
306 BOOLEAN Mapped
307 );
308
309 NTSTATUS
310 NTAPI
311 CcRosRequestVacb(
312 PROS_SHARED_CACHE_MAP SharedCacheMap,
313 LONGLONG FileOffset,
314 PVOID* BaseAddress,
315 PBOOLEAN UptoDate,
316 PROS_VACB *Vacb
317 );
318
319 NTSTATUS
320 NTAPI
321 CcRosInitializeFileCache(
322 PFILE_OBJECT FileObject,
323 PCC_FILE_SIZES FileSizes,
324 BOOLEAN PinAccess,
325 PCACHE_MANAGER_CALLBACKS CallBacks,
326 PVOID LazyWriterContext
327 );
328
329 NTSTATUS
330 NTAPI
331 CcRosReleaseFileCache(
332 PFILE_OBJECT FileObject
333 );
334
335 NTSTATUS
336 NTAPI
337 CcTryToInitializeFileCache(PFILE_OBJECT FileObject);
338
339 FORCEINLINE
340 BOOLEAN
341 DoRangesIntersect(
342 _In_ LONGLONG Offset1,
343 _In_ LONGLONG Length1,
344 _In_ LONGLONG Offset2,
345 _In_ LONGLONG Length2)
346 {
347 if (Offset1 + Length1 <= Offset2)
348 return FALSE;
349 if (Offset2 + Length2 <= Offset1)
350 return FALSE;
351 return TRUE;
352 }
353
354 FORCEINLINE
355 BOOLEAN
356 IsPointInRange(
357 _In_ LONGLONG Offset1,
358 _In_ LONGLONG Length1,
359 _In_ LONGLONG Point)
360 {
361 return DoRangesIntersect(Offset1, Length1, Point, 1);
362 }