Memory: move IsValidVirtualAddress into class

This commit is contained in:
Weiyi Wang 2018-11-21 12:30:07 -05:00
parent 296c458e0e
commit 405218c3a7
6 changed files with 27 additions and 26 deletions

View file

@ -831,8 +831,8 @@ static void ReadMemory() {
SendReply("E01");
}
if (!Memory::IsValidVirtualAddress(*Core::System::GetInstance().Kernel().GetCurrentProcess(),
addr)) {
if (!Core::System::GetInstance().Memory().IsValidVirtualAddress(
*Core::System::GetInstance().Kernel().GetCurrentProcess(), addr)) {
return SendReply("E00");
}
@ -855,8 +855,8 @@ static void WriteMemory() {
auto len_pos = std::find(start_offset, command_buffer + command_length, ':');
u32 len = HexToInt(start_offset, static_cast<u32>(len_pos - start_offset));
if (!Memory::IsValidVirtualAddress(*Core::System::GetInstance().Kernel().GetCurrentProcess(),
addr)) {
if (!Core::System::GetInstance().Memory().IsValidVirtualAddress(
*Core::System::GetInstance().Kernel().GetCurrentProcess(), addr)) {
return SendReply("E00");
}

View file

@ -105,6 +105,7 @@ public:
private:
Core::System& system;
Kernel::KernelSystem& kernel;
Memory::MemorySystem& memory;
friend class SVCWrapper<SVC>;
@ -346,7 +347,7 @@ ResultCode SVC::UnmapMemoryBlock(Handle handle, u32 addr) {
/// Connect to an OS service given the port name, returns the handle to the port to out
ResultCode SVC::ConnectToPort(Handle* out_handle, VAddr port_name_address) {
if (!Memory::IsValidVirtualAddress(*kernel.GetCurrentProcess(), port_name_address))
if (!memory.IsValidVirtualAddress(*kernel.GetCurrentProcess(), port_name_address))
return ERR_NOT_FOUND;
static constexpr std::size_t PortNameMaxLength = 11;
@ -451,7 +452,7 @@ ResultCode SVC::WaitSynchronizationN(s32* out, VAddr handles_address, s32 handle
bool wait_all, s64 nano_seconds) {
Thread* thread = kernel.GetThreadManager().GetCurrentThread();
if (!Memory::IsValidVirtualAddress(*kernel.GetCurrentProcess(), handles_address))
if (!memory.IsValidVirtualAddress(*kernel.GetCurrentProcess(), handles_address))
return ERR_INVALID_POINTER;
// NOTE: on real hardware, there is no nullptr check for 'out' (tested with firmware 4.4). If
@ -622,7 +623,7 @@ static ResultCode ReceiveIPCRequest(SharedPtr<ServerSession> server_session,
/// In a single operation, sends a IPC reply and waits for a new request.
ResultCode SVC::ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_count,
Handle reply_target) {
if (!Memory::IsValidVirtualAddress(*kernel.GetCurrentProcess(), handles_address))
if (!memory.IsValidVirtualAddress(*kernel.GetCurrentProcess(), handles_address))
return ERR_INVALID_POINTER;
// Check if 'handle_count' is invalid
@ -1584,7 +1585,7 @@ void SVC::CallSVC(u32 immediate) {
}
}
SVC::SVC(Core::System& system) : system(system), kernel(system.Kernel()) {}
SVC::SVC(Core::System& system) : system(system), kernel(system.Kernel()), memory(system.Memory()) {}
u32 SVC::GetReg(std::size_t n) {
return system.CPU().GetReg(static_cast<int>(n));

View file

@ -303,7 +303,7 @@ ResultVal<SharedPtr<Thread>> KernelSystem::CreateThread(std::string name, VAddr
// TODO(yuriks): Other checks, returning 0xD9001BEA
if (!Memory::IsValidVirtualAddress(owner_process, entry_point)) {
if (!memory.IsValidVirtualAddress(owner_process, entry_point)) {
LOG_ERROR(Kernel_SVC, "(name={}): invalid entry {:08x}", name, entry_point);
// TODO: Verify error
return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel,

View file

@ -185,7 +185,7 @@ void Write(const VAddr vaddr, const T data) {
}
}
bool IsValidVirtualAddress(const Kernel::Process& process, const VAddr vaddr) {
bool MemorySystem::IsValidVirtualAddress(const Kernel::Process& process, const VAddr vaddr) {
auto& page_table = process.vm_manager.page_table;
const u8* page_pointer = page_table.pointers[vaddr >> PAGE_BITS];

View file

@ -180,9 +180,6 @@ enum : VAddr {
extern std::array<u8, Memory::FCRAM_N3DS_SIZE> fcram;
/// Determines if the given VAddr is valid for the specified process.
bool IsValidVirtualAddress(const Kernel::Process& process, VAddr vaddr);
u8 Read8(VAddr addr);
u16 Read16(VAddr addr);
u32 Read32(VAddr addr);
@ -246,6 +243,9 @@ public:
void SetCurrentPageTable(PageTable* page_table);
PageTable* GetCurrentPageTable();
/// Determines if the given VAddr is valid for the specified process.
bool IsValidVirtualAddress(const Kernel::Process& process, VAddr vaddr);
/**
* Gets a pointer to the memory region beginning at the specified physical address.
*/