kern: randomize dynamic slab heaps to reflect 10.x changes

This commit is contained in:
Michael Scire
2020-04-19 00:35:05 -07:00
parent b4d003b4b9
commit dcfb3bc9b5
4 changed files with 45 additions and 20 deletions

View File

@@ -64,11 +64,12 @@ namespace ams::kern {
this->page_bitmap.Initialize(metadata_ptr, this->count);
/* Free the pages to the bitmap. */
PageBuffer *cur_page = GetPointer<PageBuffer>(this->address);
std::memset(GetPointer<PageBuffer>(this->address), 0, this->count * sizeof(PageBuffer));
for (size_t i = 0; i < this->count; i++) {
std::memset(cur_page, 0, sizeof(*cur_page));
this->page_bitmap.SetBit(i);
}
return ResultSuccess();
}
constexpr KVirtualAddress GetAddress() const { return this->address; }

View File

@@ -77,6 +77,23 @@ namespace ams::kern {
this->size = this->page_allocator->GetSize();
}
void Initialize(KDynamicPageManager *page_allocator, size_t num_objects) {
MESOSPHERE_ASSERT(page_allocator != nullptr);
/* Initialize members. */
this->Initialize(page_allocator);
/* Allocate until we have the correct number of objects. */
while (this->count < num_objects) {
auto *allocated = reinterpret_cast<T *>(this->page_allocator->Allocate());
MESOSPHERE_ABORT_UNLESS(allocated != nullptr);
for (size_t i = 0; i < sizeof(PageBuffer) / sizeof(T); i++) {
this->GetImpl()->Free(allocated + i);
}
this->count += sizeof(PageBuffer) / sizeof(T);
}
}
T *Allocate() {
T *allocated = reinterpret_cast<T *>(this->GetImpl()->Allocate());

View File

@@ -57,13 +57,13 @@ namespace ams::kern {
return std::addressof(this->ref_counts[(addr - this->GetAddress()) / PageSize]);
}
public:
void Initialize(KDynamicPageManager *next_allocator, RefCount *rc) {
BaseHeap::Initialize(next_allocator);
void Initialize(KDynamicPageManager *page_allocator, RefCount *rc) {
BaseHeap::Initialize(page_allocator);
this->Initialize(rc);
}
void Initialize(KVirtualAddress memory, size_t sz, RefCount *rc) {
BaseHeap::Initialize(memory, sz);
void Initialize(KDynamicPageManager *page_allocator, size_t object_count, RefCount *rc) {
BaseHeap::Initialize(page_allocator, object_count);
this->Initialize(rc);
}