From 83d199acbac98152925d004292229fe40efaed8f Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Tue, 21 Nov 2017 16:00:24 +0500 Subject: [PATCH] Driver: Micro-optimize pending buffer handling. --- src/driver/fortbuf.c | 7 +++++-- src/driver/forttmr.c | 13 +++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/driver/fortbuf.c b/src/driver/fortbuf.c index f488e49f..fc41955c 100644 --- a/src/driver/fortbuf.c +++ b/src/driver/fortbuf.c @@ -54,12 +54,14 @@ fort_buffer_blocked_write (PFORT_BUFFER buf, UINT32 remote_ip, UINT32 pid, KeAcquireSpinLock(&buf->lock, &irq); /* Try to directly write to pending client */ - if (buf->irp != NULL) { + if (buf->out_len) { const UINT32 out_top = buf->out_top; UINT32 new_top = out_top + len; /* Is it time to flush logs? */ if (buf->out_len - new_top < FORT_LOG_BLOCKED_SIZE_MAX) { + buf->out_len = 0; + *irp = buf->irp; buf->irp = NULL; @@ -105,7 +107,7 @@ fort_buffer_xmove (PFORT_BUFFER buf, PIRP irp, PVOID out, ULONG out_len, *info = buf_top = buf->top; if (!buf_top) { - if (buf->irp != NULL) { + if (buf->out_len) { status = STATUS_INSUFFICIENT_RESOURCES; } else if (out_len < FORT_LOG_BLOCKED_SIZE_MAX) { status = STATUS_BUFFER_TOO_SMALL; @@ -143,6 +145,7 @@ fort_buffer_cancel_pending (PFORT_BUFFER buf, PIRP irp, ULONG_PTR *info) KeAcquireSpinLock(&buf->lock, &irq); if (irp == buf->irp) { buf->irp = NULL; + buf->out_len = 0; if (buf->out_top) { *info = buf->out_top; diff --git a/src/driver/forttmr.c b/src/driver/forttmr.c index 6e68a76a..6d5282ea 100644 --- a/src/driver/forttmr.c +++ b/src/driver/forttmr.c @@ -12,23 +12,24 @@ static void fort_timer_callback (PKDPC dpc, PFORT_BUFFER buf, PVOID arg1, PVOID arg2) { PIRP irp = NULL; - ULONG info = 0; + ULONG info; UNUSED(dpc); UNUSED(arg1); UNUSED(arg2); KeAcquireSpinLockAtDpcLevel(&buf->lock); - if (buf->irp != NULL && buf->out_top) { + info = buf->out_top; + if (info) { + buf->out_top = 0; + buf->out_len = 0; + irp = buf->irp; buf->irp = NULL; - - info = buf->out_top; - buf->out_top = 0; } KeReleaseSpinLockFromDpcLevel(&buf->lock); - if (irp != NULL) { + if (info) { fort_request_complete_info(irp, STATUS_SUCCESS, info); } }