citra-emu
/
citra-canary
Archived
1
0
Fork 0

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.
This commit is contained in:
Lioncash 2018-11-19 08:29:25 -05:00 committed by fearlessTobi
parent 662c3ff684
commit 1cb9bea504
7 changed files with 31 additions and 18 deletions

View File

@ -65,7 +65,7 @@ ResultCode SoftwareKeyboard::StartImpl(Service::APT::AppletStartupParameter cons
boost::static_pointer_cast<Kernel::SharedMemory, Kernel::Object>(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();

View File

@ -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<std::pair<u8*, u32>> 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<Process> 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;
};

View File

@ -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;

View File

@ -50,7 +50,7 @@ void HTTP_C::Initialize(Kernel::HLERequestContext& ctx) {
u32 pid = rp.PopPID();
shared_memory = rp.PopObject<Kernel::SharedMemory>();
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);

View File

@ -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<BufferManager>(shared_memory, 0x10, 0x20,
recv_buff_packet_count, recv_buff_size);

View File

@ -40,7 +40,7 @@ struct MIC_U::Impl {
shared_memory = rp.PopObject<Kernel::SharedMemory>();
if (shared_memory) {
shared_memory->name = "MIC_U:shared_memory";
shared_memory->SetName("MIC_U:shared_memory");
}
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);

View File

@ -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);