Author: ion
Date: Wed Jun 7 05:47:33 2006
New Revision: 22264
URL:
http://svn.reactos.ru/svn/reactos?rev=22264&view=rev
Log:
- Clone ObpCreateHandle to CmpCreateHandle. I am about to fix its implementation and since
Cm* currently abuses Ob I feel it safer to give its own internal function.
- Make ObpCreateHandle internal to Ob as it should be. Change NtCreateProcessTokenEx to
use ObOpenObjectByPointer, it has no business manually trying to create a handle. Same
goes for ExpLoadInitialProcess.
Modified:
trunk/reactos/ntoskrnl/cm/ntfunc.c
trunk/reactos/ntoskrnl/ex/init.c
trunk/reactos/ntoskrnl/include/internal/ob.h
trunk/reactos/ntoskrnl/ps/security.c
Modified: trunk/reactos/ntoskrnl/cm/ntfunc.c
URL:
http://svn.reactos.ru/svn/reactos/trunk/reactos/ntoskrnl/cm/ntfunc.c?rev=22…
==============================================================================
--- trunk/reactos/ntoskrnl/cm/ntfunc.c (original)
+++ trunk/reactos/ntoskrnl/cm/ntfunc.c Wed Jun 7 05:47:33 2006
@@ -29,6 +29,106 @@
FAST_MUTEX CmiCallbackLock;
/* FUNCTIONS ****************************************************************/
+
+NTSTATUS
+NTAPI
+CmpCreateHandle(PVOID ObjectBody,
+ ACCESS_MASK GrantedAccess,
+ ULONG HandleAttributes,
+ PHANDLE HandleReturn)
+ /*
+ * FUNCTION: Add a handle referencing an object
+ * ARGUMENTS:
+ * obj = Object body that the handle should refer to
+ * RETURNS: The created handle
+ * NOTE: The handle is valid only in the context of the current process
+ */
+{
+ HANDLE_TABLE_ENTRY NewEntry;
+ PEPROCESS Process, CurrentProcess;
+ POBJECT_HEADER ObjectHeader;
+ HANDLE Handle;
+ KAPC_STATE ApcState;
+ BOOLEAN AttachedToProcess = FALSE;
+
+ PAGED_CODE();
+
+ DPRINT("CmpCreateHandle(obj %p)\n",ObjectBody);
+
+ ASSERT(ObjectBody);
+
+ CurrentProcess = PsGetCurrentProcess();
+
+ ObjectHeader = OBJECT_TO_OBJECT_HEADER(ObjectBody);
+
+ /* check that this is a valid kernel pointer */
+ ASSERT((ULONG_PTR)ObjectHeader & EX_HANDLE_ENTRY_LOCKED);
+
+ if (GrantedAccess & MAXIMUM_ALLOWED)
+ {
+ GrantedAccess &= ~MAXIMUM_ALLOWED;
+ GrantedAccess |= GENERIC_ALL;
+ }
+
+ if (GrantedAccess & GENERIC_ACCESS)
+ {
+ RtlMapGenericMask(&GrantedAccess,
+ &ObjectHeader->Type->TypeInfo.GenericMapping);
+ }
+
+ NewEntry.Object = ObjectHeader;
+ if(HandleAttributes & OBJ_INHERIT)
+ NewEntry.ObAttributes |= EX_HANDLE_ENTRY_INHERITABLE;
+ else
+ NewEntry.ObAttributes &= ~EX_HANDLE_ENTRY_INHERITABLE;
+ NewEntry.GrantedAccess = GrantedAccess;
+
+ if ((HandleAttributes & OBJ_KERNEL_HANDLE) &&
+ ExGetPreviousMode == KernelMode)
+ {
+ Process = PsInitialSystemProcess;
+ if (Process != CurrentProcess)
+ {
+ KeStackAttachProcess(&Process->Pcb,
+ &ApcState);
+ AttachedToProcess = TRUE;
+ }
+ }
+ else
+ {
+ Process = CurrentProcess;
+ /* mask out the OBJ_KERNEL_HANDLE attribute */
+ HandleAttributes &= ~OBJ_KERNEL_HANDLE;
+ }
+
+ Handle = ExCreateHandle(Process->ObjectTable,
+ &NewEntry);
+
+ if (AttachedToProcess)
+ {
+ KeUnstackDetachProcess(&ApcState);
+ }
+
+ if(Handle != NULL)
+ {
+ if (HandleAttributes & OBJ_KERNEL_HANDLE)
+ {
+ /* mark the handle value */
+ Handle = ObMarkHandleAsKernelHandle(Handle);
+ }
+
+ if(InterlockedIncrement(&ObjectHeader->HandleCount) == 1)
+ {
+ ObReferenceObject(ObjectBody);
+ }
+
+ *HandleReturn = Handle;
+
+ return STATUS_SUCCESS;
+ }
+
+ return STATUS_UNSUCCESSFUL;
+}
/*
* @implemented
@@ -291,13 +391,13 @@
goto Cleanup;
}
- Status = ObpCreateHandle(Object,
+ Status = CmpCreateHandle(Object,
DesiredAccess,
ObjectCreateInfo.Attributes,
&hKey);
if (!NT_SUCCESS(Status))
- DPRINT1("ObpCreateHandle failed Status 0x%x\n", Status);
+ DPRINT1("CmpCreateHandle failed Status 0x%x\n", Status);
PostCreateKeyInfo.Object = NULL;
PostCreateKeyInfo.Status = Status;
@@ -1361,7 +1461,7 @@
goto openkey_cleanup;
}
- Status = ObpCreateHandle(Object,
+ Status = CmpCreateHandle(Object,
DesiredAccess,
ObjectCreateInfo.Attributes,
&hKey);
Modified: trunk/reactos/ntoskrnl/ex/init.c
URL:
http://svn.reactos.ru/svn/reactos/trunk/reactos/ntoskrnl/ex/init.c?rev=2226…
==============================================================================
--- trunk/reactos/ntoskrnl/ex/init.c (original)
+++ trunk/reactos/ntoskrnl/ex/init.c Wed Jun 7 05:47:33 2006
@@ -426,21 +426,9 @@
{
UNICODE_STRING CurrentDirectory;
UNICODE_STRING ImagePath =
RTL_CONSTANT_STRING(L"\\SystemRoot\\system32\\smss.exe");
- HANDLE SystemProcessHandle;
NTSTATUS Status;
PRTL_USER_PROCESS_PARAMETERS Params=NULL;
RTL_USER_PROCESS_INFORMATION Info;
-
- /* Create a handle to the process */
- Status = ObpCreateHandle(PsInitialSystemProcess,
- PROCESS_CREATE_PROCESS | PROCESS_CREATE_THREAD |
PROCESS_QUERY_INFORMATION,
- OBJ_KERNEL_HANDLE,
- &SystemProcessHandle);
- if(!NT_SUCCESS(Status))
- {
- DPRINT1("Failed to create a handle for the system process!\n");
- return Status;
- }
RtlInitUnicodeString(&CurrentDirectory,
SharedUserData->NtSystemRoot);
@@ -459,7 +447,6 @@
if(!NT_SUCCESS(Status))
{
DPRINT1("Failed to create ppb!\n");
- ZwClose(SystemProcessHandle);
return Status;
}
@@ -469,14 +456,13 @@
Params,
NULL,
NULL,
- SystemProcessHandle,
+ NULL,
FALSE,
NULL,
NULL,
&Info);
/* Close the handle and free the params */
- ZwClose(SystemProcessHandle);
RtlDestroyProcessParameters(Params);
if (!NT_SUCCESS(Status))
Modified: trunk/reactos/ntoskrnl/include/internal/ob.h
URL:
http://svn.reactos.ru/svn/reactos/trunk/reactos/ntoskrnl/include/internal/o…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/ob.h (original)
+++ trunk/reactos/ntoskrnl/include/internal/ob.h Wed Jun 7 05:47:33 2006
@@ -68,15 +68,6 @@
NTAPI
ObInitSymbolicLinkImplementation(
VOID
-);
-
-NTSTATUS
-NTAPI
-ObpCreateHandle(
- PVOID ObjectBody,
- ACCESS_MASK GrantedAccess,
- ULONG HandleAttributes,
- PHANDLE Handle
);
NTSTATUS
Modified: trunk/reactos/ntoskrnl/ps/security.c
URL:
http://svn.reactos.ru/svn/reactos/trunk/reactos/ntoskrnl/ps/security.c?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/ps/security.c (original)
+++ trunk/reactos/ntoskrnl/ps/security.c Wed Jun 7 05:47:33 2006
@@ -97,10 +97,13 @@
&Token);
if(NT_SUCCESS(Status))
{
- Status = ObpCreateHandle(Token,
- DesiredAccess,
- HandleAttributes,
- &hToken);
+ Status = ObOpenObjectByPointer(Token,
+ 0,
+ NULL,
+ DesiredAccess,
+ SepTokenObjectType,
+ PreviousMode,
+ &hToken);
ObDereferenceObject(Token);
if(NT_SUCCESS(Status))