Skip to content

Commit 5e88008

Browse files
committed
[NEWCC]
- Create section object when creating the file shared cache map - Map the said section PsInitialSystemProcess address space and map it in kernel space using MmProbeAndLockProcessPages - Implement CcSetFileSizes on top of MmExtendSection svn path=/branches/TransitionPte/; revision=71389
1 parent 1fa758a commit 5e88008

File tree

5 files changed

+120
-119
lines changed

5 files changed

+120
-119
lines changed

ntoskrnl/cache/cachesub.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ CcpReadAhead(PVOID Context)
6464
PLIST_ENTRY ListEntry;
6565
volatile char *chptr;
6666
PNOCC_BCB Bcb;
67+
KAPC_STATE ApcState;
68+
69+
KeStackAttachProcess(&PsInitialSystemProcess->Pcb, &ApcState);
70+
6771
for (ListEntry = Map->AssociatedBcb.Flink;
6872
ListEntry != &Map->AssociatedBcb;
6973
ListEntry = ListEntry->Flink)
@@ -81,6 +85,8 @@ CcpReadAhead(PVOID Context)
8185
*chptr ^= 0;
8286
}
8387
}
88+
89+
KeUnstackDetachProcess(&ApcState);
8490
}
8591
ObDereferenceObject(WorkItem->FileObject);
8692
ExFreePool(WorkItem);
@@ -306,13 +312,13 @@ CcShutdownSystem(VOID)
306312
for (i = 0; i < CACHE_NUM_SECTIONS; i++)
307313
{
308314
PNOCC_BCB Bcb = &CcCacheSections[i];
309-
if (Bcb->SectionObject)
315+
if (Bcb->Map->SectionObject)
310316
{
311317
DPRINT1("Evicting #%02x %08x%08x %wZ\n",
312318
i,
313319
Bcb->FileOffset.u.HighPart,
314320
Bcb->FileOffset.u.LowPart,
315-
&MmGetFileObjectForSection((PROS_SECTION_OBJECT)Bcb->SectionObject)->FileName);
321+
&MmGetFileObjectForSection(Bcb->Map->SectionObject)->FileName);
316322

317323
CcpFlushCache(Bcb->Map, NULL, 0, NULL, TRUE);
318324
Bcb->Dirty = FALSE;

ntoskrnl/cache/fssup.c

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ CcInitializeCacheMap(IN PFILE_OBJECT FileObject,
218218
/* We still don't have a shared cache map. We need to create one. */
219219
if (!Map)
220220
{
221+
NTSTATUS Status;
222+
LARGE_INTEGER MaxSize = FileSizes->AllocationSize;
223+
221224
DPRINT("Initializing file object for (%p) %wZ\n",
222225
FileObject,
223226
&FileObject->FileName);
@@ -237,6 +240,20 @@ CcInitializeCacheMap(IN PFILE_OBJECT FileObject,
237240
InitializeListHead(&Map->PrivateCacheMaps);
238241
InsertTailList(&CcpAllSharedCacheMaps, &Map->Entry);
239242
DPRINT("New Map %p\n", Map);
243+
244+
Status = MmCreateSection(&Map->SectionObject,
245+
STANDARD_RIGHTS_REQUIRED | SECTION_EXTEND_SIZE,
246+
NULL,
247+
&MaxSize,
248+
PAGE_READWRITE,
249+
SEC_RESERVE, // Use ARM3 implementation
250+
NULL,
251+
FileObject);
252+
if (!NT_SUCCESS(Status))
253+
{
254+
ExFreePool(Map);
255+
RtlRaiseStatus(Status);
256+
}
240257
}
241258
/* We don't have a private cache map. Link it with the shared cache map
242259
to serve as a held reference. When the list in the shared cache map
@@ -325,6 +342,7 @@ CcUninitializeCacheMap(IN PFILE_OBJECT FileObject,
325342
CcpDereferenceCache(Bcb - CcCacheSections, TRUE);
326343
}
327344
RemoveEntryList(&PrivateCacheMap->Map->Entry);
345+
ObDereferenceObject(PrivateCacheMap->Map->SectionObject);
328346
ExFreePool(PrivateCacheMap->Map);
329347
FileObject->SectionObjectPointer->SharedCacheMap = NULL;
330348
LastMap = TRUE;
@@ -354,18 +372,36 @@ NTAPI
354372
CcSetFileSizes(IN PFILE_OBJECT FileObject,
355373
IN PCC_FILE_SIZES FileSizes)
356374
{
357-
PNOCC_CACHE_MAP Map = (PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap;
358-
PNOCC_BCB Bcb;
375+
PNOCC_CACHE_MAP Map;
376+
377+
CcpLock();
378+
379+
Map = FileObject->SectionObjectPointer->SharedCacheMap;
380+
381+
if (!Map)
382+
{
383+
CcpUnlock();
384+
return;
385+
}
386+
387+
/* FS should have unmapped the whole thing. */
388+
//ASSERT(IsListEmpty(&Map->AssociatedBcb));
389+
390+
if (Map->FileSizes.AllocationSize.QuadPart != FileSizes->AllocationSize.QuadPart)
391+
{
392+
LARGE_INTEGER SectionSize = FileSizes->AllocationSize;
393+
NTSTATUS Status = MmExtendSection(Map->SectionObject, &SectionSize);
394+
395+
if (!NT_SUCCESS(Status))
396+
{
397+
CcpUnlock();
398+
ExRaiseStatus(Status);
399+
}
400+
}
359401

360-
if (!Map) return;
361402
Map->FileSizes = *FileSizes;
362-
Bcb = Map->AssociatedBcb.Flink == &Map->AssociatedBcb ?
363-
NULL : CONTAINING_RECORD(Map->AssociatedBcb.Flink, NOCC_BCB, ThisFileList);
364-
if (!Bcb) return;
365-
MmExtendCacheSection(Bcb->SectionObject, &FileSizes->FileSize, FALSE);
366-
DPRINT("FileSizes->FileSize %x\n", FileSizes->FileSize.LowPart);
367-
DPRINT("FileSizes->AllocationSize %x\n", FileSizes->AllocationSize.LowPart);
368-
DPRINT("FileSizes->ValidDataLength %x\n", FileSizes->ValidDataLength.LowPart);
403+
404+
CcpUnlock();
369405
}
370406

371407
BOOLEAN
@@ -612,7 +648,7 @@ CcGetFileObjectFromSectionPtrs(IN PSECTION_OBJECT_POINTERS SectionObjectPointer)
612648
NOCC_BCB,
613649
ThisFileList);
614650

615-
Result = MmGetFileObjectForSection((PROS_SECTION_OBJECT)Bcb->SectionObject);
651+
Result = MmGetFileObjectForSection(Bcb->Map->SectionObject);
616652
}
617653
CcpUnlock();
618654
return Result;
@@ -624,7 +660,7 @@ CcGetFileObjectFromBcb(PVOID Bcb)
624660
{
625661
PNOCC_BCB RealBcb = (PNOCC_BCB)Bcb;
626662
DPRINT("BCB #%x\n", RealBcb - CcCacheSections);
627-
return MmGetFileObjectForSection((PROS_SECTION_OBJECT)RealBcb->SectionObject);
663+
return MmGetFileObjectForSection(RealBcb->Map->SectionObject);
628664
}
629665

630666
/* EOF */

ntoskrnl/cache/newcc.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ typedef struct _NOCC_BCB
66
PUBLIC_BCB Bcb;
77

88
struct _NOCC_CACHE_MAP *Map;
9-
PROS_SECTION_OBJECT SectionObject;
109
LARGE_INTEGER FileOffset;
1110
ULONG Length;
1211
PVOID BaseAddress;
1312
BOOLEAN Dirty;
1413
PVOID OwnerPointer;
1514

15+
PMDL Mdl;
16+
PVOID MdlAddress;
17+
1618
/* Reference counts */
1719
ULONG RefCount;
1820

@@ -36,6 +38,7 @@ typedef struct _NOCC_CACHE_MAP
3638
PVOID LogHandle;
3739
PFLUSH_TO_LSN FlushToLsn;
3840
ULONG ReadAheadGranularity;
41+
PVOID SectionObject;
3942
} NOCC_CACHE_MAP, *PNOCC_CACHE_MAP;
4043

4144
VOID

0 commit comments

Comments
 (0)