diff options
| -rw-r--r-- | include/test.h | 4 | ||||
| -rw-r--r-- | test.c | 74 |
2 files changed, 78 insertions, 0 deletions
diff --git a/include/test.h b/include/test.h index 811f92bf..9a4fdb1b 100644 --- a/include/test.h +++ b/include/test.h @@ -57,6 +57,10 @@ UINTN StrSize(IN CONST CHAR16 *s1); VOID StrCat(IN CHAR16 *Dest, IN CONST CHAR16 *Src); CHAR16 *DevicePathToStr(EFI_DEVICE_PATH *DevPath); +extern EFI_SYSTEM_TABLE *ST; +extern EFI_BOOT_SERVICES *BS; +extern EFI_RUNTIME_SERVICES *RT; + #define CompareGuid(a, b) memcmp(a, b, sizeof(a)) extern int debug; @@ -15,6 +15,80 @@ int debug = DEFAULT_DEBUG_PRINT_STATE; #pragma GCC diagnostic ignored "-Wunused-parameter" #pragma GCC diagnostic ignored "-Wunused-function" +static EFI_STATUS EFIAPI +mock_efi_allocate_pages(EFI_ALLOCATE_TYPE type, + EFI_MEMORY_TYPE memory_type, + UINTN nmemb, + EFI_PHYSICAL_ADDRESS *memory) +{ + /* + * XXX so far this does not honor the type at all, and there's no + * tracking for memory_type either. + */ + *memory = (EFI_PHYSICAL_ADDRESS)(uintptr_t)calloc(nmemb, 4096); + if ((void *)(uintptr_t)(*memory) == NULL) + return EFI_OUT_OF_RESOURCES; + + return EFI_SUCCESS; +} + +static EFI_STATUS EFIAPI +mock_efi_free_pages(EFI_PHYSICAL_ADDRESS memory, + UINTN nmemb) +{ + free((void *)(uintptr_t)memory); + + return EFI_SUCCESS; +} + +static EFI_STATUS EFIAPI +mock_efi_allocate_pool(EFI_MEMORY_TYPE pool_type, + UINTN size, + VOID **buf) +{ + *buf = calloc(1, size); + if (*buf == NULL) + return EFI_OUT_OF_RESOURCES; + + return EFI_SUCCESS; +} + +static EFI_STATUS EFIAPI +mock_efi_free_pool(void *buf) +{ + free(buf); + + return EFI_SUCCESS; +} + +EFI_BOOT_SERVICES mock_bs = { + .RaiseTPL = NULL, + .RestoreTPL = NULL, + + .AllocatePages = mock_efi_allocate_pages, + .FreePages = mock_efi_free_pages, + .AllocatePool = mock_efi_allocate_pool, + .FreePool = mock_efi_free_pool, +}; + +EFI_RUNTIME_SERVICES mock_rt = { + .Hdr = { 0, }, + .GetVariable = NULL, +}; + +EFI_SYSTEM_TABLE mock_st = { + .Hdr = { 0, }, + .BootServices = &mock_bs, + .RuntimeServices = &mock_rt, +}; + +void CONSTRUCTOR init_efi_system_table(void) +{ + ST = &mock_st; + BS = &mock_bs; + RT = &mock_rt; +} + EFI_STATUS EFIAPI LogError_(const char *file, int line, const char *func, const CHAR16 *fmt, ...) { |
