TianoCore EDK2 master
Loading...
Searching...
No Matches
StandaloneMmMemLib.c
Go to the documentation of this file.
1
17
18//
19// Maximum support address used to check input buffer
20//
21EFI_PHYSICAL_ADDRESS mMmMemLibInternalMaximumSupportAddress = 0;
22
32BOOLEAN
33EFIAPI
36 IN UINT64 Length
37 )
38{
39 //
40 // Check override.
41 // NOTE: (B:0->L:4G) is invalid for IA32, but (B:1->L:4G-1)/(B:4G-1->L:1) is valid.
42 //
43 if ((Length > mMmMemLibInternalMaximumSupportAddress) ||
44 (Buffer > mMmMemLibInternalMaximumSupportAddress) ||
45 ((Length != 0) && (Buffer > (mMmMemLibInternalMaximumSupportAddress - (Length - 1)))))
46 {
47 //
48 // Overflow happen
49 //
50 DEBUG ((
51 DEBUG_ERROR,
52 "MmIsBufferOutsideMmValid: Overflow: Buffer (0x%lx) - Length (0x%lx), MaximumSupportAddress (0x%lx)\n",
53 Buffer,
54 Length,
55 mMmMemLibInternalMaximumSupportAddress
56 ));
57 return FALSE;
58 }
59
60 return MmMemLibIsValidNonMmramRange (Buffer, Length);
61}
62
81EFIAPI
83 OUT VOID *DestinationBuffer,
84 IN CONST VOID *SourceBuffer,
85 IN UINTN Length
86 )
87{
88 if (!MmIsBufferOutsideMmValid ((EFI_PHYSICAL_ADDRESS)(UINTN)SourceBuffer, Length)) {
89 DEBUG ((DEBUG_ERROR, "MmCopyMemToMmram: Security Violation: Source (0x%x), Length (0x%x)\n", SourceBuffer, Length));
90 return EFI_SECURITY_VIOLATION;
91 }
92
93 CopyMem (DestinationBuffer, SourceBuffer, Length);
94 return EFI_SUCCESS;
95}
96
115EFIAPI
117 OUT VOID *DestinationBuffer,
118 IN CONST VOID *SourceBuffer,
119 IN UINTN Length
120 )
121{
122 if (!MmIsBufferOutsideMmValid ((EFI_PHYSICAL_ADDRESS)(UINTN)DestinationBuffer, Length)) {
123 DEBUG ((
124 DEBUG_ERROR,
125 "MmCopyMemFromMmram: Security Violation: Destination (0x%x), Length (0x%x)\n",
126 DestinationBuffer,
127 Length
128 ));
129 return EFI_SECURITY_VIOLATION;
130 }
131
132 CopyMem (DestinationBuffer, SourceBuffer, Length);
133 return EFI_SUCCESS;
134}
135
155EFIAPI
157 OUT VOID *DestinationBuffer,
158 IN CONST VOID *SourceBuffer,
159 IN UINTN Length
160 )
161{
162 if (!MmIsBufferOutsideMmValid ((EFI_PHYSICAL_ADDRESS)(UINTN)DestinationBuffer, Length)) {
163 DEBUG ((
164 DEBUG_ERROR,
165 "MmCopyMem: Security Violation: Destination (0x%x), Length (0x%x)\n",
166 DestinationBuffer,
167 Length
168 ));
169 return EFI_SECURITY_VIOLATION;
170 }
171
172 if (!MmIsBufferOutsideMmValid ((EFI_PHYSICAL_ADDRESS)(UINTN)SourceBuffer, Length)) {
173 DEBUG ((DEBUG_ERROR, "MmCopyMem: Security Violation: Source (0x%x), Length (0x%x)\n", SourceBuffer, Length));
174 return EFI_SECURITY_VIOLATION;
175 }
176
177 CopyMem (DestinationBuffer, SourceBuffer, Length);
178 return EFI_SUCCESS;
179}
180
198EFIAPI
200 OUT VOID *Buffer,
201 IN UINTN Length,
202 IN UINT8 Value
203 )
204{
205 if (!MmIsBufferOutsideMmValid ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, Length)) {
206 DEBUG ((DEBUG_ERROR, "MmSetMem: Security Violation: Source (0x%x), Length (0x%x)\n", Buffer, Length));
207 return EFI_SECURITY_VIOLATION;
208 }
209
210 SetMem (Buffer, Length, Value);
211 return EFI_SUCCESS;
212}
213
224EFIAPI
226 IN EFI_HANDLE ImageHandle,
227 IN EFI_MM_SYSTEM_TABLE *MmSystemTable
228 )
229{
230 //
231 // Calculate and save maximum support address
232 //
234
235 //
236 // Initialize valid non-Mmram Ranges from Resource HOB.
237 //
239
240 return EFI_SUCCESS;
241}
242
253EFIAPI
255 IN EFI_HANDLE ImageHandle,
256 IN EFI_MM_SYSTEM_TABLE *MmSystemTable
257 )
258{
259 //
260 // Deinitialize cached non-Mmram Ranges.
261 //
263 return EFI_SUCCESS;
264}
UINT64 UINTN
BOOLEAN MmMemLibIsValidNonMmramRange(IN EFI_PHYSICAL_ADDRESS Buffer, IN UINT64 Length)
VOID MmMemLibInitializeValidNonMmramRanges(VOID)
VOID MmMemLibFreeValidNonMmramRanges(VOID)
VOID MmMemLibCalculateMaximumSupportAddress(VOID)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
Definition: SetMemWrapper.c:38
#define CONST
Definition: Base.h:259
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_STATUS EFIAPI MmCopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
EFI_STATUS EFIAPI MmCopyMemFromMmram(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI MmIsBufferOutsideMmValid(IN EFI_PHYSICAL_ADDRESS Buffer, IN UINT64 Length)
EFI_STATUS EFIAPI MemLibDestructor(IN EFI_HANDLE ImageHandle, IN EFI_MM_SYSTEM_TABLE *MmSystemTable)
EFI_STATUS EFIAPI MmSetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
EFI_STATUS EFIAPI MmCopyMemToMmram(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
EFI_STATUS EFIAPI MemLibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_MM_SYSTEM_TABLE *MmSystemTable)
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112