问题
在minifilter中,可以使用CtxGetFileContext,CtxCreateFileContext等函数保存context。
以FileContext为例,新建的文件可以保存一个context进去,然后当这个文件被删除的时候,操作系统会调用minifilter的清理函数来删除相应的context。
那么坑:
如果海量创建文件,那么context就会越来越多,如果文件一直不删除,那么驱动里面的context就会炸掉。
场景
一般保存context如下:
NTSTATUS
CtxFindOrCreateFileContext(
_In_ PFLT_CALLBACK_DATA Cbd,
_In_ BOOLEAN CreateIfNotFound,
_When_(CreateIfNotFound != FALSE, _In_) _When_(CreateIfNotFound == FALSE, _In_opt_) PUNICODE_STRING FileName,
_Outptr_ PCTX_FILE_CONTEXT *FileContext,
_Out_opt_ PBOOLEAN ContextCreated
)
/*++
Routine Description:
This routine finds the file context for the target file.
Optionally, if the context does not exist this routing creates
a new one and attaches the context to the file.
Arguments:
Cbd - Supplies a pointer to the callbackData which
declares the requested operation.
CreateIfNotFound - Supplies if the file context must be created if missing
FileName - Supplies the file name
FileContext - Returns the file context
ContextCreated - Returns if a new context was created
Return Value:
Status
--*/
{
NTSTATUS status;
PCTX_FILE_CONTEXT fileContext;
PCTX_FILE_CONTEXT oldFileContext;
PAGED_CODE();
*FileContext = NULL;
if (ContextCreated !&