summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2015-01-11 03:43:29 -0200
committerGravatar Yuri Kunde Schlesner2015-01-30 11:47:04 -0200
commit4bb33dfc30768c536d3f0ffb980464b1ab2d25d9 (patch)
tree09f772e5283ef1302f1b29d30f3f0150dd690bf0 /src
parentCommon: Fix SCOPE_EXIT to actually create unique identifiers. (diff)
downloadyuzu-4bb33dfc30768c536d3f0ffb980464b1ab2d25d9.tar.gz
yuzu-4bb33dfc30768c536d3f0ffb980464b1ab2d25d9.tar.xz
yuzu-4bb33dfc30768c536d3f0ffb980464b1ab2d25d9.zip
Kernel: Convert SharedMemory to not use Handles
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/shared_memory.cpp65
-rw-r--r--src/core/hle/kernel/shared_memory.h60
-rw-r--r--src/core/hle/service/apt_u.cpp8
-rw-r--r--src/core/hle/service/gsp_gpu.cpp16
-rw-r--r--src/core/hle/service/hid/hid.cpp6
-rw-r--r--src/core/hle/service/hid/hid.h6
-rw-r--r--src/core/hle/service/hid/hid_user.cpp4
-rw-r--r--src/core/hle/svc.cpp44
8 files changed, 107 insertions, 102 deletions
diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp
index fa8fc6f92..536d134b0 100644
--- a/src/core/hle/kernel/shared_memory.cpp
+++ b/src/core/hle/kernel/shared_memory.cpp
@@ -9,68 +9,39 @@
9 9
10namespace Kernel { 10namespace Kernel {
11 11
12class SharedMemory : public Object { 12ResultVal<SharedPtr<SharedMemory>> SharedMemory::Create(std::string name) {
13public: 13 SharedPtr<SharedMemory> shared_memory(new SharedMemory);
14 std::string GetTypeName() const override { return "SharedMemory"; }
15 14
16 static const HandleType HANDLE_TYPE = HandleType::SharedMemory; 15 // TOOD(yuriks): Don't create Handle (see Thread::Create())
17 HandleType GetHandleType() const override { return HANDLE_TYPE; } 16 CASCADE_RESULT(auto unused, Kernel::g_handle_table.Create(shared_memory));
18 17
19 u32 base_address; ///< Address of shared memory block in RAM 18 shared_memory->name = std::move(name);
20 MemoryPermission permissions; ///< Permissions of shared memory block (SVC field) 19 return MakeResult<SharedPtr<SharedMemory>>(std::move(shared_memory));
21 MemoryPermission other_permissions; ///< Other permissions of shared memory block (SVC field)
22 std::string name; ///< Name of shared memory object (optional)
23};
24
25////////////////////////////////////////////////////////////////////////////////////////////////////
26
27/**
28 * Creates a shared memory object
29 * @param handle Handle of newly created shared memory object
30 * @param name Name of shared memory object
31 * @return Pointer to newly created shared memory object
32 */
33static SharedMemory* CreateSharedMemory(Handle& handle, const std::string& name) {
34 SharedMemory* shared_memory = new SharedMemory;
35 // TOOD(yuriks): Fix error reporting
36 handle = Kernel::g_handle_table.Create(shared_memory).ValueOr(INVALID_HANDLE);
37 shared_memory->name = name;
38 return shared_memory;
39} 20}
40 21
41Handle CreateSharedMemory(const std::string& name) { 22ResultCode SharedMemory::Map(VAddr address, MemoryPermission permissions,
42 Handle handle; 23 MemoryPermission other_permissions) {
43 CreateSharedMemory(handle, name);
44 return handle;
45}
46
47ResultCode MapSharedMemory(u32 handle, u32 address, MemoryPermission permissions,
48 MemoryPermission other_permissions) {
49 24
50 if (address < Memory::SHARED_MEMORY_VADDR || address >= Memory::SHARED_MEMORY_VADDR_END) { 25 if (address < Memory::SHARED_MEMORY_VADDR || address >= Memory::SHARED_MEMORY_VADDR_END) {
51 LOG_ERROR(Kernel_SVC, "cannot map handle=0x%08X, address=0x%08X outside of shared mem bounds!", 26 LOG_ERROR(Kernel, "cannot map handle=0x%08X, address=0x%08X outside of shared mem bounds!",
52 handle, address); 27 GetHandle(), address);
28 // TODO: Verify error code with hardware
53 return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel, 29 return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel,
54 ErrorSummary::InvalidArgument, ErrorLevel::Permanent); 30 ErrorSummary::InvalidArgument, ErrorLevel::Permanent);
55 } 31 }
56 SharedMemory* shared_memory = Kernel::g_handle_table.Get<SharedMemory>(handle).get();
57 if (shared_memory == nullptr) return InvalidHandle(ErrorModule::Kernel);
58 32
59 shared_memory->base_address = address; 33 base_address = address;
60 shared_memory->permissions = permissions; 34 permissions = permissions;
61 shared_memory->other_permissions = other_permissions; 35 other_permissions = other_permissions;
62 36
63 return RESULT_SUCCESS; 37 return RESULT_SUCCESS;
64} 38}
65 39
66ResultVal<u8*> GetSharedMemoryPointer(Handle handle, u32 offset) { 40ResultVal<u8*> SharedMemory::GetPointer(u32 offset) {
67 SharedMemory* shared_memory = Kernel::g_handle_table.Get<SharedMemory>(handle).get(); 41 if (base_address != 0)
68 if (shared_memory == nullptr) return InvalidHandle(ErrorModule::Kernel); 42 return MakeResult<u8*>(Memory::GetPointer(base_address + offset));
69
70 if (0 != shared_memory->base_address)
71 return MakeResult<u8*>(Memory::GetPointer(shared_memory->base_address + offset));
72 43
73 LOG_ERROR(Kernel_SVC, "memory block handle=0x%08X not mapped!", handle); 44 LOG_ERROR(Kernel_SVC, "memory block handle=0x%08X not mapped!", GetHandle());
74 // TODO(yuriks): Verify error code. 45 // TODO(yuriks): Verify error code.
75 return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel, 46 return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel,
76 ErrorSummary::InvalidState, ErrorLevel::Permanent); 47 ErrorSummary::InvalidState, ErrorLevel::Permanent);
diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h
index bb65c7ccd..eb063d39d 100644
--- a/src/core/hle/kernel/shared_memory.h
+++ b/src/core/hle/kernel/shared_memory.h
@@ -23,29 +23,41 @@ enum class MemoryPermission : u32 {
23 DontCare = (1u << 28) 23 DontCare = (1u << 28)
24}; 24};
25 25
26/** 26class SharedMemory : public Object {
27 * Creates a shared memory object 27public:
28 * @param name Optional name of shared memory object 28 /**
29 * @return Handle of newly created shared memory object 29 * Creates a shared memory object
30 */ 30 * @param name Optional object name, used only for debugging purposes.
31Handle CreateSharedMemory(const std::string& name="Unknown"); 31 */
32 32 static ResultVal<SharedPtr<SharedMemory>> Create(std::string name = "Unknown");
33/** 33
34 * Maps a shared memory block to an address in system memory 34 std::string GetTypeName() const override { return "SharedMemory"; }
35 * @param handle Shared memory block handle 35
36 * @param address Address in system memory to map shared memory block to 36 static const HandleType HANDLE_TYPE = HandleType::SharedMemory;
37 * @param permissions Memory block map permissions (specified by SVC field) 37 HandleType GetHandleType() const override { return HANDLE_TYPE; }
38 * @param other_permissions Memory block map other permissions (specified by SVC field) 38
39 */ 39 /**
40ResultCode MapSharedMemory(Handle handle, u32 address, MemoryPermission permissions, 40 * Maps a shared memory block to an address in system memory
41 MemoryPermission other_permissions); 41 * @param address Address in system memory to map shared memory block to
42 42 * @param permissions Memory block map permissions (specified by SVC field)
43/** 43 * @param other_permissions Memory block map other permissions (specified by SVC field)
44 * Gets a pointer to the shared memory block 44 */
45 * @param handle Shared memory block handle 45 ResultCode Map(VAddr address, MemoryPermission permissions, MemoryPermission other_permissions);
46 * @param offset Offset from the start of the shared memory block to get pointer 46
47 * @return Pointer to the shared memory block from the specified offset 47 /**
48 */ 48 * Gets a pointer to the shared memory block
49ResultVal<u8*> GetSharedMemoryPointer(Handle handle, u32 offset); 49 * @param offset Offset from the start of the shared memory block to get pointer
50 * @return Pointer to the shared memory block from the specified offset
51 */
52 ResultVal<u8*> GetPointer(u32 offset = 0);
53
54 VAddr base_address; ///< Address of shared memory block in RAM
55 MemoryPermission permissions; ///< Permissions of shared memory block (SVC field)
56 MemoryPermission other_permissions; ///< Other permissions of shared memory block (SVC field)
57 std::string name; ///< Name of shared memory object (optional)
58
59private:
60 SharedMemory() = default;
61};
50 62
51} // namespace 63} // namespace
diff --git a/src/core/hle/service/apt_u.cpp b/src/core/hle/service/apt_u.cpp
index 001b0d183..1f6b148e8 100644
--- a/src/core/hle/service/apt_u.cpp
+++ b/src/core/hle/service/apt_u.cpp
@@ -26,7 +26,7 @@ namespace APT_U {
26static const VAddr SHARED_FONT_VADDR = 0x18000000; 26static const VAddr SHARED_FONT_VADDR = 0x18000000;
27 27
28/// Handle to shared memory region designated to for shared system font 28/// Handle to shared memory region designated to for shared system font
29static Handle shared_font_mem = 0; 29static Kernel::SharedPtr<Kernel::SharedMemory> shared_font_mem;
30 30
31static Handle lock_handle = 0; 31static Handle lock_handle = 0;
32static Handle notification_event_handle = 0; ///< APT notification event handle 32static Handle notification_event_handle = 0; ///< APT notification event handle
@@ -354,7 +354,7 @@ void GetSharedFont(Service::Interface* self) {
354 cmd_buff[0] = 0x00440082; 354 cmd_buff[0] = 0x00440082;
355 cmd_buff[1] = RESULT_SUCCESS.raw; // No error 355 cmd_buff[1] = RESULT_SUCCESS.raw; // No error
356 cmd_buff[2] = SHARED_FONT_VADDR; 356 cmd_buff[2] = SHARED_FONT_VADDR;
357 cmd_buff[4] = shared_font_mem; 357 cmd_buff[4] = Kernel::g_handle_table.Create(shared_font_mem).MoveFrom();
358 } else { 358 } else {
359 cmd_buff[1] = -1; // Generic error (not really possible to verify this on hardware) 359 cmd_buff[1] = -1; // Generic error (not really possible to verify this on hardware)
360 LOG_ERROR(Kernel_SVC, "called, but %s has not been loaded!", SHARED_FONT); 360 LOG_ERROR(Kernel_SVC, "called, but %s has not been loaded!", SHARED_FONT);
@@ -514,10 +514,10 @@ Interface::Interface() {
514 file.ReadBytes(shared_font.data(), (size_t)file.GetSize()); 514 file.ReadBytes(shared_font.data(), (size_t)file.GetSize());
515 515
516 // Create shared font memory object 516 // Create shared font memory object
517 shared_font_mem = Kernel::CreateSharedMemory("APT_U:shared_font_mem"); 517 shared_font_mem = Kernel::SharedMemory::Create("APT_U:shared_font_mem").MoveFrom();
518 } else { 518 } else {
519 LOG_WARNING(Service_APT, "Unable to load shared font: %s", filepath.c_str()); 519 LOG_WARNING(Service_APT, "Unable to load shared font: %s", filepath.c_str());
520 shared_font_mem = 0; 520 shared_font_mem = nullptr;
521 } 521 }
522 522
523 lock_handle = 0; 523 lock_handle = 0;
diff --git a/src/core/hle/service/gsp_gpu.cpp b/src/core/hle/service/gsp_gpu.cpp
index 4ca2b9bd0..1be2438c8 100644
--- a/src/core/hle/service/gsp_gpu.cpp
+++ b/src/core/hle/service/gsp_gpu.cpp
@@ -23,12 +23,12 @@ GraphicsDebugger g_debugger;
23namespace GSP_GPU { 23namespace GSP_GPU {
24 24
25Handle g_interrupt_event = 0; ///< Handle to event triggered when GSP interrupt has been signalled 25Handle g_interrupt_event = 0; ///< Handle to event triggered when GSP interrupt has been signalled
26Handle g_shared_memory = 0; ///< Handle to GSP shared memorys 26Kernel::SharedPtr<Kernel::SharedMemory> g_shared_memory; ///< GSP shared memoryings
27u32 g_thread_id = 1; ///< Thread index into interrupt relay queue, 1 is arbitrary 27u32 g_thread_id = 1; ///< Thread index into interrupt relay queue, 1 is arbitrary
28 28
29/// Gets a pointer to a thread command buffer in GSP shared memory 29/// Gets a pointer to a thread command buffer in GSP shared memory
30static inline u8* GetCommandBuffer(u32 thread_id) { 30static inline u8* GetCommandBuffer(u32 thread_id) {
31 ResultVal<u8*> ptr = Kernel::GetSharedMemoryPointer(g_shared_memory, 0x800 + (thread_id * sizeof(CommandBuffer))); 31 ResultVal<u8*> ptr = g_shared_memory->GetPointer(0x800 + (thread_id * sizeof(CommandBuffer)));
32 return ptr.ValueOr(nullptr); 32 return ptr.ValueOr(nullptr);
33} 33}
34 34
@@ -37,13 +37,13 @@ static inline FrameBufferUpdate* GetFrameBufferInfo(u32 thread_id, u32 screen_in
37 37
38 // For each thread there are two FrameBufferUpdate fields 38 // For each thread there are two FrameBufferUpdate fields
39 u32 offset = 0x200 + (2 * thread_id + screen_index) * sizeof(FrameBufferUpdate); 39 u32 offset = 0x200 + (2 * thread_id + screen_index) * sizeof(FrameBufferUpdate);
40 ResultVal<u8*> ptr = Kernel::GetSharedMemoryPointer(g_shared_memory, offset); 40 ResultVal<u8*> ptr = g_shared_memory->GetPointer(offset);
41 return reinterpret_cast<FrameBufferUpdate*>(ptr.ValueOr(nullptr)); 41 return reinterpret_cast<FrameBufferUpdate*>(ptr.ValueOr(nullptr));
42} 42}
43 43
44/// Gets a pointer to the interrupt relay queue for a given thread index 44/// Gets a pointer to the interrupt relay queue for a given thread index
45static inline InterruptRelayQueue* GetInterruptRelayQueue(u32 thread_id) { 45static inline InterruptRelayQueue* GetInterruptRelayQueue(u32 thread_id) {
46 ResultVal<u8*> ptr = Kernel::GetSharedMemoryPointer(g_shared_memory, sizeof(InterruptRelayQueue) * thread_id); 46 ResultVal<u8*> ptr = g_shared_memory->GetPointer(sizeof(InterruptRelayQueue) * thread_id);
47 return reinterpret_cast<InterruptRelayQueue*>(ptr.ValueOr(nullptr)); 47 return reinterpret_cast<InterruptRelayQueue*>(ptr.ValueOr(nullptr));
48} 48}
49 49
@@ -182,13 +182,15 @@ static void RegisterInterruptRelayQueue(Service::Interface* self) {
182 u32* cmd_buff = Kernel::GetCommandBuffer(); 182 u32* cmd_buff = Kernel::GetCommandBuffer();
183 u32 flags = cmd_buff[1]; 183 u32 flags = cmd_buff[1];
184 g_interrupt_event = cmd_buff[3]; 184 g_interrupt_event = cmd_buff[3];
185 g_shared_memory = Kernel::CreateSharedMemory("GSPSharedMem"); 185 g_shared_memory = Kernel::SharedMemory::Create("GSPSharedMem").MoveFrom();
186 186
187 _assert_msg_(GSP, (g_interrupt_event != 0), "handle is not valid!"); 187 _assert_msg_(GSP, (g_interrupt_event != 0), "handle is not valid!");
188 188
189 Handle shmem_handle = Kernel::g_handle_table.Create(g_shared_memory).MoveFrom();
190
189 cmd_buff[1] = 0x2A07; // Value verified by 3dmoo team, purpose unknown, but needed for GSP init 191 cmd_buff[1] = 0x2A07; // Value verified by 3dmoo team, purpose unknown, but needed for GSP init
190 cmd_buff[2] = g_thread_id++; // Thread ID 192 cmd_buff[2] = g_thread_id++; // Thread ID
191 cmd_buff[4] = g_shared_memory; // GSP shared memory 193 cmd_buff[4] = shmem_handle; // GSP shared memory
192 194
193 Kernel::SignalEvent(g_interrupt_event); // TODO(bunnei): Is this correct? 195 Kernel::SignalEvent(g_interrupt_event); // TODO(bunnei): Is this correct?
194} 196}
@@ -204,7 +206,7 @@ void SignalInterrupt(InterruptId interrupt_id) {
204 LOG_WARNING(Service_GSP, "cannot synchronize until GSP event has been created!"); 206 LOG_WARNING(Service_GSP, "cannot synchronize until GSP event has been created!");
205 return; 207 return;
206 } 208 }
207 if (0 == g_shared_memory) { 209 if (nullptr == g_shared_memory) {
208 LOG_WARNING(Service_GSP, "cannot synchronize until GSP shared memory has been created!"); 210 LOG_WARNING(Service_GSP, "cannot synchronize until GSP shared memory has been created!");
209 return; 211 return;
210 } 212 }
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index 5abcb2596..ee2ba7e01 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -12,7 +12,7 @@
12namespace Service { 12namespace Service {
13namespace HID { 13namespace HID {
14 14
15Handle g_shared_mem = 0; 15Kernel::SharedPtr<Kernel::SharedMemory> g_shared_mem = nullptr;
16 16
17Handle g_event_pad_or_touch_1 = 0; 17Handle g_event_pad_or_touch_1 = 0;
18Handle g_event_pad_or_touch_2 = 0; 18Handle g_event_pad_or_touch_2 = 0;
@@ -30,7 +30,7 @@ static s16 next_circle_y = 0;
30 * Gets a pointer to the PadData structure inside HID shared memory 30 * Gets a pointer to the PadData structure inside HID shared memory
31 */ 31 */
32static inline PadData* GetPadData() { 32static inline PadData* GetPadData() {
33 return reinterpret_cast<PadData*>(Kernel::GetSharedMemoryPointer(g_shared_mem, 0).ValueOr(nullptr)); 33 return reinterpret_cast<PadData*>(g_shared_mem->GetPointer().ValueOr(nullptr));
34} 34}
35 35
36/** 36/**
@@ -120,7 +120,7 @@ void PadUpdateComplete() {
120} 120}
121 121
122void HIDInit() { 122void HIDInit() {
123 g_shared_mem = Kernel::CreateSharedMemory("HID:SharedMem"); // Create shared memory object 123 g_shared_mem = Kernel::SharedMemory::Create("HID:SharedMem").MoveFrom();
124 124
125 // Create event handles 125 // Create event handles
126 g_event_pad_or_touch_1 = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID:EventPadOrTouch1"); 126 g_event_pad_or_touch_1 = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID:EventPadOrTouch1");
diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h
index 73cdaa527..5e6236647 100644
--- a/src/core/hle/service/hid/hid.h
+++ b/src/core/hle/service/hid/hid.h
@@ -9,11 +9,15 @@
9#include "core/hle/kernel/kernel.h" 9#include "core/hle/kernel/kernel.h"
10#include "common/bit_field.h" 10#include "common/bit_field.h"
11 11
12namespace Kernel {
13 class SharedMemory;
14}
15
12namespace Service { 16namespace Service {
13namespace HID { 17namespace HID {
14 18
15// Handle to shared memory region designated to HID_User service 19// Handle to shared memory region designated to HID_User service
16extern Handle g_shared_mem; 20extern Kernel::SharedPtr<Kernel::SharedMemory> g_shared_mem;
17 21
18// Event handles 22// Event handles
19extern Handle g_event_pad_or_touch_1; 23extern Handle g_event_pad_or_touch_1;
diff --git a/src/core/hle/service/hid/hid_user.cpp b/src/core/hle/service/hid/hid_user.cpp
index 3a6275707..c167927ea 100644
--- a/src/core/hle/service/hid/hid_user.cpp
+++ b/src/core/hle/service/hid/hid_user.cpp
@@ -5,6 +5,7 @@
5#include "common/log.h" 5#include "common/log.h"
6 6
7#include "core/hle/hle.h" 7#include "core/hle/hle.h"
8#include "core/hle/kernel/shared_memory.h"
8#include "core/hle/service/hid/hid.h" 9#include "core/hle/service/hid/hid.h"
9#include "hid_user.h" 10#include "hid_user.h"
10 11
@@ -46,7 +47,8 @@ void GetIPCHandles(Service::Interface* self) {
46 u32* cmd_buff = Kernel::GetCommandBuffer(); 47 u32* cmd_buff = Kernel::GetCommandBuffer();
47 48
48 cmd_buff[1] = 0; // No error 49 cmd_buff[1] = 0; // No error
49 cmd_buff[3] = Service::HID::g_shared_mem; 50 // TODO(yuriks): Return error from SendSyncRequest is this fails (part of IPC marshalling)
51 cmd_buff[3] = Kernel::g_handle_table.Create(Service::HID::g_shared_mem).MoveFrom();
50 cmd_buff[4] = Service::HID::g_event_pad_or_touch_1; 52 cmd_buff[4] = Service::HID::g_event_pad_or_touch_1;
51 cmd_buff[5] = Service::HID::g_event_pad_or_touch_2; 53 cmd_buff[5] = Service::HID::g_event_pad_or_touch_2;
52 cmd_buff[6] = Service::HID::g_event_accelerometer; 54 cmd_buff[6] = Service::HID::g_event_accelerometer;
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp
index 3d743f125..165da0402 100644
--- a/src/core/hle/svc.cpp
+++ b/src/core/hle/svc.cpp
@@ -63,21 +63,28 @@ static Result ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 addr1,
63 63
64/// Maps a memory block to specified address 64/// Maps a memory block to specified address
65static Result MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 other_permissions) { 65static Result MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 other_permissions) {
66 using Kernel::SharedMemory;
67 using Kernel::MemoryPermission;
68
66 LOG_TRACE(Kernel_SVC, "called memblock=0x%08X, addr=0x%08X, mypermissions=0x%08X, otherpermission=%d", 69 LOG_TRACE(Kernel_SVC, "called memblock=0x%08X, addr=0x%08X, mypermissions=0x%08X, otherpermission=%d",
67 handle, addr, permissions, other_permissions); 70 handle, addr, permissions, other_permissions);
68 71
69 Kernel::MemoryPermission permissions_type = static_cast<Kernel::MemoryPermission>(permissions); 72 SharedPtr<SharedMemory> shared_memory = Kernel::g_handle_table.Get<SharedMemory>(handle);
73 if (shared_memory == nullptr)
74 return InvalidHandle(ErrorModule::Kernel).raw;
75
76 MemoryPermission permissions_type = static_cast<MemoryPermission>(permissions);
70 switch (permissions_type) { 77 switch (permissions_type) {
71 case Kernel::MemoryPermission::Read: 78 case MemoryPermission::Read:
72 case Kernel::MemoryPermission::Write: 79 case MemoryPermission::Write:
73 case Kernel::MemoryPermission::ReadWrite: 80 case MemoryPermission::ReadWrite:
74 case Kernel::MemoryPermission::Execute: 81 case MemoryPermission::Execute:
75 case Kernel::MemoryPermission::ReadExecute: 82 case MemoryPermission::ReadExecute:
76 case Kernel::MemoryPermission::WriteExecute: 83 case MemoryPermission::WriteExecute:
77 case Kernel::MemoryPermission::ReadWriteExecute: 84 case MemoryPermission::ReadWriteExecute:
78 case Kernel::MemoryPermission::DontCare: 85 case MemoryPermission::DontCare:
79 Kernel::MapSharedMemory(handle, addr, permissions_type, 86 shared_memory->Map(addr, permissions_type,
80 static_cast<Kernel::MemoryPermission>(other_permissions)); 87 static_cast<MemoryPermission>(other_permissions));
81 break; 88 break;
82 default: 89 default:
83 LOG_ERROR(Kernel_SVC, "unknown permissions=0x%08X", permissions); 90 LOG_ERROR(Kernel_SVC, "unknown permissions=0x%08X", permissions);
@@ -463,12 +470,19 @@ static s64 GetSystemTick() {
463 470
464/// Creates a memory block at the specified address with the specified permissions and size 471/// Creates a memory block at the specified address with the specified permissions and size
465static Result CreateMemoryBlock(Handle* memblock, u32 addr, u32 size, u32 my_permission, 472static Result CreateMemoryBlock(Handle* memblock, u32 addr, u32 size, u32 my_permission,
466 u32 other_permission) { 473 u32 other_permission) {
467 474 using Kernel::SharedMemory;
468 // TODO(Subv): Implement this function 475 // TODO(Subv): Implement this function
469 476
470 Handle shared_memory = Kernel::CreateSharedMemory(); 477 ResultVal<SharedPtr<SharedMemory>> shared_memory_res = SharedMemory::Create();
471 *memblock = shared_memory; 478 if (shared_memory_res.Failed())
479 return shared_memory_res.Code().raw;
480
481 ResultVal<Handle> handle_res = Kernel::g_handle_table.Create(*shared_memory_res);
482 if (handle_res.Failed())
483 return handle_res.Code().raw;
484
485 *memblock = *handle_res;
472 LOG_WARNING(Kernel_SVC, "(STUBBED) called addr=0x%08X", addr); 486 LOG_WARNING(Kernel_SVC, "(STUBBED) called addr=0x%08X", addr);
473 return 0; 487 return 0;
474} 488}