From f163a5d5f6802f63092229f0f9326e5fb44b7908 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sun, 9 Aug 2020 21:55:42 +0200 Subject: Added malloc/free syscall --- lib/inc/mem.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'lib/inc/mem.h') diff --git a/lib/inc/mem.h b/lib/inc/mem.h index e2d574f..9399b54 100644 --- a/lib/inc/mem.h +++ b/lib/inc/mem.h @@ -5,8 +5,17 @@ #include -#define malloc(n) ((void *)((HEAP += n) - n)) // TODO: Implement real/better malloc/free -#define free(x) +// Huh +#ifdef kernel +#define malloc(n) (void *)((HEAP += n) - n) // TODO: Implement real/better malloc/free +#define free(ptr) +#elif defined(userspace) +#include +#define malloc(n) (void *)sys1(SYS_MALLOC, n) +#define free(ptr) (void)(sys1(SYS_FREE, (int)ptr)) +#else +#error "No lib target specified. Please use -Dkernel or -Duserspace" +#endif // TODO: Use malloc as syscall u32 HEAP; -- cgit v1.2.3