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.
|
// TODO(Subv): Perform permission checks.
|
||||||
|
|
||||||
// Reserve a page of memory before the mapped buffer
|
// Reserve a page of memory before the mapped buffer
|
||||||
auto reserve_buffer = std::make_shared<std::vector<u8>>(Memory::PAGE_SIZE);
|
auto reserve_buffer = std::make_unique<u8[]>(Memory::PAGE_SIZE);
|
||||||
dst_process->vm_manager.MapMemoryBlockToBase(
|
dst_process->vm_manager.MapBackingMemoryToBase(
|
||||||
Memory::IPC_MAPPING_VADDR, Memory::IPC_MAPPING_SIZE, reserve_buffer, 0,
|
Memory::IPC_MAPPING_VADDR, Memory::IPC_MAPPING_SIZE, reserve_buffer.get(),
|
||||||
static_cast<u32>(reserve_buffer->size()), Kernel::MemoryState::Reserved);
|
Memory::PAGE_SIZE, Kernel::MemoryState::Reserved);
|
||||||
|
|
||||||
auto buffer = std::make_shared<std::vector<u8>>(num_pages * Memory::PAGE_SIZE);
|
auto buffer = std::make_unique<u8[]>(num_pages * Memory::PAGE_SIZE);
|
||||||
Memory::ReadBlock(*src_process, source_address, buffer->data() + page_offset, size);
|
Memory::ReadBlock(*src_process, source_address, buffer.get() + page_offset, size);
|
||||||
|
|
||||||
// Map the page(s) into the target process' address space.
|
// Map the page(s) into the target process' address space.
|
||||||
target_address = dst_process->vm_manager
|
target_address =
|
||||||
.MapMemoryBlockToBase(
|
dst_process->vm_manager
|
||||||
Memory::IPC_MAPPING_VADDR, Memory::IPC_MAPPING_SIZE, buffer, 0,
|
.MapBackingMemoryToBase(Memory::IPC_MAPPING_VADDR, Memory::IPC_MAPPING_SIZE,
|
||||||
static_cast<u32>(buffer->size()), Kernel::MemoryState::Shared)
|
buffer.get(), num_pages * Memory::PAGE_SIZE,
|
||||||
.Unwrap();
|
Kernel::MemoryState::Shared)
|
||||||
|
.Unwrap();
|
||||||
|
|
||||||
cmd_buf[i++] = target_address + page_offset;
|
cmd_buf[i++] = target_address + page_offset;
|
||||||
|
|
||||||
// Reserve a page of memory after the mapped buffer
|
// Reserve a page of memory after the mapped buffer
|
||||||
dst_process->vm_manager.MapMemoryBlockToBase(
|
dst_process->vm_manager.MapBackingMemoryToBase(
|
||||||
Memory::IPC_MAPPING_VADDR, Memory::IPC_MAPPING_SIZE, reserve_buffer, 0,
|
Memory::IPC_MAPPING_VADDR, Memory::IPC_MAPPING_SIZE, reserve_buffer.get(),
|
||||||
static_cast<u32>(reserve_buffer->size()), Kernel::MemoryState::Reserved);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "core/hle/ipc.h"
|
#include "core/hle/ipc.h"
|
||||||
|
@ -16,6 +17,9 @@ struct MappedBufferContext {
|
||||||
u32 size;
|
u32 size;
|
||||||
VAddr source_address;
|
VAddr source_address;
|
||||||
VAddr target_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.
|
/// 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));
|
return MakeResult<VMAHandle>(MergeAdjacent(vma_handle));
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<VAddr> VMManager::MapMemoryBlockToBase(VAddr base, u32 region_size,
|
ResultVal<VAddr> VMManager::MapBackingMemoryToBase(VAddr base, u32 region_size, u8* memory,
|
||||||
std::shared_ptr<std::vector<u8>> block,
|
u32 size, MemoryState state) {
|
||||||
std::size_t offset, u32 size, MemoryState state) {
|
|
||||||
|
|
||||||
// Find the first Free VMA.
|
// Find the first Free VMA.
|
||||||
VMAHandle vma_handle = std::find_if(vma_map.begin(), vma_map.end(), [&](const auto& 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);
|
ErrorSummary::OutOfResource, ErrorLevel::Permanent);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto result = MapMemoryBlock(target, block, offset, size, state);
|
auto result = MapBackingMemory(target, memory, size, state);
|
||||||
|
|
||||||
if (result.Failed())
|
if (result.Failed())
|
||||||
return result.Code();
|
return result.Code();
|
||||||
|
|
|
@ -150,15 +150,13 @@ public:
|
||||||
*
|
*
|
||||||
* @param base The base address to start the mapping at.
|
* @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 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 memory The memory to be mapped.
|
||||||
* @param offset Offset into `block` to map from.
|
|
||||||
* @param size Size of the mapping.
|
* @param size Size of the mapping.
|
||||||
* @param state MemoryState tag to attach to the VMA.
|
* @param state MemoryState tag to attach to the VMA.
|
||||||
* @returns The address at which the memory was mapped.
|
* @returns The address at which the memory was mapped.
|
||||||
*/
|
*/
|
||||||
ResultVal<VAddr> MapMemoryBlockToBase(VAddr base, u32 region_size,
|
ResultVal<VAddr> MapBackingMemoryToBase(VAddr base, u32 region_size, u8* memory, u32 size,
|
||||||
std::shared_ptr<std::vector<u8>> block,
|
MemoryState state);
|
||||||
std::size_t offset, u32 size, MemoryState state);
|
|
||||||
/**
|
/**
|
||||||
* Maps an unmanaged host memory pointer at a given address.
|
* Maps an unmanaged host memory pointer at a given address.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue