From 19ea176f6df0d7f1325a7187211f702126e4b01e Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Sun, 15 May 2005 19:40:57 +0000 Subject: [PATCH] Properly create the Object Type Type and remove previous hacks added svn path=/trunk/; revision=15319 --- reactos/ntoskrnl/include/internal/ob.h | 11 +- reactos/ntoskrnl/ob/namespc.c | 322 +++++++++++-------------- reactos/ntoskrnl/ob/object.c | 98 +++++--- 3 files changed, 207 insertions(+), 224 deletions(-) diff --git a/reactos/ntoskrnl/include/internal/ob.h b/reactos/ntoskrnl/include/internal/ob.h index 40d1bc39f27..b7522cefde6 100644 --- a/reactos/ntoskrnl/include/internal/ob.h +++ b/reactos/ntoskrnl/include/internal/ob.h @@ -115,16 +115,6 @@ typedef struct _SYMLINK_OBJECT LARGE_INTEGER CreateTime; } SYMLINK_OBJECT, *PSYMLINK_OBJECT; - -typedef struct _TYPE_OBJECT -{ - CSHORT Type; - CSHORT Size; - - /* pointer to object type data */ - POBJECT_TYPE ObjectType; -} TYPE_OBJECT, *PTYPE_OBJECT; - /* * Enumeration of object types */ @@ -197,6 +187,7 @@ ObpSetHandleAttributes(HANDLE Handle, POBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleInfo); NTSTATUS +STDCALL ObpCreateTypeObject(POBJECT_TYPE_INITIALIZER ObjectTypeInitializer, PUNICODE_STRING TypeName, POBJECT_TYPE *ObjectType); diff --git a/reactos/ntoskrnl/ob/namespc.c b/reactos/ntoskrnl/ob/namespc.c index b6301ff2ce5..30974240ba1 100644 --- a/reactos/ntoskrnl/ob/namespc.c +++ b/reactos/ntoskrnl/ob/namespc.c @@ -21,9 +21,11 @@ POBJECT_TYPE ObDirectoryType = NULL; POBJECT_TYPE ObTypeObjectType = NULL; PDIRECTORY_OBJECT NameSpaceRoot = NULL; +PDIRECTORY_OBJECT ObpTypeDirectoryObject = NULL; /* FIXME: Move this somewhere else once devicemap support is in */ PDEVICE_MAP ObSystemDeviceMap = NULL; + static GENERIC_MAPPING ObpDirectoryMapping = { STANDARD_RIGHTS_READ|DIRECTORY_QUERY|DIRECTORY_TRAVERSE, STANDARD_RIGHTS_WRITE|DIRECTORY_CREATE_OBJECT|DIRECTORY_CREATE_SUBDIRECTORY, @@ -36,6 +38,13 @@ static GENERIC_MAPPING ObpTypeMapping = { STANDARD_RIGHTS_EXECUTE, 0x000F0001}; +NTSTATUS +STDCALL +ObpAllocateObject(POBJECT_ATTRIBUTES ObjectAttributes, + POBJECT_TYPE ObjectType, + ULONG ObjectSize, + POBJECT_HEADER *ObjectHeader); + /* FUNCTIONS **************************************************************/ /* @@ -367,193 +376,152 @@ ObpParseDirectory(PVOID Object, return STATUS_SUCCESS; } -/* HACKS FOR COMPATIBILITY. TEMPORARY */ -NTSTATUS -ObpCreateInitTypeObject(POBJECT_TYPE ObjectType) -{ - OBJECT_ATTRIBUTES ObjectAttributes; - WCHAR NameString[120]; - PTYPE_OBJECT TypeObject = NULL; - UNICODE_STRING Name; - NTSTATUS Status; - - DPRINT("ObpCreateTypeObject(ObjectType: %wZ)\n", &ObjectType->Name); - wcscpy(NameString, L"\\ObjectTypes\\"); - wcscat(NameString, ObjectType->Name.Buffer); - RtlInitUnicodeString(&Name, - NameString); - - InitializeObjectAttributes(&ObjectAttributes, - &Name, - OBJ_PERMANENT, - NULL, - NULL); - Status = ObCreateObject(KernelMode, - ObTypeObjectType, - &ObjectAttributes, - KernelMode, - NULL, - sizeof(TYPE_OBJECT), - 0, - 0, - (PVOID*)&TypeObject); - if (NT_SUCCESS(Status)) - { - TypeObject->ObjectType = ObjectType; - } - - return(STATUS_SUCCESS); -} - -VOID INIT_FUNCTION +VOID +INIT_FUNCTION ObInit(VOID) -/* - * FUNCTION: Initialize the object manager namespace - */ -{ - OBJECT_ATTRIBUTES ObjectAttributes; - UNICODE_STRING Name; - SECURITY_DESCRIPTOR SecurityDescriptor; - - /* Initialize the security descriptor cache */ - ObpInitSdCache(); - - /* HACKS FOR COMPATIBILITY. TEMPORARY */ - /* create 'directory' object type */ - ObDirectoryType = ExAllocatePool(NonPagedPool,sizeof(OBJECT_TYPE)); - RtlZeroMemory(ObDirectoryType, sizeof(OBJECT_TYPE)); - ObDirectoryType->TypeInfo.DefaultNonPagedPoolCharge = sizeof(DIRECTORY_OBJECT); - ObDirectoryType->TypeInfo.GenericMapping = ObpDirectoryMapping; - ObDirectoryType->TypeInfo.ParseProcedure = ObpParseDirectory; - ObDirectoryType->TypeInfo.OpenProcedure = ObpCreateDirectory; - - RtlInitUnicodeString(&ObDirectoryType->Name, - L"Directory"); - - /* HACKS FOR COMPATIBILITY. TEMPORARY */ - /* create 'type' object type*/ - ObTypeObjectType = ExAllocatePool(NonPagedPool,sizeof(OBJECT_TYPE)); - RtlZeroMemory(ObTypeObjectType, sizeof(OBJECT_TYPE)); - ObTypeObjectType->TypeInfo.DefaultNonPagedPoolCharge = sizeof(TYPE_OBJECT); - ObTypeObjectType->TypeInfo.GenericMapping = ObpTypeMapping; - - - RtlInitUnicodeString(&ObTypeObjectType->Name, - L"ObjectType"); - - /* Create security descriptor */ - RtlCreateSecurityDescriptor(&SecurityDescriptor, - SECURITY_DESCRIPTOR_REVISION1); - - RtlSetOwnerSecurityDescriptor(&SecurityDescriptor, - SeAliasAdminsSid, - FALSE); - - RtlSetGroupSecurityDescriptor(&SecurityDescriptor, - SeLocalSystemSid, - FALSE); - - RtlSetDaclSecurityDescriptor(&SecurityDescriptor, - TRUE, - SePublicDefaultDacl, - FALSE); - - /* Create root directory */ - InitializeObjectAttributes(&ObjectAttributes, - NULL, - OBJ_PERMANENT, - NULL, - &SecurityDescriptor); - ObCreateObject(KernelMode, - ObDirectoryType, - &ObjectAttributes, - KernelMode, - NULL, - sizeof(DIRECTORY_OBJECT), - 0, - 0, - (PVOID*)&NameSpaceRoot); - - /* Create '\ObjectTypes' directory */ - RtlRosInitUnicodeStringFromLiteral(&Name, - L"\\ObjectTypes"); - InitializeObjectAttributes(&ObjectAttributes, - &Name, - OBJ_PERMANENT, - NULL, - &SecurityDescriptor); - ObCreateObject(KernelMode, - ObDirectoryType, - &ObjectAttributes, - KernelMode, - NULL, - sizeof(DIRECTORY_OBJECT), - 0, - 0, - NULL); - - /* HACKS FOR COMPATIBILITY. TEMPORARY */ - ObpCreateInitTypeObject(ObDirectoryType); - ObpCreateInitTypeObject(ObTypeObjectType); - - /* Create 'symbolic link' object type */ - ObInitSymbolicLinkImplementation(); - - /* FIXME: Hack Hack! */ - ObSystemDeviceMap = ExAllocatePoolWithTag(NonPagedPool, sizeof(*ObSystemDeviceMap), TAG('O', 'b', 'D', 'm')); - RtlZeroMemory(ObSystemDeviceMap, sizeof(*ObSystemDeviceMap)); -} - - -NTSTATUS -ObpCreateTypeObject(POBJECT_TYPE_INITIALIZER ObjectTypeInitializer, - PUNICODE_STRING TypeName, - POBJECT_TYPE *ObjectType) { OBJECT_ATTRIBUTES ObjectAttributes; - WCHAR NameString[120]; - PTYPE_OBJECT TypeObject = NULL; - POBJECT_TYPE LocalObjectType; UNICODE_STRING Name; - NTSTATUS Status; + SECURITY_DESCRIPTOR SecurityDescriptor; + OBJECT_TYPE_INITIALIZER ObjectTypeInitializer; - DPRINT("ObpCreateTypeObject(ObjectType: %wZ)\n", TypeName); - - /* Set up the Name */ - wcscpy(NameString, L"\\ObjectTypes\\"); - wcscat(NameString, TypeName->Buffer); - RtlInitUnicodeString(&Name, NameString); - - /* Allocate the Object Type */ - LocalObjectType = ExAllocatePool(NonPagedPool, sizeof(OBJECT_TYPE)); - - /* Set it up */ - LocalObjectType->TypeInfo = *ObjectTypeInitializer; - LocalObjectType->Name = *TypeName; - - /* FIXME: Generate Tag */ - - /* Create the Object Type Type (WRONG, it shoudl be OBJECT_TYPE itself!) */ + /* Initialize the security descriptor cache */ + ObpInitSdCache(); + + /* Create the Type Type */ + DPRINT1("Creating Type Type\n"); + RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer)); + RtlInitUnicodeString(&Name, L"Type"); + ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer); + ObjectTypeInitializer.ValidAccessMask = OBJECT_TYPE_ALL_ACCESS; + ObjectTypeInitializer.UseDefaultObject = TRUE; + ObjectTypeInitializer.MaintainTypeList = TRUE; + ObjectTypeInitializer.PoolType = NonPagedPool; + ObjectTypeInitializer.GenericMapping = ObpTypeMapping; + ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(OBJECT_TYPE); + ObpCreateTypeObject(&ObjectTypeInitializer, &Name, &ObTypeObjectType); + + /* Create the Directory Type */ + DPRINT1("Creating Directory Type\n"); + RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer)); + RtlInitUnicodeString(&Name, L"Directory"); + ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer); + ObjectTypeInitializer.ValidAccessMask = DIRECTORY_ALL_ACCESS; + ObjectTypeInitializer.UseDefaultObject = FALSE; + ObjectTypeInitializer.OpenProcedure = ObpCreateDirectory; + ObjectTypeInitializer.ParseProcedure = ObpParseDirectory; + ObjectTypeInitializer.MaintainTypeList = FALSE; + ObjectTypeInitializer.GenericMapping = ObpDirectoryMapping; + ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(DIRECTORY_OBJECT); + ObpCreateTypeObject(&ObjectTypeInitializer, &Name, &ObDirectoryType); + + /* Create security descriptor */ + RtlCreateSecurityDescriptor(&SecurityDescriptor, + SECURITY_DESCRIPTOR_REVISION1); + RtlSetOwnerSecurityDescriptor(&SecurityDescriptor, + SeAliasAdminsSid, + FALSE); + RtlSetGroupSecurityDescriptor(&SecurityDescriptor, + SeLocalSystemSid, + FALSE); + RtlSetDaclSecurityDescriptor(&SecurityDescriptor, + TRUE, + SePublicDefaultDacl, + FALSE); + + /* Create root directory */ + DPRINT1("Creating Root Directory\n"); + InitializeObjectAttributes(&ObjectAttributes, + NULL, + OBJ_PERMANENT, + NULL, + &SecurityDescriptor); + ObCreateObject(KernelMode, + ObDirectoryType, + &ObjectAttributes, + KernelMode, + NULL, + sizeof(DIRECTORY_OBJECT), + 0, + 0, + (PVOID*)&NameSpaceRoot); + + /* Create '\ObjectTypes' directory */ + RtlInitUnicodeString(&Name, L"\\ObjectTypes"); InitializeObjectAttributes(&ObjectAttributes, &Name, OBJ_PERMANENT, NULL, - NULL); - Status = ObCreateObject(KernelMode, - ObTypeObjectType, - &ObjectAttributes, - KernelMode, - NULL, - sizeof(TYPE_OBJECT), - 0, - 0, - (PVOID*)&TypeObject); - if (NT_SUCCESS(Status)) - { - TypeObject->ObjectType = LocalObjectType; - *ObjectType = LocalObjectType; - } + &SecurityDescriptor); + ObCreateObject(KernelMode, + ObDirectoryType, + &ObjectAttributes, + KernelMode, + NULL, + sizeof(DIRECTORY_OBJECT), + 0, + 0, + (PVOID*)&ObpTypeDirectoryObject); + + /* Insert the two objects we already created but couldn't add */ + /* NOTE: Uses TypeList & Creator Info in OB 2.0 */ + ObpAddEntryDirectory(ObpTypeDirectoryObject, BODY_TO_HEADER(ObTypeObjectType), L"Type"); + ObpAddEntryDirectory(ObpTypeDirectoryObject, BODY_TO_HEADER(ObDirectoryType), L"Directory"); + /* Create 'symbolic link' object type */ + ObInitSymbolicLinkImplementation(); + + /* FIXME: Hack Hack! */ + ObSystemDeviceMap = ExAllocatePoolWithTag(NonPagedPool, sizeof(*ObSystemDeviceMap), TAG('O', 'b', 'D', 'm')); + RtlZeroMemory(ObSystemDeviceMap, sizeof(*ObSystemDeviceMap)); +} + +NTSTATUS +STDCALL +ObpCreateTypeObject(POBJECT_TYPE_INITIALIZER ObjectTypeInitializer, + PUNICODE_STRING TypeName, + POBJECT_TYPE *ObjectType) +{ + POBJECT_HEADER Header; + POBJECT_TYPE LocalObjectType; + NTSTATUS Status; + + DPRINT("ObpCreateTypeObject(ObjectType: %wZ)\n", TypeName); + + /* Allocate the Object */ + Status = ObpAllocateObject(NULL, + ObTypeObjectType, + OBJECT_ALLOC_SIZE(sizeof(OBJECT_TYPE)), + &Header); + if (!NT_SUCCESS(Status)) + { + DPRINT1("ObpAllocateObject failed!\n"); + return Status; + } + + LocalObjectType = HEADER_TO_BODY(Header); + + /* Check if this is the first Object Type */ + if (!ObTypeObjectType) + { + ObTypeObjectType = LocalObjectType; + Header->ObjectType = ObTypeObjectType; + } + + /* FIXME: Generate Tag */ + + /* Set it up */ + LocalObjectType->TypeInfo = *ObjectTypeInitializer; + LocalObjectType->Name = *TypeName; + + /* Insert it into the Object Directory */ + if (ObpTypeDirectoryObject) + { + ObpAddEntryDirectory(ObpTypeDirectoryObject, Header, TypeName->Buffer); + ObReferenceObject(ObpTypeDirectoryObject); + } + + *ObjectType = LocalObjectType; return Status; } diff --git a/reactos/ntoskrnl/ob/object.c b/reactos/ntoskrnl/ob/object.c index 1f48191a2a6..d0f91a1c0e7 100644 --- a/reactos/ntoskrnl/ob/object.c +++ b/reactos/ntoskrnl/ob/object.c @@ -637,6 +637,57 @@ ObQueryNameString (IN PVOID Object, return Status; } +NTSTATUS +STDCALL +ObpAllocateObject(POBJECT_ATTRIBUTES ObjectAttributes, + POBJECT_TYPE ObjectType, + ULONG ObjectSize, + POBJECT_HEADER *ObjectHeader) +{ + POBJECT_HEADER Header; + POOL_TYPE PoolType; + ULONG Tag; + + /* If we don't have an Object Type yet, force NonPaged */ + DPRINT("ObpAllocateObject\n"); + if (!ObjectType) + { + PoolType = NonPagedPool; + Tag = TAG('O', 'b', 'j', 'T'); + } + else + { + PoolType = ObjectType->TypeInfo.PoolType; + Tag = ObjectType->Key; + } + + /* Allocate memory for the Object */ + Header = (POBJECT_HEADER)ExAllocatePoolWithTag(PoolType, ObjectSize, Tag); + if (!Header) { + DPRINT1("Not enough memory!\n"); + return STATUS_INSUFFICIENT_RESOURCES; + } + + /* Initialize the object header */ + RtlZeroMemory(Header, ObjectSize); + DPRINT("Initalizing header %p\n", Header); + Header->HandleCount = 0; + Header->RefCount = 1; + Header->ObjectType = ObjectType; + if (ObjectAttributes && ObjectAttributes->Attributes & OBJ_PERMANENT) + { + Header->Permanent = TRUE; + } + if (ObjectAttributes && ObjectAttributes->Attributes & OBJ_INHERIT) + { + Header->Inherit = TRUE; + } + RtlInitUnicodeString(&Header->Name, NULL); + + /* Return Header */ + *ObjectHeader = Header; + return STATUS_SUCCESS; +} /********************************************************************** * NAME EXPORTED @@ -666,7 +717,7 @@ ObCreateObject (IN KPROCESSOR_MODE ObjectAttributesAccessMode OPTIONAL, UNICODE_STRING RemainingPath; POBJECT_HEADER Header; POBJECT_HEADER ParentHeader = NULL; - NTSTATUS Status = 0; + NTSTATUS Status; BOOLEAN ObjectAttached = FALSE; PWCHAR NamePtr; PSECURITY_DESCRIPTOR NewSecurityDescriptor = NULL; @@ -738,44 +789,17 @@ ObCreateObject (IN KPROCESSOR_MODE ObjectAttributesAccessMode OPTIONAL, { RtlInitUnicodeString(&RemainingPath, NULL); } - - DPRINT("Allocating memory\n"); - Header = (POBJECT_HEADER)ExAllocatePoolWithTag(NonPagedPool, - OBJECT_ALLOC_SIZE(ObjectSize), - Type->Key); - if (Header == NULL) { - DPRINT1("Not enough memory!\n"); - return STATUS_INSUFFICIENT_RESOURCES; - } - - RtlZeroMemory(Header, OBJECT_ALLOC_SIZE(ObjectSize)); - - /* Initialize the object header */ - DPRINT("Initalizing header 0x%x (%wZ)\n", Header, &Type->TypeName); - Header->HandleCount = 0; - Header->RefCount = 1; - Header->ObjectType = Type; - if (ObjectAttributes != NULL && - ObjectAttributes->Attributes & OBJ_PERMANENT) + + /* Allocate the Object */ + Status = ObpAllocateObject(ObjectAttributes, + Type, + OBJECT_ALLOC_SIZE(ObjectSize), + &Header); + if (!NT_SUCCESS(Status)) { - Header->Permanent = TRUE; + DPRINT1("ObpAllocateObject failed!\n"); + return Status; } - else - { - Header->Permanent = FALSE; - } - - if (ObjectAttributes != NULL && - ObjectAttributes->Attributes & OBJ_INHERIT) - { - Header->Inherit = TRUE; - } - else - { - Header->Inherit = FALSE; - } - - RtlInitUnicodeString(&(Header->Name),NULL); DPRINT("Getting Parent and adding entry\n"); if (ParentHeader != NULL &&