Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenobinit.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Kernel 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: ntoskrnl/ob/obinit.c 00005 * PURPOSE: Handles Object Manager Initialization and Shutdown 00006 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org) 00007 * Eric Kohl 00008 * Thomas Weidenmueller (w3seek@reactos.org) 00009 */ 00010 00011 /* INCLUDES ******************************************************************/ 00012 00013 #include <ntoskrnl.h> 00014 #define NDEBUG 00015 #include <debug.h> 00016 00017 /* GLOBALS *******************************************************************/ 00018 00019 GENERIC_MAPPING ObpTypeMapping = 00020 { 00021 STANDARD_RIGHTS_READ, 00022 STANDARD_RIGHTS_WRITE, 00023 STANDARD_RIGHTS_EXECUTE, 00024 0x000F0001 00025 }; 00026 00027 GENERIC_MAPPING ObpDirectoryMapping = 00028 { 00029 STANDARD_RIGHTS_READ | DIRECTORY_QUERY | 00030 DIRECTORY_TRAVERSE, 00031 STANDARD_RIGHTS_WRITE | DIRECTORY_CREATE_SUBDIRECTORY | 00032 DIRECTORY_CREATE_OBJECT, 00033 STANDARD_RIGHTS_EXECUTE | DIRECTORY_QUERY | 00034 DIRECTORY_TRAVERSE, 00035 DIRECTORY_ALL_ACCESS 00036 }; 00037 00038 GENERIC_MAPPING ObpSymbolicLinkMapping = 00039 { 00040 STANDARD_RIGHTS_READ | SYMBOLIC_LINK_QUERY, 00041 STANDARD_RIGHTS_WRITE, 00042 STANDARD_RIGHTS_EXECUTE | SYMBOLIC_LINK_QUERY, 00043 SYMBOLIC_LINK_ALL_ACCESS 00044 }; 00045 00046 PDEVICE_MAP ObSystemDeviceMap = NULL; 00047 ULONG ObpTraceLevel = 0; 00048 00049 VOID 00050 NTAPI 00051 PsInitializeQuotaSystem(VOID); 00052 00053 ULONG ObpInitializationPhase; 00054 00055 /* PRIVATE FUNCTIONS *********************************************************/ 00056 00057 BOOLEAN 00058 INIT_FUNCTION 00059 NTAPI 00060 ObInit2(VOID) 00061 { 00062 CCHAR i; 00063 PKPRCB Prcb; 00064 PGENERAL_LOOKASIDE CurrentList = NULL; 00065 00066 /* Now allocate the per-processor lists */ 00067 for (i = 0; i < KeNumberProcessors; i++) 00068 { 00069 /* Get the PRCB for this CPU */ 00070 Prcb = KiProcessorBlock[(int)i]; 00071 00072 /* Set the OBJECT_CREATE_INFORMATION List */ 00073 Prcb->PPLookasideList[LookasideCreateInfoList].L = &ObpCreateInfoLookasideList; 00074 CurrentList = ExAllocatePoolWithTag(NonPagedPool, 00075 sizeof(GENERAL_LOOKASIDE), 00076 'ICbO'); 00077 if (CurrentList) 00078 { 00079 /* Initialize it */ 00080 ExInitializeSystemLookasideList(CurrentList, 00081 NonPagedPool, 00082 sizeof(OBJECT_CREATE_INFORMATION), 00083 'ICbO', 00084 32, 00085 &ExSystemLookasideListHead); 00086 } 00087 else 00088 { 00089 /* No list, use the static buffer */ 00090 CurrentList = &ObpCreateInfoLookasideList; 00091 } 00092 00093 /* Link it */ 00094 Prcb->PPLookasideList[LookasideCreateInfoList].P = CurrentList; 00095 00096 /* Set the captured UNICODE_STRING Object Name List */ 00097 Prcb->PPLookasideList[LookasideNameBufferList].L = &ObpNameBufferLookasideList; 00098 CurrentList = ExAllocatePoolWithTag(NonPagedPool, 00099 sizeof(GENERAL_LOOKASIDE), 00100 'MNbO'); 00101 if (CurrentList) 00102 { 00103 /* Initialize it */ 00104 ExInitializeSystemLookasideList(CurrentList, 00105 PagedPool, 00106 248, 00107 'MNbO', 00108 16, 00109 &ExSystemLookasideListHead); 00110 } 00111 else 00112 { 00113 /* No list, use the static buffer */ 00114 CurrentList = &ObpNameBufferLookasideList; 00115 } 00116 00117 /* Link it */ 00118 Prcb->PPLookasideList[LookasideNameBufferList].P = CurrentList; 00119 } 00120 00121 return TRUE; 00122 } 00123 00124 BOOLEAN 00125 INIT_FUNCTION 00126 NTAPI 00127 ObInitSystem(VOID) 00128 { 00129 OBJECT_ATTRIBUTES ObjectAttributes; 00130 UNICODE_STRING Name; 00131 OBJECT_TYPE_INITIALIZER ObjectTypeInitializer; 00132 OBP_LOOKUP_CONTEXT Context; 00133 HANDLE Handle; 00134 PKPRCB Prcb = KeGetCurrentPrcb(); 00135 PLIST_ENTRY ListHead, NextEntry; 00136 POBJECT_HEADER Header; 00137 POBJECT_HEADER_CREATOR_INFO CreatorInfo; 00138 POBJECT_HEADER_NAME_INFO NameInfo; 00139 NTSTATUS Status; 00140 00141 /* Check if this is actually Phase 1 initialization */ 00142 if (ObpInitializationPhase != 0) goto ObPostPhase0; 00143 00144 /* Initialize the OBJECT_CREATE_INFORMATION List */ 00145 ExInitializeSystemLookasideList(&ObpCreateInfoLookasideList, 00146 NonPagedPool, 00147 sizeof(OBJECT_CREATE_INFORMATION), 00148 'ICbO', 00149 32, 00150 &ExSystemLookasideListHead); 00151 00152 /* Set the captured UNICODE_STRING Object Name List */ 00153 ExInitializeSystemLookasideList(&ObpNameBufferLookasideList, 00154 PagedPool, 00155 248, 00156 'MNbO', 00157 16, 00158 &ExSystemLookasideListHead); 00159 00160 /* Temporarily setup both pointers to the shared list */ 00161 Prcb->PPLookasideList[LookasideCreateInfoList].L = &ObpCreateInfoLookasideList; 00162 Prcb->PPLookasideList[LookasideCreateInfoList].P = &ObpCreateInfoLookasideList; 00163 Prcb->PPLookasideList[LookasideNameBufferList].L = &ObpNameBufferLookasideList; 00164 Prcb->PPLookasideList[LookasideNameBufferList].P = &ObpNameBufferLookasideList; 00165 00166 /* Initialize the security descriptor cache */ 00167 ObpInitSdCache(); 00168 00169 /* Initialize the Default Event */ 00170 KeInitializeEvent(&ObpDefaultObject, NotificationEvent, TRUE); 00171 00172 /* Initialize the Dos Device Map mutex */ 00173 KeInitializeGuardedMutex(&ObpDeviceMapLock); 00174 00175 /* Setup default access for the system process */ 00176 PsGetCurrentProcess()->GrantedAccess = PROCESS_ALL_ACCESS; 00177 PsGetCurrentThread()->GrantedAccess = THREAD_ALL_ACCESS; 00178 00179 /* Setup the Object Reaper */ 00180 ExInitializeWorkItem(&ObpReaperWorkItem, ObpReapObject, NULL); 00181 00182 /* Initialize default Quota block */ 00183 PsInitializeQuotaSystem(); 00184 00185 /* Create kernel handle table */ 00186 PsGetCurrentProcess()->ObjectTable = ExCreateHandleTable(NULL); 00187 ObpKernelHandleTable = PsGetCurrentProcess()->ObjectTable; 00188 00189 /* Create the Type Type */ 00190 RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer)); 00191 RtlInitUnicodeString(&Name, L"Type"); 00192 ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer); 00193 ObjectTypeInitializer.ValidAccessMask = OBJECT_TYPE_ALL_ACCESS; 00194 ObjectTypeInitializer.UseDefaultObject = TRUE; 00195 ObjectTypeInitializer.MaintainTypeList = TRUE; 00196 ObjectTypeInitializer.PoolType = NonPagedPool; 00197 ObjectTypeInitializer.GenericMapping = ObpTypeMapping; 00198 ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(OBJECT_TYPE); 00199 ObjectTypeInitializer.InvalidAttributes = OBJ_OPENLINK; 00200 ObjectTypeInitializer.DeleteProcedure = ObpDeleteObjectType; 00201 ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &ObpTypeObjectType); 00202 00203 /* Create the Directory Type */ 00204 RtlInitUnicodeString(&Name, L"Directory"); 00205 ObjectTypeInitializer.ValidAccessMask = DIRECTORY_ALL_ACCESS; 00206 ObjectTypeInitializer.CaseInsensitive = TRUE; 00207 ObjectTypeInitializer.MaintainTypeList = FALSE; 00208 ObjectTypeInitializer.GenericMapping = ObpDirectoryMapping; 00209 ObjectTypeInitializer.DeleteProcedure = NULL; 00210 ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(OBJECT_DIRECTORY); 00211 ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &ObDirectoryType); 00212 00213 /* Create 'symbolic link' object type */ 00214 RtlInitUnicodeString(&Name, L"SymbolicLink"); 00215 ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(OBJECT_SYMBOLIC_LINK); 00216 ObjectTypeInitializer.GenericMapping = ObpSymbolicLinkMapping; 00217 ObjectTypeInitializer.ValidAccessMask = SYMBOLIC_LINK_ALL_ACCESS; 00218 ObjectTypeInitializer.ParseProcedure = ObpParseSymbolicLink; 00219 ObjectTypeInitializer.DeleteProcedure = ObpDeleteSymbolicLink; 00220 ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &ObSymbolicLinkType); 00221 00222 /* Phase 0 initialization complete */ 00223 ObpInitializationPhase++; 00224 return TRUE; 00225 00226 ObPostPhase0: 00227 00228 /* Re-initialize lookaside lists */ 00229 ObInit2(); 00230 00231 /* Initialize Object Types directory attributes */ 00232 RtlInitUnicodeString(&Name, L"\\"); 00233 InitializeObjectAttributes(&ObjectAttributes, 00234 &Name, 00235 OBJ_CASE_INSENSITIVE | OBJ_PERMANENT, 00236 NULL, 00237 SePublicDefaultUnrestrictedSd); 00238 00239 /* Create the directory */ 00240 Status = NtCreateDirectoryObject(&Handle, 00241 DIRECTORY_ALL_ACCESS, 00242 &ObjectAttributes); 00243 if (!NT_SUCCESS(Status)) return FALSE; 00244 00245 /* Get a handle to it */ 00246 Status = ObReferenceObjectByHandle(Handle, 00247 0, 00248 ObDirectoryType, 00249 KernelMode, 00250 (PVOID*)&ObpRootDirectoryObject, 00251 NULL); 00252 if (!NT_SUCCESS(Status)) return FALSE; 00253 00254 /* Close the extra handle */ 00255 Status = NtClose(Handle); 00256 if (!NT_SUCCESS(Status)) return FALSE; 00257 00258 /* Initialize Object Types directory attributes */ 00259 RtlInitUnicodeString(&Name, L"\\KernelObjects"); 00260 InitializeObjectAttributes(&ObjectAttributes, 00261 &Name, 00262 OBJ_CASE_INSENSITIVE | OBJ_PERMANENT, 00263 NULL, 00264 NULL); 00265 00266 /* Create the directory */ 00267 Status = NtCreateDirectoryObject(&Handle, 00268 DIRECTORY_ALL_ACCESS, 00269 &ObjectAttributes); 00270 if (!NT_SUCCESS(Status)) return FALSE; 00271 00272 /* Close the extra handle */ 00273 Status = NtClose(Handle); 00274 if (!NT_SUCCESS(Status)) return FALSE; 00275 00276 /* Initialize Object Types directory attributes */ 00277 RtlInitUnicodeString(&Name, L"\\ObjectTypes"); 00278 InitializeObjectAttributes(&ObjectAttributes, 00279 &Name, 00280 OBJ_CASE_INSENSITIVE | OBJ_PERMANENT, 00281 NULL, 00282 NULL); 00283 00284 /* Create the directory */ 00285 Status = NtCreateDirectoryObject(&Handle, 00286 DIRECTORY_ALL_ACCESS, 00287 &ObjectAttributes); 00288 if (!NT_SUCCESS(Status)) return FALSE; 00289 00290 /* Get a handle to it */ 00291 Status = ObReferenceObjectByHandle(Handle, 00292 0, 00293 ObDirectoryType, 00294 KernelMode, 00295 (PVOID*)&ObpTypeDirectoryObject, 00296 NULL); 00297 if (!NT_SUCCESS(Status)) return FALSE; 00298 00299 /* Close the extra handle */ 00300 Status = NtClose(Handle); 00301 if (!NT_SUCCESS(Status)) return FALSE; 00302 00303 /* Initialize lookup context */ 00304 ObpInitializeLookupContext(&Context); 00305 00306 /* Lock it */ 00307 ObpAcquireDirectoryLockExclusive(ObpTypeDirectoryObject, &Context); 00308 00309 /* Loop the object types */ 00310 ListHead = &ObpTypeObjectType->TypeList; 00311 NextEntry = ListHead->Flink; 00312 while (ListHead != NextEntry) 00313 { 00314 /* Get the creator info from the list */ 00315 CreatorInfo = CONTAINING_RECORD(NextEntry, 00316 OBJECT_HEADER_CREATOR_INFO, 00317 TypeList); 00318 00319 /* Recover the header and the name header from the creator info */ 00320 Header = (POBJECT_HEADER)(CreatorInfo + 1); 00321 NameInfo = OBJECT_HEADER_TO_NAME_INFO(Header); 00322 00323 /* Make sure we have a name, and aren't inserted yet */ 00324 if ((NameInfo) && !(NameInfo->Directory)) 00325 { 00326 /* Do the initial lookup to setup the context */ 00327 if (!ObpLookupEntryDirectory(ObpTypeDirectoryObject, 00328 &NameInfo->Name, 00329 OBJ_CASE_INSENSITIVE, 00330 FALSE, 00331 &Context)) 00332 { 00333 /* Insert this object type */ 00334 ObpInsertEntryDirectory(ObpTypeDirectoryObject, 00335 &Context, 00336 Header); 00337 } 00338 } 00339 00340 /* Move to the next entry */ 00341 NextEntry = NextEntry->Flink; 00342 } 00343 00344 /* Cleanup after lookup */ 00345 ObpReleaseLookupContext(&Context); 00346 00347 /* Initialize DOS Devices Directory and related Symbolic Links */ 00348 Status = ObpCreateDosDevicesDirectory(); 00349 if (!NT_SUCCESS(Status)) return FALSE; 00350 return TRUE; 00351 } 00352 00353 /* EOF */ Generated on Sat May 26 2012 04:36:31 for ReactOS by
1.7.6.1
|