From 1cb9bea504cf6804f982467a00c37561e98c4dfd Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 19 Nov 2018 08:29:25 -0500 Subject: [PATCH] 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/applets/swkbd.cpp | 2 +- src/core/hle/kernel/shared_memory.h | 37 +++++++++++++++++++--------- src/core/hle/service/apt/apt.cpp | 2 +- src/core/hle/service/http_c.cpp | 2 +- src/core/hle/service/ir/ir_user.cpp | 2 +- src/core/hle/service/mic_u.cpp | 2 +- src/core/hle/service/nwm/nwm_uds.cpp | 2 +- 7 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/core/hle/applets/swkbd.cpp b/src/core/hle/applets/swkbd.cpp index 0de0555c0b..fc185bd7bc 100644 --- a/src/core/hle/applets/swkbd.cpp +++ b/src/core/hle/applets/swkbd.cpp @@ -65,7 +65,7 @@ ResultCode SoftwareKeyboard::StartImpl(Service::APT::AppletStartupParameter cons boost::static_pointer_cast(parameter.object); // TODO(Subv): Verify if this is the correct behavior - memset(text_memory->GetPointer(), 0, text_memory->size); + memset(text_memory->GetPointer(), 0, text_memory->GetSize()); DrawScreenKeyboard(); diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h index a48f607baf..7ba45dd00e 100644 --- a/src/core/hle/kernel/shared_memory.h +++ b/src/core/hle/kernel/shared_memory.h @@ -20,12 +20,25 @@ public: std::string GetName() const override { return name; } + void SetName(std::string name) { + this->name = name; + } static const HandleType HANDLE_TYPE = HandleType::SharedMemory; HandleType GetHandleType() const override { return HANDLE_TYPE; } + /// Gets the size of the underlying memory block in bytes. + u64 GetSize() const { + return size; + } + + /// Gets the linear heap physical offset + u64 GetLinearHeapPhysicalOffset() const { + return linear_heap_phys_offset; + } + /** * Converts the specified MemoryPermission into the equivalent VMAPermission. * @param permission The MemoryPermission to convert. @@ -57,30 +70,30 @@ public: */ u8* GetPointer(u32 offset = 0); - /// Process that created this shared memory block. - Process* owner_process; - /// Address of shared memory block in the owner process if specified. - VAddr base_address; +private: + explicit SharedMemory(KernelSystem& kernel); + ~SharedMemory() override; + /// Offset in FCRAM of the shared memory block in the linear heap if no address was specified /// during creation. - PAddr linear_heap_phys_offset; + PAddr linear_heap_phys_offset = 0; /// Backing memory for this shared memory block. std::vector> backing_blocks; /// Size of the memory block. Page-aligned. - u32 size; + u32 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; MemoryRegionInfo::IntervalSet holding_memory; -private: - explicit SharedMemory(KernelSystem& kernel); - ~SharedMemory() override; - friend class KernelSystem; KernelSystem& kernel; }; diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index db8247a2aa..6b779bc309 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -217,7 +217,7 @@ void Module::Interface::GetSharedFont(Kernel::HLERequestContext& ctx) { // shared font, different linear heap region would have required shared font to relocate // according to two different addresses at the same time, which is impossible. VAddr target_address = - apt->shared_font_mem->linear_heap_phys_offset + Memory::LINEAR_HEAP_VADDR; + apt->shared_font_mem->GetLinearHeapPhysicalOffset() + Memory::LINEAR_HEAP_VADDR; if (!apt->shared_font_relocated) { BCFNT::RelocateSharedFont(apt->shared_font_mem, target_address); apt->shared_font_relocated = true; diff --git a/src/core/hle/service/http_c.cpp b/src/core/hle/service/http_c.cpp index f55d6ed0e2..e873e914ef 100644 --- a/src/core/hle/service/http_c.cpp +++ b/src/core/hle/service/http_c.cpp @@ -50,7 +50,7 @@ void HTTP_C::Initialize(Kernel::HLERequestContext& ctx) { u32 pid = rp.PopPID(); shared_memory = rp.PopObject(); if (shared_memory) { - shared_memory->name = "HTTP_C:shared_memory"; + shared_memory->SetName("HTTP_C:shared_memory"); } LOG_WARNING(Service_HTTP, "(STUBBED) called, shared memory size: {} pid: {}", shmem_size, pid); diff --git a/src/core/hle/service/ir/ir_user.cpp b/src/core/hle/service/ir/ir_user.cpp index e0158f67ec..c4466a13f8 100644 --- a/src/core/hle/service/ir/ir_user.cpp +++ b/src/core/hle/service/ir/ir_user.cpp @@ -240,7 +240,7 @@ void IR_USER::InitializeIrNopShared(Kernel::HLERequestContext& ctx) { IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); - shared_memory->name = "IR_USER: shared memory"; + shared_memory->SetName("IR_USER: shared memory"); receive_buffer = std::make_unique(shared_memory, 0x10, 0x20, recv_buff_packet_count, recv_buff_size); diff --git a/src/core/hle/service/mic_u.cpp b/src/core/hle/service/mic_u.cpp index ce95947510..6c97282aa1 100644 --- a/src/core/hle/service/mic_u.cpp +++ b/src/core/hle/service/mic_u.cpp @@ -40,7 +40,7 @@ struct MIC_U::Impl { shared_memory = rp.PopObject(); if (shared_memory) { - shared_memory->name = "MIC_U:shared_memory"; + shared_memory->SetName("MIC_U:shared_memory"); } IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index 85b309f43c..755da4f1d3 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -724,7 +724,7 @@ void NWM_UDS::InitializeWithVersion(Kernel::HLERequestContext& ctx) { initialized = true; - ASSERT_MSG(recv_buffer_memory->size == sharedmem_size, "Invalid shared memory size."); + ASSERT_MSG(recv_buffer_memory->GetSize() == sharedmem_size, "Invalid shared memory size."); if (auto room_member = Network::GetRoomMember().lock()) { wifi_packet_received = room_member->BindOnWifiPacketReceived(OnWifiPacketReceived);