summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
/// Connect to an OS service given the port name, returns the handle to the port to out
static ResultCode ConnectToNamedPort(Core::System& system, Handle* out_handle,
VAddr port_name_address) {
- if (!system.Memory().IsValidVirtualAddress(port_name_address)) {
+ auto& memory = system.Memory();
+
+ if (!memory.IsValidVirtualAddress(port_name_address)) {
LOG_ERROR(Kernel_SVC,
"Port Name Address is not a valid virtual address, port_name_address=0x{:016X}",
port_name_address);
@@ -341,7 +343,7 @@ static ResultCode ConnectToNamedPort(Core::System& system, Handle* out_handle,
static constexpr std::size_t PortNameMaxLength = 11;
// Read 1 char beyond the max allowed port name to detect names that are too long.
- std::string port_name = Memory::ReadCString(port_name_address, PortNameMaxLength + 1);
+ const std::string port_name = memory.ReadCString(port_name_address, PortNameMaxLength + 1);
if (port_name.size() > PortNameMaxLength) {
LOG_ERROR(Kernel_SVC, "Port name is too long, expected {} but got {}", PortNameMaxLength,
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 {
return nullptr;
}
+ std::string ReadCString(VAddr vaddr, std::size_t max_length) {
+ std::string string;
+ string.reserve(max_length);
+ for (std::size_t i = 0; i < max_length; ++i) {
+ const char c = Read8(vaddr);
+ if (c == '\0') {
+ break;
+ }
+ string.push_back(c);
+ ++vaddr;
+ }
+ string.shrink_to_fit();
+ return string;
+ }
+
/**
* Maps a region of pages as a specific type.
*
@@ -299,6 +314,10 @@ const u8* Memory::GetPointer(VAddr vaddr) const {
return impl->GetPointer(vaddr);
}
+std::string Memory::ReadCString(VAddr vaddr, std::size_t max_length) {
+ return impl->ReadCString(vaddr, max_length);
+}
+
void SetCurrentPageTable(Kernel::Process& process) {
current_page_table = &process.VMManager().page_table;
@@ -315,20 +334,6 @@ bool IsKernelVirtualAddress(const VAddr vaddr) {
return KERNEL_REGION_VADDR <= vaddr && vaddr < KERNEL_REGION_END;
}
-std::string ReadCString(VAddr vaddr, std::size_t max_length) {
- std::string string;
- string.reserve(max_length);
- for (std::size_t i = 0; i < max_length; ++i) {
- char c = Read8(vaddr);
- if (c == '\0')
- break;
- string.push_back(c);
- ++vaddr;
- }
- string.shrink_to_fit();
- return string;
-}
-
void RasterizerMarkRegionCached(VAddr vaddr, u64 size, bool cached) {
if (vaddr == 0) {
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:
*/
const u8* GetPointer(VAddr vaddr) const;
+ /**
+ * Reads a null-terminated string from the given virtual address.
+ * This function will continually read characters until either:
+ *
+ * - A null character ('\0') is reached.
+ * - max_length characters have been read.
+ *
+ * @note The final null-terminating character (if found) is not included
+ * in the returned string.
+ *
+ * @param vaddr The address to begin reading the string from.
+ * @param max_length The maximum length of the string to read in characters.
+ *
+ * @returns The read string.
+ */
+ std::string ReadCString(VAddr vaddr, std::size_t max_length);
+
private:
struct Impl;
std::unique_ptr<Impl> impl;
@@ -182,8 +199,6 @@ void WriteBlock(VAddr dest_addr, const void* src_buffer, std::size_t size);
void ZeroBlock(const Kernel::Process& process, VAddr dest_addr, std::size_t size);
void CopyBlock(VAddr dest_addr, VAddr src_addr, std::size_t size);
-std::string ReadCString(VAddr vaddr, std::size_t max_length);
-
/**
* Mark each page touching the region as cached.
*/