commit a62a7e75e11e9f03227ad7a5c1a602eb63234870 parent 47d71278f948085b401f52654d207b949d48c0a8 Author: Matsuda Kenji <info@mtkn.jp> Date: Mon, 1 Apr 2024 17:24:07 +0900 try to implement malloc Diffstat:
A | sys/src/kernel/alloc.c | | | 17 | +++++++++++++++++ |
1 file changed, 17 insertions(+), 0 deletions(-)
diff --git a/sys/src/kernel/alloc.c b/sys/src/kernel/alloc.c @@ -0,0 +1,16 @@ +#include <libc.h> + +Memmap memmap; + +void * +malloc(uintptr size) +{ + void *ptr = NULL; + for (int i = 0; i < memmap.nfreespace; i++) { + if (memmap.freespace[i].end - memmap.freespace[i].start >= size) { + ptr = memmap.freespace[i].start; + break; + } + } + return ptr; +} +\ No newline at end of file