From b87fc6b140772ba3017de311c7063c259424264c Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 15 Aug 2016 17:11:31 +0200 Subject: First public release. Used by VeraCrypt 1.18. --- Library/CommonLib/EfiMem.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 Library/CommonLib/EfiMem.c (limited to 'Library/CommonLib/EfiMem.c') diff --git a/Library/CommonLib/EfiMem.c b/Library/CommonLib/EfiMem.c new file mode 100644 index 0000000..d9386c0 --- /dev/null +++ b/Library/CommonLib/EfiMem.c @@ -0,0 +1,74 @@ +/** @file +EFI memory helpers routines/wrappers + +Copyright (c) 2016. Disk Cryptography Services for EFI (DCS), Alex Kolotnikov +Copyright (c) 2016. VeraCrypt, Mounir IDRASSI + +This program and the accompanying materials are licensed and made available +under the terms and conditions of the GNU Lesser General Public License, version 3.0 (LGPL-3.0). + +The full text of the license may be found at +https://opensource.org/licenses/LGPL-3.0 +**/ + +#include +#include +#include +#include + +#include "Library/CommonLib.h" + + +////////////////////////////////////////////////////////////////////////// +// Memory procedures wrappers +////////////////////////////////////////////////////////////////////////// + +VOID* +MemAlloc( + IN UINTN size + ) { + return AllocateZeroPool(size); +} + +VOID* +MemRealloc( + IN UINTN OldSize, + IN UINTN NewSize, + IN VOID *OldBuffer OPTIONAL + ) { + return ReallocatePool(OldSize, NewSize, OldBuffer); +} + +VOID +MemFree( + IN VOID* ptr + ) { + if(ptr != NULL) FreePool(ptr); +} + +////////////////////////////////////////////////////////////////////////// +// Memory mapped IO +////////////////////////////////////////////////////////////////////////// + +EFI_STATUS +PrepareMemory( + IN UINTN address, + IN UINTN len, + OUT VOID** mem) +{ + EFI_STATUS status; + EFI_PHYSICAL_ADDRESS ptr; + VOID* buf; + UINTN pages; + pages = ((len & ~0x0FFF) + 0x1000) >> 12; + ptr = address & ~0x0FFF; +// OUT_PRINT(L"mem try %0x, %0x\n", pages, (UINTN)ptr); + status = gBS->AllocatePages(AllocateAddress, EfiMemoryMappedIO, pages, &ptr); + if (EFI_ERROR(status)) { + return status; + } + buf = (void*)(UINTN)ptr; + SetMem(buf, pages << 12, 0); + *mem = buf; + return status; +} -- cgit v1.2.3