"Fix" debug console, we were checking the cvar before any cvars were loaded, and the condition it checks in AttachConsole is somehow always false
Remove dead #if 0'd code in math.h On amd64, page_size == 4096 constant, on amd64 w/ win32, allocation_granularity == 65536. These values for x86 windows havent changed over the last 20 years so this is probably safe and gives a modest code size reduction Enable XE_USE_KUSER_SHARED. This sources host time from KUSER_SHARED instead of from QueryPerformanceCounter, which is far faster, but only has a granularity of 100 nanoseconds. In some games seemingly random crashes were happening that were hard to trace because the faulting thread was actually not the one that was misbehaving, another threads stack was underflowing into the faulting thread. Added a bunch of code to synchronize the guest stack and host stack so that if a guest longjmps the host's stack will be adjusted. Changes were also made to allow the guest to call into a piece of an existing x64 function. This synchronization might have a slight performance impact on lower end cpus, to disable it set enable_host_guest_stack_synchronization to false. It is possible it may have introduced regressions, but i dont know of any yet So far, i know the synchronization change fixes the "hub crash" in super sonic and allows the game "london 2012" to go ingame. Removed emit_useless_fpscr_updates, not emitting these updates breaks the raiden game MapGuestAddressToMachineCode now returns nullptr if no address was found, instead of the start of the function add Processor::LookupModule Add Backend::DeinitializeBackendContext Use WriteRegisterRangeFromRing_WithKnownBound<0, 0xFFFF> in WriteRegisterRangeFromRing for inlining (previously regressed on performance of ExecutePacketType0) add notes about flags that trap in XamInputGetCapabilities 0 == 3 in XamInputGetCapabilities Name arg 2 of XamInputSetState PrefetchW in critical section kernel funcs if available & doing cmpxchg Add terminated field to X_KTHREAD, set it on termination Expanded the logic of NtResumeThread/NtSuspendThread to include checking the type of the handle (in release, LookupObject doesnt seem to do anything with the type) and returning X_STATUS_OBJECT_TYPE_MISMATCH if invalid. Do termination check in NtSuspendThread. Add basic host exception messagebox, need to flesh it out more (maybe use the new stack tracking stuff if on guest thrd?) Add rdrand patching hack, mostly affects users with nvidia cards who have many threads on zen Use page_size_shift in more places Once again disable precompilation! Raiden is mostly weird ppc asm which probably breaks the precompilation. The code is still useful for running the compiler over the whole of an xex in debug to test for issues "Fix" debug console, we were checking the cvar before any cvars were loaded, and the condition it checks in AttachConsole is somehow always false Remove dead #if 0'd code in math.h On amd64, page_size == 4096 constant, on amd64 w/ win32, allocation_granularity == 65536. These values for x86 windows havent changed over the last 20 years so this is probably safe and gives a modest code size reduction Enable XE_USE_KUSER_SHARED. This sources host time from KUSER_SHARED instead of from QueryPerformanceCounter, which is far faster, but only has a granularity of 100 nanoseconds. In some games seemingly random crashes were happening that were hard to trace because the faulting thread was actually not the one that was misbehaving, another threads stack was underflowing into the faulting thread. Added a bunch of code to synchronize the guest stack and host stack so that if a guest longjmps the host's stack will be adjusted. Changes were also made to allow the guest to call into a piece of an existing x64 function. This synchronization might have a slight performance impact on lower end cpus, to disable it set enable_host_guest_stack_synchronization to false. It is possible it may have introduced regressions, but i dont know of any yet So far, i know the synchronization change fixes the "hub crash" in super sonic and allows the game "london 2012" to go ingame. Removed emit_useless_fpscr_updates, not emitting these updates breaks the raiden game MapGuestAddressToMachineCode now returns nullptr if no address was found, instead of the start of the function add Processor::LookupModule Add Backend::DeinitializeBackendContext Use WriteRegisterRangeFromRing_WithKnownBound<0, 0xFFFF> in WriteRegisterRangeFromRing for inlining (previously regressed on performance of ExecutePacketType0) add notes about flags that trap in XamInputGetCapabilities 0 == 3 in XamInputGetCapabilities Name arg 2 of XamInputSetState PrefetchW in critical section kernel funcs if available & doing cmpxchg Add terminated field to X_KTHREAD, set it on termination Expanded the logic of NtResumeThread/NtSuspendThread to include checking the type of the handle (in release, LookupObject doesnt seem to do anything with the type) and returning X_STATUS_OBJECT_TYPE_MISMATCH if invalid. Do termination check in NtSuspendThread. Add basic host exception messagebox, need to flesh it out more (maybe use the new stack tracking stuff if on guest thrd?) Add rdrand patching hack, mostly affects users with nvidia cards who have many threads on zen Use page_size_shift in more places Once again disable precompilation! Raiden is mostly weird ppc asm which probably breaks the precompilation. The code is still useful for running the compiler over the whole of an xex in debug to test for issues
This commit is contained in:
@@ -316,8 +316,8 @@ void Memory::Reset() {
|
||||
heaps_.v90000000.Reset();
|
||||
heaps_.physical.Reset();
|
||||
}
|
||||
//clang does not like non-standard layout offsetof
|
||||
#if XE_COMPILER_MSVC == 1 && XE_COMPILER_CLANG_CL==0
|
||||
// clang does not like non-standard layout offsetof
|
||||
#if XE_COMPILER_MSVC == 1 && XE_COMPILER_CLANG_CL == 0
|
||||
XE_NOALIAS
|
||||
const BaseHeap* Memory::LookupHeap(uint32_t address) const {
|
||||
#define HEAP_INDEX(name) \
|
||||
@@ -359,7 +359,6 @@ const BaseHeap* Memory::LookupHeap(uint32_t address) const {
|
||||
#else
|
||||
XE_NOALIAS
|
||||
const BaseHeap* Memory::LookupHeap(uint32_t address) const {
|
||||
|
||||
if (address < 0x40000000) {
|
||||
return &heaps_.v00000000;
|
||||
} else if (address < 0x7F000000) {
|
||||
@@ -964,6 +963,14 @@ bool BaseHeap::AllocFixed(uint32_t base_address, uint32_t size,
|
||||
|
||||
return true;
|
||||
}
|
||||
template<typename T>
|
||||
static inline T QuickMod(T value, uint32_t modv) {
|
||||
if (xe::is_pow2(modv)) {
|
||||
return value & (modv - 1);
|
||||
} else {
|
||||
return value % modv;
|
||||
}
|
||||
}
|
||||
|
||||
bool BaseHeap::AllocRange(uint32_t low_address, uint32_t high_address,
|
||||
uint32_t size, uint32_t alignment,
|
||||
@@ -976,8 +983,9 @@ bool BaseHeap::AllocRange(uint32_t low_address, uint32_t high_address,
|
||||
low_address = std::max(heap_base_, xe::align(low_address, alignment));
|
||||
high_address = std::min(heap_base_ + (heap_size_ - 1),
|
||||
xe::align(high_address, alignment));
|
||||
uint32_t low_page_number = (low_address - heap_base_) / page_size_;
|
||||
uint32_t high_page_number = (high_address - heap_base_) / page_size_;
|
||||
|
||||
uint32_t low_page_number = (low_address - heap_base_) >> page_size_shift_;
|
||||
uint32_t high_page_number = (high_address - heap_base_) >> page_size_shift_;
|
||||
low_page_number = std::min(uint32_t(page_table_.size()) - 1, low_page_number);
|
||||
high_page_number =
|
||||
std::min(uint32_t(page_table_.size()) - 1, high_page_number);
|
||||
@@ -995,8 +1003,10 @@ bool BaseHeap::AllocRange(uint32_t low_address, uint32_t high_address,
|
||||
// TODO(benvanik): optimized searching (free list buckets, bitmap, etc).
|
||||
uint32_t start_page_number = UINT_MAX;
|
||||
uint32_t end_page_number = UINT_MAX;
|
||||
uint32_t page_scan_stride = alignment / page_size_;
|
||||
high_page_number = high_page_number - (high_page_number % page_scan_stride);
|
||||
// chrispy:todo, page_scan_stride is probably always a power of two...
|
||||
uint32_t page_scan_stride = alignment >> page_size_shift_;
|
||||
high_page_number =
|
||||
high_page_number - QuickMod(high_page_number, page_scan_stride);
|
||||
if (top_down) {
|
||||
for (int64_t base_page_number =
|
||||
high_page_number - xe::round_up(page_count, page_scan_stride);
|
||||
@@ -1024,7 +1034,7 @@ bool BaseHeap::AllocRange(uint32_t low_address, uint32_t high_address,
|
||||
base_page_number = -1;
|
||||
} else {
|
||||
base_page_number = page_number - page_count;
|
||||
base_page_number -= base_page_number % page_scan_stride;
|
||||
base_page_number -= QuickMod(base_page_number, page_scan_stride);
|
||||
base_page_number += page_scan_stride; // cancel out loop logic
|
||||
}
|
||||
break;
|
||||
@@ -1072,7 +1082,7 @@ bool BaseHeap::AllocRange(uint32_t low_address, uint32_t high_address,
|
||||
if (start_page_number == UINT_MAX || end_page_number == UINT_MAX) {
|
||||
// Out of memory.
|
||||
XELOGE("BaseHeap::Alloc failed to find contiguous range");
|
||||
//assert_always("Heap exhausted!");
|
||||
// assert_always("Heap exhausted!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1084,15 +1094,15 @@ bool BaseHeap::AllocRange(uint32_t low_address, uint32_t high_address,
|
||||
? xe::memory::AllocationType::kCommit
|
||||
: xe::memory::AllocationType::kReserve;
|
||||
void* result = xe::memory::AllocFixed(
|
||||
TranslateRelative(start_page_number * page_size_),
|
||||
page_count * page_size_, alloc_type, ToPageAccess(protect));
|
||||
TranslateRelative(start_page_number << page_size_shift_),
|
||||
page_count << page_size_shift_, alloc_type, ToPageAccess(protect));
|
||||
if (!result) {
|
||||
XELOGE("BaseHeap::Alloc failed to alloc range from host");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cvars::scribble_heap && (protect & kMemoryProtectWrite)) {
|
||||
std::memset(result, 0xCD, page_count * page_size_);
|
||||
std::memset(result, 0xCD, page_count << page_size_shift_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1108,7 +1118,7 @@ bool BaseHeap::AllocRange(uint32_t low_address, uint32_t high_address,
|
||||
unreserved_page_count_--;
|
||||
}
|
||||
|
||||
*out_address = heap_base_ + (start_page_number * page_size_);
|
||||
*out_address = heap_base_ + (start_page_number << page_size_shift_);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1719,8 +1729,7 @@ XE_NOINLINE void PhysicalHeap::EnableAccessCallbacksInner(
|
||||
uint32_t first_guest_page = SystemPagenumToGuestPagenum(system_page_first);
|
||||
uint32_t last_guest_page = SystemPagenumToGuestPagenum(system_page_last);
|
||||
|
||||
uint32_t guest_one =
|
||||
SystemPagenumToGuestPagenum(1);
|
||||
uint32_t guest_one = SystemPagenumToGuestPagenum(1);
|
||||
|
||||
uint32_t system_one = GuestPagenumToSystemPagenum(1);
|
||||
for (; i <= system_page_last; ++i) {
|
||||
@@ -1755,7 +1764,6 @@ XE_NOINLINE void PhysicalHeap::EnableAccessCallbacksInner(
|
||||
#endif
|
||||
|
||||
uint32_t guest_page_number = SystemPagenumToGuestPagenum(i);
|
||||
//swcache::PrefetchL1(&page_table_ptr[guest_page_number + 8]);
|
||||
xe::memory::PageAccess current_page_access =
|
||||
ToPageAccess(page_table_ptr[guest_page_number].current_protect);
|
||||
bool protect_system_page = false;
|
||||
|
||||
Reference in New Issue
Block a user