From 24e07f0eacb44f41caa2eb4435f5e89208723a07 Mon Sep 17 00:00:00 2001 From: Aleksey Bragin Date: Tue, 1 Apr 2008 19:27:58 +0000 Subject: [PATCH] - Fix initialiization of the object manager lookaside lists. - Rename the variables to understandable names. - Don't leak object locks when destroying an object type. - Directory objects must be case-insensitive. - Symbolic links must be case-insensitive. - Create \KernelObjects directory during startup. svn path=/trunk/; revision=32811 --- reactos/ntoskrnl/include/internal/ob.h | 23 ++++++- reactos/ntoskrnl/ob/obinit.c | 89 +++++++++++++++----------- reactos/ntoskrnl/ob/oblife.c | 20 +++++- 3 files changed, 93 insertions(+), 39 deletions(-) diff --git a/reactos/ntoskrnl/include/internal/ob.h b/reactos/ntoskrnl/include/internal/ob.h index a155da288cf..1919559de44 100644 --- a/reactos/ntoskrnl/include/internal/ob.h +++ b/reactos/ntoskrnl/include/internal/ob.h @@ -123,6 +123,21 @@ typedef struct _OB_TEMP_BUFFER AUX_DATA AuxData; } OB_TEMP_BUFFER, *POB_TEMP_BUFFER; +// +// Startup and Shutdown Functions +// +BOOLEAN +NTAPI +ObInitSystem( + VOID +); + +VOID +NTAPI +ObShutdownSystem( + VOID +); + // // Directory Namespace Functions // @@ -330,6 +345,12 @@ ObpFreeObjectNameBuffer( IN PUNICODE_STRING Name ); +VOID +NTAPI +ObpDeleteObjectType( + IN PVOID Object +); + // // DOS Devices Functions // @@ -541,7 +562,7 @@ extern POBJECT_DIRECTORY ObpTypeDirectoryObject; extern PHANDLE_TABLE ObpKernelHandleTable; extern WORK_QUEUE_ITEM ObpReaperWorkItem; extern volatile PVOID ObpReaperList; -extern NPAGED_LOOKASIDE_LIST ObpNmLookasideList, ObpCiLookasideList; +extern GENERAL_LOOKASIDE ObpNameBufferLookasideList, ObpCreateInfoLookasideList; extern BOOLEAN IoCountOperations; extern ALIGNEDNAME ObpDosDevicesShortNamePrefix; extern ALIGNEDNAME ObpDosDevicesShortNameRoot; diff --git a/reactos/ntoskrnl/ob/obinit.c b/reactos/ntoskrnl/ob/obinit.c index ee5a400708f..f6673c85e6b 100644 --- a/reactos/ntoskrnl/ob/obinit.c +++ b/reactos/ntoskrnl/ob/obinit.c @@ -61,7 +61,7 @@ ObInit2(VOID) { CCHAR i; PKPRCB Prcb; - PNPAGED_LOOKASIDE_LIST CurrentList = NULL; + PGENERAL_LOOKASIDE CurrentList = NULL; /* Now allocate the per-processor lists */ for (i = 0; i < KeNumberProcessors; i++) @@ -70,54 +70,52 @@ ObInit2(VOID) Prcb = KiProcessorBlock[(int)i]; /* Set the OBJECT_CREATE_INFORMATION List */ - Prcb->PPLookasideList[LookasideCreateInfoList].L = &ObpCiLookasideList.L; + Prcb->PPLookasideList[LookasideCreateInfoList].L = &ObpCreateInfoLookasideList; CurrentList = ExAllocatePoolWithTag(NonPagedPool, - sizeof(NPAGED_LOOKASIDE_LIST), + sizeof(GENERAL_LOOKASIDE), TAG('O', 'b', 'C', 'I')); if (CurrentList) { /* Initialize it */ - ExInitializeNPagedLookasideList(CurrentList, - NULL, - NULL, - 0, + ExInitializeSystemLookasideList(CurrentList, + NonPagedPool, sizeof(OBJECT_CREATE_INFORMATION), TAG('O', 'b', 'C', 'I'), - 32); + 32, + &ExSystemLookasideListHead); } else { /* No list, use the static buffer */ - CurrentList = &ObpCiLookasideList; + CurrentList = &ObpCreateInfoLookasideList; } /* Link it */ - Prcb->PPLookasideList[LookasideCreateInfoList].P = &CurrentList->L; + Prcb->PPLookasideList[LookasideCreateInfoList].P = CurrentList; /* Set the captured UNICODE_STRING Object Name List */ - Prcb->PPLookasideList[LookasideNameBufferList].L = &ObpNmLookasideList.L; + Prcb->PPLookasideList[LookasideNameBufferList].L = &ObpNameBufferLookasideList; CurrentList = ExAllocatePoolWithTag(NonPagedPool, - sizeof(NPAGED_LOOKASIDE_LIST), + sizeof(GENERAL_LOOKASIDE), TAG('O', 'b', 'N', 'M')); if (CurrentList) { /* Initialize it */ - ExInitializeNPagedLookasideList(CurrentList, - NULL, - NULL, - 0, + ExInitializeSystemLookasideList(CurrentList, + PagedPool, 248, TAG('O', 'b', 'N', 'M'), - 16); + 16, + &ExSystemLookasideListHead); } else { /* No list, use the static buffer */ - CurrentList = &ObpNmLookasideList; + CurrentList = &ObpNameBufferLookasideList; } /* Link it */ - Prcb->PPLookasideList[LookasideNameBufferList].P = &CurrentList->L; + Prcb->PPLookasideList[LookasideNameBufferList].P = CurrentList; } return TRUE; @@ -144,34 +142,32 @@ ObInit(VOID) if (ObpInitializationPhase != 0) goto ObPostPhase0; /* Initialize the OBJECT_CREATE_INFORMATION List */ - ExInitializeNPagedLookasideList(&ObpCiLookasideList, - NULL, - NULL, - 0, + ExInitializeSystemLookasideList(&ObpCreateInfoLookasideList, + NonPagedPool, sizeof(OBJECT_CREATE_INFORMATION), TAG('O', 'b', 'C', 'I'), - 32); + 32, + &ExSystemLookasideListHead); /* Set the captured UNICODE_STRING Object Name List */ - ExInitializeNPagedLookasideList(&ObpNmLookasideList, - NULL, - NULL, - 0, + ExInitializeSystemLookasideList(&ObpNameBufferLookasideList, + PagedPool, 248, TAG('O', 'b', 'N', 'M'), - 16); + 16, + &ExSystemLookasideListHead); /* Temporarily setup both pointers to the shared list */ - Prcb->PPLookasideList[LookasideCreateInfoList].L = &ObpCiLookasideList.L; - Prcb->PPLookasideList[LookasideCreateInfoList].P = &ObpCiLookasideList.L; - Prcb->PPLookasideList[LookasideNameBufferList].L = &ObpNmLookasideList.L; - Prcb->PPLookasideList[LookasideNameBufferList].P = &ObpNmLookasideList.L; + Prcb->PPLookasideList[LookasideCreateInfoList].L = &ObpCreateInfoLookasideList; + Prcb->PPLookasideList[LookasideCreateInfoList].P = &ObpCreateInfoLookasideList; + Prcb->PPLookasideList[LookasideNameBufferList].L = &ObpNameBufferLookasideList; + Prcb->PPLookasideList[LookasideNameBufferList].P = &ObpNameBufferLookasideList; /* Initialize the security descriptor cache */ ObpInitSdCache(); /* Initialize the Default Event */ - KeInitializeEvent(&ObpDefaultObject, NotificationEvent, TRUE ); + KeInitializeEvent(&ObpDefaultObject, NotificationEvent, TRUE); /* Setup default access for the system process */ PsGetCurrentProcess()->GrantedAccess = PROCESS_ALL_ACCESS; @@ -198,21 +194,22 @@ ObInit(VOID) ObjectTypeInitializer.GenericMapping = ObpTypeMapping; ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(OBJECT_TYPE); ObjectTypeInitializer.InvalidAttributes = OBJ_OPENLINK; + ObjectTypeInitializer.DeleteProcedure = ObpDeleteObjectType; ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &ObpTypeObjectType); /* Create the Directory Type */ RtlInitUnicodeString(&Name, L"Directory"); ObjectTypeInitializer.ValidAccessMask = DIRECTORY_ALL_ACCESS; - ObjectTypeInitializer.UseDefaultObject = FALSE; + ObjectTypeInitializer.CaseInsensitive = TRUE; ObjectTypeInitializer.MaintainTypeList = FALSE; ObjectTypeInitializer.GenericMapping = ObpDirectoryMapping; + ObjectTypeInitializer.DeleteProcedure = NULL; ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(OBJECT_DIRECTORY); ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &ObDirectoryType); /* Create 'symbolic link' object type */ RtlInitUnicodeString(&Name, L"SymbolicLink"); - ObjectTypeInitializer.DefaultNonPagedPoolCharge = - sizeof(OBJECT_SYMBOLIC_LINK); + ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(OBJECT_SYMBOLIC_LINK); ObjectTypeInitializer.GenericMapping = ObpSymbolicLinkMapping; ObjectTypeInitializer.ValidAccessMask = SYMBOLIC_LINK_ALL_ACCESS; ObjectTypeInitializer.ParseProcedure = ObpParseSymbolicLink; @@ -255,6 +252,24 @@ ObPostPhase0: Status = NtClose(Handle); if (!NT_SUCCESS(Status)) return FALSE; + /* Initialize Object Types directory attributes */ + RtlInitUnicodeString(&Name, L"\\KernelObjects"); + InitializeObjectAttributes(&ObjectAttributes, + &Name, + OBJ_CASE_INSENSITIVE | OBJ_PERMANENT, + NULL, + NULL); + + /* Create the directory */ + Status = NtCreateDirectoryObject(&Handle, + DIRECTORY_ALL_ACCESS, + &ObjectAttributes); + if (!NT_SUCCESS(Status)) return FALSE; + + /* Close the extra handle */ + Status = NtClose(Handle); + if (!NT_SUCCESS(Status)) return FALSE; + /* Initialize Object Types directory attributes */ RtlInitUnicodeString(&Name, L"\\ObjectTypes"); InitializeObjectAttributes(&ObjectAttributes, diff --git a/reactos/ntoskrnl/ob/oblife.c b/reactos/ntoskrnl/ob/oblife.c index 3a2caeb8614..804fc3e03f0 100644 --- a/reactos/ntoskrnl/ob/oblife.c +++ b/reactos/ntoskrnl/ob/oblife.c @@ -22,7 +22,7 @@ extern ULONG NtGlobalFlag; POBJECT_TYPE ObpTypeObjectType = NULL; KEVENT ObpDefaultObject; -NPAGED_LOOKASIDE_LIST ObpNmLookasideList, ObpCiLookasideList; +GENERAL_LOOKASIDE ObpNameBufferLookasideList, ObpCreateInfoLookasideList; WORK_QUEUE_ITEM ObpReaperWorkItem; volatile PVOID ObpReaperList; @@ -1236,6 +1236,24 @@ ObCreateObjectType(IN PUNICODE_STRING TypeName, return STATUS_INSUFFICIENT_RESOURCES; } +VOID +NTAPI +ObpDeleteObjectType(IN PVOID Object) +{ + ULONG i; + POBJECT_TYPE ObjectType = (PVOID)Object; + + /* Loop our locks */ + for (i = 0; i < 4; i++) + { + /* Delete each one */ + ExDeleteResourceLite(&ObjectType->ObjectLocks[i]); + } + + /* Delete our main mutex */ + ExDeleteResourceLite(&ObjectType->Mutex); +} + /*++ * @name ObMakeTemporaryObject * @implemented NT4