Properly create the Object Type Type and remove previous hacks added
Modified: trunk/reactos/ntoskrnl/include/internal/ob.h
Modified: trunk/reactos/ntoskrnl/ob/namespc.c
Modified: trunk/reactos/ntoskrnl/ob/object.c
_____
Modified: trunk/reactos/ntoskrnl/include/internal/ob.h
--- trunk/reactos/ntoskrnl/include/internal/ob.h 2005-05-15
18:10:51 UTC (rev 15318)
+++ trunk/reactos/ntoskrnl/include/internal/ob.h 2005-05-15
19:40:57 UTC (rev 15319)
@@ -115,16 +115,6 @@
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 @@
POBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleInfo);
NTSTATUS
+STDCALL
ObpCreateTypeObject(POBJECT_TYPE_INITIALIZER ObjectTypeInitializer,
PUNICODE_STRING TypeName,
POBJECT_TYPE *ObjectType);
_____
Modified: trunk/reactos/ntoskrnl/ob/namespc.c
--- trunk/reactos/ntoskrnl/ob/namespc.c 2005-05-15 18:10:51 UTC (rev
15318)
+++ trunk/reactos/ntoskrnl/ob/namespc.c 2005-05-15 19:40:57 UTC (rev
15319)
@@ -21,9 +21,11 @@
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_SUBDIRECT
ORY,
@@ -36,6 +38,13 @@
STANDARD_RIGHTS_EXECUTE,
0x000F0001};
+NTSTATUS
+STDCALL
+ObpAllocateObject(POBJECT_ATTRIBUTES ObjectAttributes,
+ POBJECT_TYPE ObjectType,
+ ULONG ObjectSize,
+ POBJECT_HEADER *ObjectHeader);
+
/* FUNCTIONS
**************************************************************/
/*
@@ -367,193 +376,152 @@
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;
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ UNICODE_STRING Name;
+ SECURITY_DESCRIPTOR SecurityDescriptor;
+ OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
- /* Initialize the security descriptor cache */
- ObpInitSdCache();
+ /* 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;
+ /* 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);
- RtlInitUnicodeString(&ObDirectoryType->Name,
- L"Directory");
+ /* Create security descriptor */
+ RtlCreateSecurityDescriptor(&SecurityDescriptor,
+ SECURITY_DESCRIPTOR_REVISION1);
+ RtlSetOwnerSecurityDescriptor(&SecurityDescriptor,
+ SeAliasAdminsSid,
+ FALSE);
+ RtlSetGroupSecurityDescriptor(&SecurityDescriptor,
+ SeLocalSystemSid,
+ FALSE);
+ RtlSetDaclSecurityDescriptor(&SecurityDescriptor,
+ TRUE,
+ SePublicDefaultDacl,
+ FALSE);
- /* 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;
+ /* 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,
+ &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");
- RtlInitUnicodeString(&ObTypeObjectType->Name,
- L"ObjectType");
+ /* Create 'symbolic link' object type */
+ ObInitSymbolicLinkImplementation();
- /* 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));
+ /* 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)
{
- OBJECT_ATTRIBUTES ObjectAttributes;
- WCHAR NameString[120];
- PTYPE_OBJECT TypeObject = NULL;
+ POBJECT_HEADER Header;
POBJECT_TYPE LocalObjectType;
- UNICODE_STRING Name;
NTSTATUS Status;
DPRINT("ObpCreateTypeObject(ObjectType: %wZ)\n", TypeName);
- /* Set up the Name */
- wcscpy(NameString, L"\\ObjectTypes\\");
- wcscat(NameString, TypeName->Buffer);
- RtlInitUnicodeString(&Name, NameString);
+ /* Allocate the Object */
+ Status = ObpAllocateObject(NULL,
+ ObTypeObjectType,
+ OBJECT_ALLOC_SIZE(sizeof(OBJECT_TYPE)),
+ &Header);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("ObpAllocateObject failed!\n");
+ return Status;
+ }
- /* Allocate the Object Type */
- LocalObjectType = ExAllocatePool(NonPagedPool,
sizeof(OBJECT_TYPE));
+ 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;
- /* FIXME: Generate Tag */
-
- /* Create the Object Type Type (WRONG, it shoudl be OBJECT_TYPE
itself!) */
- 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))
+ /* Insert it into the Object Directory */
+ if (ObpTypeDirectoryObject)
{
- TypeObject->ObjectType = LocalObjectType;
- *ObjectType = LocalObjectType;
+ ObpAddEntryDirectory(ObpTypeDirectoryObject, Header,
TypeName->Buffer);
+ ObReferenceObject(ObpTypeDirectoryObject);
}
-
+
+ *ObjectType = LocalObjectType;
return Status;
}
_____
Modified: trunk/reactos/ntoskrnl/ob/object.c
--- trunk/reactos/ntoskrnl/ob/object.c 2005-05-15 18:10:51 UTC (rev
15318)
+++ trunk/reactos/ntoskrnl/ob/object.c 2005-05-15 19:40:57 UTC (rev
15319)
@@ -637,6 +637,57 @@
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 @@
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,45 +789,18 @@
{
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 &&
ParentHeader->ObjectType == ObDirectoryType &&