Memory/Utils: Added a function to retrieve a string from emulated memory.

This commit is contained in:
Subv 2016-01-02 16:16:23 -05:00 committed by Sean Maas
parent 4b1ae3a24e
commit d964ab667f
2 changed files with 24 additions and 5 deletions

View file

@ -183,6 +183,15 @@ u8* GetPointer(const VAddr vaddr) {
return nullptr; return nullptr;
} }
std::string GetString(const VAddr vaddr, const u32 size) {
std::string string;
string.reserve(size);
for (u32 offset = 0; offset < size; ++offset)
string.push_back(Read8(vaddr + offset));
return string;
}
u8* GetPhysicalPointer(PAddr address) { u8* GetPhysicalPointer(PAddr address) {
return GetPointer(PhysicalToVirtualAddress(address)); return GetPointer(PhysicalToVirtualAddress(address));
} }

View file

@ -5,6 +5,7 @@
#pragma once #pragma once
#include <cstddef> #include <cstddef>
#include <string>
#include "common/common_types.h" #include "common/common_types.h"
@ -131,14 +132,23 @@ void WriteBlock(VAddr addr, const u8* data, size_t size);
u8* GetPointer(VAddr virtual_address); u8* GetPointer(VAddr virtual_address);
/** /**
* Converts a virtual address inside a region with 1:1 mapping to physical memory to a physical * Reads a fixed-size string of the specified size starting at
* address. This should be used by services to translate addresses for use by the hardware. * the specified address and returns a copy of it.
*/ * @param vaddr Starting address of the string.
* @param size Size of the string.
* @return A copy of the string that was read.
*/
std::string GetString(const VAddr vaddr, const u32 size);
/**
* Converts a virtual address inside a region with 1:1 mapping to physical memory to a physical
* address. This should be used by services to translate addresses for use by the hardware.
*/
PAddr VirtualToPhysicalAddress(VAddr addr); PAddr VirtualToPhysicalAddress(VAddr addr);
/** /**
* Undoes a mapping performed by VirtualToPhysicalAddress(). * Undoes a mapping performed by VirtualToPhysicalAddress().
*/ */
VAddr PhysicalToVirtualAddress(PAddr addr); VAddr PhysicalToVirtualAddress(PAddr addr);
/** /**