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
)
95 // No matching GUIDs were found, so this is an add operation.
100 // If Table is NULL on an add operation, then return an error.
102 return EFI_NOT_FOUND
;
106 // Assume that Index == gDxeCoreST->NumberOfTableEntries
108 if ((Index
* sizeof (EFI_CONFIGURATION_TABLE
)) >= mSystemTableAllocateSize
) {
110 // Allocate a table with one additional entry.
112 mSystemTableAllocateSize
+= (CONFIG_TABLE_SIZE_INCREASED
* sizeof (EFI_CONFIGURATION_TABLE
));
113 EfiConfigurationTable
= AllocateRuntimePool (mSystemTableAllocateSize
);
114 if (EfiConfigurationTable
== NULL
) {
116 // If a new table could not be allocated, then return an error.
118 return EFI_OUT_OF_RESOURCES
;
121 if (gDxeCoreST
->ConfigurationTable
!= NULL
) {
123 // Copy the old table to the new table.
126 EfiConfigurationTable
,
127 gDxeCoreST
->ConfigurationTable
,
128 Index
* sizeof (EFI_CONFIGURATION_TABLE
)
132 // Record the old table pointer.
134 OldTable
= gDxeCoreST
->ConfigurationTable
;
137 // As the CoreInstallConfigurationTable() may be re-entered by CoreFreePool()
138 // in its calling stack, updating System table to the new table pointer must
139 // be done before calling CoreFreePool() to free the old table.
140 // It can make sure the gDxeCoreST->ConfigurationTable point to the new table
141 // and avoid the errors of use-after-free to the old table by the reenter of
142 // CoreInstallConfigurationTable() in CoreFreePool()'s calling stack.
144 gDxeCoreST
->ConfigurationTable
= EfiConfigurationTable
;
147 // Free the old table after updating System Table to the new table pointer.
149 CoreFreePool (OldTable
);
152 // Update System Table
154 gDxeCoreST
->ConfigurationTable
= EfiConfigurationTable
;
159 // Fill in the new entry
161 CopyGuid ((VOID
*)&EfiConfigurationTable
[Index
].VendorGuid
, Guid
);
162 EfiConfigurationTable
[Index
].VendorTable
= Table
;
165 // This is an add operation, so increment the number of table entries
167 gDxeCoreST
->NumberOfTableEntries
++;
171 // Fix up the CRC-32 in the EFI System Table
173 CalculateEfiHdrCrc (&gDxeCoreST
->Hdr
);
176 // Signal Configuration Table change
178 CoreNotifySignalList (Guid
);