diff options
| author | Fabian Vogt <fabian@ritter-vogt.de> | 2014-09-03 16:59:33 +0200 |
|---|---|---|
| committer | Fabian Vogt <fabian@ritter-vogt.de> | 2014-09-03 23:07:42 +0200 |
| commit | b7235b8412a7511c94b31c0391eaf5c1b35ed3a8 (patch) | |
| tree | 2112ee4a17967fe8bf1cedcc59d1934434bad309 /py/asmx64.c | |
| parent | fc54250d3158bcd897d43187b822765fb97f369f (diff) | |
Add cache flush in py/asmarm.c and add new MP_PLAT_ALLOC_EXEC and MP_PLAT_FREE_EXEC macros
Fixes issue #840
Diffstat (limited to 'py/asmx64.c')
| -rw-r--r-- | py/asmx64.c | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/py/asmx64.c b/py/asmx64.c index 4695bdc73..cf9d8b0f2 100644 --- a/py/asmx64.c +++ b/py/asmx64.c @@ -113,8 +113,8 @@ struct _asm_x64_t { uint pass; - uint code_offset; - uint code_size; + mp_uint_t code_offset; + mp_uint_t code_size; byte *code_base; byte dummy_data[8]; @@ -123,18 +123,6 @@ struct _asm_x64_t { int num_locals; }; -// for allocating memory, see src/v8/src/platform-linux.cc -void *alloc_mem(uint req_size, uint *alloc_size, bool is_exec) { - req_size = (req_size + 0xfff) & (~0xfff); - int prot = PROT_READ | PROT_WRITE | (is_exec ? PROT_EXEC : 0); - void *ptr = mmap(NULL, req_size, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - if (ptr == MAP_FAILED) { - assert(0); - } - *alloc_size = req_size; - return ptr; -} - asm_x64_t *asm_x64_new(uint max_num_labels) { asm_x64_t *as; @@ -147,8 +135,7 @@ asm_x64_t *asm_x64_new(uint max_num_labels) { void asm_x64_free(asm_x64_t *as, bool free_code) { if (free_code) { - // need to un-mmap - //m_free(as->code_base); + MP_PLAT_FREE_EXEC(as->code_base, as->code_size); } /* if (as->label != NULL) { @@ -176,11 +163,10 @@ void asm_x64_start_pass(asm_x64_t *as, uint pass) { void asm_x64_end_pass(asm_x64_t *as) { if (as->pass == ASM_X64_PASS_COMPUTE) { - // calculate size of code in bytes - as->code_size = as->code_offset; - //as->code_base = m_new(byte, as->code_size); need to allocale executable memory - uint actual_alloc; - as->code_base = alloc_mem(as->code_size, &actual_alloc, true); + MP_PLAT_ALLOC_EXEC(as->code_offset, (void**) &as->code_base, &as->code_size); + if(as->code_base == NULL) { + assert(0); + } //printf("code_size: %u\n", as->code_size); } |
