From 763c34c8dedf71249e978e594eee62cfa4e1383e Mon Sep 17 00:00:00 2001 From: Edgaru089 Date: Sun, 7 Nov 2021 01:24:40 +0800 Subject: [PATCH] memory: use libc malloc/free in testing --- memory/memory.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/memory/memory.h b/memory/memory.h index ca45893..5c08ed7 100644 --- a/memory/memory.h +++ b/memory/memory.h @@ -52,12 +52,28 @@ void *efiMalloc(size_t size); void efiFree(void *data); +#ifdef HELOS // kMalloc allocates from system memory directly after paging has been set up void *kMalloc(size_t size); // kFree frees data allocated from kMalloc. void kFree(void *data); +#else +// use stdc malloc/free in testing +#include +#include +static inline void *kMalloc(size_t size) { + void *mem = malloc(size); + printf("kMalloc: size=%llu, pos=0x%llx\n", size, mem); + return mem; +} +static inline void kFree(void *data) { + printf("kFree: 0x%llx\n", data); + free(data); +} +#endif + // runtime_InitPaging initializes paging and kMalloc/kFree allocator. // This function calls ExitBootServices()!!! which is great