Browse Source
[hle] fix explicitly allocated memory, workaround for TLS pages
pull/4181/head
Exverge
1 week ago
No known key found for this signature in database
GPG Key ID: DAD399BCC5FB77E4
4 changed files with
9 additions and
4 deletions
-
src/core/hle/kernel/k_memory_manager.cpp
-
src/core/hle/kernel/k_memory_manager.h
-
src/core/hle/kernel/k_page_table_base.cpp
-
src/core/hle/kernel/k_thread_local_page.cpp
|
|
|
@ -388,7 +388,7 @@ Result KMemoryManager::AllocateAndOpen(KPageGroup* out, size_t num_pages, u32 op |
|
|
|
} |
|
|
|
|
|
|
|
Result KMemoryManager::AllocateForProcess(KPageGroup* out, size_t num_pages, u32 option, |
|
|
|
u64 process_id, u8 fill_pattern) { |
|
|
|
u64 process_id, u8 fill_pattern, KProcessAddress expected_vaddr) { |
|
|
|
ASSERT(out != nullptr); |
|
|
|
ASSERT(out->GetNumPages() == 0); |
|
|
|
|
|
|
|
@ -407,7 +407,7 @@ Result KMemoryManager::AllocateForProcess(KPageGroup* out, size_t num_pages, u32 |
|
|
|
|
|
|
|
// Allocate the page group.
|
|
|
|
R_TRY(this->AllocatePageGroupImpl(out, num_pages, pool, dir, has_optimized && !is_optimized, |
|
|
|
false, 0)); |
|
|
|
false, expected_vaddr)); |
|
|
|
|
|
|
|
// Set whether we should optimize.
|
|
|
|
optimized = has_optimized && is_optimized; |
|
|
|
|
|
|
|
@ -61,7 +61,7 @@ public: |
|
|
|
KPhysicalAddress AllocateAndOpenContinuous(size_t num_pages, size_t align_pages, u32 option); |
|
|
|
Result AllocateAndOpen(KPageGroup* out, size_t num_pages, u32 option, KProcessAddress expected_vaddr = 0); |
|
|
|
Result AllocateForProcess(KPageGroup* out, size_t num_pages, u32 option, u64 process_id, |
|
|
|
u8 fill_pattern); |
|
|
|
u8 fill_pattern, KProcessAddress expected_vaddr = 0); |
|
|
|
|
|
|
|
Pool GetPool(KPhysicalAddress address) const { |
|
|
|
return this->GetManager(address).GetPool(); |
|
|
|
|
|
|
|
@ -5206,7 +5206,7 @@ Result KPageTableBase::MapPhysicalMemory(KProcessAddress address, size_t size) { |
|
|
|
KPageGroup pg(m_system.Kernel(), m_block_info_manager); |
|
|
|
R_TRY(m_system.Kernel().MemoryManager().AllocateForProcess( |
|
|
|
std::addressof(pg), (size - mapped_size) / PageSize, m_allocate_option, |
|
|
|
GetCurrentProcess(m_system.Kernel()).GetId(), m_heap_fill_value)); |
|
|
|
GetCurrentProcess(m_system.Kernel()).GetId(), m_heap_fill_value, address)); |
|
|
|
|
|
|
|
// If we fail in the next bit (or retry), we need to cleanup the pages.
|
|
|
|
auto pg_guard = SCOPE_GUARD { |
|
|
|
|
|
|
|
@ -20,6 +20,11 @@ Result KThreadLocalPage::Initialize(KernelCore& kernel, KProcess* process) { |
|
|
|
|
|
|
|
// Allocate a new page.
|
|
|
|
KPageBuffer* page_buf = KPageBuffer::Allocate(kernel); |
|
|
|
// TODO: this sucks and wastes memory don't do this
|
|
|
|
while (!Common::IsAligned(reinterpret_cast<u64>(page_buf), Common::HostPageSize)) { |
|
|
|
page_buf = KPageBuffer::Allocate(kernel); |
|
|
|
} |
|
|
|
|
|
|
|
R_UNLESS(page_buf != nullptr, ResultOutOfMemory); |
|
|
|
auto page_buf_guard = SCOPE_GUARD { |
|
|
|
KPageBuffer::Free(kernel, page_buf); |
|
|
|
|