diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/hle/kernel/process.cpp | 6 | ||||
-rw-r--r-- | src/core/hle/kernel/process.h | 1 | ||||
-rw-r--r-- | src/core/hle/result.h | 58 | ||||
-rw-r--r-- | src/core/memory.cpp | 2 |
4 files changed, 22 insertions, 45 deletions
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 16eb972fb..24b266eae 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp @@ -130,9 +130,11 @@ void Process::Run(s32 main_thread_priority, u32 stack_size) { Kernel::SetupMainThread(codeset->entrypoint, main_thread_priority); } +VAddr Process::GetLinearHeapAreaAddress() const { + return kernel_version < 0x22C ? Memory::LINEAR_HEAP_VADDR : Memory::NEW_LINEAR_HEAP_VADDR; +} VAddr Process::GetLinearHeapBase() const { - return (kernel_version < 0x22C ? Memory::LINEAR_HEAP_VADDR : Memory::NEW_LINEAR_HEAP_VADDR) - + memory_region->base; + return GetLinearHeapAreaAddress() + memory_region->base; } VAddr Process::GetLinearHeapLimit() const { diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h index 60e17f251..6d2ca96a2 100644 --- a/src/core/hle/kernel/process.h +++ b/src/core/hle/kernel/process.h @@ -143,6 +143,7 @@ public: /// Bitmask of the used TLS slots std::bitset<300> used_tls_slots; + VAddr GetLinearHeapAreaAddress() const; VAddr GetLinearHeapBase() const; VAddr GetLinearHeapLimit() const; diff --git a/src/core/hle/result.h b/src/core/hle/result.h index 0fce5988b..69613fbbb 100644 --- a/src/core/hle/result.h +++ b/src/core/hle/result.h @@ -269,7 +269,6 @@ public: : result_code(error_code) { ASSERT(error_code.IsError()); - UpdateDebugPtr(); } /** @@ -287,40 +286,37 @@ public: : result_code(o.result_code) { if (!o.empty()) { - new (&storage) T(*o.GetPointer()); + new (&object) T(o.object); } - UpdateDebugPtr(); } ResultVal(ResultVal&& o) : result_code(o.result_code) { if (!o.empty()) { - new (&storage) T(std::move(*o.GetPointer())); + new (&object) T(std::move(o.object)); } - UpdateDebugPtr(); } ~ResultVal() { if (!empty()) { - GetPointer()->~T(); + object.~T(); } } ResultVal& operator=(const ResultVal& o) { if (!empty()) { if (!o.empty()) { - *GetPointer() = *o.GetPointer(); + object = o.object; } else { - GetPointer()->~T(); + object.~T(); } } else { if (!o.empty()) { - new (&storage) T(*o.GetPointer()); + new (&object) T(o.object); } } result_code = o.result_code; - UpdateDebugPtr(); return *this; } @@ -333,11 +329,10 @@ public: void emplace(ResultCode success_code, Args&&... args) { ASSERT(success_code.IsSuccess()); if (!empty()) { - GetPointer()->~T(); + object.~T(); } - new (&storage) T(std::forward<Args>(args)...); + new (&object) T(std::forward<Args>(args)...); result_code = success_code; - UpdateDebugPtr(); } /// Returns true if the `ResultVal` contains an error code and no value. @@ -350,15 +345,15 @@ public: ResultCode Code() const { return result_code; } - const T& operator* () const { return *GetPointer(); } - T& operator* () { return *GetPointer(); } - const T* operator->() const { return GetPointer(); } - T* operator->() { return GetPointer(); } + const T& operator* () const { return object; } + T& operator* () { return object; } + const T* operator->() const { return &object; } + T* operator->() { return &object; } /// Returns the value contained in this `ResultVal`, or the supplied default if it is missing. template <typename U> T ValueOr(U&& value) const { - return !empty() ? *GetPointer() : std::move(value); + return !empty() ? object : std::move(value); } /// Asserts that the result succeeded and returns a reference to it. @@ -372,31 +367,10 @@ public: } private: - typedef typename std::aligned_storage<sizeof(T), std::alignment_of<T>::value>::type StorageType; - - StorageType storage; + // A union is used to allocate the storage for the value, while allowing us to construct and + // destruct it at will. + union { T object; }; ResultCode result_code; -#ifdef _DEBUG - // The purpose of this pointer is to aid inspecting the type with a debugger, eliminating the - // need to cast `storage` to a pointer or pay attention to `result_code`. - const T* debug_ptr; -#endif - - void UpdateDebugPtr() { -#ifdef _DEBUG - debug_ptr = empty() ? nullptr : static_cast<const T*>(static_cast<const void*>(&storage)); -#endif - } - - const T* GetPointer() const { - ASSERT(!empty()); - return static_cast<const T*>(static_cast<const void*>(&storage)); - } - - T* GetPointer() { - ASSERT(!empty()); - return static_cast<T*>(static_cast<void*>(&storage)); - } }; /** diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 4753c63a7..7de5bd15d 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -291,7 +291,7 @@ VAddr PhysicalToVirtualAddress(const PAddr addr) { } else if (addr >= VRAM_PADDR && addr < VRAM_PADDR_END) { return addr - VRAM_PADDR + VRAM_VADDR; } else if (addr >= FCRAM_PADDR && addr < FCRAM_PADDR_END) { - return addr - FCRAM_PADDR + Kernel::g_current_process->GetLinearHeapBase(); + return addr - FCRAM_PADDR + Kernel::g_current_process->GetLinearHeapAreaAddress(); } else if (addr >= DSP_RAM_PADDR && addr < DSP_RAM_PADDR_END) { return addr - DSP_RAM_PADDR + DSP_RAM_VADDR; } else if (addr >= IO_AREA_PADDR && addr < IO_AREA_PADDR_END) { |