ReactOS通过对象管理机制为内核提供了一致的和安全的访问方式。对象管理器是一个用于创建、删除、保护和跟踪对象的内核一部份。由于I/O管理的设备是多方面的,就需要创建很多对象来表达这种设备,下面就来了解关于I/O相关的对象,初始化的代码如下:
#001 BOOLEAN
#002 INIT_FUNCTION
#003 NTAPI
#004 IopCreateObjectTypes(VOID)
#005 {
#006 OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
#007 UNICODE_STRING Name;
#008
初始化对象为缺省的设置。
#009 /* Initialize default settings */
#010 RtlZeroMemory(&ObjectTypeInitializer,sizeof(ObjectTypeInitializer));
#011 ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
#012 ObjectTypeInitializer.PoolType = NonPagedPool;
#013 ObjectTypeInitializer.InvalidAttributes = OBJ_OPENLINK;
#014 ObjectTypeInitializer.ValidAccessMask = FILE_ALL_ACCESS;
#015 ObjectTypeInitializer.UseDefaultObject = TRUE;
#016 ObjectTypeInitializer.GenericMapping = IopFileMapping;
#017
创建适配器对象。
#018 /* Do the Adapter Type */
#019 RtlInitUnicodeString(&Name,L"Adapter");
#020 if (!NT_SUCCESS(ObCreateObjectType(&Name,
#021 &ObjectTypeInitializer,
#022 NULL,
#023 &IoAdapterObjectType))) return FALSE;
#024
创建控制器对象。
#025 /* Do the Controller Type */
#026 RtlInitUnicodeString(&Name,L"Controller");
#027 ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(CONTROLLER_OBJECT);
#028 if (!NT_SUCCESS(ObCreateObjectType(&Name,
#029 &ObjectTypeInitializer,
#030 NULL,
#031 &IoControllerObjectType))) return FALSE;
#032
创建设备对象,设置分析回调函数是IopParseDevice。
#033 /* Do the Device Type. FIXME: Needs Delete Routine! */
#034 RtlInitUnicodeString(&Name,L"Device");
#035 ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(DEVICE_OBJECT);
#036 ObjectTypeInitializer.ParseProcedure = IopParseDevice;
#037 ObjectTypeInitializer.SecurityProcedure = IopSecurityFile;
#038 if (!NT_SUCCESS(ObCreateObjectType(&Name,
#039 &ObjectTypeInitializer,
#040 NULL,
#041 &IoDeviceObjectType))) return FALSE;
#042
创建驱动程序对象。
#043 /* Initialize the Driver object type */
#044 RtlInitUnicodeString(&Name,L"Driver");
#045 ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(DRIVER_OBJECT);
#046 ObjectTypeInitializer.DeleteProcedure = IopDeleteDriver;
#047 ObjectTypeInitializer.ParseProcedure = NULL;
#048 ObjectTypeInitializer.SecurityProcedure = NULL;
#049 if (!NT_SUCCESS(ObCreateObjectType(&Name,
#050 &ObjectTypeInitializer,
#051 NULL,
#052 &IoDriverObjectType))) return FALSE;
#053
创建I/O端口完成对象。
#054 /* Initialize the I/O Completion object type */
#055 RtlInitUnicodeString(&Name,L"IoCompletion");
#056 ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(KQUEUE);
#057 ObjectTypeInitializer.ValidAccessMask = IO_COMPLETION_ALL_ACCESS;
#058 ObjectTypeInitializer.InvalidAttributes |= OBJ_PERMANENT;
#059 ObjectTypeInitializer.GenericMapping = IopCompletionMapping;
#060 ObjectTypeInitializer.DeleteProcedure = IopDeleteIoCompletion;
#061 if (!NT_SUCCESS(ObCreateObjectType(&Name,
#062 &ObjectTypeInitializer,
#063 NULL,
#064 &IoCompletionType))) return FALSE;
#065
创建文件对象。
#066 /* Initialize the File object type */
#067 RtlInitUnicodeString(&Name,L"File");
#068 ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(FILE_OBJECT);
#069 ObjectTypeInitializer.InvalidAttributes |= OBJ_EXCLUSIVE;
#070 ObjectTypeInitializer.MaintainHandleCount = TRUE;
#071 ObjectTypeInitializer.ValidAccessMask = FILE_ALL_ACCESS;
#072 ObjectTypeInitializer.GenericMapping = IopFileMapping;
#073 ObjectTypeInitializer.CloseProcedure = IopCloseFile;
#074 ObjectTypeInitializer.DeleteProcedure = IopDeleteFile;
#075 ObjectTypeInitializer.SecurityProcedure = IopSecurityFile;
#076 ObjectTypeInitializer.QueryNameProcedure = IopQueryNameFile;
#077 ObjectTypeInitializer.ParseProcedure = IopParseFile;
#078 ObjectTypeInitializer.UseDefaultObject = FALSE;
#079 if (!NT_SUCCESS(ObCreateObjectType(&Name,
#080 &ObjectTypeInitializer,
#081 NULL,
#082 &IoFileObjectType))) return FALSE;
#083
#084 /* Success */
#085 return TRUE;
#086 }
这里主要就是根据不同的对象,设置不同的特性。
原文链接:/react/308458.html