From cdb563f38066b38dc7aaa0a6bfcb4a80e3f9dee4 Mon Sep 17 00:00:00 2001 From: Sir Richard Date: Sat, 23 Jan 2010 21:27:26 +0000 Subject: [PATCH] [PERF]: Replace early ZwClose system calls with ObCloseHandle(KernelMode). This avoids taking a system call for those cases and gives a slight perf boost to booting up the system. It also pushes the first system call somewhat later in the boot process, allowing for easier debugging should the interface have issues/need tracing. [NTOS]: Do not attempt querying the Registry Primary Handle for the Backing Hive File Size in the case where there is no actual Primary! There was no error checking so nobody noticed this happens -- it also probably resets Cluster to 0 (instead of 1), which can cause corruption in some cases. [NTOS]: Make KiUserTrap use the MODE_MASK instead of hard-coding a check for Ring 0 CS (which is slower and not as correct). svn path=/trunk/; revision=45217 --- reactos/ntoskrnl/config/cminit.c | 18 +++++++++++------- reactos/ntoskrnl/ex/init.c | 2 +- reactos/ntoskrnl/ex/work.c | 4 ++-- reactos/ntoskrnl/include/internal/trap_x.h | 2 +- reactos/ntoskrnl/ke/i386/traphdlr.c | 2 +- reactos/ntoskrnl/ps/psmgr.c | 2 +- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/reactos/ntoskrnl/config/cminit.c b/reactos/ntoskrnl/config/cminit.c index 553b84a962c..154ba1530b6 100644 --- a/reactos/ntoskrnl/config/cminit.c +++ b/reactos/ntoskrnl/config/cminit.c @@ -163,13 +163,17 @@ CmpInitializeHive(OUT PCMHIVE *RegistryHive, /* Set flags */ Hive->Flags = HiveFlags; - /* Check how large the file is */ - ZwQueryInformationFile(Primary, - &IoStatusBlock, - &FileInformation, - sizeof(FileInformation), - FileStandardInformation); - Cluster = FileInformation.EndOfFile.LowPart; + /* Check if this is a primary */ + if (Primary) + { + /* Check how large the file is */ + ZwQueryInformationFile(Primary, + &IoStatusBlock, + &FileInformation, + sizeof(FileInformation), + FileStandardInformation); + Cluster = FileInformation.EndOfFile.LowPart; + } /* Initialize it */ Status = HvInitialize(&Hive->Hive, diff --git a/reactos/ntoskrnl/ex/init.c b/reactos/ntoskrnl/ex/init.c index d2794a4b52f..fed59bce758 100644 --- a/reactos/ntoskrnl/ex/init.c +++ b/reactos/ntoskrnl/ex/init.c @@ -303,7 +303,7 @@ ExpInitNls(IN PLOADER_PARAMETER_BLOCK LoaderBlock) KernelMode, &ExpNlsSectionPointer, NULL); - ZwClose(NlsSection); + ObCloseHandle(NlsSection, KernelMode); if (!NT_SUCCESS(Status)) { /* Failed */ diff --git a/reactos/ntoskrnl/ex/work.c b/reactos/ntoskrnl/ex/work.c index d7bdae23583..abedd6b4985 100644 --- a/reactos/ntoskrnl/ex/work.c +++ b/reactos/ntoskrnl/ex/work.c @@ -310,7 +310,7 @@ ExpCreateWorkerThread(WORK_QUEUE_TYPE WorkQueueType, /* Dereference and close handle */ ObDereferenceObject(Thread); - ZwClose(hThread); + ObCloseHandle(hThread, KernelMode); } /*++ @@ -586,7 +586,7 @@ ExpInitializeWorkerThreads(VOID) ExpWorkerThreadBalanceManagerPtr = Thread; /* Close the handle and return */ - ZwClose(ThreadHandle); + ObCloseHandle(ThreadHandle, KernelMode); } /* PUBLIC FUNCTIONS **********************************************************/ diff --git a/reactos/ntoskrnl/include/internal/trap_x.h b/reactos/ntoskrnl/include/internal/trap_x.h index b5f6e58e06e..bf82738f22d 100644 --- a/reactos/ntoskrnl/include/internal/trap_x.h +++ b/reactos/ntoskrnl/include/internal/trap_x.h @@ -165,7 +165,7 @@ FORCEINLINE KiUserTrap(IN PKTRAP_FRAME TrapFrame) { /* Anything else but Ring 0 is Ring 3 */ - return (TrapFrame->SegCs != KGDT_R0_CODE); + return (TrapFrame->SegCs & MODE_MASK); } BOOLEAN diff --git a/reactos/ntoskrnl/ke/i386/traphdlr.c b/reactos/ntoskrnl/ke/i386/traphdlr.c index 1bbb520b43c..bf82b8e51a2 100644 --- a/reactos/ntoskrnl/ke/i386/traphdlr.c +++ b/reactos/ntoskrnl/ke/i386/traphdlr.c @@ -466,7 +466,7 @@ KiDispatchExceptionFromTrapFrame(IN NTSTATUS Code, NULL, TrapFrame, TrapFrame->EFlags & EFLAGS_V86_MASK ? - -1 : TrapFrame->SegCs & MODE_MASK, + -1 : KiUserTrap(TrapFrame), TRUE); /* Return from this trap */ diff --git a/reactos/ntoskrnl/ps/psmgr.c b/reactos/ntoskrnl/ps/psmgr.c index f30a03d93f1..9fa513b0f17 100644 --- a/reactos/ntoskrnl/ps/psmgr.c +++ b/reactos/ntoskrnl/ps/psmgr.c @@ -586,7 +586,7 @@ PspInitPhase0(IN PLOADER_PARAMETER_BLOCK LoaderBlock) KernelMode, (PVOID*)&SysThread, NULL); - ZwClose(SysThreadHandle); + ObCloseHandle(SysThreadHandle, KernelMode); SysThreadCreated = TRUE; /* Return success */