From 0f544af89a63a9aac6ddc3d57e093fa6c91fcb49 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 19 Nov 2018 09:00:32 -0500 Subject: [PATCH] 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.cpp | 7 +++++++ src/core/hle/kernel/shared_memory.h | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp index eec74bfde..92d6985c3 100644 --- a/src/core/hle/kernel/shared_memory.cpp +++ b/src/core/hle/kernel/shared_memory.cpp @@ -196,4 +196,11 @@ u8* SharedMemory::GetPointer(u32 offset) { return backing_blocks[0].first + offset; } +const u8* SharedMemory::GetPointer(u32 offset) const { + if (backing_blocks.size() != 1) { + LOG_WARNING(Kernel, "Unsafe GetPointer on discontinuous SharedMemory"); + } + return backing_blocks[0].first + offset; +} + } // namespace Kernel diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h index 7ba45dd00..510d47631 100644 --- a/src/core/hle/kernel/shared_memory.h +++ b/src/core/hle/kernel/shared_memory.h @@ -66,10 +66,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(u32 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(u32 offset = 0) const; + private: explicit SharedMemory(KernelSystem& kernel); ~SharedMemory() override;