Started building the kernel memory manager in userspace

This commit is contained in:
2022-12-29 19:22:16 +00:00
parent 7f51b0755b
commit 2b59afcaf3
3 changed files with 82 additions and 0 deletions

29
sandbox/vm/main.c Normal file
View File

@@ -0,0 +1,29 @@
#include <stdio.h>
#include <sys/mman.h>
#include "vm.h"
/* amount of memory to allocate for system RAM in megabytes */
#define SIMULATED_MEMORY_MB 16
#define MEMPTR(offset) ((void *)((uintptr_t)system_memory) + (offset))
int main(int argc, const char **argv)
{
printf("Hello, world!\n");
void *system_memory = mmap(
NULL,
SIMULATED_MEMORY_MB * 0x100000,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS,
-1, 0);
if (system_memory == MAP_FAILED) {
perror("mmap");
fprintf(stderr, "cannot allocated simulated system RAM buffer\n");
return -1;
}
munmap(system_memory, SIMULATED_MEMORY_MB * 0x100000);
return 0;
}