Re-factored sandbox into a single executable
This commit is contained in:
8
sandbox/base/include/socks/types.h
Normal file
8
sandbox/base/include/socks/types.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef SOCKS_TYPES_H_
|
||||
#define SOCKS_TYPES_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef uintptr_t phys_addr_t;
|
||||
|
||||
#endif
|
||||
68
sandbox/base/main.c
Normal file
68
sandbox/base/main.c
Normal file
@@ -0,0 +1,68 @@
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <inttypes.h>
|
||||
#include <sys/mman.h>
|
||||
#include <socks/memblock.h>
|
||||
|
||||
/* we're working with 4MiB of simulated system RAM */
|
||||
#define MEMORY_SIZE_MB 128
|
||||
|
||||
/* virtual address of where system memory is mapped */
|
||||
static void *system_memory = NULL;
|
||||
|
||||
#define MEMPTR(offset) ((uintptr_t)system_memory + (offset))
|
||||
#define MB_TO_BYTES(v) ((size_t)(v) * 0x100000)
|
||||
|
||||
#define PHYS_TO_VIRT(p) ((void *)((uintptr_t)system_memory + (p)))
|
||||
#define VIRT_TO_PHYS(p) ((void *)((p) - (uintptr_t)system_memory))
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
system_memory = mmap(
|
||||
NULL,
|
||||
MB_TO_BYTES(MEMORY_SIZE_MB),
|
||||
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 %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);
|
||||
|
||||
memblock_add(0, MB_TO_BYTES(MEMORY_SIZE_MB));
|
||||
|
||||
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, MB_TO_BYTES(MEMORY_SIZE_MB));
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user