mirror of
https://github.com/Lime3DS/Lime3DS
synced 2024-12-27 09:32:30 -06:00
kernel: Fix freeing shared memory with wrong region. (#7301)
This commit is contained in:
parent
5bcdcffd96
commit
811303ea54
2 changed files with 7 additions and 3 deletions
|
@ -18,8 +18,7 @@ SharedMemory::SharedMemory(KernelSystem& kernel) : Object(kernel), kernel(kernel
|
||||||
|
|
||||||
SharedMemory::~SharedMemory() {
|
SharedMemory::~SharedMemory() {
|
||||||
for (const auto& interval : holding_memory) {
|
for (const auto& interval : holding_memory) {
|
||||||
kernel.GetMemoryRegion(MemoryRegion::SYSTEM)
|
memory_region->Free(interval.lower(), interval.upper() - interval.lower());
|
||||||
->Free(interval.lower(), interval.upper() - interval.lower());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto process = owner_process.lock();
|
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,
|
std::shared_ptr<Process> owner_process, u32 size, MemoryPermission permissions,
|
||||||
MemoryPermission other_permissions, VAddr address, MemoryRegion region, std::string name) {
|
MemoryPermission other_permissions, VAddr address, MemoryRegion region, std::string name) {
|
||||||
|
|
||||||
|
auto memory_region = GetMemoryRegion(region);
|
||||||
auto shared_memory = std::make_shared<SharedMemory>(*this);
|
auto shared_memory = std::make_shared<SharedMemory>(*this);
|
||||||
shared_memory->owner_process = owner_process;
|
shared_memory->owner_process = owner_process;
|
||||||
shared_memory->name = std::move(name);
|
shared_memory->name = std::move(name);
|
||||||
shared_memory->size = size;
|
shared_memory->size = size;
|
||||||
|
shared_memory->memory_region = memory_region;
|
||||||
shared_memory->permissions = permissions;
|
shared_memory->permissions = permissions;
|
||||||
shared_memory->other_permissions = other_permissions;
|
shared_memory->other_permissions = other_permissions;
|
||||||
|
|
||||||
if (address == 0) {
|
if (address == 0) {
|
||||||
// We need to allocate a block from the Linear Heap ourselves.
|
// 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.
|
// 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);
|
auto offset = memory_region->LinearAllocate(size);
|
||||||
|
|
||||||
ASSERT_MSG(offset, "Not enough space in region to allocate shared memory!");
|
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->owner_process = std::weak_ptr<Process>();
|
||||||
shared_memory->name = std::move(name);
|
shared_memory->name = std::move(name);
|
||||||
shared_memory->size = size;
|
shared_memory->size = size;
|
||||||
|
shared_memory->memory_region = memory_region;
|
||||||
shared_memory->permissions = permissions;
|
shared_memory->permissions = permissions;
|
||||||
shared_memory->other_permissions = other_permissions;
|
shared_memory->other_permissions = other_permissions;
|
||||||
for (const auto& interval : backing_blocks) {
|
for (const auto& interval : backing_blocks) {
|
||||||
|
|
|
@ -94,6 +94,8 @@ private:
|
||||||
std::vector<std::pair<MemoryRef, u32>> backing_blocks;
|
std::vector<std::pair<MemoryRef, u32>> backing_blocks;
|
||||||
/// Size of the memory block. Page-aligned.
|
/// Size of the memory block. Page-aligned.
|
||||||
u32 size = 0;
|
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.
|
/// Permission restrictions applied to the process which created the block.
|
||||||
MemoryPermission permissions{};
|
MemoryPermission permissions{};
|
||||||
/// Permission restrictions applied to other processes mapping the block.
|
/// Permission restrictions applied to other processes mapping the block.
|
||||||
|
@ -116,6 +118,7 @@ private:
|
||||||
ar& linear_heap_phys_offset;
|
ar& linear_heap_phys_offset;
|
||||||
ar& backing_blocks;
|
ar& backing_blocks;
|
||||||
ar& size;
|
ar& size;
|
||||||
|
ar& memory_region;
|
||||||
ar& permissions;
|
ar& permissions;
|
||||||
ar& other_permissions;
|
ar& other_permissions;
|
||||||
ar& owner_process;
|
ar& owner_process;
|
||||||
|
|
Loading…
Reference in a new issue