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