2 UEFI Miscellaneous boot Services InstallConfigurationTable service
4 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #define CONFIG_TABLE_SIZE_INCREASED 0x10
19 UINTN mSystemTableAllocateSize
= 0;
22 Boot Service called to add, modify, or remove a system configuration table from
25 @param Guid Pointer to the GUID for the entry to add, update, or
27 @param Table Pointer to the configuration table for the entry to add,
28 update, or remove, may be NULL.
30 @return EFI_SUCCESS Guid, Table pair added, updated, or removed.
31 @return EFI_INVALID_PARAMETER Input GUID is NULL.
32 @return EFI_NOT_FOUND Attempted to delete non-existant entry
33 @return EFI_OUT_OF_RESOURCES Not enough memory available
38 CoreInstallConfigurationTable (
44 EFI_CONFIGURATION_TABLE
*EfiConfigurationTable
;
45 EFI_CONFIGURATION_TABLE
*OldTable
;
48 // If Guid is NULL, then this operation cannot be performed
51 return EFI_INVALID_PARAMETER
;
54 EfiConfigurationTable
= gDxeCoreST
->ConfigurationTable
;
57 // Search all the table for an entry that matches Guid
59 for (Index
= 0; Index
< gDxeCoreST
->NumberOfTableEntries
; Index
++) {
60 if (CompareGuid (Guid
, &(gDxeCoreST
->ConfigurationTable
[Index
].VendorGuid
))) {
65 if (Index
< gDxeCoreST
->NumberOfTableEntries
) {
67 // A match was found, so this is either a modify or a delete operation
71 // If Table is not NULL, then this is a modify operation.
72 // Modify the table entry and return.
74 gDxeCoreST
->ConfigurationTable
[Index
].VendorTable
= Table
;
77 // Signal Configuration Table change
79 CoreNotifySignalList (Guid
);
85 // A match was found and Table is NULL, so this is a delete operation.
87 gDxeCoreST
->NumberOfTableEntries
--;
90 // Copy over deleted entry
93 &(EfiConfigurationTable
[Index
]),
94 &(gDxeCoreST
->ConfigurationTable
[Index
+ 1]),
95 (gDxeCoreST
->NumberOfTableEntries
- Index
) * sizeof (EFI_CONFIGURATION_TABLE
)
101 // No matching GUIDs were found, so this is an add operation.
106 // If Table is NULL on an add operation, then return an error.
108 return EFI_NOT_FOUND
;
112 // Assume that Index == gDxeCoreST->NumberOfTableEntries
114 if ((Index
* sizeof (EFI_CONFIGURATION_TABLE
)) >= mSystemTableAllocateSize
) {
116 // Allocate a table with one additional entry.
118 mSystemTableAllocateSize
+= (CONFIG_TABLE_SIZE_INCREASED
* sizeof (EFI_CONFIGURATION_TABLE
));
119 EfiConfigurationTable
= AllocateRuntimePool (mSystemTableAllocateSize
);
120 if (EfiConfigurationTable
== NULL
) {
122 // If a new table could not be allocated, then return an error.
124 return EFI_OUT_OF_RESOURCES
;
127 if (gDxeCoreST
->ConfigurationTable
!= NULL
) {
129 // Copy the old table to the new table.
132 EfiConfigurationTable
,
133 gDxeCoreST
->ConfigurationTable
,
134 Index
* sizeof (EFI_CONFIGURATION_TABLE
)
138 // Record the old table pointer.
140 OldTable
= gDxeCoreST
->ConfigurationTable
;
143 // As the CoreInstallConfigurationTable() may be re-entered by CoreFreePool()
144 // in its calling stack, updating System table to the new table pointer must
145 // be done before calling CoreFreePool() to free the old table.
146 // It can make sure the gDxeCoreST->ConfigurationTable point to the new table
147 // and avoid the errors of use-after-free to the old table by the reenter of
148 // CoreInstallConfigurationTable() in CoreFreePool()'s calling stack.
150 gDxeCoreST
->ConfigurationTable
= EfiConfigurationTable
;
153 // Free the old table after updating System Table to the new table pointer.
155 CoreFreePool (OldTable
);
158 // Update System Table
160 gDxeCoreST
->ConfigurationTable
= EfiConfigurationTable
;
165 // Fill in the new entry
167 CopyGuid ((VOID
*)&EfiConfigurationTable
[Index
].VendorGuid
, Guid
);
168 EfiConfigurationTable
[Index
].VendorTable
= Table
;
171 // This is an add operation, so increment the number of table entries
173 gDxeCoreST
->NumberOfTableEntries
++;
177 // Fix up the CRC-32 in the EFI System Table
179 CalculateEfiHdrCrc (&gDxeCoreST
->Hdr
);
182 // Signal Configuration Table change
184 CoreNotifySignalList (Guid
);