#include <sys/types.h>
#include <unistd.h>
+#define PAGE_SIZE (64 * 1024) // assumption
#define MAXDUMPS 10
#define RAMSIZE (64 * 1024 * 1024)
#define PROGSTART 0x20000000
printf("Loading binary %u bytes\n", binlen);
- if (posix_memalign((void **) &progmem, 64 * 1024, binlen))
+ const unsigned progmemlen = (binlen + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
+
+ if (posix_memalign((void **) &progmem, 64 * 1024, progmemlen))
abort();
if (fread(progmem, binlen, 1, binary) != 1)
region.slot = 1;
region.guest_phys_addr = PROGSTART;
- region.memory_size = binlen;
+ region.memory_size = progmemlen;
region.userspace_addr = (uint64_t) progmem;
region.flags = KVM_MEM_READONLY;
if (ioctl(vmfd, KVM_SET_USER_MEMORY_REGION, ®ion) == -1)