summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2015-05-10 19:47:07 -0300
committerGravatar Yuri Kunde Schlesner2015-05-10 19:47:07 -0300
commitc96f22490a4a459d477f446fd4e5f894f580b69c (patch)
tree3047a04a88ecd381f2e2984b41b2fb21119940d9 /src
parentMerge pull request #736 from yuriks/remove-BIT (diff)
downloadyuzu-c96f22490a4a459d477f446fd4e5f894f580b69c.tar.gz
yuzu-c96f22490a4a459d477f446fd4e5f894f580b69c.tar.xz
yuzu-c96f22490a4a459d477f446fd4e5f894f580b69c.zip
Kernel: Capture SharedMemory attributes at creation, not when mapping
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/shared_memory.cpp20
-rw-r--r--src/core/hle/kernel/shared_memory.h25
-rw-r--r--src/core/hle/service/apt/apt.cpp4
-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/ir/ir.cpp4
-rw-r--r--src/core/hle/svc.cpp4
7 files changed, 51 insertions, 28 deletions
diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp
index cb5c16696..178589cbb 100644
--- a/src/core/hle/kernel/shared_memory.cpp
+++ b/src/core/hle/kernel/shared_memory.cpp
@@ -12,11 +12,15 @@ namespace Kernel {
12SharedMemory::SharedMemory() {} 12SharedMemory::SharedMemory() {}
13SharedMemory::~SharedMemory() {} 13SharedMemory::~SharedMemory() {}
14 14
15SharedPtr<SharedMemory> SharedMemory::Create(std::string name) { 15SharedPtr<SharedMemory> SharedMemory::Create(u32 size, MemoryPermission permissions,
16 MemoryPermission other_permissions, std::string name) {
16 SharedPtr<SharedMemory> shared_memory(new SharedMemory); 17 SharedPtr<SharedMemory> shared_memory(new SharedMemory);
17 18
18 shared_memory->name = std::move(name); 19 shared_memory->name = std::move(name);
19 shared_memory->base_address = 0x0; 20 shared_memory->base_address = 0x0;
21 shared_memory->size = size;
22 shared_memory->permissions = permissions;
23 shared_memory->other_permissions = other_permissions;
20 24
21 return shared_memory; 25 return shared_memory;
22} 26}
@@ -24,7 +28,7 @@ SharedPtr<SharedMemory> SharedMemory::Create(std::string name) {
24ResultCode SharedMemory::Map(VAddr address, MemoryPermission permissions, 28ResultCode SharedMemory::Map(VAddr address, MemoryPermission permissions,
25 MemoryPermission other_permissions) { 29 MemoryPermission other_permissions) {
26 30
27 if (address < Memory::SHARED_MEMORY_VADDR || address >= Memory::SHARED_MEMORY_VADDR_END) { 31 if (address < Memory::SHARED_MEMORY_VADDR || address + size >= Memory::SHARED_MEMORY_VADDR_END) {
28 LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X outside of shared mem bounds!", 32 LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X outside of shared mem bounds!",
29 GetObjectId(), address); 33 GetObjectId(), address);
30 // TODO: Verify error code with hardware 34 // TODO: Verify error code with hardware
@@ -32,21 +36,19 @@ ResultCode SharedMemory::Map(VAddr address, MemoryPermission permissions,
32 ErrorSummary::InvalidArgument, ErrorLevel::Permanent); 36 ErrorSummary::InvalidArgument, ErrorLevel::Permanent);
33 } 37 }
34 38
39 // TODO: Test permissions
40
35 this->base_address = address; 41 this->base_address = address;
36 this->permissions = permissions;
37 this->other_permissions = other_permissions;
38 42
39 return RESULT_SUCCESS; 43 return RESULT_SUCCESS;
40} 44}
41 45
42ResultVal<u8*> SharedMemory::GetPointer(u32 offset) { 46u8* SharedMemory::GetPointer(u32 offset) {
43 if (base_address != 0) 47 if (base_address != 0)
44 return MakeResult<u8*>(Memory::GetPointer(base_address + offset)); 48 return Memory::GetPointer(base_address + offset);
45 49
46 LOG_ERROR(Kernel_SVC, "memory block id=%u not mapped!", GetObjectId()); 50 LOG_ERROR(Kernel_SVC, "memory block id=%u not mapped!", GetObjectId());
47 // TODO(yuriks): Verify error code. 51 return nullptr;
48 return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel,
49 ErrorSummary::InvalidState, ErrorLevel::Permanent);
50} 52}
51 53
52} // namespace 54} // namespace
diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h
index 5833b411c..204266896 100644
--- a/src/core/hle/kernel/shared_memory.h
+++ b/src/core/hle/kernel/shared_memory.h
@@ -27,11 +27,16 @@ class SharedMemory final : public Object {
27public: 27public:
28 /** 28 /**
29 * Creates a shared memory object 29 * Creates a shared memory object
30 * @param name Optional object name, used only for debugging purposes. 30 * @param size Size of the memory block. Must be page-aligned.
31 * @param permissions Permission restrictions applied to the process which created the block.
32 * @param other_permissions Permission restrictions applied to other processes mapping the block.
33 * @param name Optional object name, used for debugging purposes.
31 */ 34 */
32 static SharedPtr<SharedMemory> Create(std::string name = "Unknown"); 35 static SharedPtr<SharedMemory> Create(u32 size, MemoryPermission permissions,
36 MemoryPermission other_permissions, std::string name = "Unknown");
33 37
34 std::string GetTypeName() const override { return "SharedMemory"; } 38 std::string GetTypeName() const override { return "SharedMemory"; }
39 std::string GetName() const override { return name; }
35 40
36 static const HandleType HANDLE_TYPE = HandleType::SharedMemory; 41 static const HandleType HANDLE_TYPE = HandleType::SharedMemory;
37 HandleType GetHandleType() const override { return HANDLE_TYPE; } 42 HandleType GetHandleType() const override { return HANDLE_TYPE; }
@@ -49,12 +54,18 @@ public:
49 * @param offset Offset from the start of the shared memory block to get pointer 54 * @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 55 * @return Pointer to the shared memory block from the specified offset
51 */ 56 */
52 ResultVal<u8*> GetPointer(u32 offset = 0); 57 u8* GetPointer(u32 offset = 0);
53 58
54 VAddr base_address; ///< Address of shared memory block in RAM 59 /// Address of shared memory block in the process.
55 MemoryPermission permissions; ///< Permissions of shared memory block (SVC field) 60 VAddr base_address;
56 MemoryPermission other_permissions; ///< Other permissions of shared memory block (SVC field) 61 /// Size of the memory block. Page-aligned.
57 std::string name; ///< Name of shared memory object (optional) 62 u32 size;
63 /// Permission restrictions applied to the process which created the block.
64 MemoryPermission permissions;
65 /// Permission restrictions applied to other processes mapping the block.
66 MemoryPermission other_permissions;
67 /// Name of shared memory object.
68 std::string name;
58 69
59private: 70private:
60 SharedMemory(); 71 SharedMemory();
diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp
index 560c9dcf6..09d463dd5 100644
--- a/src/core/hle/service/apt/apt.cpp
+++ b/src/core/hle/service/apt/apt.cpp
@@ -304,7 +304,9 @@ void Init() {
304 file.ReadBytes(shared_font.data(), (size_t)file.GetSize()); 304 file.ReadBytes(shared_font.data(), (size_t)file.GetSize());
305 305
306 // Create shared font memory object 306 // Create shared font memory object
307 shared_font_mem = Kernel::SharedMemory::Create("APT_U:shared_font_mem"); 307 using Kernel::MemoryPermission;
308 shared_font_mem = Kernel::SharedMemory::Create(3 * 1024 * 1024, // 3MB
309 MemoryPermission::ReadWrite, MemoryPermission::Read, "APT_U:shared_font_mem");
308 } else { 310 } else {
309 LOG_WARNING(Service_APT, "Unable to load shared font: %s", filepath.c_str()); 311 LOG_WARNING(Service_APT, "Unable to load shared font: %s", filepath.c_str());
310 shared_font_mem = nullptr; 312 shared_font_mem = nullptr;
diff --git a/src/core/hle/service/gsp_gpu.cpp b/src/core/hle/service/gsp_gpu.cpp
index 8da063bd2..e2b6b0b02 100644
--- a/src/core/hle/service/gsp_gpu.cpp
+++ b/src/core/hle/service/gsp_gpu.cpp
@@ -35,8 +35,7 @@ u32 g_thread_id = 1;
35 35
36/// Gets a pointer to a thread command buffer in GSP shared memory 36/// Gets a pointer to a thread command buffer in GSP shared memory
37static inline u8* GetCommandBuffer(u32 thread_id) { 37static inline u8* GetCommandBuffer(u32 thread_id) {
38 ResultVal<u8*> ptr = g_shared_memory->GetPointer(0x800 + (thread_id * sizeof(CommandBuffer))); 38 return g_shared_memory->GetPointer(0x800 + (thread_id * sizeof(CommandBuffer)));
39 return ptr.ValueOr(nullptr);
40} 39}
41 40
42static inline FrameBufferUpdate* GetFrameBufferInfo(u32 thread_id, u32 screen_index) { 41static inline FrameBufferUpdate* GetFrameBufferInfo(u32 thread_id, u32 screen_index) {
@@ -44,14 +43,14 @@ static inline FrameBufferUpdate* GetFrameBufferInfo(u32 thread_id, u32 screen_in
44 43
45 // For each thread there are two FrameBufferUpdate fields 44 // For each thread there are two FrameBufferUpdate fields
46 u32 offset = 0x200 + (2 * thread_id + screen_index) * sizeof(FrameBufferUpdate); 45 u32 offset = 0x200 + (2 * thread_id + screen_index) * sizeof(FrameBufferUpdate);
47 ResultVal<u8*> ptr = g_shared_memory->GetPointer(offset); 46 u8* ptr = g_shared_memory->GetPointer(offset);
48 return reinterpret_cast<FrameBufferUpdate*>(ptr.ValueOr(nullptr)); 47 return reinterpret_cast<FrameBufferUpdate*>(ptr);
49} 48}
50 49
51/// Gets a pointer to the interrupt relay queue for a given thread index 50/// Gets a pointer to the interrupt relay queue for a given thread index
52static inline InterruptRelayQueue* GetInterruptRelayQueue(u32 thread_id) { 51static inline InterruptRelayQueue* GetInterruptRelayQueue(u32 thread_id) {
53 ResultVal<u8*> ptr = g_shared_memory->GetPointer(sizeof(InterruptRelayQueue) * thread_id); 52 u8* ptr = g_shared_memory->GetPointer(sizeof(InterruptRelayQueue) * thread_id);
54 return reinterpret_cast<InterruptRelayQueue*>(ptr.ValueOr(nullptr)); 53 return reinterpret_cast<InterruptRelayQueue*>(ptr);
55} 54}
56 55
57/** 56/**
@@ -288,7 +287,10 @@ static void RegisterInterruptRelayQueue(Service::Interface* self) {
288 287
289 g_interrupt_event = Kernel::g_handle_table.Get<Kernel::Event>(cmd_buff[3]); 288 g_interrupt_event = Kernel::g_handle_table.Get<Kernel::Event>(cmd_buff[3]);
290 ASSERT_MSG((g_interrupt_event != nullptr), "handle is not valid!"); 289 ASSERT_MSG((g_interrupt_event != nullptr), "handle is not valid!");
291 g_shared_memory = Kernel::SharedMemory::Create("GSPSharedMem"); 290
291 using Kernel::MemoryPermission;
292 g_shared_memory = Kernel::SharedMemory::Create(0x1000, MemoryPermission::ReadWrite,
293 MemoryPermission::ReadWrite, "GSPSharedMem");
292 294
293 Handle shmem_handle = Kernel::g_handle_table.Create(g_shared_memory).MoveFrom(); 295 Handle shmem_handle = Kernel::g_handle_table.Create(g_shared_memory).MoveFrom();
294 296
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index dd85848d0..9695f7e56 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -48,7 +48,7 @@ static u32 next_touch_index;
48// * Set PadData.current_state.circle_right = 1 if current PadEntry.circle_pad_y <= -41 48// * Set PadData.current_state.circle_right = 1 if current PadEntry.circle_pad_y <= -41
49 49
50void Update() { 50void Update() {
51 SharedMem* mem = reinterpret_cast<SharedMem*>(shared_mem->GetPointer().ValueOr(nullptr)); 51 SharedMem* mem = reinterpret_cast<SharedMem*>(shared_mem->GetPointer());
52 const PadState state = VideoCore::g_emu_window->GetPadState(); 52 const PadState state = VideoCore::g_emu_window->GetPadState();
53 53
54 if (mem == nullptr) { 54 if (mem == nullptr) {
@@ -163,7 +163,9 @@ void Init() {
163 AddService(new HID_U_Interface); 163 AddService(new HID_U_Interface);
164 AddService(new HID_SPVR_Interface); 164 AddService(new HID_SPVR_Interface);
165 165
166 shared_mem = SharedMemory::Create("HID:SharedMem"); 166 using Kernel::MemoryPermission;
167 shared_mem = SharedMemory::Create(0x1000, MemoryPermission::ReadWrite,
168 MemoryPermission::Read, "HID:SharedMem");
167 169
168 next_pad_index = 0; 170 next_pad_index = 0;
169 next_touch_index = 0; 171 next_touch_index = 0;
diff --git a/src/core/hle/service/ir/ir.cpp b/src/core/hle/service/ir/ir.cpp
index 15ac477ef..adfbb258d 100644
--- a/src/core/hle/service/ir/ir.cpp
+++ b/src/core/hle/service/ir/ir.cpp
@@ -34,7 +34,9 @@ void Init() {
34 AddService(new IR_U_Interface); 34 AddService(new IR_U_Interface);
35 AddService(new IR_User_Interface); 35 AddService(new IR_User_Interface);
36 36
37 shared_memory = SharedMemory::Create("IR:SharedMemory"); 37 using Kernel::MemoryPermission;
38 shared_memory = SharedMemory::Create(0x1000, Kernel::MemoryPermission::ReadWrite,
39 Kernel::MemoryPermission::ReadWrite, "IR:SharedMemory");
38 40
39 // Create event handle(s) 41 // Create event handle(s)
40 handle_event = Event::Create(RESETTYPE_ONESHOT, "IR:HandleEvent"); 42 handle_event = Event::Create(RESETTYPE_ONESHOT, "IR:HandleEvent");
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp
index 393cfbe79..1ec6599c7 100644
--- a/src/core/hle/svc.cpp
+++ b/src/core/hle/svc.cpp
@@ -601,7 +601,9 @@ static ResultCode CreateMemoryBlock(Handle* out_handle, u32 addr, u32 size, u32
601 using Kernel::SharedMemory; 601 using Kernel::SharedMemory;
602 // TODO(Subv): Implement this function 602 // TODO(Subv): Implement this function
603 603
604 SharedPtr<SharedMemory> shared_memory = SharedMemory::Create(); 604 using Kernel::MemoryPermission;
605 SharedPtr<SharedMemory> shared_memory = SharedMemory::Create(size,
606 (MemoryPermission)my_permission, (MemoryPermission)other_permission);
605 CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(shared_memory))); 607 CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(shared_memory)));
606 608
607 LOG_WARNING(Kernel_SVC, "(STUBBED) called addr=0x%08X", addr); 609 LOG_WARNING(Kernel_SVC, "(STUBBED) called addr=0x%08X", addr);