citra-emu
/
citra
Archived
1
0
Fork 0

kernel: Fix freeing shared memory with wrong region. (#7301)

This commit is contained in:
Steveice10 2023-12-30 15:36:12 -08:00 committed by GitHub
parent 5bcdcffd96
commit 811303ea54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -18,8 +18,7 @@ SharedMemory::SharedMemory(KernelSystem& kernel) : Object(kernel), kernel(kernel
SharedMemory::~SharedMemory() {
for (const auto& interval : holding_memory) {
kernel.GetMemoryRegion(MemoryRegion::SYSTEM)
->Free(interval.lower(), interval.upper() - interval.lower());
memory_region->Free(interval.lower(), interval.upper() - interval.lower());
}
auto process = owner_process.lock();
@ -39,17 +38,18 @@ ResultVal<std::shared_ptr<SharedMemory>> KernelSystem::CreateSharedMemory(
std::shared_ptr<Process> owner_process, u32 size, MemoryPermission permissions,
MemoryPermission other_permissions, VAddr address, MemoryRegion region, std::string name) {
auto memory_region = GetMemoryRegion(region);
auto shared_memory = std::make_shared<SharedMemory>(*this);
shared_memory->owner_process = owner_process;
shared_memory->name = std::move(name);
shared_memory->size = size;
shared_memory->memory_region = memory_region;
shared_memory->permissions = permissions;
shared_memory->other_permissions = other_permissions;
if (address == 0) {
// We need to allocate a block from the Linear Heap ourselves.
// We'll manually allocate some memory from the linear heap in the specified region.
auto memory_region = GetMemoryRegion(region);
auto offset = memory_region->LinearAllocate(size);
ASSERT_MSG(offset, "Not enough space in region to allocate shared memory!");
@ -93,6 +93,7 @@ std::shared_ptr<SharedMemory> KernelSystem::CreateSharedMemoryForApplet(
shared_memory->owner_process = std::weak_ptr<Process>();
shared_memory->name = std::move(name);
shared_memory->size = size;
shared_memory->memory_region = memory_region;
shared_memory->permissions = permissions;
shared_memory->other_permissions = other_permissions;
for (const auto& interval : backing_blocks) {

View File

@ -94,6 +94,8 @@ private:
std::vector<std::pair<MemoryRef, u32>> backing_blocks;
/// Size of the memory block. Page-aligned.
u32 size = 0;
/// Region of memory this block exists in.
std::shared_ptr<MemoryRegionInfo> memory_region = nullptr;
/// Permission restrictions applied to the process which created the block.
MemoryPermission permissions{};
/// Permission restrictions applied to other processes mapping the block.
@ -116,6 +118,7 @@ private:
ar& linear_heap_phys_offset;
ar& backing_blocks;
ar& size;
ar& memory_region;
ar& permissions;
ar& other_permissions;
ar& owner_process;