ArmPkg/ArmMmuLib ARM: fix thinko in second level page table handling
[mirror_edk2.git] / SecurityPkg / UserIdentification / UserIdentifyManagerDxe / LoadDeferredImage.c
1 /** @file\r
2   Load the deferred images after user is identified.\r
3 \r
4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution.  The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9 \r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12 \r
13 **/\r
14 \r
15 #include "UserIdentifyManager.h"\r
16 \r
17 EFI_HANDLE        mDeferredImageHandle;\r
18 \r
19 /**\r
20   The function will load all the deferred images again. If the deferred image is loaded\r
21   successfully, try to start it.\r
22 \r
23   @param  Event         Event whose notification function is being invoked.\r
24   @param  Context       Pointer to the notification function's context\r
25 \r
26 **/\r
27 VOID\r
28 EFIAPI\r
29 LoadDeferredImage (\r
30   IN EFI_EVENT                       Event,\r
31   IN VOID                            *Context\r
32   )\r
33 {\r
34   EFI_STATUS                         Status;\r
35   EFI_DEFERRED_IMAGE_LOAD_PROTOCOL   *DeferredImage;\r
36   UINTN                              HandleCount;\r
37   EFI_HANDLE                         *HandleBuf;\r
38   UINTN                              Index;\r
39   UINTN                              DriverIndex;\r
40   EFI_DEVICE_PATH_PROTOCOL           *ImageDevicePath;\r
41   VOID                               *DriverImage;\r
42   UINTN                              ImageSize;\r
43   BOOLEAN                            BootOption;\r
44   EFI_HANDLE                         ImageHandle;\r
45   UINTN                              ExitDataSize;\r
46   CHAR16                             *ExitData;\r
47 \r
48   //\r
49   // Find all the deferred image load protocols.\r
50   //\r
51   HandleCount = 0;\r
52   HandleBuf   = NULL;\r
53   Status = gBS->LocateHandleBuffer (\r
54                   ByProtocol,\r
55                   &gEfiDeferredImageLoadProtocolGuid,\r
56                   NULL,\r
57                   &HandleCount,\r
58                   &HandleBuf\r
59                   );\r
60   if (EFI_ERROR (Status)) {\r
61     return ;\r
62   }\r
63 \r
64   for (Index = 0; Index < HandleCount; Index++) {\r
65     Status = gBS->HandleProtocol (\r
66                     HandleBuf[Index],\r
67                     &gEfiDeferredImageLoadProtocolGuid,\r
68                     (VOID **) &DeferredImage\r
69                     );\r
70     if (EFI_ERROR (Status)) {\r
71       continue ;\r
72     }\r
73 \r
74     DriverIndex = 0;\r
75     do {\r
76       //\r
77       // Load all the deferred images in this protocol instance.\r
78       //\r
79       Status = DeferredImage->GetImageInfo(\r
80                                 DeferredImage,\r
81                                 DriverIndex,\r
82                                 &ImageDevicePath,\r
83                                 (VOID **) &DriverImage,\r
84                                 &ImageSize,\r
85                                 &BootOption\r
86                                 );\r
87       if (EFI_ERROR (Status)) {\r
88         break;\r
89       }\r
90 \r
91       //\r
92       // Load and start the image.\r
93       //\r
94       Status = gBS->LoadImage (\r
95                       BootOption,\r
96                       mDeferredImageHandle,\r
97                       ImageDevicePath,\r
98                       NULL,\r
99                       0,\r
100                       &ImageHandle\r
101                       );\r
102       if (!EFI_ERROR (Status)) {\r
103         //\r
104         // Before calling the image, enable the Watchdog Timer for\r
105         // a 5 Minute period\r
106         //\r
107         gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);\r
108         Status = gBS->StartImage (ImageHandle, &ExitDataSize, &ExitData);\r
109 \r
110         //\r
111         // Clear the Watchdog Timer after the image returns.\r
112         //\r
113         gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);\r
114       }\r
115       DriverIndex++;\r
116     } while (TRUE);\r
117   }\r
118   FreePool (HandleBuf);\r
119 }\r
120 \r
121 \r
122 /**\r
123   Register an event notification function for user profile changed.\r
124 \r
125   @param[in]  ImageHandle     Image handle this driver.\r
126 \r
127 **/\r
128 VOID\r
129 LoadDeferredImageInit (\r
130   IN EFI_HANDLE        ImageHandle\r
131   )\r
132 {\r
133   EFI_STATUS    Status;\r
134   EFI_EVENT     Event;\r
135 \r
136   mDeferredImageHandle = ImageHandle;\r
137 \r
138   Status = gBS->CreateEventEx (\r
139                   EVT_NOTIFY_SIGNAL,\r
140                   TPL_CALLBACK,\r
141                   LoadDeferredImage,\r
142                   NULL,\r
143                   &gEfiEventUserProfileChangedGuid,\r
144                   &Event\r
145                   );\r
146 \r
147   ASSERT (Status == EFI_SUCCESS);\r
148 }\r