From f4722327059b3a618ea63539a31c4f5a16e14bd4 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 19 Nov 2018 08:29:25 -0500 Subject: kernel/shared_memory: Make data members private Rather than allow unfettered access to the class internals, we hide all members by default and create and API that other code can operate against. --- src/core/hle/kernel/shared_memory.h | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src/core/hle/kernel/shared_memory.h') diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h index 2c06bb7ce..9a7c189e8 100644 --- a/src/core/hle/kernel/shared_memory.h +++ b/src/core/hle/kernel/shared_memory.h @@ -81,6 +81,11 @@ public: return HANDLE_TYPE; } + /// Gets the size of the underlying memory block in bytes. + u64 GetSize() const { + return size; + } + /** * Converts the specified MemoryPermission into the equivalent VMAPermission. * @param permission The MemoryPermission to convert. @@ -112,26 +117,26 @@ public: */ u8* GetPointer(u32 offset = 0); - /// Process that created this shared memory block. - SharedPtr owner_process; - /// Address of shared memory block in the owner process if specified. - VAddr base_address; +private: + explicit SharedMemory(KernelCore& kernel); + ~SharedMemory() override; + /// Backing memory for this shared memory block. std::shared_ptr> backing_block; /// Offset into the backing block for this shared memory. - std::size_t backing_block_offset; + std::size_t backing_block_offset = 0; /// Size of the memory block. Page-aligned. - u64 size; + u64 size = 0; /// Permission restrictions applied to the process which created the block. - MemoryPermission permissions; + MemoryPermission permissions{}; /// Permission restrictions applied to other processes mapping the block. - MemoryPermission other_permissions; + MemoryPermission other_permissions{}; + /// Process that created this shared memory block. + SharedPtr owner_process; + /// Address of shared memory block in the owner process if specified. + VAddr base_address = 0; /// Name of shared memory object. std::string name; - -private: - explicit SharedMemory(KernelCore& kernel); - ~SharedMemory() override; }; } // namespace Kernel -- cgit v1.2.3 From 76ac234bf66a5cad7898056dcd33f52d2c38a232 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 19 Nov 2018 08:50:28 -0500 Subject: kernel/shared_memory: Make GetPointer() take a std::size_t instead of a u32 Makes the interface nicer to use in terms of 64-bit code, as it makes it less likely for one to get truncation warnings (and also makes sense in the context of the rest of the interface where 64-bit types are used for sizes and offsets --- src/core/hle/kernel/shared_memory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/hle/kernel/shared_memory.h') diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h index 9a7c189e8..7d7d6486d 100644 --- a/src/core/hle/kernel/shared_memory.h +++ b/src/core/hle/kernel/shared_memory.h @@ -115,7 +115,7 @@ public: * @param offset Offset from the start of the shared memory block to get pointer * @return Pointer to the shared memory block from the specified offset */ - u8* GetPointer(u32 offset = 0); + u8* GetPointer(std::size_t offset = 0); private: explicit SharedMemory(KernelCore& kernel); -- cgit v1.2.3 From 2d37ca372615e8e3e2a1feca07c1077dc4a001dd Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 19 Nov 2018 08:56:15 -0500 Subject: kernel/shared_memory: Use 64-bit types for offset and size in CreateForApplet Keeps the interface consistent with the regular Create() function. --- src/core/hle/kernel/shared_memory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/hle/kernel/shared_memory.h') diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h index 7d7d6486d..60433f09b 100644 --- a/src/core/hle/kernel/shared_memory.h +++ b/src/core/hle/kernel/shared_memory.h @@ -64,7 +64,7 @@ public: */ static SharedPtr CreateForApplet(KernelCore& kernel, std::shared_ptr> heap_block, - u32 offset, u32 size, + std::size_t offset, u64 size, MemoryPermission permissions, MemoryPermission other_permissions, std::string name = "Unknown Applet"); -- cgit v1.2.3 From fb5d4b17de035e3682e64513ae7612f40afd01bd Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 19 Nov 2018 09:00:32 -0500 Subject: kernel/shared_memory: Add a const qualified member function overload for GetPointer() Given this doesn't mutate instance state, we can provide a const-qualified variant as well. --- src/core/hle/kernel/shared_memory.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/core/hle/kernel/shared_memory.h') diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h index 60433f09b..f3b05e48b 100644 --- a/src/core/hle/kernel/shared_memory.h +++ b/src/core/hle/kernel/shared_memory.h @@ -113,10 +113,17 @@ public: /** * Gets a pointer to the shared memory block * @param offset Offset from the start of the shared memory block to get pointer - * @return Pointer to the shared memory block from the specified offset + * @return A pointer to the shared memory block from the specified offset */ u8* GetPointer(std::size_t offset = 0); + /** + * Gets a constant pointer to the shared memory block + * @param offset Offset from the start of the shared memory block to get pointer + * @return A constant pointer to the shared memory block from the specified offset + */ + const u8* GetPointer(std::size_t offset = 0) const; + private: explicit SharedMemory(KernelCore& kernel); ~SharedMemory() override; -- cgit v1.2.3 From 233e495c1411a813460ce71efb7be69ff73649ee Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 19 Nov 2018 09:05:04 -0500 Subject: kernel/shared_memory: Make Map() and Unmap() take the target process by reference rather than as a pointer Both member functions assume the passed in target process will not be null. Instead of making this assumption implicit, we can change the functions to be references and enforce this at the type-system level. --- src/core/hle/kernel/shared_memory.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/core/hle/kernel/shared_memory.h') diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h index f3b05e48b..0b48db699 100644 --- a/src/core/hle/kernel/shared_memory.h +++ b/src/core/hle/kernel/shared_memory.h @@ -99,16 +99,16 @@ public: * @param permissions Memory block map permissions (specified by SVC field) * @param other_permissions Memory block map other permissions (specified by SVC field) */ - ResultCode Map(Process* target_process, VAddr address, MemoryPermission permissions, + ResultCode Map(Process& target_process, VAddr address, MemoryPermission permissions, MemoryPermission other_permissions); /** * Unmaps a shared memory block from the specified address in system memory - * @param target_process Process from which to umap the memory block. + * @param target_process Process from which to unmap the memory block. * @param address Address in system memory where the shared memory block is mapped * @return Result code of the unmap operation */ - ResultCode Unmap(Process* target_process, VAddr address); + ResultCode Unmap(Process& target_process, VAddr address); /** * Gets a pointer to the shared memory block -- cgit v1.2.3