summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel
diff options
context:
space:
mode:
authorGravatar archshift2015-05-10 18:07:44 -0700
committerGravatar archshift2015-05-10 18:07:44 -0700
commite98fbadf4a49eecc6d39c082cba683d5d88ea2c5 (patch)
tree7901b6ad673f8950d4f36d731eaa45b195cac763 /src/core/hle/kernel
parentMerge pull request #741 from Subv/tls (diff)
parentfixup! GSP: Small tweaks to shared memory initialization (diff)
downloadyuzu-e98fbadf4a49eecc6d39c082cba683d5d88ea2c5.tar.gz
yuzu-e98fbadf4a49eecc6d39c082cba683d5d88ea2c5.tar.xz
yuzu-e98fbadf4a49eecc6d39c082cba683d5d88ea2c5.zip
Merge pull request #740 from yuriks/gsp-shmem
Fix crashes due to un-initialized GSP shared memory
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r--src/core/hle/kernel/shared_memory.cpp28
-rw-r--r--src/core/hle/kernel/shared_memory.h25
2 files changed, 37 insertions, 16 deletions
diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp
index cb5c16696..0c59f4876 100644
--- a/src/core/hle/kernel/shared_memory.cpp
+++ b/src/core/hle/kernel/shared_memory.cpp
@@ -2,6 +2,8 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <cstring>
6
5#include "common/logging/log.h" 7#include "common/logging/log.h"
6 8
7#include "core/mem_map.h" 9#include "core/mem_map.h"
@@ -12,11 +14,15 @@ namespace Kernel {
12SharedMemory::SharedMemory() {} 14SharedMemory::SharedMemory() {}
13SharedMemory::~SharedMemory() {} 15SharedMemory::~SharedMemory() {}
14 16
15SharedPtr<SharedMemory> SharedMemory::Create(std::string name) { 17SharedPtr<SharedMemory> SharedMemory::Create(u32 size, MemoryPermission permissions,
18 MemoryPermission other_permissions, std::string name) {
16 SharedPtr<SharedMemory> shared_memory(new SharedMemory); 19 SharedPtr<SharedMemory> shared_memory(new SharedMemory);
17 20
18 shared_memory->name = std::move(name); 21 shared_memory->name = std::move(name);
19 shared_memory->base_address = 0x0; 22 shared_memory->base_address = 0x0;
23 shared_memory->size = size;
24 shared_memory->permissions = permissions;
25 shared_memory->other_permissions = other_permissions;
20 26
21 return shared_memory; 27 return shared_memory;
22} 28}
@@ -24,7 +30,7 @@ SharedPtr<SharedMemory> SharedMemory::Create(std::string name) {
24ResultCode SharedMemory::Map(VAddr address, MemoryPermission permissions, 30ResultCode SharedMemory::Map(VAddr address, MemoryPermission permissions,
25 MemoryPermission other_permissions) { 31 MemoryPermission other_permissions) {
26 32
27 if (address < Memory::SHARED_MEMORY_VADDR || address >= Memory::SHARED_MEMORY_VADDR_END) { 33 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!", 34 LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X outside of shared mem bounds!",
29 GetObjectId(), address); 35 GetObjectId(), address);
30 // TODO: Verify error code with hardware 36 // TODO: Verify error code with hardware
@@ -32,21 +38,25 @@ ResultCode SharedMemory::Map(VAddr address, MemoryPermission permissions,
32 ErrorSummary::InvalidArgument, ErrorLevel::Permanent); 38 ErrorSummary::InvalidArgument, ErrorLevel::Permanent);
33 } 39 }
34 40
41 // TODO: Test permissions
42
43 // HACK: Since there's no way to write to the memory block without mapping it onto the game
44 // process yet, at least initialize memory the first time it's mapped.
45 if (address != this->base_address) {
46 std::memset(Memory::GetPointer(address), 0, size);
47 }
48
35 this->base_address = address; 49 this->base_address = address;
36 this->permissions = permissions;
37 this->other_permissions = other_permissions;
38 50
39 return RESULT_SUCCESS; 51 return RESULT_SUCCESS;
40} 52}
41 53
42ResultVal<u8*> SharedMemory::GetPointer(u32 offset) { 54u8* SharedMemory::GetPointer(u32 offset) {
43 if (base_address != 0) 55 if (base_address != 0)
44 return MakeResult<u8*>(Memory::GetPointer(base_address + offset)); 56 return Memory::GetPointer(base_address + offset);
45 57
46 LOG_ERROR(Kernel_SVC, "memory block id=%u not mapped!", GetObjectId()); 58 LOG_ERROR(Kernel_SVC, "memory block id=%u not mapped!", GetObjectId());
47 // TODO(yuriks): Verify error code. 59 return nullptr;
48 return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel,
49 ErrorSummary::InvalidState, ErrorLevel::Permanent);
50} 60}
51 61
52} // namespace 62} // 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();