2 UEFI Miscellaneous boot Services InstallConfigurationTable service
4 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #define CONFIG_TABLE_SIZE_INCREASED 0x10
13 UINTN mSystemTableAllocateSize
= 0;
16 Boot Service called to add, modify, or remove a system configuration table from
19 @param Guid Pointer to the GUID for the entry to add, update, or
21 @param Table Pointer to the configuration table for the entry to add,
22 update, or remove, may be NULL.
24 @return EFI_SUCCESS Guid, Table pair added, updated, or removed.
25 @return EFI_INVALID_PARAMETER Input GUID is NULL.
26 @return EFI_NOT_FOUND Attempted to delete non-existant entry
27 @return EFI_OUT_OF_RESOURCES Not enough memory available
32 CoreInstallConfigurationTable (
38 EFI_CONFIGURATION_TABLE
*EfiConfigurationTable
;
39 EFI_CONFIGURATION_TABLE
*OldTable
;
42 // If Guid is NULL, then this operation cannot be performed
45 return EFI_INVALID_PARAMETER
;
48 EfiConfigurationTable
= gDxeCoreST
->ConfigurationTable
;
51 // Search all the table for an entry that matches Guid
53 for (Index
= 0; Index
< gDxeCoreST
->NumberOfTableEntries
; Index
++) {
54 if (CompareGuid (Guid
, &(gDxeCoreST
->ConfigurationTable
[Index
].VendorGuid
))) {
59 if (Index
< gDxeCoreST
->NumberOfTableEntries
) {
61 // A match was found, so this is either a modify or a delete operation
65 // If Table is not NULL, then this is a modify operation.
66 // Modify the table entry and return.
68 gDxeCoreST
->ConfigurationTable
[Index
].VendorTable
= Table
;
71 // Signal Configuration Table change
73 CoreNotifySignalList (Guid
);
79 // A match was found and Table is NULL, so this is a delete operation.
81 gDxeCoreST
->NumberOfTableEntries
--;
84 // Copy over deleted entry
87 &(EfiConfigurationTable
[Index
]),
88 &(gDxeCoreST
->ConfigurationTable
[Index
+ 1]),
89 (gDxeCoreST
->NumberOfTableEntries
- Index
) * sizeof (EFI_CONFIGURATION_TABLE
)
93 // No matching GUIDs were found, so this is an add operation.
98 // If Table is NULL on an add operation, then return an error.
100 return EFI_NOT_FOUND
;
104 // Assume that Index == gDxeCoreST->NumberOfTableEntries
106 if ((Index
* sizeof (EFI_CONFIGURATION_TABLE
)) >= mSystemTableAllocateSize
) {
108 // Allocate a table with one additional entry.
110 mSystemTableAllocateSize
+= (CONFIG_TABLE_SIZE_INCREASED
* sizeof (EFI_CONFIGURATION_TABLE
));
111 EfiConfigurationTable
= AllocateRuntimePool (mSystemTableAllocateSize
);
112 if (EfiConfigurationTable
== NULL
) {
114 // If a new table could not be allocated, then return an error.
116 return EFI_OUT_OF_RESOURCES
;
119 if (gDxeCoreST
->ConfigurationTable
!= NULL
) {
121 // Copy the old table to the new table.
124 EfiConfigurationTable
,
125 gDxeCoreST
->ConfigurationTable
,
126 Index
* sizeof (EFI_CONFIGURATION_TABLE
)
130 // Record the old table pointer.
132 OldTable
= gDxeCoreST
->ConfigurationTable
;
135 // As the CoreInstallConfigurationTable() may be re-entered by CoreFreePool()
136 // in its calling stack, updating System table to the new table pointer must
137 // be done before calling CoreFreePool() to free the old table.
138 // It can make sure the gDxeCoreST->ConfigurationTable point to the new table
139 // and avoid the errors of use-after-free to the old table by the reenter of
140 // CoreInstallConfigurationTable() in CoreFreePool()'s calling stack.
142 gDxeCoreST
->ConfigurationTable
= EfiConfigurationTable
;
145 // Free the old table after updating System Table to the new table pointer.
147 CoreFreePool (OldTable
);
150 // Update System Table
152 gDxeCoreST
->ConfigurationTable
= EfiConfigurationTable
;
157 // Fill in the new entry
159 CopyGuid ((VOID
*)&EfiConfigurationTable
[Index
].VendorGuid
, Guid
);
160 EfiConfigurationTable
[Index
].VendorTable
= Table
;
163 // This is an add operation, so increment the number of table entries
165 gDxeCoreST
->NumberOfTableEntries
++;
169 // Fix up the CRC-32 in the EFI System Table
171 CalculateEfiHdrCrc (&gDxeCoreST
->Hdr
);
174 // Signal Configuration Table change
176 CoreNotifySignalList (Guid
);