VMManager: change MapMemoryBlockToBase to use raw backing memory
And let ServerSession.MappedBufferContext hold the mapped memory
This commit is contained in:
parent
0b8d2ecabe
commit
7f9873d7ec
|
@ -181,29 +181,31 @@ ResultCode TranslateCommandBuffer(SharedPtr<Thread> src_thread, SharedPtr<Thread
|
|||
// TODO(Subv): Perform permission checks.
|
||||
|
||||
// Reserve a page of memory before the mapped buffer
|
||||
auto reserve_buffer = std::make_shared<std::vector<u8>>(Memory::PAGE_SIZE);
|
||||
dst_process->vm_manager.MapMemoryBlockToBase(
|
||||
Memory::IPC_MAPPING_VADDR, Memory::IPC_MAPPING_SIZE, reserve_buffer, 0,
|
||||
static_cast<u32>(reserve_buffer->size()), Kernel::MemoryState::Reserved);
|
||||
auto reserve_buffer = std::make_unique<u8[]>(Memory::PAGE_SIZE);
|
||||
dst_process->vm_manager.MapBackingMemoryToBase(
|
||||
Memory::IPC_MAPPING_VADDR, Memory::IPC_MAPPING_SIZE, reserve_buffer.get(),
|
||||
Memory::PAGE_SIZE, Kernel::MemoryState::Reserved);
|
||||
|
||||
auto buffer = std::make_shared<std::vector<u8>>(num_pages * Memory::PAGE_SIZE);
|
||||
Memory::ReadBlock(*src_process, source_address, buffer->data() + page_offset, size);
|
||||
auto buffer = std::make_unique<u8[]>(num_pages * Memory::PAGE_SIZE);
|
||||
Memory::ReadBlock(*src_process, source_address, buffer.get() + page_offset, size);
|
||||
|
||||
// Map the page(s) into the target process' address space.
|
||||
target_address = dst_process->vm_manager
|
||||
.MapMemoryBlockToBase(
|
||||
Memory::IPC_MAPPING_VADDR, Memory::IPC_MAPPING_SIZE, buffer, 0,
|
||||
static_cast<u32>(buffer->size()), Kernel::MemoryState::Shared)
|
||||
.Unwrap();
|
||||
target_address =
|
||||
dst_process->vm_manager
|
||||
.MapBackingMemoryToBase(Memory::IPC_MAPPING_VADDR, Memory::IPC_MAPPING_SIZE,
|
||||
buffer.get(), num_pages * Memory::PAGE_SIZE,
|
||||
Kernel::MemoryState::Shared)
|
||||
.Unwrap();
|
||||
|
||||
cmd_buf[i++] = target_address + page_offset;
|
||||
|
||||
// Reserve a page of memory after the mapped buffer
|
||||
dst_process->vm_manager.MapMemoryBlockToBase(
|
||||
Memory::IPC_MAPPING_VADDR, Memory::IPC_MAPPING_SIZE, reserve_buffer, 0,
|
||||
static_cast<u32>(reserve_buffer->size()), Kernel::MemoryState::Reserved);
|
||||
dst_process->vm_manager.MapBackingMemoryToBase(
|
||||
Memory::IPC_MAPPING_VADDR, Memory::IPC_MAPPING_SIZE, reserve_buffer.get(),
|
||||
Memory::PAGE_SIZE, Kernel::MemoryState::Reserved);
|
||||
|
||||
mapped_buffer_context.push_back({permissions, size, source_address, target_address});
|
||||
mapped_buffer_context.push_back({permissions, size, source_address, target_address,
|
||||
std::move(buffer), std::move(reserve_buffer)});
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "common/common_types.h"
|
||||
#include "core/hle/ipc.h"
|
||||
|
@ -16,6 +17,9 @@ struct MappedBufferContext {
|
|||
u32 size;
|
||||
VAddr source_address;
|
||||
VAddr target_address;
|
||||
|
||||
std::unique_ptr<u8[]> buffer;
|
||||
std::unique_ptr<u8[]> reserve_buffer;
|
||||
};
|
||||
|
||||
/// Performs IPC command buffer translation from one process to another.
|
||||
|
|
|
@ -93,9 +93,8 @@ ResultVal<VMManager::VMAHandle> VMManager::MapMemoryBlock(VAddr target,
|
|||
return MakeResult<VMAHandle>(MergeAdjacent(vma_handle));
|
||||
}
|
||||
|
||||
ResultVal<VAddr> VMManager::MapMemoryBlockToBase(VAddr base, u32 region_size,
|
||||
std::shared_ptr<std::vector<u8>> block,
|
||||
std::size_t offset, u32 size, MemoryState state) {
|
||||
ResultVal<VAddr> VMManager::MapBackingMemoryToBase(VAddr base, u32 region_size, u8* memory,
|
||||
u32 size, MemoryState state) {
|
||||
|
||||
// Find the first Free VMA.
|
||||
VMAHandle vma_handle = std::find_if(vma_map.begin(), vma_map.end(), [&](const auto& vma) {
|
||||
|
@ -115,7 +114,7 @@ ResultVal<VAddr> VMManager::MapMemoryBlockToBase(VAddr base, u32 region_size,
|
|||
ErrorSummary::OutOfResource, ErrorLevel::Permanent);
|
||||
}
|
||||
|
||||
auto result = MapMemoryBlock(target, block, offset, size, state);
|
||||
auto result = MapBackingMemory(target, memory, size, state);
|
||||
|
||||
if (result.Failed())
|
||||
return result.Code();
|
||||
|
|
|
@ -150,15 +150,13 @@ public:
|
|||
*
|
||||
* @param base The base address to start the mapping at.
|
||||
* @param region_size The max size of the region from where we'll try to find an address.
|
||||
* @param block The block to be mapped.
|
||||
* @param offset Offset into `block` to map from.
|
||||
* @param memory The memory to be mapped.
|
||||
* @param size Size of the mapping.
|
||||
* @param state MemoryState tag to attach to the VMA.
|
||||
* @returns The address at which the memory was mapped.
|
||||
*/
|
||||
ResultVal<VAddr> MapMemoryBlockToBase(VAddr base, u32 region_size,
|
||||
std::shared_ptr<std::vector<u8>> block,
|
||||
std::size_t offset, u32 size, MemoryState state);
|
||||
ResultVal<VAddr> MapBackingMemoryToBase(VAddr base, u32 region_size, u8* memory, u32 size,
|
||||
MemoryState state);
|
||||
/**
|
||||
* Maps an unmanaged host memory pointer at a given address.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue