Re-factored sandbox into a single executable

This commit is contained in:
2022-12-29 19:47:25 +00:00
parent 2b59afcaf3
commit 2ac3e8602f
7 changed files with 44 additions and 46 deletions

View File

@@ -1,2 +0,0 @@
include ../sandbox-config.mk
include ../sandbox-template.mk

View File

@@ -1,59 +0,0 @@
#include <stdio.h>
#include <stddef.h>
#include <inttypes.h>
#include <sys/mman.h>
#include "memblock.h"
/* we're working with 4MiB of simulated system RAM */
#define MEMORY_SIZE 0x400000ULL
int main(int argc, const char **argv)
{
void *system_memory = mmap(
NULL,
MEMORY_SIZE,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS,
-1, 0);
if (system_memory == MAP_FAILED) {
perror("mmap");
fprintf(stderr, "cannot allocate simulated system RAM buffer\n");
return -1;
}
printf("allocated 0x%llx bytes of memory to act as system RAM at %p\n", MEMORY_SIZE, system_memory);
memblock_add(0, MEMORY_SIZE);
memblock_reserve(0x10000, 0x40000);
memblock_reserve(0x60000, 0x20000);
memblock_reserve(0x30000, 0x40000);
memblock_reserve(0x100000, 0x10000);
printf("memory regions:\n");
memblock_iter_t it;
for_each_mem_range(&it, 0, 0x100000) {
printf("\t%08" PRIxPTR "-%08" PRIxPTR "\n",
it.base,
it.limit);
}
printf("reserved regions:\n");
for_each_reserved_mem_range(&it, 0, 0x100000) {
printf("\t%08" PRIxPTR "-%08" PRIxPTR "\n",
it.base,
it.limit);
}
printf("free regions:\n");
for_each_free_mem_range(&it, 0, ULLONG_MAX) {
printf("\t%08" PRIxPTR "-%08" PRIxPTR "\n",
it.base,
it.limit);
}
munmap(system_memory, MEMORY_SIZE);
return 0;
}

View File

@@ -1,7 +1,7 @@
#include <stdbool.h>
#include <limits.h>
#include <string.h>
#include "memblock.h"
#include <socks/memblock.h>
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))