VERY experimental Nintendo Switch 2 emulator
C++
kernel: Various 64-bit fixes in memory/process/thread
bunnei78531342a4fc
diff --git a/src/core/hle/kernel/memory.h b/src/core/hle/kernel/memory.hindex da6bb35633..61e30c679a 100644--- a/src/core/hle/kernel/memory.h+++ b/src/core/hle/kernel/memory.h@@ -13,9 +13,9 @@ namespace Kernel {class VMManager;struct MemoryRegionInfo {- u32 base; // Not an address, but offset from start of FCRAM- u32 size;- u32 used;+ u64 base; // Not an address, but offset from start of FCRAM+ u64 size;+ u64 used;std::shared_ptr<std::vector<u8>> linear_heap_memory;};diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cppindex 9bcb08fc96..80b1be1fd0 100644--- a/src/core/hle/kernel/process.cpp+++ b/src/core/hle/kernel/process.cpp@@ -167,7 +167,7 @@ VAddr Process::GetLinearHeapLimit() const {return GetLinearHeapBase() + memory_region->size;}-ResultVal<VAddr> Process::HeapAllocate(VAddr target, u32 size, VMAPermission perms) {+ResultVal<VAddr> Process::HeapAllocate(VAddr target, u64 size, VMAPermission perms) {if (target < Memory::HEAP_VADDR || target + size > Memory::HEAP_VADDR_END ||target + size < target) {return ERR_INVALID_ADDRESS;diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.hindex 3b646c076d..6774168e53 100644--- a/src/core/hle/kernel/process.h+++ b/src/core/hle/kernel/process.h@@ -19,7 +19,7 @@ namespace Kernel {struct AddressMapping {// Address and size must be page-alignedVAddr address;- u32 size;+ u64 size;bool read_only;bool unk_flag;};@@ -154,7 +154,7 @@ public:// The left/right bounds of the address space covered by heap_memory.VAddr heap_start = 0, heap_end = 0;- u32 heap_used = 0, linear_heap_used = 0, misc_memory_used = 0;+ u64 heap_used = 0, linear_heap_used = 0, misc_memory_used = 0;MemoryRegionInfo* memory_region = nullptr;@@ -171,7 +171,7 @@ public:VAddr GetLinearHeapBase() const;VAddr GetLinearHeapLimit() const;- ResultVal<VAddr> HeapAllocate(VAddr target, u32 size, VMAPermission perms);+ ResultVal<VAddr> HeapAllocate(VAddr target, u64 size, VMAPermission perms);ResultCode HeapFree(VAddr target, u32 size);ResultVal<VAddr> LinearAllocate(VAddr target, u32 size, VMAPermission perms);diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cppindex 372cafdd98..1645437b68 100644--- a/src/core/hle/kernel/thread.cpp+++ b/src/core/hle/kernel/thread.cpp@@ -103,8 +103,8 @@ void Thread::Stop() {ReleaseThreadMutexes(this);// Mark the TLS slot in the thread's page as free.- u32 tls_page = (tls_address - Memory::TLS_AREA_VADDR) / Memory::PAGE_SIZE;- u32 tls_slot =+ u64 tls_page = (tls_address - Memory::TLS_AREA_VADDR) / Memory::PAGE_SIZE;+ u64 tls_slot =((tls_address - Memory::TLS_AREA_VADDR) % Memory::PAGE_SIZE) / Memory::TLS_ENTRY_SIZE;Kernel::g_current_process->tls_slots[tls_page].reset(tls_slot);}@@ -184,7 +184,7 @@ static void SwitchContext(Thread* new_thread) {}Core::CPU().LoadContext(new_thread->context);- Core::CPU().SetCP15Register(CP15_THREAD_URO, new_thread->GetTLSAddress());+ Core::CPU().SetTlsAddress(new_thread->GetTLSAddress());} else {current_thread = nullptr;// Note: We do not reset the current process and current page table when idling because@@ -369,7 +369,7 @@ static void ResetThreadContext(ARM_Interface::ThreadContext& context, VAddr stac}ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, u32 priority,- u32 arg, s32 processor_id, VAddr stack_top,+ u64 arg, s32 processor_id, VAddr stack_top,SharedPtr<Process> owner_process) {// Check if priority is in ranged. Lowest priority -> highest priority id.if (priority > THREADPRIO_LOWEST) {@@ -493,7 +493,7 @@ void Thread::BoostPriority(u32 priority) {current_priority = priority;}-SharedPtr<Thread> SetupMainThread(u32 entry_point, u32 priority, SharedPtr<Process> owner_process) {+SharedPtr<Thread> SetupMainThread(VAddr entry_point, u32 priority, SharedPtr<Process> owner_process) {// Setup page table so we can write to memorySetCurrentPageTable(&Kernel::g_current_process->vm_manager.page_table);diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.hindex fafcab156a..25d678ba37 100644--- a/src/core/hle/kernel/thread.h+++ b/src/core/hle/kernel/thread.h@@ -65,7 +65,7 @@ public:* @return A shared pointer to the newly created thread*/static ResultVal<SharedPtr<Thread>> Create(std::string name, VAddr entry_point, u32 priority,- u32 arg, s32 processor_id, VAddr stack_top,+ u64 arg, s32 processor_id, VAddr stack_top,SharedPtr<Process> owner_process);std::string GetName() const override {@@ -234,7 +234,7 @@ private:* @param owner_process The parent process for the main thread* @return A shared pointer to the main thread*/-SharedPtr<Thread> SetupMainThread(u32 entry_point, u32 priority, SharedPtr<Process> owner_process);+SharedPtr<Thread> SetupMainThread(VAddr entry_point, u32 priority, SharedPtr<Process> owner_process);/*** Returns whether there are any threads that are ready to run.