summaryrefslogtreecommitdiff
path: root/src/common/page_table.cpp
diff options
context:
space:
mode:
authorGravatar Liam2024-01-07 13:59:48 -0500
committerGravatar Liam2024-01-12 18:31:33 -0500
commitf2fed21c1139c8d5c030bc5caee5c612dfe7979f (patch)
tree4051a2e4e1c34370fa259ecf36783b76ea66a56f /src/common/page_table.cpp
parentMerge pull request #12605 from german77/abstract (diff)
downloadyuzu-f2fed21c1139c8d5c030bc5caee5c612dfe7979f.tar.gz
yuzu-f2fed21c1139c8d5c030bc5caee5c612dfe7979f.tar.xz
yuzu-f2fed21c1139c8d5c030bc5caee5c612dfe7979f.zip
kernel: fix page leak on process termination
Diffstat (limited to '')
-rw-r--r--src/common/page_table.cpp34
1 files changed, 10 insertions, 24 deletions
diff --git a/src/common/page_table.cpp b/src/common/page_table.cpp
index 166dc3dce..85dc18c11 100644
--- a/src/common/page_table.cpp
+++ b/src/common/page_table.cpp
@@ -2,6 +2,7 @@
2// SPDX-License-Identifier: GPL-2.0-or-later 2// SPDX-License-Identifier: GPL-2.0-or-later
3 3
4#include "common/page_table.h" 4#include "common/page_table.h"
5#include "common/scope_exit.h"
5 6
6namespace Common { 7namespace Common {
7 8
@@ -11,29 +12,10 @@ PageTable::~PageTable() noexcept = default;
11 12
12bool PageTable::BeginTraversal(TraversalEntry* out_entry, TraversalContext* out_context, 13bool PageTable::BeginTraversal(TraversalEntry* out_entry, TraversalContext* out_context,
13 Common::ProcessAddress address) const { 14 Common::ProcessAddress address) const {
14 // Setup invalid defaults. 15 out_context->next_offset = GetInteger(address);
15 out_entry->phys_addr = 0; 16 out_context->next_page = address / page_size;
16 out_entry->block_size = page_size;
17 out_context->next_page = 0;
18
19 // Validate that we can read the actual entry.
20 const auto page = address / page_size;
21 if (page >= backing_addr.size()) {
22 return false;
23 }
24
25 // Validate that the entry is mapped.
26 const auto phys_addr = backing_addr[page];
27 if (phys_addr == 0) {
28 return false;
29 }
30 17
31 // Populate the results. 18 return this->ContinueTraversal(out_entry, out_context);
32 out_entry->phys_addr = phys_addr + GetInteger(address);
33 out_context->next_page = page + 1;
34 out_context->next_offset = GetInteger(address) + page_size;
35
36 return true;
37} 19}
38 20
39bool PageTable::ContinueTraversal(TraversalEntry* out_entry, TraversalContext* context) const { 21bool PageTable::ContinueTraversal(TraversalEntry* out_entry, TraversalContext* context) const {
@@ -41,6 +23,12 @@ bool PageTable::ContinueTraversal(TraversalEntry* out_entry, TraversalContext* c
41 out_entry->phys_addr = 0; 23 out_entry->phys_addr = 0;
42 out_entry->block_size = page_size; 24 out_entry->block_size = page_size;
43 25
26 // Regardless of whether the page was mapped, advance on exit.
27 SCOPE_EXIT({
28 context->next_page += 1;
29 context->next_offset += page_size;
30 });
31
44 // Validate that we can read the actual entry. 32 // Validate that we can read the actual entry.
45 const auto page = context->next_page; 33 const auto page = context->next_page;
46 if (page >= backing_addr.size()) { 34 if (page >= backing_addr.size()) {
@@ -55,8 +43,6 @@ bool PageTable::ContinueTraversal(TraversalEntry* out_entry, TraversalContext* c
55 43
56 // Populate the results. 44 // Populate the results.
57 out_entry->phys_addr = phys_addr + context->next_offset; 45 out_entry->phys_addr = phys_addr + context->next_offset;
58 context->next_page = page + 1;
59 context->next_offset += page_size;
60 46
61 return true; 47 return true;
62} 48}