[Memory/CPU] UWP: Support separate code execution and write memory, FromApp functions + other Windows memory fixes
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
#define XENIA_CPU_BACKEND_X64_X64_CODE_CACHE_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@@ -46,8 +48,10 @@ class X64CodeCache : public CodeCache {
|
||||
virtual bool Initialize();
|
||||
|
||||
const std::filesystem::path& file_name() const override { return file_name_; }
|
||||
uint32_t base_address() const override { return kGeneratedCodeBase; }
|
||||
uint32_t total_size() const override { return kGeneratedCodeSize; }
|
||||
uintptr_t execute_base_address() const override {
|
||||
return kGeneratedCodeExecuteBase;
|
||||
}
|
||||
size_t total_size() const override { return kGeneratedCodeSize; }
|
||||
|
||||
// TODO(benvanik): ELF serialization/etc
|
||||
// TODO(benvanik): keep track of code blocks
|
||||
@@ -59,11 +63,15 @@ class X64CodeCache : public CodeCache {
|
||||
|
||||
void CommitExecutableRange(uint32_t guest_low, uint32_t guest_high);
|
||||
|
||||
void* PlaceHostCode(uint32_t guest_address, void* machine_code,
|
||||
const EmitFunctionInfo& func_info);
|
||||
void* PlaceGuestCode(uint32_t guest_address, void* machine_code,
|
||||
const EmitFunctionInfo& func_info,
|
||||
GuestFunction* function_info);
|
||||
void PlaceHostCode(uint32_t guest_address, void* machine_code,
|
||||
const EmitFunctionInfo& func_info,
|
||||
void*& code_execute_address_out,
|
||||
void*& code_write_address_out);
|
||||
void PlaceGuestCode(uint32_t guest_address, void* machine_code,
|
||||
const EmitFunctionInfo& func_info,
|
||||
GuestFunction* function_info,
|
||||
void*& code_execute_address_out,
|
||||
void*& code_write_address_out);
|
||||
uint32_t PlaceData(const void* data, size_t length);
|
||||
|
||||
GuestFunction* LookupFunction(uint64_t host_pc) override;
|
||||
@@ -71,13 +79,16 @@ class X64CodeCache : public CodeCache {
|
||||
protected:
|
||||
// All executable code falls within 0x80000000 to 0x9FFFFFFF, so we can
|
||||
// only map enough for lookups within that range.
|
||||
static const uint64_t kIndirectionTableBase = 0x80000000;
|
||||
static const uint64_t kIndirectionTableSize = 0x1FFFFFFF;
|
||||
static const size_t kIndirectionTableSize = 0x1FFFFFFF;
|
||||
static const uintptr_t kIndirectionTableBase = 0x80000000;
|
||||
// The code range is 512MB, but we know the total code games will have is
|
||||
// pretty small (dozens of mb at most) and our expansion is reasonablish
|
||||
// so 256MB should be more than enough.
|
||||
static const uint64_t kGeneratedCodeBase = 0xA0000000;
|
||||
static const uint64_t kGeneratedCodeSize = 0x0FFFFFFF;
|
||||
static const size_t kGeneratedCodeSize = 0x0FFFFFFF;
|
||||
static const uintptr_t kGeneratedCodeExecuteBase = 0xA0000000;
|
||||
// Used for writing when PageAccess::kExecuteReadWrite is not supported.
|
||||
static const uintptr_t kGeneratedCodeWriteBase =
|
||||
kGeneratedCodeExecuteBase + kGeneratedCodeSize + 1;
|
||||
|
||||
// This is picked to be high enough to cover whatever we can reasonably
|
||||
// expect. If we hit issues with this it probably means some corner case
|
||||
@@ -96,7 +107,8 @@ class X64CodeCache : public CodeCache {
|
||||
return UnwindReservation();
|
||||
}
|
||||
virtual void PlaceCode(uint32_t guest_address, void* machine_code,
|
||||
const EmitFunctionInfo& func_info, void* code_address,
|
||||
const EmitFunctionInfo& func_info,
|
||||
void* code_execute_address,
|
||||
UnwindReservation unwind_reservation) {}
|
||||
|
||||
std::filesystem::path file_name_;
|
||||
@@ -114,9 +126,13 @@ class X64CodeCache : public CodeCache {
|
||||
// the generated code table that correspond to the PPC functions in guest
|
||||
// space.
|
||||
uint8_t* indirection_table_base_ = nullptr;
|
||||
// Fixed at kGeneratedCodeBase and holding all generated code, growing as
|
||||
// needed.
|
||||
uint8_t* generated_code_base_ = nullptr;
|
||||
// Fixed at kGeneratedCodeExecuteBase and holding all generated code, growing
|
||||
// as needed.
|
||||
uint8_t* generated_code_execute_base_ = nullptr;
|
||||
// View of the memory that backs generated_code_execute_base_ when
|
||||
// PageAccess::kExecuteReadWrite is not supported, for writing the generated
|
||||
// code. Equals to generated_code_execute_base_ when it's supported.
|
||||
uint8_t* generated_code_write_base_ = nullptr;
|
||||
// Current offset to empty space in generated code.
|
||||
size_t generated_code_offset_ = 0;
|
||||
// Current high water mark of COMMITTED code.
|
||||
|
||||
Reference in New Issue
Block a user