From 93551abbd20555389ac09d895473e8ddb559ffb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9=20van=20Geldorp?= Date: Mon, 24 Jan 2005 22:02:09 +0000 Subject: [PATCH] Implement IO_NO_PARAMETER_CHECKING flag svn path=/trunk/; revision=13256 --- reactos/include/ddk/iodef.h | 5 ++++ reactos/ntoskrnl/io/create.c | 51 ++++++++++++++++++++++++++-------- reactos/ntoskrnl/mm/pagefile.c | 2 +- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/reactos/include/ddk/iodef.h b/reactos/include/ddk/iodef.h index e35d19df60e..b7de74992f9 100644 --- a/reactos/include/ddk/iodef.h +++ b/reactos/include/ddk/iodef.h @@ -160,6 +160,11 @@ enum #define SL_INVOKE_ON_SUCCESS 0x40 #define SL_INVOKE_ON_ERROR 0x80 +/* + * IoCreateFile options + */ +#define IO_NO_PARAMETER_CHECKING 0x100 + /* * Possible flags for the device object flags */ diff --git a/reactos/ntoskrnl/io/create.c b/reactos/ntoskrnl/io/create.c index 22bf1c37c16..8742c41c3fd 100644 --- a/reactos/ntoskrnl/io/create.c +++ b/reactos/ntoskrnl/io/create.c @@ -321,7 +321,7 @@ IoCreateStreamFileObject(PFILE_OBJECT FileObject, * @implemented */ NTSTATUS STDCALL -IoCreateFile(OUT PHANDLE FileHandle, +IoCreateFile(OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, @@ -341,7 +341,9 @@ IoCreateFile(OUT PHANDLE FileHandle, PIRP Irp; PIO_STACK_LOCATION StackLoc; IO_SECURITY_CONTEXT SecurityContext; - KPROCESSOR_MODE PreviousMode; + KPROCESSOR_MODE PreviousMode; + HANDLE LocalFileHandle; + IO_STATUS_BLOCK LocalIoStatusBlock; DPRINT("IoCreateFile(FileHandle %x, DesiredAccess %x, " "ObjectAttributes %x ObjectAttributes->ObjectName->Buffer %S)\n", @@ -350,14 +352,14 @@ IoCreateFile(OUT PHANDLE FileHandle, ASSERT_IRQL(PASSIVE_LEVEL); - if (IoStatusBlock == NULL) - return STATUS_ACCESS_VIOLATION; + if (IoStatusBlock == NULL || FileHandle == NULL) + return STATUS_ACCESS_VIOLATION; - *FileHandle = 0; + LocalFileHandle = 0; PreviousMode = ExGetPreviousMode(); - Status = ObCreateObject(PreviousMode, + Status = ObCreateObject(0 == (Options & IO_NO_PARAMETER_CHECKING) ? PreviousMode : KernelMode, IoFileObjectType, ObjectAttributes, PreviousMode, @@ -380,7 +382,7 @@ IoCreateFile(OUT PHANDLE FileHandle, DesiredAccess, 0, NULL, - FileHandle); + &LocalFileHandle); if (!NT_SUCCESS(Status)) { DPRINT("ObInsertObject() failed! (Status %lx)\n", Status); @@ -418,14 +420,14 @@ IoCreateFile(OUT PHANDLE FileHandle, Irp = IoAllocateIrp(FileObject->DeviceObject->StackSize, FALSE); if (Irp == NULL) { - ZwClose(*FileHandle); + ZwClose(LocalFileHandle); return STATUS_UNSUCCESSFUL; } //trigger FileObject/Event dereferencing Irp->Tail.Overlay.OriginalFileObject = FileObject; Irp->RequestorMode = PreviousMode; - Irp->UserIosb = IoStatusBlock; + Irp->UserIosb = &LocalIoStatusBlock; Irp->AssociatedIrp.SystemBuffer = EaBuffer; Irp->Tail.Overlay.AuxiliaryBuffer = NULL; Irp->Tail.Overlay.Thread = PsGetCurrentThread(); @@ -493,7 +495,7 @@ IoCreateFile(OUT PHANDLE FileHandle, PreviousMode, FALSE, NULL); - Status = IoStatusBlock->Status; + Status = LocalIoStatusBlock.Status; } if (!NT_SUCCESS(Status)) { @@ -501,7 +503,34 @@ IoCreateFile(OUT PHANDLE FileHandle, FileObject->DeviceObject = NULL; FileObject->Vpb = NULL; - ZwClose(*FileHandle); + ZwClose(LocalFileHandle); + } + else + { + if (KernelMode == PreviousMode || 0 != (Options & IO_NO_PARAMETER_CHECKING)) + { + *FileHandle = LocalFileHandle; + *IoStatusBlock = LocalIoStatusBlock; + } + else + { + _SEH_TRY + { + ProbeForWrite(FileHandle, + sizeof(HANDLE), + sizeof(ULONG)); + *FileHandle = LocalFileHandle; + ProbeForWrite(IoStatusBlock, + sizeof(IO_STATUS_BLOCK), + sizeof(ULONG)); + *IoStatusBlock = LocalIoStatusBlock; + } + _SEH_HANDLE + { + Status = _SEH_GetExceptionCode(); + } + _SEH_END; + } } ASSERT_IRQL(PASSIVE_LEVEL); diff --git a/reactos/ntoskrnl/mm/pagefile.c b/reactos/ntoskrnl/mm/pagefile.c index 3ce699945c7..c27fabb04f3 100644 --- a/reactos/ntoskrnl/mm/pagefile.c +++ b/reactos/ntoskrnl/mm/pagefile.c @@ -833,7 +833,7 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName, 0, CreateFileTypeNone, NULL, - SL_OPEN_PAGING_FILE); + SL_OPEN_PAGING_FILE | IO_NO_PARAMETER_CHECKING); RtlReleaseCapturedUnicodeString(&CapturedFileName, PreviousMode, FALSE);