mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-12-11 16:16:19 +01:00
HLE/Applets: Give each applet its own block of heap memory, and use that when creating the framebuffer shared memory block.
This commit is contained in:
parent
d261984f54
commit
ac2de12ed8
5 changed files with 44 additions and 5 deletions
|
@ -65,6 +65,7 @@ protected:
|
||||||
virtual ResultCode StartImpl(const Service::APT::AppletStartupParameter& parameter) = 0;
|
virtual ResultCode StartImpl(const Service::APT::AppletStartupParameter& parameter) = 0;
|
||||||
|
|
||||||
Service::APT::AppletId id; ///< Id of this Applet
|
Service::APT::AppletId id; ///< Id of this Applet
|
||||||
|
std::shared_ptr<std::vector<u8>> heap_memory; ///< Heap memory for this Applet
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Returns whether a library applet is currently running
|
/// Returns whether a library applet is currently running
|
||||||
|
|
|
@ -35,9 +35,14 @@ ResultCode MiiSelector::ReceiveParameter(const Service::APT::MessageParameter& p
|
||||||
ASSERT(sizeof(capture_info) == parameter.buffer_size);
|
ASSERT(sizeof(capture_info) == parameter.buffer_size);
|
||||||
|
|
||||||
memcpy(&capture_info, parameter.data, sizeof(capture_info));
|
memcpy(&capture_info, parameter.data, sizeof(capture_info));
|
||||||
|
|
||||||
using Kernel::MemoryPermission;
|
using Kernel::MemoryPermission;
|
||||||
framebuffer_memory = Kernel::SharedMemory::Create(nullptr, capture_info.size, MemoryPermission::ReadWrite,
|
// Allocate a heap block of the required size for this applet.
|
||||||
MemoryPermission::ReadWrite, 0, Kernel::MemoryRegion::BASE, "MiiSelector Memory");
|
heap_memory = std::make_shared<std::vector<u8>>(capture_info.size);
|
||||||
|
// Create a SharedMemory that directly points to this heap block.
|
||||||
|
framebuffer_memory = Kernel::SharedMemory::CreateForApplet(heap_memory, 0, heap_memory->size(),
|
||||||
|
MemoryPermission::ReadWrite, MemoryPermission::ReadWrite,
|
||||||
|
"MiiSelector Memory");
|
||||||
|
|
||||||
// Send the response message with the newly created SharedMemory
|
// Send the response message with the newly created SharedMemory
|
||||||
Service::APT::MessageParameter result;
|
Service::APT::MessageParameter result;
|
||||||
|
|
|
@ -40,8 +40,12 @@ ResultCode SoftwareKeyboard::ReceiveParameter(Service::APT::MessageParameter con
|
||||||
memcpy(&capture_info, parameter.data, sizeof(capture_info));
|
memcpy(&capture_info, parameter.data, sizeof(capture_info));
|
||||||
|
|
||||||
using Kernel::MemoryPermission;
|
using Kernel::MemoryPermission;
|
||||||
framebuffer_memory = Kernel::SharedMemory::Create(nullptr, capture_info.size, MemoryPermission::ReadWrite,
|
// Allocate a heap block of the required size for this applet.
|
||||||
MemoryPermission::ReadWrite, 0, Kernel::MemoryRegion::BASE, "SoftwareKeyboard Memory");
|
heap_memory = std::make_shared<std::vector<u8>>(capture_info.size);
|
||||||
|
// Create a SharedMemory that directly points to this heap block.
|
||||||
|
framebuffer_memory = Kernel::SharedMemory::CreateForApplet(heap_memory, 0, heap_memory->size(),
|
||||||
|
MemoryPermission::ReadWrite, MemoryPermission::ReadWrite,
|
||||||
|
"SoftwareKeyboard Memory");
|
||||||
|
|
||||||
// Send the response message with the newly created SharedMemory
|
// Send the response message with the newly created SharedMemory
|
||||||
Service::APT::MessageParameter result;
|
Service::APT::MessageParameter result;
|
||||||
|
|
|
@ -58,6 +58,7 @@ SharedPtr<SharedMemory> SharedMemory::Create(SharedPtr<Process> owner_process, u
|
||||||
// Copy it over to our own storage
|
// Copy it over to our own storage
|
||||||
shared_memory->backing_block = std::make_shared<std::vector<u8>>(vma.backing_block->data() + vma.offset,
|
shared_memory->backing_block = std::make_shared<std::vector<u8>>(vma.backing_block->data() + vma.offset,
|
||||||
vma.backing_block->data() + vma.offset + size);
|
vma.backing_block->data() + vma.offset + size);
|
||||||
|
shared_memory->backing_block_offset = 0;
|
||||||
// Unmap the existing pages
|
// Unmap the existing pages
|
||||||
vm_manager.UnmapRange(address, size);
|
vm_manager.UnmapRange(address, size);
|
||||||
// Map our own block into the address space
|
// Map our own block into the address space
|
||||||
|
@ -70,6 +71,22 @@ SharedPtr<SharedMemory> SharedMemory::Create(SharedPtr<Process> owner_process, u
|
||||||
return shared_memory;
|
return shared_memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SharedPtr<SharedMemory> SharedMemory::CreateForApplet(std::shared_ptr<std::vector<u8>> heap_block, u32 offset, u32 size,
|
||||||
|
MemoryPermission permissions, MemoryPermission other_permissions, std::string name) {
|
||||||
|
SharedPtr<SharedMemory> shared_memory(new SharedMemory);
|
||||||
|
|
||||||
|
shared_memory->owner_process = nullptr;
|
||||||
|
shared_memory->name = std::move(name);
|
||||||
|
shared_memory->size = size;
|
||||||
|
shared_memory->permissions = permissions;
|
||||||
|
shared_memory->other_permissions = other_permissions;
|
||||||
|
shared_memory->backing_block = heap_block;
|
||||||
|
shared_memory->backing_block_offset = offset;
|
||||||
|
shared_memory->base_address = Memory::HEAP_VADDR + offset;
|
||||||
|
|
||||||
|
return shared_memory;
|
||||||
|
}
|
||||||
|
|
||||||
ResultCode SharedMemory::Map(Process* target_process, VAddr address, MemoryPermission permissions,
|
ResultCode SharedMemory::Map(Process* target_process, VAddr address, MemoryPermission permissions,
|
||||||
MemoryPermission other_permissions) {
|
MemoryPermission other_permissions) {
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ enum class MemoryPermission : u32 {
|
||||||
class SharedMemory final : public Object {
|
class SharedMemory final : public Object {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Creates a shared memory object
|
* Creates a shared memory object.
|
||||||
* @param owner_process Process that created this shared memory object.
|
* @param owner_process Process that created this shared memory object.
|
||||||
* @param size Size of the memory block. Must be page-aligned.
|
* @param size Size of the memory block. Must be page-aligned.
|
||||||
* @param permissions Permission restrictions applied to the process which created the block.
|
* @param permissions Permission restrictions applied to the process which created the block.
|
||||||
|
@ -42,6 +42,18 @@ public:
|
||||||
static SharedPtr<SharedMemory> Create(SharedPtr<Process> owner_process, u32 size, MemoryPermission permissions,
|
static SharedPtr<SharedMemory> Create(SharedPtr<Process> owner_process, u32 size, MemoryPermission permissions,
|
||||||
MemoryPermission other_permissions, VAddr address = 0, MemoryRegion region = MemoryRegion::BASE, std::string name = "Unknown");
|
MemoryPermission other_permissions, VAddr address = 0, MemoryRegion region = MemoryRegion::BASE, std::string name = "Unknown");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a shared memory object from a block of memory managed by an HLE applet.
|
||||||
|
* @param heap_block Heap block of the HLE applet.
|
||||||
|
* @param offset The offset into the heap block that the SharedMemory will map.
|
||||||
|
* @param size Size of the memory block. Must be page-aligned.
|
||||||
|
* @param permissions Permission restrictions applied to the process which created the block.
|
||||||
|
* @param other_permissions Permission restrictions applied to other processes mapping the block.
|
||||||
|
* @param name Optional object name, used for debugging purposes.
|
||||||
|
*/
|
||||||
|
static SharedPtr<SharedMemory> CreateForApplet(std::shared_ptr<std::vector<u8>> heap_block, u32 offset, u32 size,
|
||||||
|
MemoryPermission permissions, MemoryPermission other_permissions, std::string name = "Unknown Applet");
|
||||||
|
|
||||||
std::string GetTypeName() const override { return "SharedMemory"; }
|
std::string GetTypeName() const override { return "SharedMemory"; }
|
||||||
std::string GetName() const override { return name; }
|
std::string GetName() const override { return name; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue