FileContext等的坑?

在Minifilter驱动中,使用CtxGetFileContext和CtxCreateFileContext保存FileContext可能导致大量积累,尤其是在大量创建文件而不删除的情况下。这将影响驱动性能,如查找速度变慢和资源耗尽。为解决此问题,可以实现CtxContextCleanup删除不再需要的context,但可能影响后续操作。目前,寻求更优解决方案是一个挑战。
摘要由CSDN通过智能技术生成

FileContext等的坑?

问题

在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 !&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值