]>
Commit | Line | Data |
---|---|---|
2b5778c6 AA |
1 | /** @file\r |
2 | UEFI Dxe DebugLib constructor that prevent some debug service after ExitBootServices event,\r | |
3 | because some pointer is nulled at that phase.\r | |
4 | \r | |
5 | Copyright (c) 2018, Microsoft Corporation\r | |
6 | Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>\r | |
7 | \r | |
8 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
9 | **/\r | |
10 | \r | |
11 | #include <Uefi.h>\r | |
12 | #include <Library/BaseLib.h>\r | |
13 | #include <Library/BaseMemoryLib.h>\r | |
14 | \r | |
15 | //\r | |
16 | // BOOLEAN value to indicate if it is at the post ExitBootServices pahse\r | |
17 | //\r | |
2f88bd3a | 18 | BOOLEAN mPostEBS = FALSE;\r |
2b5778c6 | 19 | \r |
2f88bd3a | 20 | static EFI_EVENT mExitBootServicesEvent;\r |
2b5778c6 AA |
21 | \r |
22 | //\r | |
23 | // Pointer to SystemTable\r | |
24 | // This library instance may have a cycle consume with UefiBootServicesTableLib\r | |
25 | // because of the constructors.\r | |
26 | //\r | |
2f88bd3a | 27 | EFI_BOOT_SERVICES *mDebugBS;\r |
2b5778c6 AA |
28 | \r |
29 | /**\r | |
30 | This routine sets the mPostEBS for exit boot servies true\r | |
31 | to prevent DebugPort protocol dereferences when the pointer is nulled.\r | |
32 | \r | |
33 | @param Event Event whose notification function is being invoked.\r | |
34 | @param Context Pointer to the notification function's context.\r | |
35 | \r | |
36 | **/\r | |
37 | VOID\r | |
38 | EFIAPI\r | |
39 | ExitBootServicesCallback (\r | |
2f88bd3a MK |
40 | EFI_EVENT Event,\r |
41 | VOID *Context\r | |
2b5778c6 AA |
42 | )\r |
43 | {\r | |
44 | mPostEBS = TRUE;\r | |
45 | return;\r | |
46 | }\r | |
47 | \r | |
48 | /**\r | |
49 | The constructor gets the pointers to boot services table.\r | |
50 | And create a event to indicate it is after ExitBootServices.\r | |
51 | \r | |
52 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
53 | @param SystemTable A pointer to the EFI System Table.\r | |
54 | \r | |
55 | @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r | |
56 | \r | |
57 | **/\r | |
58 | EFI_STATUS\r | |
59 | EFIAPI\r | |
2f88bd3a MK |
60 | DxeDebugLibConstructor (\r |
61 | IN EFI_HANDLE ImageHandle,\r | |
62 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
2b5778c6 AA |
63 | )\r |
64 | {\r | |
65 | mDebugBS = SystemTable->BootServices;\r | |
66 | \r | |
df851da3 VC |
67 | mDebugBS->CreateEvent (\r |
68 | EVT_SIGNAL_EXIT_BOOT_SERVICES,\r | |
2b5778c6 AA |
69 | TPL_NOTIFY,\r |
70 | ExitBootServicesCallback,\r | |
71 | NULL,\r | |
2b5778c6 AA |
72 | &mExitBootServicesEvent\r |
73 | );\r | |
74 | \r | |
75 | return EFI_SUCCESS;\r | |
76 | }\r | |
0f4b77f5 WX |
77 | \r |
78 | /**\r | |
79 | The destructor closes Exit Boot Services Event.\r | |
80 | \r | |
81 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
82 | @param SystemTable A pointer to the EFI System Table.\r | |
83 | \r | |
84 | @retval EFI_SUCCESS The destructor always returns EFI_SUCCESS.\r | |
85 | \r | |
86 | **/\r | |
87 | EFI_STATUS\r | |
88 | EFIAPI\r | |
2f88bd3a MK |
89 | DxeDebugLibDestructor (\r |
90 | IN EFI_HANDLE ImageHandle,\r | |
91 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
0f4b77f5 WX |
92 | )\r |
93 | {\r | |
94 | if (mExitBootServicesEvent != NULL) {\r | |
95 | SystemTable->BootServices->CloseEvent (mExitBootServicesEvent);\r | |
96 | }\r | |
97 | \r | |
98 | return EFI_SUCCESS;\r | |
99 | }\r |