diff --git a/core/hw/aica/dsp_arm64.cpp b/core/hw/aica/dsp_arm64.cpp index 8a9cbb177..afa064943 100644 --- a/core/hw/aica/dsp_arm64.cpp +++ b/core/hw/aica/dsp_arm64.cpp @@ -328,7 +328,7 @@ public: FinalizeCode(); vmem_platform_flush_cache( - GetBuffer()->GetStartAddress(), GetBuffer()->GetEndAddress(), + GetBuffer()->GetStartAddress() + rx_offset, GetBuffer()->GetEndAddress() + rx_offset, GetBuffer()->GetStartAddress(), GetBuffer()->GetEndAddress()); } @@ -455,7 +455,7 @@ void dsp_recompile() void dsp_rec_init() { #ifdef FEAT_NO_RWX_PAGES - verify(vmem_platform_prepare_jit_block(dsp.DynCode, sizeof(dsp.DynCode), (void**)&pCodeBuffer, (uintptr_t *)&rx_offset)); + verify(vmem_platform_prepare_jit_block(dsp.DynCode, sizeof(dsp.DynCode), (void**)&pCodeBuffer, &rx_offset)); #else verify(vmem_platform_prepare_jit_block(dsp.DynCode, sizeof(dsp.DynCode), (void**)&pCodeBuffer)); #endif diff --git a/core/hw/arm7/arm7_rec.cpp b/core/hw/arm7/arm7_rec.cpp index 14c866b0c..412411297 100644 --- a/core/hw/arm7/arm7_rec.cpp +++ b/core/hw/arm7/arm7_rec.cpp @@ -562,7 +562,7 @@ void compile() // also the size of the EntryPoints table. This way the dynarec // main loop doesn't have to worry about the actual aica // ram size. The aica ram always wraps to 8 MB anyway. - EntryPoints[(pc & (ARAM_SIZE_MAX - 1)) / 4] = (void (*)())rv; + EntryPoints[(pc & (ARAM_SIZE_MAX - 1)) / 4] = (void (*)())writeToExec(rv); block_ops.clear(); @@ -657,7 +657,7 @@ void flush() void init() { #ifdef FEAT_NO_RWX_PAGES - verify(vmem_platform_prepare_jit_block(ARM7_TCB, ICacheSize, (void**)&ICache, (uintptr_t *)&rx_offset)); + verify(vmem_platform_prepare_jit_block(ARM7_TCB, ICacheSize, (void**)&ICache, &rx_offset)); #else verify(vmem_platform_prepare_jit_block(ARM7_TCB, ICacheSize, (void**)&ICache)); #endif diff --git a/core/hw/arm7/arm7_rec_arm64.cpp b/core/hw/arm7/arm7_rec_arm64.cpp index d3ec0d484..eea86b2db 100644 --- a/core/hw/arm7/arm7_rec_arm64.cpp +++ b/core/hw/arm7/arm7_rec_arm64.cpp @@ -602,7 +602,7 @@ public: FinalizeCode(); verify(GetBuffer()->GetCursorOffset() <= GetBuffer()->GetCapacity()); vmem_platform_flush_cache( - GetBuffer()->GetStartAddress(), GetBuffer()->GetEndAddress(), + recompiler::writeToExec(GetBuffer()->GetStartAddress()), recompiler::writeToExec(GetBuffer()->GetEndAddress()), GetBuffer()->GetStartAddress(), GetBuffer()->GetEndAddress()); recompiler::advance(GetBuffer()->GetSizeInBytes()); @@ -683,7 +683,7 @@ public: FinalizeCode(); vmem_platform_flush_cache( - GetBuffer()->GetStartAddress(), GetBuffer()->GetEndAddress(), + recompiler::writeToExec(GetBuffer()->GetStartAddress()), recompiler::writeToExec(GetBuffer()->GetEndAddress()), GetBuffer()->GetStartAddress(), GetBuffer()->GetEndAddress()); recompiler::advance(GetBuffer()->GetSizeInBytes()); } diff --git a/core/hw/mem/_vmem.h b/core/hw/mem/_vmem.h index 7776afa64..e4ab503fa 100644 --- a/core/hw/mem/_vmem.h +++ b/core/hw/mem/_vmem.h @@ -29,7 +29,7 @@ void vmem_platform_destroy(); bool vmem_platform_prepare_jit_block(void *code_area, unsigned size, void **code_area_rwx); // Same as above but uses two address spaces one with RX and RW protections. // Note: this function doesnt have to be implemented, it's a fallback for the above one. -bool vmem_platform_prepare_jit_block(void *code_area, unsigned size, void **code_area_rw, uintptr_t *rx_offset); +bool vmem_platform_prepare_jit_block(void *code_area, unsigned size, void **code_area_rw, ptrdiff_t *rx_offset); // This might not need an implementation (ie x86/64 cpus). void vmem_platform_flush_cache(void *icache_start, void *icache_end, void *dcache_start, void *dcache_end); diff --git a/core/hw/sh4/dyna/driver.cpp b/core/hw/sh4/dyna/driver.cpp index a87d2a0ab..6c514110b 100644 --- a/core/hw/sh4/dyna/driver.cpp +++ b/core/hw/sh4/dyna/driver.cpp @@ -33,7 +33,7 @@ u8 SH4_TCB[CODE_SIZE + TEMP_CODE_SIZE + 4096] u8* CodeCache; u8* TempCodeCache; -uintptr_t cc_rx_offset; +ptrdiff_t cc_rx_offset; u32 LastAddr; u32 LastAddr_min; diff --git a/core/hw/sh4/dyna/ngen.h b/core/hw/sh4/dyna/ngen.h index 4f3eaca20..10e76eea9 100644 --- a/core/hw/sh4/dyna/ngen.h +++ b/core/hw/sh4/dyna/ngen.h @@ -54,7 +54,7 @@ // (ie. exceptions) are RX pointers. These two macros convert between them by // sub/add the pointer offset. CodeCache will point to the RW pointer for simplicity. #ifdef FEAT_NO_RWX_PAGES - extern uintptr_t cc_rx_offset; + extern ptrdiff_t cc_rx_offset; #define CC_RW2RX(ptr) (void*)(((uintptr_t)(ptr)) + cc_rx_offset) #define CC_RX2RW(ptr) (void*)(((uintptr_t)(ptr)) - cc_rx_offset) #else diff --git a/core/linux/libnx_vmem.cpp b/core/linux/libnx_vmem.cpp index 2fa4b09e1..2e6a0b616 100644 --- a/core/linux/libnx_vmem.cpp +++ b/core/linux/libnx_vmem.cpp @@ -206,13 +206,9 @@ bool vmem_platform_prepare_jit_block(void *code_area, unsigned size, void **code } // Use two addr spaces: need to remap something twice, therefore use allocate_shared_filemem() -bool vmem_platform_prepare_jit_block(void *code_area, unsigned size, void **code_area_rw, uintptr_t *rx_offset) +bool vmem_platform_prepare_jit_block(void *code_area, unsigned size, void **code_area_rw, ptrdiff_t *rx_offset) { const unsigned size_aligned = ((size + PAGE_SIZE) & (~(PAGE_SIZE-1))); - void *ptr_rx = code_area; - - if (ptr_rx != code_area) - return false; virtmemLock(); void* ptr_rw = virtmemFindAslr(size_aligned, 0); @@ -226,8 +222,8 @@ bool vmem_platform_prepare_jit_block(void *code_area, unsigned size, void **code } *code_area_rw = ptr_rw; - *rx_offset = (char*)ptr_rx - (char*)ptr_rw; - INFO_LOG(DYNAREC, "Info: Using NO_RWX mode, rx ptr: %p, rw ptr: %p, offset: %lu\n", ptr_rx, ptr_rw, (unsigned long)*rx_offset); + *rx_offset = (char*)code_area - (char*)ptr_rw; + INFO_LOG(DYNAREC, "Info: Using NO_RWX mode, rx ptr: %p, rw ptr: %p, offset: %ld\n", code_area, ptr_rw, (long)*rx_offset); return true; } diff --git a/core/linux/posix_vmem.cpp b/core/linux/posix_vmem.cpp index 44a5d9b5b..2590edb67 100644 --- a/core/linux/posix_vmem.cpp +++ b/core/linux/posix_vmem.cpp @@ -258,7 +258,7 @@ bool vmem_platform_prepare_jit_block(void *code_area, unsigned size, void **code } // Use two addr spaces: need to remap something twice, therefore use allocate_shared_filemem() -bool vmem_platform_prepare_jit_block(void *code_area, unsigned size, void **code_area_rw, uintptr_t *rx_offset) { +bool vmem_platform_prepare_jit_block(void *code_area, unsigned size, void **code_area_rw, ptrdiff_t *rx_offset) { shmem_fd2 = allocate_shared_filemem(size); if (shmem_fd2 < 0) return false; @@ -278,7 +278,7 @@ bool vmem_platform_prepare_jit_block(void *code_area, unsigned size, void **code *code_area_rw = ptr_rw; *rx_offset = (char*)ptr_rx - (char*)ptr_rw; - INFO_LOG(DYNAREC, "Info: Using NO_RWX mode, rx ptr: %p, rw ptr: %p, offset: %lu", ptr_rx, ptr_rw, (unsigned long)*rx_offset); + INFO_LOG(DYNAREC, "Info: Using NO_RWX mode, rx ptr: %p, rw ptr: %p, offset: %ld", ptr_rx, ptr_rw, (long)*rx_offset); return (ptr_rw != MAP_FAILED); } diff --git a/core/windows/win_vmem.cpp b/core/windows/win_vmem.cpp index 71e15b729..4b8306c00 100644 --- a/core/windows/win_vmem.cpp +++ b/core/windows/win_vmem.cpp @@ -206,7 +206,7 @@ static void* mem_file_map(void *addr, unsigned size) { } // Use two addr spaces: need to remap something twice, therefore use CreateFileMapping() -bool vmem_platform_prepare_jit_block(void *code_area, unsigned size, void **code_area_rw, uintptr_t *rx_offset) { +bool vmem_platform_prepare_jit_block(void *code_area, unsigned size, void **code_area_rw, ptrdiff_t *rx_offset) { mem_handle2 = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_EXECUTE_READWRITE, 0, size, 0); // Get the RX page close to the code_area