由于操作系统会使用一些缺省的驱动程序,需要在启动时加载指定的驱动程序。下面这个函数,主要实现系统启动时指定加载的驱动程序。代码如下:
#001 VOID
#002 FASTCALL
#003 IopInitializeSystemDrivers(VOID)
#004 {
#005 PSERVICE_GROUP CurrentGroup;
#006 PSERVICE CurrentService;
#007 NTSTATUS Status;
#008 ULONG i;
#009 PLIST_ENTRY NextGroupEntry,NextServiceEntry;
#010
#011 DPRINT("IopInitializeSystemDrivers()/n");
#012
循环地加载所有当前启动时加载的驱动程序。
#013 /* Start looping */
#014 for (NextGroupEntry = GroupListHead.Flink;
#015 NextGroupEntry != &GroupListHead;
#016 NextGroupEntry = NextGroupEntry->Flink)
#017 {
#018 /* Get the entry */
#019 CurrentGroup = CONTAINING_RECORD(NextGroupEntry,
#020 SERVICE_GROUP,
#021 GroupListEntry);
#022
#023 DPRINT("Group: %wZ/n",&CurrentGroup->GroupName);
#024
#025 /* Load all drivers with a valid tag */
#026 for (i = 0; i < CurrentGroup->TagCount; i++)
#027 {
#028 /* Start looping */
#029 for (NextServiceEntry = ServiceListHead.Flink;
#030 NextServiceEntry != &ServiceListHead;
#031 NextServiceEntry = NextServiceEntry->Flink)
#032 {
获取当服务的入口。
#033 /* Get the entry */
#034 CurrentService = CONTAINING_RECORD(NextServiceEntry,
#035 SERVICE,
#036 ServiceListEntry);
#037
#038 if ((!RtlCompareUnicodeString(&CurrentGroup->GroupName,
#039 &CurrentService->ServiceGroup,
#040 TRUE)) &&
#041 (CurrentService->Start == SERVICE_SYSTEM_START) &&
#042 (CurrentService->Tag == CurrentGroup->TagArray[i]))
#043
#044 {
#045 DPRINT(" Path: %wZ/n",&CurrentService->RegistryPath);
加载当前服务驱动程序。
#046 Status = IopLoadDriver(CurrentService);
#047 }
#048 }
#049 }
#050
加载所有没有标记的驱动程序。
#051 /* Load all drivers without a tag or with an invalid tag */
#052 for (NextServiceEntry = ServiceListHead.Flink;
#053 NextServiceEntry != &ServiceListHead;
#054 NextServiceEntry = NextServiceEntry->Flink)
#055 {
#056 /* Get the entry */
#057 CurrentService = CONTAINING_RECORD(NextServiceEntry,
#058 SERVICE,
#059 ServiceListEntry);
#060
#061 if ((!RtlCompareUnicodeString(&CurrentGroup->GroupName,
#062 &CurrentService->ServiceGroup,
#063 TRUE)) &&
#064 (CurrentService->Start == SERVICE_SYSTEM_START))
#065 {
#066 for (i = 0; i < CurrentGroup->TagCount; i++)
#067 {
#068 if (CurrentGroup->TagArray[i] == CurrentService->Tag)
#069 {
#070 break;
#071 }
#072 }
#073
#074 if (i >= CurrentGroup->TagCount)
#075 {
#076 DPRINT(" Path: %wZ/n",&CurrentService->RegistryPath);
开始加载当前驱动程序。
#077 Status = IopLoadDriver(CurrentService);
#078 }
#079 }
#080 }
#081 }
#082
#083 DPRINT("IopInitializeSystemDrivers() done/n");
#084 }
#085
原文链接:https://www.f2er.com/react/308449.html