/* Copyright 2013 Michael Pavone This file is part of BlastEm. BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. */ #include #include #include #include #include #include "mem.h" #ifndef MAP_ANONYMOUS #define MAP_ANONYMOUS MAP_ANON #endif void * alloc_code(size_t *size) { //start at the 1GB mark to allow plenty of room for sbrk based malloc implementations //while still keeping well within 32-bit displacement range for calling code compiled into the executable static uint8_t *next = (uint8_t *)0x40000000; *size += PAGE_SIZE - (*size & (PAGE_SIZE - 1)); uint8_t *ret = mmap(NULL, *size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); next = ret + *size; return ret; }