memblock can now self re-allocate its internal buffers

memory allocated by memblock_alloc() can now be limited to a certain region.
This commit is contained in:
2023-01-08 12:13:59 +00:00
parent 02211e6eba
commit 0d77d97561
6 changed files with 125 additions and 12 deletions

View File

@@ -0,0 +1,9 @@
#ifndef SOCKS_STATUS_H_
#define SOCKS_STATUS_H_
typedef unsigned int kern_status_t;
#define KERN_OK (0)
#define KERN_ERR_UNIMPLEMENTED (1)
#endif

View File

@@ -2,11 +2,15 @@
#include <stddef.h>
#include <inttypes.h>
#include <sys/mman.h>
#include <socks/types.h>
#include <socks/memblock.h>
/* we're working with 4MiB of simulated system RAM */
#define MEMORY_SIZE_MB 128
#define ALLOC_START_MB 16
#define ALLOC_END_MB 18
/* virtual address of where system memory is mapped */
static void *system_memory = NULL;
@@ -33,6 +37,12 @@ int main(int argc, const char **argv)
printf("allocated %u MiB (0x%zx bytes) of memory to act as system RAM at %p\n", MEMORY_SIZE_MB, MB_TO_BYTES(MEMORY_SIZE_MB), system_memory);
uintptr_t voffset = (uintptr_t)system_memory;
memblock_init(MB_TO_BYTES(ALLOC_START_MB) + voffset, MB_TO_BYTES(ALLOC_END_MB) + voffset, voffset);
printf("memblock heap initialised in 0x%zx-0x%zx\n", MB_TO_BYTES(ALLOC_START_MB), MB_TO_BYTES(ALLOC_END_MB));
memblock_add(0, MB_TO_BYTES(MEMORY_SIZE_MB));
memblock_reserve(0x00000, 0x40000);