From 7bf6af0dce5d4f5759f2f10e77e81144b332b271 Mon Sep 17 00:00:00 2001 From: Hartmut Birr Date: Fri, 1 Apr 2005 18:22:17 +0000 Subject: [PATCH] - Use IoBuildAsynchronousFsdRequest instead IoBuildSynchronousFsdRequest in NtRead/WriteFile. - Guard the calls to IoBuildAsynchronousFsdRequest with an exception frame. svn path=/trunk/; revision=14421 --- reactos/ntoskrnl/io/rw.c | 102 ++++++++++++++++++++++++++++++--------- 1 file changed, 79 insertions(+), 23 deletions(-) diff --git a/reactos/ntoskrnl/io/rw.c b/reactos/ntoskrnl/io/rw.c index 07af4e53701..5c75dd0a131 100644 --- a/reactos/ntoskrnl/io/rw.c +++ b/reactos/ntoskrnl/io/rw.c @@ -44,7 +44,7 @@ NtReadFile (IN HANDLE FileHandle, { NTSTATUS Status; PFILE_OBJECT FileObject; - PIRP Irp; + PIRP Irp = NULL; PIO_STACK_LOCATION StackPtr; KPROCESSOR_MODE PreviousMode; PKEVENT EventObject = NULL; @@ -92,24 +92,52 @@ NtReadFile (IN HANDLE FileHandle, PreviousMode, (PVOID*)&EventObject, NULL); - if (!NT_SUCCESS(Status)) - { - ObDereferenceObject(FileObject); - return Status; - } + if (!NT_SUCCESS(Status)) + { + ObDereferenceObject(FileObject); + return Status; + } KeClearEvent(EventObject); } - KeClearEvent(&FileObject->Event); + _SEH_TRY + { + Irp = IoBuildAsynchronousFsdRequest(IRP_MJ_READ, + FileObject->DeviceObject, + Buffer, + Length, + ByteOffset, + IoStatusBlock); + } + _SEH_HANDLE + { + Status = _SEH_GetExceptionCode(); + } + _SEH_END; - Irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ, - FileObject->DeviceObject, - Buffer, - Length, - ByteOffset, - EventObject, - IoStatusBlock); + if (!NT_SUCCESS(Status) || Irp == NULL) + { + if (Event) + { + ObDereferenceObject(&EventObject); + } + ObDereferenceObject(FileObject); + if (Irp) + { + IoFreeIrp(Irp); + } + return NT_SUCCESS(Status) ? STATUS_INSUFFICIENT_RESOURCES : Status; + } + + Irp->UserEvent = Event; + if (FileObject->Flags & FO_SYNCHRONOUS_IO) + { + /* synchronous irp's are queued to requestor thread's irp cancel/cleanup list */ + IoQueueThreadIrp(Irp); + } + + KeClearEvent(&FileObject->Event); /* Trigger FileObject/Event dereferencing */ Irp->Tail.Overlay.OriginalFileObject = FileObject; @@ -172,7 +200,7 @@ NtWriteFile (IN HANDLE FileHandle, OBJECT_HANDLE_INFORMATION HandleInformation; NTSTATUS Status; PFILE_OBJECT FileObject; - PIRP Irp; + PIRP Irp = NULL; PIO_STACK_LOCATION StackPtr; KPROCESSOR_MODE PreviousMode; PKEVENT EventObject = NULL; @@ -253,15 +281,43 @@ NtWriteFile (IN HANDLE FileHandle, KeClearEvent(EventObject); } - KeClearEvent(&FileObject->Event); + _SEH_TRY + { + Irp = IoBuildAsynchronousFsdRequest(IRP_MJ_WRITE, + FileObject->DeviceObject, + Buffer, + Length, + ByteOffset, + IoStatusBlock); + } + _SEH_HANDLE + { + Status = _SEH_GetExceptionCode(); + } + _SEH_END; - Irp = IoBuildSynchronousFsdRequest(IRP_MJ_WRITE, - FileObject->DeviceObject, - Buffer, - Length, - ByteOffset, - EventObject, - IoStatusBlock); + if (!NT_SUCCESS(Status) || Irp == NULL) + { + if (Event) + { + ObDereferenceObject(&EventObject); + } + ObDereferenceObject(FileObject); + if (Irp) + { + IoFreeIrp(Irp); + } + return NT_SUCCESS(Status) ? STATUS_INSUFFICIENT_RESOURCES : Status; + } + + Irp->UserEvent = Event; + if (FileObject->Flags & FO_SYNCHRONOUS_IO) + { + /* synchronous irp's are queued to requestor thread's irp cancel/cleanup list */ + IoQueueThreadIrp(Irp); + } + + KeClearEvent(&FileObject->Event); /* Trigger FileObject/Event dereferencing */ Irp->Tail.Overlay.OriginalFileObject = FileObject;