20#include <Library/BaseLib.h>
21#include <Library/BaseMemoryLib.h>
22#include <Library/BaseOverflowLib.h>
23#include <Library/DebugLib.h>
24#include <Library/MemoryAllocationLib.h>
26#define PRIV_OC_BLOB_FIELDS(_, __) \
27 OC_BLOB (CHAR8, [], {0}, _, __)
30#define PRIV_OC_MAP_FIELDS(_, __) \
31 OC_MAP (PRIV_OC_BLOB, PRIV_OC_BLOB, _, __)
34#define PRIV_OC_ARRAY_FIELDS(_, __) \
35 OC_ARRAY (PRIV_OC_BLOB, _, __)
46#if defined (__GNUC__) || defined (__clang__)
47STATIC_ASSERT (OFFSET_OF (PRIV_OC_ARRAY, Count) == OFFSET_OF (PRIV_OC_MAP, Count),
"PRIV_OC_ARRAY vs PRIV_OC_MAP");
48STATIC_ASSERT (OFFSET_OF (PRIV_OC_ARRAY, AllocCount) == OFFSET_OF (PRIV_OC_MAP, AllocCount),
"PRIV_OC_ARRAY vs PRIV_OC_MAP");
49STATIC_ASSERT (OFFSET_OF (PRIV_OC_ARRAY, Construct) == OFFSET_OF (PRIV_OC_MAP, Construct),
"PRIV_OC_ARRAY vs PRIV_OC_MAP");
50STATIC_ASSERT (OFFSET_OF (PRIV_OC_ARRAY, Destruct) == OFFSET_OF (PRIV_OC_MAP, Destruct),
"PRIV_OC_ARRAY vs PRIV_OC_MAP");
51STATIC_ASSERT (OFFSET_OF (PRIV_OC_ARRAY, Values) == OFFSET_OF (PRIV_OC_MAP, Values),
"PRIV_OC_ARRAY vs PRIV_OC_MAP");
52STATIC_ASSERT (OFFSET_OF (PRIV_OC_ARRAY, ValueSize) == OFFSET_OF (PRIV_OC_MAP, ValueSize),
"PRIV_OC_ARRAY vs PRIV_OC_MAP");
61 VOID **Field = (VOID **)Pointer;
100 for (Index = 0; Index < List->
Array.Count; Index++) {
101 List->
Array.Destruct (List->
Array.Values[Index], List->
Array.ValueSize);
102 FreePool (List->
Array.Values[Index]);
105 List->
Map.KeyDestruct (List->
Map.Keys[Index], List->
Map.KeySize);
106 FreePool (List->
Map.Keys[Index]);
115 List->
Array.Count = 0;
116 List->
Array.AllocCount = 0;
141 UINT32 **OutSize OPTIONAL
147 Blob = (PRIV_OC_BLOB *)Pointer;
151 "OCTPL: Allocating %u bytes in blob %p with size %u/%u curr %p\n",
165 if (OutSize != NULL) {
166 *OutSize = &Blob->Size;
175 if (
Size > Blob->Size) {
177 DynValue = AllocatePool (
Size);
178 if (DynValue == NULL) {
179 DEBUG ((DEBUG_VERBOSE,
"OCTPL: Failed to fit %u bytes in OC_BLOB\n",
Size));
186 CopyMem (DynValue, Blob->Value, Blob->MaxSize);
187 Blob->DynValue = DynValue;
191 if (OutSize != NULL) {
192 *OutSize = &Blob->Size;
195 return Blob->DynValue;
216 *Value = AllocatePool (List->
Array.ValueSize);
217 if (*Value == NULL) {
222 *Key = AllocatePool (List->
Map.KeySize);
232 List->
Array.Construct (*Value, List->
Array.ValueSize);
234 List->
Map.KeyConstruct (*Key, List->
Map.KeySize);
243 if (List->
Array.Values != NULL) {
244 Count = List->
Array.Count;
245 AllocCount = List->
Array.AllocCount;
247 if (AllocCount > Count) {
249 List->
Array.Values[Count] = *Value;
251 List->
Map.Keys[Count] = *Key;
263 NewValues = (VOID **)AllocatePool (
264 sizeof (VOID *) * AllocCount
267 if (NewValues == NULL) {
268 List->
Array.Destruct (*Value, List->
Array.ValueSize);
271 List->
Map.KeyDestruct (*Key, List->
Map.KeySize);
279 NewKeys = (VOID **)AllocatePool (
280 sizeof (VOID *) * AllocCount
283 if (NewKeys == NULL) {
284 List->
Array.Destruct (*Value, List->
Array.ValueSize);
285 List->
Map.KeyDestruct (*Key, List->
Map.KeySize);
286 FreePool (NewValues);
298 if (List->
Array.Values != NULL) {
301 &List->
Array.Values[0],
302 sizeof (VOID *) * Count
305 FreePool (List->
Array.Values);
308 if ((Key != NULL) && (List->
Map.Keys != NULL)) {
312 sizeof (VOID *) * Count
315 FreePool (List->
Map.Keys);
319 List->
Array.AllocCount = AllocCount;
321 NewValues[Count] = *Value;
322 List->
Array.Values = (PRIV_OC_BLOB **)NewValues;
325 NewKeys[Count] = *Key;
326 List->
Map.Keys = (PRIV_OC_BLOB **)NewKeys;
DMG_SIZE_DEVICE_PATH Size
STATIC_ASSERT(BYTES_PER_PIXEL==sizeof(UINT32), "Non 4-byte pixels are unsupported!")
VOID OcDestructEmpty(VOID *Pointer, UINT32 Size)
VOID OcZeroField(VOID *Pointer, UINT32 Size)
VOID OcFreeMap(VOID *Pointer, UINT32 Size)
VOID OcFreeArray(VOID *Pointer, UINT32 Size)
BOOLEAN OcListEntryAllocate(VOID *Pointer, VOID **Value, VOID **Key)
STATIC VOID OcFreeList(VOID *Pointer, BOOLEAN HasKeys)
VOID OcFreePointer(VOID *Pointer, UINT32 Size)
union PRIV_OC_LIST_ PRIV_OC_LIST
VOID * OcBlobAllocate(VOID *Pointer, UINT32 Size, UINT32 **OutSize OPTIONAL)
#define OC_MAP_STRUCTORS(Name)
#define OC_BLOB_STRUCTORS(Name)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)