summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Lioncash2019-11-26 15:48:19 -0500
committerGravatar Lioncash2019-11-26 21:55:38 -0500
commitb2165c6b353be5e8117d1f9bc677bb198fa9d8cd (patch)
tree1b08113cf73a864c7c3e74cd4a3e1cca53879ce2
parentcore/memory: Migrate over GetPointer() (diff)
downloadyuzu-b2165c6b353be5e8117d1f9bc677bb198fa9d8cd.tar.gz
yuzu-b2165c6b353be5e8117d1f9bc677bb198fa9d8cd.tar.xz
yuzu-b2165c6b353be5e8117d1f9bc677bb198fa9d8cd.zip
core/memory: Migrate over ReadCString() to the Memory class
This only had one usage spot, so this is fairly straightforward to convert over.
-rw-r--r--src/core/hle/kernel/svc.cpp6
-rw-r--r--src/core/memory.cpp33
-rw-r--r--src/core/memory.h19
3 files changed, 40 insertions, 18 deletions
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 68bff11ec..738db528d 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -332,7 +332,9 @@ static ResultCode UnmapMemory(Core::System& system, VAddr dst_addr, VAddr src_ad
332/// Connect to an OS service given the port name, returns the handle to the port to out 332/// Connect to an OS service given the port name, returns the handle to the port to out
333static ResultCode ConnectToNamedPort(Core::System& system, Handle* out_handle, 333static ResultCode ConnectToNamedPort(Core::System& system, Handle* out_handle,
334 VAddr port_name_address) { 334 VAddr port_name_address) {
335 if (!system.Memory().IsValidVirtualAddress(port_name_address)) { 335 auto& memory = system.Memory();
336
337 if (!memory.IsValidVirtualAddress(port_name_address)) {
336 LOG_ERROR(Kernel_SVC, 338 LOG_ERROR(Kernel_SVC,
337 "Port Name Address is not a valid virtual address, port_name_address=0x{:016X}", 339 "Port Name Address is not a valid virtual address, port_name_address=0x{:016X}",
338 port_name_address); 340 port_name_address);
@@ -341,7 +343,7 @@ static ResultCode ConnectToNamedPort(Core::System& system, Handle* out_handle,
341 343
342 static constexpr std::size_t PortNameMaxLength = 11; 344 static constexpr std::size_t PortNameMaxLength = 11;
343 // Read 1 char beyond the max allowed port name to detect names that are too long. 345 // Read 1 char beyond the max allowed port name to detect names that are too long.
344 std::string port_name = Memory::ReadCString(port_name_address, PortNameMaxLength + 1); 346 const std::string port_name = memory.ReadCString(port_name_address, PortNameMaxLength + 1);
345 if (port_name.size() > PortNameMaxLength) { 347 if (port_name.size() > PortNameMaxLength) {
346 LOG_ERROR(Kernel_SVC, "Port name is too long, expected {} but got {}", PortNameMaxLength, 348 LOG_ERROR(Kernel_SVC, "Port name is too long, expected {} but got {}", PortNameMaxLength,
347 port_name.size()); 349 port_name.size());
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index 93cd67e39..fb824d710 100644
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -210,6 +210,21 @@ struct Memory::Impl {
210 return nullptr; 210 return nullptr;
211 } 211 }
212 212
213 std::string ReadCString(VAddr vaddr, std::size_t max_length) {
214 std::string string;
215 string.reserve(max_length);
216 for (std::size_t i = 0; i < max_length; ++i) {
217 const char c = Read8(vaddr);
218 if (c == '\0') {
219 break;
220 }
221 string.push_back(c);
222 ++vaddr;
223 }
224 string.shrink_to_fit();
225 return string;
226 }
227
213 /** 228 /**
214 * Maps a region of pages as a specific type. 229 * Maps a region of pages as a specific type.
215 * 230 *
@@ -299,6 +314,10 @@ const u8* Memory::GetPointer(VAddr vaddr) const {
299 return impl->GetPointer(vaddr); 314 return impl->GetPointer(vaddr);
300} 315}
301 316
317std::string Memory::ReadCString(VAddr vaddr, std::size_t max_length) {
318 return impl->ReadCString(vaddr, max_length);
319}
320
302void SetCurrentPageTable(Kernel::Process& process) { 321void SetCurrentPageTable(Kernel::Process& process) {
303 current_page_table = &process.VMManager().page_table; 322 current_page_table = &process.VMManager().page_table;
304 323
@@ -315,20 +334,6 @@ bool IsKernelVirtualAddress(const VAddr vaddr) {
315 return KERNEL_REGION_VADDR <= vaddr && vaddr < KERNEL_REGION_END; 334 return KERNEL_REGION_VADDR <= vaddr && vaddr < KERNEL_REGION_END;
316} 335}
317 336
318std::string ReadCString(VAddr vaddr, std::size_t max_length) {
319 std::string string;
320 string.reserve(max_length);
321 for (std::size_t i = 0; i < max_length; ++i) {
322 char c = Read8(vaddr);
323 if (c == '\0')
324 break;
325 string.push_back(c);
326 ++vaddr;
327 }
328 string.shrink_to_fit();
329 return string;
330}
331
332void RasterizerMarkRegionCached(VAddr vaddr, u64 size, bool cached) { 337void RasterizerMarkRegionCached(VAddr vaddr, u64 size, bool cached) {
333 if (vaddr == 0) { 338 if (vaddr == 0) {
334 return; 339 return;
diff --git a/src/core/memory.h b/src/core/memory.h
index 59b9ce2bb..47765c8a0 100644
--- a/src/core/memory.h
+++ b/src/core/memory.h
@@ -152,6 +152,23 @@ public:
152 */ 152 */
153 const u8* GetPointer(VAddr vaddr) const; 153 const u8* GetPointer(VAddr vaddr) const;
154 154
155 /**
156 * Reads a null-terminated string from the given virtual address.
157 * This function will continually read characters until either:
158 *
159 * - A null character ('\0') is reached.
160 * - max_length characters have been read.
161 *
162 * @note The final null-terminating character (if found) is not included
163 * in the returned string.
164 *
165 * @param vaddr The address to begin reading the string from.
166 * @param max_length The maximum length of the string to read in characters.
167 *
168 * @returns The read string.
169 */
170 std::string ReadCString(VAddr vaddr, std::size_t max_length);
171
155private: 172private:
156 struct Impl; 173 struct Impl;
157 std::unique_ptr<Impl> impl; 174 std::unique_ptr<Impl> impl;
@@ -182,8 +199,6 @@ void WriteBlock(VAddr dest_addr, const void* src_buffer, std::size_t size);
182void ZeroBlock(const Kernel::Process& process, VAddr dest_addr, std::size_t size); 199void ZeroBlock(const Kernel::Process& process, VAddr dest_addr, std::size_t size);
183void CopyBlock(VAddr dest_addr, VAddr src_addr, std::size_t size); 200void CopyBlock(VAddr dest_addr, VAddr src_addr, std::size_t size);
184 201
185std::string ReadCString(VAddr vaddr, std::size_t max_length);
186
187/** 202/**
188 * Mark each page touching the region as cached. 203 * Mark each page touching the region as cached.
189 */ 204 */