Browse Source

[hle] fix explicitly allocated memory, workaround for TLS pages

pull/4181/head
Exverge 1 week ago
parent
commit
3a56c75fe4
No known key found for this signature in database GPG Key ID: DAD399BCC5FB77E4
  1. 4
      src/core/hle/kernel/k_memory_manager.cpp
  2. 2
      src/core/hle/kernel/k_memory_manager.h
  3. 2
      src/core/hle/kernel/k_page_table_base.cpp
  4. 5
      src/core/hle/kernel/k_thread_local_page.cpp

4
src/core/hle/kernel/k_memory_manager.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, 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 != nullptr);
ASSERT(out->GetNumPages() == 0); ASSERT(out->GetNumPages() == 0);
@ -407,7 +407,7 @@ Result KMemoryManager::AllocateForProcess(KPageGroup* out, size_t num_pages, u32
// Allocate the page group. // Allocate the page group.
R_TRY(this->AllocatePageGroupImpl(out, num_pages, pool, dir, has_optimized && !is_optimized, R_TRY(this->AllocatePageGroupImpl(out, num_pages, pool, dir, has_optimized && !is_optimized,
false, 0));
false, expected_vaddr));
// Set whether we should optimize. // Set whether we should optimize.
optimized = has_optimized && is_optimized; optimized = has_optimized && is_optimized;

2
src/core/hle/kernel/k_memory_manager.h

@ -61,7 +61,7 @@ public:
KPhysicalAddress AllocateAndOpenContinuous(size_t num_pages, size_t align_pages, u32 option); 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 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, 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 { Pool GetPool(KPhysicalAddress address) const {
return this->GetManager(address).GetPool(); return this->GetManager(address).GetPool();

2
src/core/hle/kernel/k_page_table_base.cpp

@ -5206,7 +5206,7 @@ Result KPageTableBase::MapPhysicalMemory(KProcessAddress address, size_t size) {
KPageGroup pg(m_system.Kernel(), m_block_info_manager); KPageGroup pg(m_system.Kernel(), m_block_info_manager);
R_TRY(m_system.Kernel().MemoryManager().AllocateForProcess( R_TRY(m_system.Kernel().MemoryManager().AllocateForProcess(
std::addressof(pg), (size - mapped_size) / PageSize, m_allocate_option, 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. // If we fail in the next bit (or retry), we need to cleanup the pages.
auto pg_guard = SCOPE_GUARD { auto pg_guard = SCOPE_GUARD {

5
src/core/hle/kernel/k_thread_local_page.cpp

@ -20,6 +20,11 @@ Result KThreadLocalPage::Initialize(KernelCore& kernel, KProcess* process) {
// Allocate a new page. // Allocate a new page.
KPageBuffer* page_buf = KPageBuffer::Allocate(kernel); 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); R_UNLESS(page_buf != nullptr, ResultOutOfMemory);
auto page_buf_guard = SCOPE_GUARD { auto page_buf_guard = SCOPE_GUARD {
KPageBuffer::Free(kernel, page_buf); KPageBuffer::Free(kernel, page_buf);

Loading…
Cancel
Save