kern: implement improved [new page tables are zero] invariant

This commit is contained in:
Michael Scire
2021-06-17 13:03:46 -07:00
parent 25305257d6
commit 4892ffae15
5 changed files with 33 additions and 12 deletions

View File

@@ -22,7 +22,7 @@
namespace ams::kern {
template<typename T>
template<typename T, bool ClearNode = false>
class KDynamicSlabHeap {
NON_COPYABLE(KDynamicSlabHeap);
NON_MOVEABLE(KDynamicSlabHeap);
@@ -97,6 +97,13 @@ namespace ams::kern {
T *Allocate() {
T *allocated = reinterpret_cast<T *>(this->GetImpl()->Allocate());
/* If we successfully allocated and we should clear the node, do so. */
if constexpr (ClearNode) {
if (AMS_LIKELY(allocated != nullptr)) {
reinterpret_cast<Impl::Node *>(allocated)->next = nullptr;
}
}
/* If we fail to allocate, try to get a new page from our next allocator. */
if (AMS_UNLIKELY(allocated == nullptr)) {
if (m_page_allocator != nullptr) {