diff options
| author | 2015-05-10 19:47:07 -0300 | |
|---|---|---|
| committer | 2015-05-10 19:47:07 -0300 | |
| commit | c96f22490a4a459d477f446fd4e5f894f580b69c (patch) | |
| tree | 3047a04a88ecd381f2e2984b41b2fb21119940d9 /src/core/hle/kernel | |
| parent | Merge pull request #736 from yuriks/remove-BIT (diff) | |
| download | yuzu-c96f22490a4a459d477f446fd4e5f894f580b69c.tar.gz yuzu-c96f22490a4a459d477f446fd4e5f894f580b69c.tar.xz yuzu-c96f22490a4a459d477f446fd4e5f894f580b69c.zip | |
Kernel: Capture SharedMemory attributes at creation, not when mapping
Diffstat (limited to 'src/core/hle/kernel')
| -rw-r--r-- | src/core/hle/kernel/shared_memory.cpp | 20 | ||||
| -rw-r--r-- | src/core/hle/kernel/shared_memory.h | 25 |
2 files changed, 29 insertions, 16 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 { | |||
| 12 | SharedMemory::SharedMemory() {} | 12 | SharedMemory::SharedMemory() {} |
| 13 | SharedMemory::~SharedMemory() {} | 13 | SharedMemory::~SharedMemory() {} |
| 14 | 14 | ||
| 15 | SharedPtr<SharedMemory> SharedMemory::Create(std::string name) { | 15 | SharedPtr<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) { | |||
| 24 | ResultCode SharedMemory::Map(VAddr address, MemoryPermission permissions, | 28 | ResultCode 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 | ||
| 42 | ResultVal<u8*> SharedMemory::GetPointer(u32 offset) { | 46 | u8* 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 { | |||
| 27 | public: | 27 | public: |
| 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 | ||
| 59 | private: | 70 | private: |
| 60 | SharedMemory(); | 71 | SharedMemory(); |