xref: /reactos/ntoskrnl/cache/newcc.h (revision 84344399)
1 #pragma once
2 
3 typedef struct _NOCC_BCB
4 {
5     /* Public part */
6     PUBLIC_BCB Bcb;
7 
8     struct _NOCC_CACHE_MAP *Map;
9     PSECTION SectionObject;
10     LARGE_INTEGER FileOffset;
11     ULONG Length;
12     PVOID BaseAddress;
13     BOOLEAN Dirty;
14     PVOID OwnerPointer;
15 
16     /* Reference counts */
17     ULONG RefCount;
18 
19     LIST_ENTRY ThisFileList;
20 
21     KEVENT ExclusiveWait;
22     ULONG ExclusiveWaiter;
23     BOOLEAN Exclusive;
24 } NOCC_BCB, *PNOCC_BCB;
25 
26 typedef struct _NOCC_CACHE_MAP
27 {
28     LIST_ENTRY Entry;
29     LIST_ENTRY AssociatedBcb;
30     LIST_ENTRY PrivateCacheMaps;
31     ULONG NumberOfMaps;
32     ULONG RefCount;
33     CC_FILE_SIZES FileSizes;
34     CACHE_MANAGER_CALLBACKS Callbacks;
35     PVOID LazyContext;
36     PVOID LogHandle;
37     PFLUSH_TO_LSN FlushToLsn;
38     ULONG ReadAheadGranularity;
39 } NOCC_CACHE_MAP, *PNOCC_CACHE_MAP;
40 
41 CODE_SEG("INIT")
42 VOID
43 NTAPI
44 CcPfInitializePrefetcher(VOID);
45 
46 VOID
47 NTAPI
48 CcMdlReadComplete2(IN PFILE_OBJECT FileObject,
49                    IN PMDL MemoryDescriptorList);
50 
51 VOID
52 NTAPI
53 CcMdlWriteComplete2(IN PFILE_OBJECT FileObject,
54                     IN PLARGE_INTEGER FileOffset,
55                     IN PMDL MdlChain);
56 
57 CODE_SEG("INIT")
58 VOID
59 NTAPI
60 CcInitView(VOID);
61 
62 BOOLEAN
63 NTAPI
64 CcpUnpinData(PNOCC_BCB Bcb,
65              BOOLEAN ActuallyRelease);
66 
67 VOID
68 NTAPI
69 CcShutdownSystem(VOID);
70 
71 VOID
72 NTAPI
73 CcInitCacheZeroPage(VOID);
74 
75 /* Called by section.c */
76 BOOLEAN
77 NTAPI
78 CcFlushImageSection(PSECTION_OBJECT_POINTERS SectionObjectPointer,
79                     MMFLUSH_TYPE FlushType);
80 
81 VOID
82 NTAPI
83 _CcpFlushCache(IN PNOCC_CACHE_MAP Map,
84                IN OPTIONAL PLARGE_INTEGER FileOffset,
85                IN ULONG Length,
86                OUT OPTIONAL PIO_STATUS_BLOCK IoStatus,
87                BOOLEAN Delete,
88                const char *File,
89                int Line);
90 
91 #define CcpFlushCache(M,F,L,I,D) _CcpFlushCache(M,F,L,I,D,__FILE__,__LINE__)
92 
93 BOOLEAN
94 NTAPI
95 CcGetFileSizes(PFILE_OBJECT FileObject,
96                PCC_FILE_SIZES FileSizes);
97 
98 ULONG
99 NTAPI
100 CcpCountCacheSections(PNOCC_CACHE_MAP Map);
101 
102 BOOLEAN
103 NTAPI
104 CcpAcquireFileLock(PNOCC_CACHE_MAP Map);
105 
106 VOID
107 NTAPI
108 CcpReleaseFileLock(PNOCC_CACHE_MAP Map);
109 
110 /*
111  * Macro for generic cache manage bugchecking. Note that this macro assumes
112  * that the file name including extension is always longer than 4 characters.
113  */
114 #define KEBUGCHECKCC \
115     KEBUGCHECKEX(CACHE_MANAGER, \
116     (*(ULONG*)(__FILE__ + sizeof(__FILE__) - 4) << 16) | \
117     (__LINE__ & 0xFFFF), 0, 0, 0)
118 
119 /* Private data */
120 
121 #define CACHE_SINGLE_FILE_MAX (16)
122 #define CACHE_OVERALL_SIZE    (32 * 1024 * 1024)
123 #define CACHE_STRIPE          VACB_MAPPING_GRANULARITY
124 #define CACHE_SHIFT           18
125 #define CACHE_NUM_SECTIONS    (CACHE_OVERALL_SIZE / CACHE_STRIPE)
126 #define CACHE_ROUND_UP(x)     (((x) + (CACHE_STRIPE-1)) & ~(CACHE_STRIPE-1))
127 #define CACHE_ROUND_DOWN(x)   ((x) & ~(CACHE_STRIPE-1))
128 #define INVALID_CACHE         ((ULONG)~0)
129 
130 extern NOCC_BCB CcCacheSections[CACHE_NUM_SECTIONS];
131 extern PRTL_BITMAP CcCacheBitmap;
132 extern FAST_MUTEX CcMutex;
133 extern KEVENT CcDeleteEvent;
134 extern ULONG CcCacheClockHand;
135 extern LIST_ENTRY CcPendingUnmap;
136 extern KEVENT CcpLazyWriteEvent;
137 
138 #define CcpLock() _CcpLock(__FILE__,__LINE__)
139 #define CcpUnlock() _CcpUnlock(__FILE__,__LINE__)
140 
141 extern VOID _CcpLock(const char *file, int line);
142 extern VOID _CcpUnlock(const char *file, int line);
143 
144 extern VOID CcpReferenceCache(ULONG Sector);
145 extern VOID CcpDereferenceCache(ULONG Sector, BOOLEAN Immediate);
146 
147 BOOLEAN
148 NTAPI
149 CcpMapData(IN PFILE_OBJECT FileObject,
150            IN PLARGE_INTEGER FileOffset,
151            IN ULONG Length,
152            IN ULONG Flags,
153            OUT PVOID *BcbResult,
154            OUT PVOID *Buffer);
155 
156 BOOLEAN
157 NTAPI
158 CcpPinMappedData(IN PNOCC_CACHE_MAP Map,
159                  IN PLARGE_INTEGER FileOffset,
160                  IN ULONG Length,
161                  IN ULONG Flags,
162                  IN OUT PVOID *Bcb);
163 
164 ULONG
165 MmGetReferenceCountPageWithoutLock(PFN_NUMBER Page)
166 {
167     ULONG Ret;
168     KIRQL OldIrql = MiAcquirePfnLock();
169 
170     Ret = MmGetReferenceCountPage(Page);
171 
172     MiReleasePfnLock(OldIrql);
173 
174     return Ret;
175 }
176