backend\A64\emitter: Fix Windows build

constify

constify2

constify3: the uncostification
This commit is contained in:
SachinVin 2022-05-30 22:20:10 +05:30
parent 8e0ec356c0
commit 0d66d30d42
2 changed files with 20 additions and 14 deletions

View File

@ -8,10 +8,6 @@
#include <cstring>
#include <vector>
#if defined(__APPLE__)
#include <libkern/OSCacheControl.h>
#endif
#include <mcl/assert.hpp>
#include <mcl/bit_cast.hpp>
#include <mcl/bit/bit_count.hpp>
@ -20,6 +16,13 @@
#include "a64_emitter.h"
#include "dynarmic/common/math_util.h"
#ifdef _WIN32
# include <Windows.h>
#endif
#ifdef __APPLE__
# include <libkern/OSCacheControl.h>
#endif
namespace Dynarmic::BackendA64::Arm64Gen {
namespace {
@ -37,6 +40,7 @@ int CountLeadingZeros(u64 value, int width) {
return __builtin_clzll(value);
}
#endif
// TODO(jbramley): Optimize this for ARM64 hosts.
int count = 0;
uint64_t bit_test = 1ULL << (width - 1);
@ -367,10 +371,11 @@ void ARM64XEmitter::FlushIcacheSection(const u8* start, const u8* end) {
if (start == end)
return;
#if defined(__APPLE__)
// Header file says this is equivalent to: sys_icache_invalidate(start, end -
// start);
#if defined(IOS) || defined(__APPLE__)
// Header file says this is equivalent to: sys_icache_invalidate(start, end - start);
sys_cache_control(kCacheFunctionPrepareForExecution, const_cast<u8*>(start), end - start);
#elif defined(WIN32)
FlushInstructionCache(GetCurrentProcess(), start, end - start);
#else
// Don't rely on GCC's __clear_cache implementation, as it caches
// icache/dcache cache line sizes, that can vary between cores on

View File

@ -82,7 +82,13 @@ public:
// it'll do the job.
void FreeCodeSpace() {
ASSERT(!m_is_child);
ASSERT(munmap(region, total_region_size) == 0);
if (region) {
#ifdef _WIN32
ASSERT(VirtualFree(region, 0, MEM_RELEASE));
#else
ASSERT(munmap(region, total_region_size) == 0);
#endif
}
region = nullptr;
region_size = 0;
total_region_size = 0;
@ -96,12 +102,7 @@ public:
bool IsInSpace(const u8* ptr) const {
return ptr >= region && ptr < (region + region_size);
}
// Cannot currently be undone. Will write protect the entire code region.
// Start over if you need to change the code (call FreeCodeSpace(),
// AllocCodeSpace()).
void WriteProtect() {
ASSERT(mprotect(region, region_size, PROT_READ | PROT_EXEC) != 0);
}
void ResetCodePtr() {
T::SetCodePtr(region);
}