TianoCore EDK2 master
Loading...
Searching...
No Matches
InstallConfigurationTable.c
Go to the documentation of this file.
1
9#include "PiSmmCore.h"
10
11#define CONFIG_TABLE_SIZE_INCREASED 0x10
12
13UINTN mSmmSystemTableAllocateSize = 0;
14
33EFIAPI
35 IN CONST EFI_SMM_SYSTEM_TABLE2 *SystemTable,
36 IN CONST EFI_GUID *Guid,
37 IN VOID *Table,
38 IN UINTN TableSize
39 )
40{
41 UINTN Index;
42 EFI_CONFIGURATION_TABLE *ConfigurationTable;
44
45 //
46 // If Guid is NULL, then this operation cannot be performed
47 //
48 if (Guid == NULL) {
49 return EFI_INVALID_PARAMETER;
50 }
51
52 ConfigurationTable = gSmmCoreSmst.SmmConfigurationTable;
53
54 //
55 // Search all the table for an entry that matches Guid
56 //
57 for (Index = 0; Index < gSmmCoreSmst.NumberOfTableEntries; Index++) {
58 if (CompareGuid (Guid, &(ConfigurationTable[Index].VendorGuid))) {
59 break;
60 }
61 }
62
63 if (Index < gSmmCoreSmst.NumberOfTableEntries) {
64 //
65 // A match was found, so this is either a modify or a delete operation
66 //
67 if (Table != NULL) {
68 //
69 // If Table is not NULL, then this is a modify operation.
70 // Modify the table entry and return.
71 //
72 ConfigurationTable[Index].VendorTable = Table;
73 return EFI_SUCCESS;
74 }
75
76 //
77 // A match was found and Table is NULL, so this is a delete operation.
78 //
79 gSmmCoreSmst.NumberOfTableEntries--;
80
81 //
82 // Copy over deleted entry
83 //
84 CopyMem (
85 &(ConfigurationTable[Index]),
86 &(ConfigurationTable[Index + 1]),
87 (gSmmCoreSmst.NumberOfTableEntries - Index) * sizeof (EFI_CONFIGURATION_TABLE)
88 );
89 } else {
90 //
91 // No matching GUIDs were found, so this is an add operation.
92 //
93 if (Table == NULL) {
94 //
95 // If Table is NULL on an add operation, then return an error.
96 //
97 return EFI_NOT_FOUND;
98 }
99
100 //
101 // Assume that Index == gSmmCoreSmst.NumberOfTableEntries
102 //
103 if ((Index * sizeof (EFI_CONFIGURATION_TABLE)) >= mSmmSystemTableAllocateSize) {
104 //
105 // Allocate a table with one additional entry.
106 //
107 mSmmSystemTableAllocateSize += (CONFIG_TABLE_SIZE_INCREASED * sizeof (EFI_CONFIGURATION_TABLE));
108 ConfigurationTable = AllocatePool (mSmmSystemTableAllocateSize);
109 if (ConfigurationTable == NULL) {
110 //
111 // If a new table could not be allocated, then return an error.
112 //
113 return EFI_OUT_OF_RESOURCES;
114 }
115
116 if (gSmmCoreSmst.SmmConfigurationTable != NULL) {
117 //
118 // Copy the old table to the new table.
119 //
120 CopyMem (
121 ConfigurationTable,
122 gSmmCoreSmst.SmmConfigurationTable,
123 Index * sizeof (EFI_CONFIGURATION_TABLE)
124 );
125
126 //
127 // Record the old table pointer.
128 //
129 OldTable = gSmmCoreSmst.SmmConfigurationTable;
130
131 //
132 // As the SmmInstallConfigurationTable() may be re-entered by FreePool() in
133 // its calling stack, updating System table to the new table pointer must
134 // be done before calling FreePool() to free the old table.
135 // It can make sure the gSmmCoreSmst.SmmConfigurationTable point to the new
136 // table and avoid the errors of use-after-free to the old table by the
137 // reenter of SmmInstallConfigurationTable() in FreePool()'s calling stack.
138 //
139 gSmmCoreSmst.SmmConfigurationTable = ConfigurationTable;
140
141 //
142 // Free the old table after updating System Table to the new table pointer.
143 //
144 FreePool (OldTable);
145 } else {
146 //
147 // Update System Table
148 //
149 gSmmCoreSmst.SmmConfigurationTable = ConfigurationTable;
150 }
151 }
152
153 //
154 // Fill in the new entry
155 //
156 CopyGuid ((VOID *)&ConfigurationTable[Index].VendorGuid, Guid);
157 ConfigurationTable[Index].VendorTable = Table;
158
159 //
160 // This is an add operation, so increment the number of table entries
161 //
162 gSmmCoreSmst.NumberOfTableEntries++;
163 }
164
165 //
166 // CRC-32 field is ignorable for SMM System Table and should be set to zero
167 //
168
169 return EFI_SUCCESS;
170}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
Definition: MemLibGuid.c:39
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI SmmInstallConfigurationTable(IN CONST EFI_SMM_SYSTEM_TABLE2 *SystemTable, IN CONST EFI_GUID *Guid, IN VOID *Table, IN UINTN TableSize)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define VOID
Definition: Base.h:269
#define IN
Definition: Base.h:279
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_CONFIGURATION_TABLE * SmmConfigurationTable
Definition: PiSmmCis.h:180
Definition: Base.h:213