summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/init
diff options
context:
space:
mode:
authorGravatar bunnei2021-05-01 12:25:51 -0700
committerGravatar bunnei2021-05-05 16:40:53 -0700
commit91d865795933136fa57fe7fdceffddd1b6c49084 (patch)
tree0c5be20bb3a51d21ef4ecc963b2cf0be531c3084 /src/core/hle/kernel/init
parentcommon: Rename NON_COPYABLE/NON_MOVABLE with YUZU_ prefix. (diff)
downloadyuzu-91d865795933136fa57fe7fdceffddd1b6c49084.tar.gz
yuzu-91d865795933136fa57fe7fdceffddd1b6c49084.tar.xz
yuzu-91d865795933136fa57fe7fdceffddd1b6c49084.zip
fixup! hle: kernel: Add initial impl. of slab setup.
Diffstat (limited to 'src/core/hle/kernel/init')
-rw-r--r--src/core/hle/kernel/init/init_slab_setup.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/core/hle/kernel/init/init_slab_setup.cpp b/src/core/hle/kernel/init/init_slab_setup.cpp
index 04e481a0a..3aa76ee33 100644
--- a/src/core/hle/kernel/init/init_slab_setup.cpp
+++ b/src/core/hle/kernel/init/init_slab_setup.cpp
@@ -146,21 +146,21 @@ void InitializeSlabHeaps(Core::System& system, KMemoryLayout& memory_layout) {
146 VAddr address = memory_layout.GetSlabRegionAddress(); 146 VAddr address = memory_layout.GetSlabRegionAddress();
147 147
148 // Initialize slab type array to be in sorted order. 148 // Initialize slab type array to be in sorted order.
149 KSlabType slab_types[KSlabType_Count]; 149 std::array<KSlabType, KSlabType_Count> slab_types;
150 for (size_t i = 0; i < Common::Size(slab_types); i++) { 150 for (size_t i = 0; i < slab_types.size(); i++) {
151 slab_types[i] = static_cast<KSlabType>(i); 151 slab_types[i] = static_cast<KSlabType>(i);
152 } 152 }
153 153
154 // N shuffles the slab type array with the following simple algorithm. 154 // N shuffles the slab type array with the following simple algorithm.
155 for (size_t i = 0; i < Common::Size(slab_types); i++) { 155 for (size_t i = 0; i < slab_types.size(); i++) {
156 const size_t rnd = KSystemControl::GenerateRandomRange(0, Common::Size(slab_types) - 1); 156 const size_t rnd = KSystemControl::GenerateRandomRange(0, slab_types.size() - 1);
157 std::swap(slab_types[i], slab_types[rnd]); 157 std::swap(slab_types[i], slab_types[rnd]);
158 } 158 }
159 159
160 // Create an array to represent the gaps between the slabs. 160 // Create an array to represent the gaps between the slabs.
161 const size_t total_gap_size = CalculateSlabHeapGapSize(); 161 const size_t total_gap_size = CalculateSlabHeapGapSize();
162 size_t slab_gaps[Common::Size(slab_types)]; 162 std::array<size_t, slab_types.size()> slab_gaps;
163 for (size_t i = 0; i < Common::Size(slab_gaps); i++) { 163 for (size_t i = 0; i < slab_gaps.size(); i++) {
164 // Note: This is an off-by-one error from Nintendo's intention, because GenerateRandomRange 164 // Note: This is an off-by-one error from Nintendo's intention, because GenerateRandomRange
165 // is inclusive. However, Nintendo also has the off-by-one error, and it's "harmless", so we 165 // is inclusive. However, Nintendo also has the off-by-one error, and it's "harmless", so we
166 // will include it ourselves. 166 // will include it ourselves.
@@ -169,13 +169,13 @@ void InitializeSlabHeaps(Core::System& system, KMemoryLayout& memory_layout) {
169 169
170 // Sort the array, so that we can treat differences between values as offsets to the starts of 170 // Sort the array, so that we can treat differences between values as offsets to the starts of
171 // slabs. 171 // slabs.
172 for (size_t i = 1; i < Common::Size(slab_gaps); i++) { 172 for (size_t i = 1; i < slab_gaps.size(); i++) {
173 for (size_t j = i; j > 0 && slab_gaps[j - 1] > slab_gaps[j]; j--) { 173 for (size_t j = i; j > 0 && slab_gaps[j - 1] > slab_gaps[j]; j--) {
174 std::swap(slab_gaps[j], slab_gaps[j - 1]); 174 std::swap(slab_gaps[j], slab_gaps[j - 1]);
175 } 175 }
176 } 176 }
177 177
178 for (size_t i = 0; i < Common::Size(slab_types); i++) { 178 for (size_t i = 0; i < slab_types.size(); i++) {
179 // Add the random gap to the address. 179 // Add the random gap to the address.
180 address += (i == 0) ? slab_gaps[0] : slab_gaps[i] - slab_gaps[i - 1]; 180 address += (i == 0) ? slab_gaps[0] : slab_gaps[i] - slab_gaps[i - 1];
181 181