Commit 24ef9228 authored by Chris Toshok's avatar Chris Toshok

allocate runtime ics using mmap (with PROT_EXEC) so valgrind doesn't die horribly

parent 3a5b3e50
......@@ -14,6 +14,8 @@
#include "runtime/ics.h"
#include <sys/mman.h>
#include "asm_writing/icinfo.h"
#include "asm_writing/rewriter.h"
#include "codegen/compvars.h"
......@@ -26,6 +28,8 @@
#include "core/stats.h"
#include "core/types.h"
#define PAGE_SIZE 4096
namespace pyston {
// I am not sure if we should use the equivalent of -fomit-frame-pointer for these trampolines.
......@@ -163,7 +167,9 @@ static void writeTrivialEhFrame(void* eh_frame_addr, void* func_addr, uint64_t f
void EHFrameManager::writeAndRegister(void* func_addr, uint64_t func_size) {
assert(eh_frame_addr == NULL);
eh_frame_addr = malloc(EH_FRAME_SIZE);
eh_frame_addr = mmap(NULL, (EH_FRAME_SIZE + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1), PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
RELEASE_ASSERT(eh_frame_addr != MAP_FAILED, "");
writeTrivialEhFrame(eh_frame_addr, func_addr, func_size);
// (EH_FRAME_SIZE - 4) to omit the 4-byte null terminator, otherwise we trip an assert in parseEhFrame.
// TODO: can we omit the terminator in general?
......@@ -174,7 +180,7 @@ void EHFrameManager::writeAndRegister(void* func_addr, uint64_t func_size) {
EHFrameManager::~EHFrameManager() {
if (eh_frame_addr) {
deregisterEHFrames((uint8_t*)eh_frame_addr, (uint64_t)eh_frame_addr, EH_FRAME_SIZE);
free(eh_frame_addr);
munmap(eh_frame_addr, (EH_FRAME_SIZE + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1));
}
}
......@@ -227,8 +233,11 @@ RuntimeIC::RuntimeIC(void* func_addr, int num_slots, int slot_size) {
static const int CALL_SIZE = 13;
int patchable_size = num_slots * slot_size;
int total_size = PROLOGUE_SIZE + patchable_size + CALL_SIZE + EPILOGUE_SIZE;
addr = malloc(total_size);
total_size = PROLOGUE_SIZE + patchable_size + CALL_SIZE + EPILOGUE_SIZE;
addr = mmap(NULL, (total_size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1), PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
RELEASE_ASSERT(addr != MAP_FAILED, "");
// printf("Allocated runtime IC at %p\n", addr);
......@@ -285,7 +294,7 @@ RuntimeIC::RuntimeIC(void* func_addr, int num_slots, int slot_size) {
RuntimeIC::~RuntimeIC() {
if (ENABLE_RUNTIME_ICS) {
deregisterCompiledPatchpoint(icinfo.get());
free(addr);
munmap(addr, total_size);
} else {
}
}
......
......@@ -35,6 +35,7 @@ public:
class RuntimeIC {
private:
void* addr;
size_t total_size;
EHFrameManager eh_frame;
std::unique_ptr<ICInfo> icinfo;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment