https://git.reactos.org/?p=reactos.git;a=commitdiff;h=a6b281c2280710e684a20…
commit a6b281c2280710e684a208deb07abd9838ce7cb6
Author: Oleg Dubinskiy <oleg.dubinskij30(a)gmail.com>
AuthorDate: Tue Oct 10 22:30:00 2023 +0200
Commit: GitHub <noreply(a)github.com>
CommitDate: Tue Oct 10 13:30:00 2023 -0700
[KS] KsRead/WriteFile: finish IRP initialization and properly setup I/O stack location
for it (#5784)
- Initialize the rest of IRP data which is not initialized by
IoBuildSynchronousFsdRequest.
- Setup an IO_STACK_LOCATION structure for the IRP before calling the driver's
read/write routine.
- Do this for both KsReadFile and KsWriteFile functions in our Kernel Streaming driver
(ks.sys).
This fixes several problems when calling these functions from outside, so now they are
working correctly, as expected.
Discovered during my audio investigations.
CORE-19232
---
drivers/ksfilter/ks/irp.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/drivers/ksfilter/ks/irp.c b/drivers/ksfilter/ks/irp.c
index 91302e67299..01ee18c2832 100644
--- a/drivers/ksfilter/ks/irp.c
+++ b/drivers/ksfilter/ks/irp.c
@@ -150,6 +150,7 @@ KsReadFile(
IN KPROCESSOR_MODE RequestorMode)
{
PDEVICE_OBJECT DeviceObject;
+ PIO_STACK_LOCATION IoStack;
PIRP Irp;
NTSTATUS Status;
BOOLEAN Result;
@@ -216,6 +217,16 @@ KsReadFile(
return STATUS_INSUFFICIENT_RESOURCES;
}
+ /* setup the rest of irp */
+ Irp->RequestorMode = RequestorMode;
+ Irp->Overlay.AsynchronousParameters.UserApcContext = PortContext;
+ Irp->Tail.Overlay.OriginalFileObject = FileObject;
+
+ /* setup irp stack */
+ IoStack = IoGetNextIrpStackLocation(Irp);
+ IoStack->FileObject = FileObject;
+ IoStack->Parameters.Read.Key = Key;
+
/* send the packet */
Status = IoCallDriver(DeviceObject, Irp);
@@ -250,6 +261,7 @@ KsWriteFile(
IN KPROCESSOR_MODE RequestorMode)
{
PDEVICE_OBJECT DeviceObject;
+ PIO_STACK_LOCATION IoStack;
PIRP Irp;
NTSTATUS Status;
BOOLEAN Result;
@@ -316,6 +328,16 @@ KsWriteFile(
return STATUS_INSUFFICIENT_RESOURCES;
}
+ /* setup the rest of irp */
+ Irp->RequestorMode = RequestorMode;
+ Irp->Overlay.AsynchronousParameters.UserApcContext = PortContext;
+ Irp->Tail.Overlay.OriginalFileObject = FileObject;
+
+ /* setup irp stack */
+ IoStack = IoGetNextIrpStackLocation(Irp);
+ IoStack->FileObject = FileObject;
+ IoStack->Parameters.Write.Key = Key;
+
/* send the packet */
Status = IoCallDriver(DeviceObject, Irp);