Hi,
I bring a cache purge issue again even though it has been discussed
many times.
I have a filter driver to encrypt/decrypt on the fly. One of the
requirement is when each time application reads the encrypted file,
the filter driver need to force it not read from cache, read from disk
instead, so that driver can decrypt data. I use following code someone
suggested in this forum to purge cache in post IRP_MJ_CREATE (completion
routine) and force system to launch paging IO to read from disk.
pFCBHeader = (PFSRTL_COMMON_FCB_HEADER)(pIrpStack->FileObject->FsContext);
pSection = pIrpStack->FileObject->SectionObjectPointer;
KeEnterCriticalRegion();
ExAcquireResourceExclusiveLite(pFcbHeader->Resource, TRUE);
ExAcquireResourceExclusiveLite(pFcbHeader->PagingIoResource, TRUE);
CcFlushCache(pSection, 0, 0, NULL);
If (pSection->ImageSectionObject != NULL)
MmFlushImageSection(pSection, MmFlushForWrite);
If (pSection->DataSectionObject != NULL)
CcPurgeCacheSection(pSection, NULL, 0, TRUE);
CcUninitializeCacheMap(pIrpStack->FileObject, NULL, NULL);
ExReleaseResourceLite(pFcbHeader->PagingIoResource);
ExReleaseResourceLite(pFcbHeader->Resource);
KeLeaveCriticalRegion();
After the cache is purged, I can see IRP_MJ_CLEANUP, IRP_MJ_CLOSE
and IRP_MJ_READ for paging request. So, it seems cache is purged
successfully and filter driver can decrypt the file for paging IO.
However, on one of our XP SP2 NTFS testing machine(there are more
than 20 testing machines set to different configurations), it
cause KERNEL_APC_PENDING_DURING_EXIT on every time machine reboot
or shutdown. All other testing machines work fine.
I put the memory dump in here:
In memory dump, the arg2 is negative. I can not figure out how I call
KeEnterCriticalRegion() cause APC disable count is not zero. If I
disable all Cc and Mm functions and just leave resource acquire and
release in there, the problem won't happen. Of course, when application
second time open the encrypted file, it will read from cache, not from
disk because driver don't see paging IO. So, it seems that ntoskrnal.exe
is broken by I call Cc Mm functions. But I can't get reasonable
interpretation and don't know how to solve that.
Do you guys have any ideal? Any suggestion will be appreciated.
I'm sorry that is long post because I try to give some detail about what I
did and where the problem is.
BugCheck 20, {8a210cac, fffffffe, 0, 0}
Probably caused by : ntoskrnl.exe ( nt!PsWaitForAllProcesses+9e )
Followup: MachineOwner
kd> !analyze -v
****************************************************************
*
*
* Bugcheck Analysis
*
*
*
****************************************************************
KERNEL_APC_PENDING_DURING_EXIT (20)
Arguments:
Arg1: 8a210cac, The address of the APC found pending during exit.
Arg2: fffffffe, The thread's APC disable count
Arg3: 00000000, The current IRQL
Arg4: 00000000
Debugging Details:
DEFAULT_BUCKET_ID: DRIVER_FAULT
BUGCHECK_STR: 0x20
LAST_CONTROL_TRANSFER: from 805f9e4c to 8053331e
STACK_TEXT:
aed7ac50 805f9e4c 00000020 8a210cac fffffffe nt!KeBugCheckEx+0x1b
aed7ad08 8057a46a 00000000 8a14bbc0 00000000 nt!PsWaitForAllProcesses+0x9e
aed7ad28 80582d13 8a14bbc0 00000000 aed7ad64
nt!PspTerminateThreadByPointer+0x52
aed7ad54 804de7ec 00000000 00000000 00eaff24 nt!NtTerminateProcess+0x118
aed7ad54 7c90eb94 00000000 00000000 00eaff24 nt!KiFastCallEntry+0xf8
WARNING: Frame IP not in any known module. Following frames may be wrong.
00eafe24 00000000 00000000 00000000 00000000 0x7c90eb94
FOLLOWUP_IP:
nt!PsWaitForAllProcesses+9e
805f9e4c 43 inc ebx
SYMBOL_STACK_INDEX: 1
FOLLOWUP_NAME: MachineOwner
SYMBOL_NAME: nt!PsWaitForAllProcesses+9e
MODULE_NAME: nt
IMAGE_NAME: ntoskrnl.exe
DEBUG_FLR_IMAGE_TIMESTAMP: 42250ff9
STACK_COMMAND: kb
BUCKET_ID: 0x20_nt!PsWaitForAllProcesses+9e
Followup: MachineOwner
kd> kb
ChildEBP RetAddr Args to Child
aed7ac50 805f9e4c 00000020 8a210cac fffffffe nt!KeBugCheckEx+0x1b
aed7ad08 8057a46a 00000000 8a14bbc0 00000000 nt!PsWaitForAllProcesses+0x9e
aed7ad28 80582d13 8a14bbc0 00000000 aed7ad64
nt!PspTerminateThreadByPointer+0x52
aed7ad54 804de7ec 00000000 00000000 00eaff24 nt!NtTerminateProcess+0x118
aed7ad54 7c90eb94 00000000 00000000 00eaff24 nt!KiFastCallEntry+0xf8
WARNING: Frame IP not in any known module. Following frames may be wrong.
00eafe24 00000000 00000000 00000000 00000000 0x7c90eb94