summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/applets/applet.h1
-rw-r--r--src/core/hle/applets/mii_selector.cpp9
-rw-r--r--src/core/hle/applets/swkbd.cpp8
-rw-r--r--src/core/hle/kernel/shared_memory.cpp17
-rw-r--r--src/core/hle/kernel/shared_memory.h14
5 files changed, 44 insertions, 5 deletions
diff --git a/src/core/hle/applets/applet.h b/src/core/hle/applets/applet.h
index af442f81d..754c6f7db 100644
--- a/src/core/hle/applets/applet.h
+++ b/src/core/hle/applets/applet.h
@@ -65,6 +65,7 @@ protected:
65 virtual ResultCode StartImpl(const Service::APT::AppletStartupParameter& parameter) = 0; 65 virtual ResultCode StartImpl(const Service::APT::AppletStartupParameter& parameter) = 0;
66 66
67 Service::APT::AppletId id; ///< Id of this Applet 67 Service::APT::AppletId id; ///< Id of this Applet
68 std::shared_ptr<std::vector<u8>> heap_memory; ///< Heap memory for this Applet
68}; 69};
69 70
70/// Returns whether a library applet is currently running 71/// Returns whether a library applet is currently running
diff --git a/src/core/hle/applets/mii_selector.cpp b/src/core/hle/applets/mii_selector.cpp
index 7f174f3e6..bf39eca22 100644
--- a/src/core/hle/applets/mii_selector.cpp
+++ b/src/core/hle/applets/mii_selector.cpp
@@ -35,9 +35,14 @@ ResultCode MiiSelector::ReceiveParameter(const Service::APT::MessageParameter& p
35 ASSERT(sizeof(capture_info) == parameter.buffer_size); 35 ASSERT(sizeof(capture_info) == parameter.buffer_size);
36 36
37 memcpy(&capture_info, parameter.data, sizeof(capture_info)); 37 memcpy(&capture_info, parameter.data, sizeof(capture_info));
38
38 using Kernel::MemoryPermission; 39 using Kernel::MemoryPermission;
39 framebuffer_memory = Kernel::SharedMemory::Create(nullptr, capture_info.size, MemoryPermission::ReadWrite, 40 // Allocate a heap block of the required size for this applet.
40 MemoryPermission::ReadWrite, 0, Kernel::MemoryRegion::BASE, "MiiSelector Memory"); 41 heap_memory = std::make_shared<std::vector<u8>>(capture_info.size);
42 // Create a SharedMemory that directly points to this heap block.
43 framebuffer_memory = Kernel::SharedMemory::CreateForApplet(heap_memory, 0, heap_memory->size(),
44 MemoryPermission::ReadWrite, MemoryPermission::ReadWrite,
45 "MiiSelector Memory");
41 46
42 // Send the response message with the newly created SharedMemory 47 // Send the response message with the newly created SharedMemory
43 Service::APT::MessageParameter result; 48 Service::APT::MessageParameter result;
diff --git a/src/core/hle/applets/swkbd.cpp b/src/core/hle/applets/swkbd.cpp
index e0c134182..90c6adc65 100644
--- a/src/core/hle/applets/swkbd.cpp
+++ b/src/core/hle/applets/swkbd.cpp
@@ -40,8 +40,12 @@ ResultCode SoftwareKeyboard::ReceiveParameter(Service::APT::MessageParameter con
40 memcpy(&capture_info, parameter.data, sizeof(capture_info)); 40 memcpy(&capture_info, parameter.data, sizeof(capture_info));
41 41
42 using Kernel::MemoryPermission; 42 using Kernel::MemoryPermission;
43 framebuffer_memory = Kernel::SharedMemory::Create(nullptr, capture_info.size, MemoryPermission::ReadWrite, 43 // Allocate a heap block of the required size for this applet.
44 MemoryPermission::ReadWrite, 0, Kernel::MemoryRegion::BASE, "SoftwareKeyboard Memory"); 44 heap_memory = std::make_shared<std::vector<u8>>(capture_info.size);
45 // Create a SharedMemory that directly points to this heap block.
46 framebuffer_memory = Kernel::SharedMemory::CreateForApplet(heap_memory, 0, heap_memory->size(),
47 MemoryPermission::ReadWrite, MemoryPermission::ReadWrite,
48 "SoftwareKeyboard Memory");
45 49
46 // Send the response message with the newly created SharedMemory 50 // Send the response message with the newly created SharedMemory
47 Service::APT::MessageParameter result; 51 Service::APT::MessageParameter result;
diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp
index 74947f023..6a22c8986 100644
--- a/src/core/hle/kernel/shared_memory.cpp
+++ b/src/core/hle/kernel/shared_memory.cpp
@@ -58,6 +58,7 @@ SharedPtr<SharedMemory> SharedMemory::Create(SharedPtr<Process> owner_process, u
58 // Copy it over to our own storage 58 // Copy it over to our own storage
59 shared_memory->backing_block = std::make_shared<std::vector<u8>>(vma.backing_block->data() + vma.offset, 59 shared_memory->backing_block = std::make_shared<std::vector<u8>>(vma.backing_block->data() + vma.offset,
60 vma.backing_block->data() + vma.offset + size); 60 vma.backing_block->data() + vma.offset + size);
61 shared_memory->backing_block_offset = 0;
61 // Unmap the existing pages 62 // Unmap the existing pages
62 vm_manager.UnmapRange(address, size); 63 vm_manager.UnmapRange(address, size);
63 // Map our own block into the address space 64 // Map our own block into the address space
@@ -70,6 +71,22 @@ SharedPtr<SharedMemory> SharedMemory::Create(SharedPtr<Process> owner_process, u
70 return shared_memory; 71 return shared_memory;
71} 72}
72 73
74SharedPtr<SharedMemory> SharedMemory::CreateForApplet(std::shared_ptr<std::vector<u8>> heap_block, u32 offset, u32 size,
75 MemoryPermission permissions, MemoryPermission other_permissions, std::string name) {
76 SharedPtr<SharedMemory> shared_memory(new SharedMemory);
77
78 shared_memory->owner_process = nullptr;
79 shared_memory->name = std::move(name);
80 shared_memory->size = size;
81 shared_memory->permissions = permissions;
82 shared_memory->other_permissions = other_permissions;
83 shared_memory->backing_block = heap_block;
84 shared_memory->backing_block_offset = offset;
85 shared_memory->base_address = Memory::HEAP_VADDR + offset;
86
87 return shared_memory;
88}
89
73ResultCode SharedMemory::Map(Process* target_process, VAddr address, MemoryPermission permissions, 90ResultCode SharedMemory::Map(Process* target_process, VAddr address, MemoryPermission permissions,
74 MemoryPermission other_permissions) { 91 MemoryPermission other_permissions) {
75 92
diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h
index af145bef5..0c404a9f8 100644
--- a/src/core/hle/kernel/shared_memory.h
+++ b/src/core/hle/kernel/shared_memory.h
@@ -30,7 +30,7 @@ enum class MemoryPermission : u32 {
30class SharedMemory final : public Object { 30class SharedMemory final : public Object {
31public: 31public:
32 /** 32 /**
33 * Creates a shared memory object 33 * Creates a shared memory object.
34 * @param owner_process Process that created this shared memory object. 34 * @param owner_process Process that created this shared memory object.
35 * @param size Size of the memory block. Must be page-aligned. 35 * @param size Size of the memory block. Must be page-aligned.
36 * @param permissions Permission restrictions applied to the process which created the block. 36 * @param permissions Permission restrictions applied to the process which created the block.
@@ -42,6 +42,18 @@ public:
42 static SharedPtr<SharedMemory> Create(SharedPtr<Process> owner_process, u32 size, MemoryPermission permissions, 42 static SharedPtr<SharedMemory> Create(SharedPtr<Process> owner_process, u32 size, MemoryPermission permissions,
43 MemoryPermission other_permissions, VAddr address = 0, MemoryRegion region = MemoryRegion::BASE, std::string name = "Unknown"); 43 MemoryPermission other_permissions, VAddr address = 0, MemoryRegion region = MemoryRegion::BASE, std::string name = "Unknown");
44 44
45 /**
46 * Creates a shared memory object from a block of memory managed by an HLE applet.
47 * @param heap_block Heap block of the HLE applet.
48 * @param offset The offset into the heap block that the SharedMemory will map.
49 * @param size Size of the memory block. Must be page-aligned.
50 * @param permissions Permission restrictions applied to the process which created the block.
51 * @param other_permissions Permission restrictions applied to other processes mapping the block.
52 * @param name Optional object name, used for debugging purposes.
53 */
54 static SharedPtr<SharedMemory> CreateForApplet(std::shared_ptr<std::vector<u8>> heap_block, u32 offset, u32 size,
55 MemoryPermission permissions, MemoryPermission other_permissions, std::string name = "Unknown Applet");
56
45 std::string GetTypeName() const override { return "SharedMemory"; } 57 std::string GetTypeName() const override { return "SharedMemory"; }
46 std::string GetName() const override { return name; } 58 std::string GetName() const override { return name; }
47 59