Memory: move block operations into class
This commit is contained in:
parent
323990d402
commit
2582d64fb3
13 changed files with 174 additions and 159 deletions
|
@ -48,12 +48,13 @@ SharedPtr<Event> HLERequestContext::SleepClientThread(SharedPtr<Thread> thread,
|
|||
// the translation might need to read from it in order to retrieve the StaticBuffer
|
||||
// target addresses.
|
||||
std::array<u32_le, IPC::COMMAND_BUFFER_LENGTH + 2 * IPC::MAX_STATIC_BUFFERS> cmd_buff;
|
||||
Memory::ReadBlock(*process, thread->GetCommandBufferAddress(), cmd_buff.data(),
|
||||
cmd_buff.size() * sizeof(u32));
|
||||
Memory::MemorySystem& memory = Core::System::GetInstance().Memory();
|
||||
memory.ReadBlock(*process, thread->GetCommandBufferAddress(), cmd_buff.data(),
|
||||
cmd_buff.size() * sizeof(u32));
|
||||
context.WriteToOutgoingCommandBuffer(cmd_buff.data(), *process);
|
||||
// Copy the translated command buffer back into the thread's command buffer area.
|
||||
Memory::WriteBlock(*process, thread->GetCommandBufferAddress(), cmd_buff.data(),
|
||||
cmd_buff.size() * sizeof(u32));
|
||||
memory.WriteBlock(*process, thread->GetCommandBufferAddress(), cmd_buff.data(),
|
||||
cmd_buff.size() * sizeof(u32));
|
||||
};
|
||||
|
||||
auto event = Core::System::GetInstance().Kernel().CreateEvent(Kernel::ResetType::OneShot,
|
||||
|
@ -142,7 +143,8 @@ ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(const u32_le* sr
|
|||
|
||||
// Copy the input buffer into our own vector and store it.
|
||||
std::vector<u8> data(buffer_info.size);
|
||||
Memory::ReadBlock(src_process, source_address, data.data(), data.size());
|
||||
Core::System::GetInstance().Memory().ReadBlock(src_process, source_address, data.data(),
|
||||
data.size());
|
||||
|
||||
AddStaticBuffer(buffer_info.buffer_id, std::move(data));
|
||||
cmd_buf[i++] = source_address;
|
||||
|
@ -209,7 +211,8 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(u32_le* dst_cmdbuf,
|
|||
|
||||
ASSERT_MSG(target_descriptor.size >= data.size(), "Static buffer data is too big");
|
||||
|
||||
Memory::WriteBlock(dst_process, target_address, data.data(), data.size());
|
||||
Core::System::GetInstance().Memory().WriteBlock(dst_process, target_address,
|
||||
data.data(), data.size());
|
||||
|
||||
dst_cmdbuf[i++] = target_address;
|
||||
break;
|
||||
|
@ -242,13 +245,15 @@ MappedBuffer::MappedBuffer(const Process& process, u32 descriptor, VAddr address
|
|||
void MappedBuffer::Read(void* dest_buffer, std::size_t offset, std::size_t size) {
|
||||
ASSERT(perms & IPC::R);
|
||||
ASSERT(offset + size <= this->size);
|
||||
Memory::ReadBlock(*process, address + static_cast<VAddr>(offset), dest_buffer, size);
|
||||
Core::System::GetInstance().Memory().ReadBlock(*process, address + static_cast<VAddr>(offset),
|
||||
dest_buffer, size);
|
||||
}
|
||||
|
||||
void MappedBuffer::Write(const void* src_buffer, std::size_t offset, std::size_t size) {
|
||||
ASSERT(perms & IPC::W);
|
||||
ASSERT(offset + size <= this->size);
|
||||
Memory::WriteBlock(*process, address + static_cast<VAddr>(offset), src_buffer, size);
|
||||
Core::System::GetInstance().Memory().WriteBlock(*process, address + static_cast<VAddr>(offset),
|
||||
src_buffer, size);
|
||||
}
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include "common/alignment.h"
|
||||
#include "core/core.h"
|
||||
#include "core/hle/ipc.h"
|
||||
#include "core/hle/kernel/handle_table.h"
|
||||
#include "core/hle/kernel/ipc.h"
|
||||
|
@ -19,13 +20,13 @@ ResultCode TranslateCommandBuffer(SharedPtr<Thread> src_thread, SharedPtr<Thread
|
|||
VAddr src_address, VAddr dst_address,
|
||||
std::vector<MappedBufferContext>& mapped_buffer_context,
|
||||
bool reply) {
|
||||
|
||||
Memory::MemorySystem& memory = Core::System::GetInstance().Memory();
|
||||
auto& src_process = src_thread->owner_process;
|
||||
auto& dst_process = dst_thread->owner_process;
|
||||
|
||||
IPC::Header header;
|
||||
// TODO(Subv): Replace by Memory::Read32 when possible.
|
||||
Memory::ReadBlock(*src_process, src_address, &header.raw, sizeof(header.raw));
|
||||
memory.ReadBlock(*src_process, src_address, &header.raw, sizeof(header.raw));
|
||||
|
||||
std::size_t untranslated_size = 1u + header.normal_params_size;
|
||||
std::size_t command_size = untranslated_size + header.translate_params_size;
|
||||
|
@ -34,7 +35,7 @@ ResultCode TranslateCommandBuffer(SharedPtr<Thread> src_thread, SharedPtr<Thread
|
|||
ASSERT(command_size <= IPC::COMMAND_BUFFER_LENGTH);
|
||||
|
||||
std::array<u32, IPC::COMMAND_BUFFER_LENGTH> cmd_buf;
|
||||
Memory::ReadBlock(*src_process, src_address, cmd_buf.data(), command_size * sizeof(u32));
|
||||
memory.ReadBlock(*src_process, src_address, cmd_buf.data(), command_size * sizeof(u32));
|
||||
|
||||
std::size_t i = untranslated_size;
|
||||
while (i < command_size) {
|
||||
|
@ -90,7 +91,7 @@ ResultCode TranslateCommandBuffer(SharedPtr<Thread> src_thread, SharedPtr<Thread
|
|||
VAddr static_buffer_src_address = cmd_buf[i];
|
||||
|
||||
std::vector<u8> data(bufferInfo.size);
|
||||
Memory::ReadBlock(*src_process, static_buffer_src_address, data.data(), data.size());
|
||||
memory.ReadBlock(*src_process, static_buffer_src_address, data.data(), data.size());
|
||||
|
||||
// Grab the address that the target thread set up to receive the response static buffer
|
||||
// and write our data there. The static buffers area is located right after the command
|
||||
|
@ -106,15 +107,15 @@ ResultCode TranslateCommandBuffer(SharedPtr<Thread> src_thread, SharedPtr<Thread
|
|||
|
||||
u32 static_buffer_offset = IPC::COMMAND_BUFFER_LENGTH * sizeof(u32) +
|
||||
sizeof(StaticBuffer) * bufferInfo.buffer_id;
|
||||
Memory::ReadBlock(*dst_process, dst_address + static_buffer_offset, &target_buffer,
|
||||
sizeof(target_buffer));
|
||||
memory.ReadBlock(*dst_process, dst_address + static_buffer_offset, &target_buffer,
|
||||
sizeof(target_buffer));
|
||||
|
||||
// Note: The real kernel doesn't seem to have any error recovery mechanisms for this
|
||||
// case.
|
||||
ASSERT_MSG(target_buffer.descriptor.size >= data.size(),
|
||||
"Static buffer data is too big");
|
||||
|
||||
Memory::WriteBlock(*dst_process, target_buffer.address, data.data(), data.size());
|
||||
memory.WriteBlock(*dst_process, target_buffer.address, data.data(), data.size());
|
||||
|
||||
cmd_buf[i++] = target_buffer.address;
|
||||
break;
|
||||
|
@ -153,8 +154,8 @@ ResultCode TranslateCommandBuffer(SharedPtr<Thread> src_thread, SharedPtr<Thread
|
|||
|
||||
if (permissions != IPC::MappedBufferPermissions::R) {
|
||||
// Copy the modified buffer back into the target process
|
||||
Memory::CopyBlock(*src_process, *dst_process, found->target_address,
|
||||
found->source_address, size);
|
||||
memory.CopyBlock(*src_process, *dst_process, found->target_address,
|
||||
found->source_address, size);
|
||||
}
|
||||
|
||||
VAddr prev_reserve = page_start - Memory::PAGE_SIZE;
|
||||
|
@ -187,7 +188,7 @@ ResultCode TranslateCommandBuffer(SharedPtr<Thread> src_thread, SharedPtr<Thread
|
|||
Memory::PAGE_SIZE, Kernel::MemoryState::Reserved);
|
||||
|
||||
auto buffer = std::make_unique<u8[]>(num_pages * Memory::PAGE_SIZE);
|
||||
Memory::ReadBlock(*src_process, source_address, buffer.get() + page_offset, size);
|
||||
memory.ReadBlock(*src_process, source_address, buffer.get() + page_offset, size);
|
||||
|
||||
// Map the page(s) into the target process' address space.
|
||||
target_address =
|
||||
|
@ -215,7 +216,7 @@ ResultCode TranslateCommandBuffer(SharedPtr<Thread> src_thread, SharedPtr<Thread
|
|||
}
|
||||
}
|
||||
|
||||
Memory::WriteBlock(*dst_process, dst_address, cmd_buf.data(), command_size * sizeof(u32));
|
||||
memory.WriteBlock(*dst_process, dst_address, cmd_buf.data(), command_size * sizeof(u32));
|
||||
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -120,8 +120,8 @@ void Process::Run(s32 main_thread_priority, u32 stack_size) {
|
|||
auto MapSegment = [&](CodeSet::Segment& segment, VMAPermission permissions,
|
||||
MemoryState memory_state) {
|
||||
HeapAllocate(segment.addr, segment.size, permissions, memory_state, true);
|
||||
Memory::WriteBlock(*this, segment.addr, codeset->memory->data() + segment.offset,
|
||||
segment.size);
|
||||
kernel.memory.WriteBlock(*this, segment.addr, codeset->memory->data() + segment.offset,
|
||||
segment.size);
|
||||
};
|
||||
|
||||
// Map CodeSet segments
|
||||
|
|
|
@ -802,7 +802,7 @@ void SVC::OutputDebugString(VAddr address, s32 len) {
|
|||
}
|
||||
|
||||
std::string string(len, ' ');
|
||||
Memory::ReadBlock(*kernel.GetCurrentProcess(), address, string.data(), len);
|
||||
memory.ReadBlock(*kernel.GetCurrentProcess(), address, string.data(), len);
|
||||
LOG_DEBUG(Debug_Emulated, "{}", string);
|
||||
}
|
||||
|
||||
|
|
|
@ -364,7 +364,7 @@ ResultVal<SharedPtr<Thread>> KernelSystem::CreateThread(std::string name, VAddr
|
|||
thread->tls_address = Memory::TLS_AREA_VADDR + available_page * Memory::PAGE_SIZE +
|
||||
available_slot * Memory::TLS_ENTRY_SIZE;
|
||||
|
||||
Memory::ZeroBlock(owner_process, thread->tls_address, Memory::TLS_ENTRY_SIZE);
|
||||
memory.ZeroBlock(owner_process, thread->tls_address, Memory::TLS_ENTRY_SIZE);
|
||||
|
||||
// TODO(peachum): move to ScheduleThread() when scheduler is added so selected core is used
|
||||
// to initialize the context
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue