summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/hle/kernel/server_session.cpp3
-rw-r--r--src/core/memory.cpp38
-rw-r--r--src/core/memory.h22
3 files changed, 45 insertions, 18 deletions
diff --git a/src/core/hle/kernel/server_session.cpp b/src/core/hle/kernel/server_session.cpp
index 57878514d..1198c7a97 100644
--- a/src/core/hle/kernel/server_session.cpp
+++ b/src/core/hle/kernel/server_session.cpp
@@ -19,6 +19,7 @@
19#include "core/hle/kernel/server_session.h" 19#include "core/hle/kernel/server_session.h"
20#include "core/hle/kernel/session.h" 20#include "core/hle/kernel/session.h"
21#include "core/hle/kernel/thread.h" 21#include "core/hle/kernel/thread.h"
22#include "core/memory.h"
22 23
23namespace Kernel { 24namespace Kernel {
24 25
@@ -133,7 +134,7 @@ ResultCode ServerSession::HandleSyncRequest(std::shared_ptr<Thread> thread,
133 // from its ClientSession, so wake up any threads that may be waiting on a svcReplyAndReceive or 134 // from its ClientSession, so wake up any threads that may be waiting on a svcReplyAndReceive or
134 // similar. 135 // similar.
135 Kernel::HLERequestContext context(SharedFrom(this), thread); 136 Kernel::HLERequestContext context(SharedFrom(this), thread);
136 u32* cmd_buf = (u32*)Memory::GetPointer(thread->GetTLSAddress()); 137 u32* cmd_buf = (u32*)memory.GetPointer(thread->GetTLSAddress());
137 context.PopulateFromIncomingCommandBuffer(kernel.CurrentProcess()->GetHandleTable(), cmd_buf); 138 context.PopulateFromIncomingCommandBuffer(kernel.CurrentProcess()->GetHandleTable(), cmd_buf);
138 139
139 ResultCode result = RESULT_SUCCESS; 140 ResultCode result = RESULT_SUCCESS;
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index 017033613..93cd67e39 100644
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -195,6 +195,21 @@ struct Memory::Impl {
195 return IsValidVirtualAddress(*system.CurrentProcess(), vaddr); 195 return IsValidVirtualAddress(*system.CurrentProcess(), vaddr);
196 } 196 }
197 197
198 u8* GetPointer(const VAddr vaddr) {
199 u8* const page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS];
200 if (page_pointer != nullptr) {
201 return page_pointer + (vaddr & PAGE_MASK);
202 }
203
204 if (current_page_table->attributes[vaddr >> PAGE_BITS] ==
205 Common::PageType::RasterizerCachedMemory) {
206 return GetPointerFromVMA(vaddr);
207 }
208
209 LOG_ERROR(HW_Memory, "Unknown GetPointer @ 0x{:016X}", vaddr);
210 return nullptr;
211 }
212
198 /** 213 /**
199 * Maps a region of pages as a specific type. 214 * Maps a region of pages as a specific type.
200 * 215 *
@@ -276,6 +291,14 @@ bool Memory::IsValidVirtualAddress(const VAddr vaddr) const {
276 return impl->IsValidVirtualAddress(vaddr); 291 return impl->IsValidVirtualAddress(vaddr);
277} 292}
278 293
294u8* Memory::GetPointer(VAddr vaddr) {
295 return impl->GetPointer(vaddr);
296}
297
298const u8* Memory::GetPointer(VAddr vaddr) const {
299 return impl->GetPointer(vaddr);
300}
301
279void SetCurrentPageTable(Kernel::Process& process) { 302void SetCurrentPageTable(Kernel::Process& process) {
280 current_page_table = &process.VMManager().page_table; 303 current_page_table = &process.VMManager().page_table;
281 304
@@ -292,21 +315,6 @@ bool IsKernelVirtualAddress(const VAddr vaddr) {
292 return KERNEL_REGION_VADDR <= vaddr && vaddr < KERNEL_REGION_END; 315 return KERNEL_REGION_VADDR <= vaddr && vaddr < KERNEL_REGION_END;
293} 316}
294 317
295u8* GetPointer(const VAddr vaddr) {
296 u8* page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS];
297 if (page_pointer) {
298 return page_pointer + (vaddr & PAGE_MASK);
299 }
300
301 if (current_page_table->attributes[vaddr >> PAGE_BITS] ==
302 Common::PageType::RasterizerCachedMemory) {
303 return GetPointerFromVMA(vaddr);
304 }
305
306 LOG_ERROR(HW_Memory, "Unknown GetPointer @ 0x{:016X}", vaddr);
307 return nullptr;
308}
309
310std::string ReadCString(VAddr vaddr, std::size_t max_length) { 318std::string ReadCString(VAddr vaddr, std::size_t max_length) {
311 std::string string; 319 std::string string;
312 string.reserve(max_length); 320 string.reserve(max_length);
diff --git a/src/core/memory.h b/src/core/memory.h
index cacf4fb1a..59b9ce2bb 100644
--- a/src/core/memory.h
+++ b/src/core/memory.h
@@ -132,6 +132,26 @@ public:
132 */ 132 */
133 bool IsValidVirtualAddress(VAddr vaddr) const; 133 bool IsValidVirtualAddress(VAddr vaddr) const;
134 134
135 /**
136 * Gets a pointer to the given address.
137 *
138 * @param vaddr Virtual address to retrieve a pointer to.
139 *
140 * @returns The pointer to the given address, if the address is valid.
141 * If the address is not valid, nullptr will be returned.
142 */
143 u8* GetPointer(VAddr vaddr);
144
145 /**
146 * Gets a pointer to the given address.
147 *
148 * @param vaddr Virtual address to retrieve a pointer to.
149 *
150 * @returns The pointer to the given address, if the address is valid.
151 * If the address is not valid, nullptr will be returned.
152 */
153 const u8* GetPointer(VAddr vaddr) const;
154
135private: 155private:
136 struct Impl; 156 struct Impl;
137 std::unique_ptr<Impl> impl; 157 std::unique_ptr<Impl> impl;
@@ -162,8 +182,6 @@ void WriteBlock(VAddr dest_addr, const void* src_buffer, std::size_t size);
162void ZeroBlock(const Kernel::Process& process, VAddr dest_addr, std::size_t size); 182void ZeroBlock(const Kernel::Process& process, VAddr dest_addr, std::size_t size);
163void CopyBlock(VAddr dest_addr, VAddr src_addr, std::size_t size); 183void CopyBlock(VAddr dest_addr, VAddr src_addr, std::size_t size);
164 184
165u8* GetPointer(VAddr vaddr);
166
167std::string ReadCString(VAddr vaddr, std::size_t max_length); 185std::string ReadCString(VAddr vaddr, std::size_t max_length);
168 186
169/** 187/**