core: hle: kernel: k_process: Improve management of page table & cleanup.

This commit is contained in:
bunnei 2022-10-02 14:26:30 -07:00
parent 79bcb38321
commit abcc009dff
7 changed files with 92 additions and 60 deletions

View file

@ -256,16 +256,21 @@ Result KPageTable::InitializeForProcess(FileSys::ProgramAddressSpaceType as_type
m_mapped_physical_memory_size = 0; m_mapped_physical_memory_size = 0;
m_memory_pool = pool; m_memory_pool = pool;
m_page_table_impl.Resize(m_address_space_width, PageBits); m_page_table_impl = std::make_unique<Common::PageTable>();
m_page_table_impl->Resize(m_address_space_width, PageBits);
return m_memory_block_manager.Initialize(m_address_space_start, m_address_space_end, return m_memory_block_manager.Initialize(m_address_space_start, m_address_space_end,
m_memory_block_slab_manager); m_memory_block_slab_manager);
} }
void KPageTable::Finalize() { void KPageTable::Finalize() {
// Finalize memory blocks.
m_memory_block_manager.Finalize(m_memory_block_slab_manager, [&](VAddr addr, u64 size) { m_memory_block_manager.Finalize(m_memory_block_slab_manager, [&](VAddr addr, u64 size) {
m_system.Memory().UnmapRegion(m_page_table_impl, addr, size); m_system.Memory().UnmapRegion(*m_page_table_impl, addr, size);
}); });
// Close the backing page table, as the destructor is not called for guest objects.
m_page_table_impl.reset();
} }
Result KPageTable::MapProcessCode(VAddr addr, size_t num_pages, KMemoryState state, Result KPageTable::MapProcessCode(VAddr addr, size_t num_pages, KMemoryState state,
@ -514,7 +519,7 @@ Result KPageTable::MakePageGroup(KPageGroup& pg, VAddr addr, size_t num_pages) {
// Begin traversal. // Begin traversal.
Common::PageTable::TraversalContext context; Common::PageTable::TraversalContext context;
Common::PageTable::TraversalEntry next_entry; Common::PageTable::TraversalEntry next_entry;
R_UNLESS(m_page_table_impl.BeginTraversal(next_entry, context, addr), R_UNLESS(m_page_table_impl->BeginTraversal(next_entry, context, addr),
ResultInvalidCurrentMemory); ResultInvalidCurrentMemory);
// Prepare tracking variables. // Prepare tracking variables.
@ -525,7 +530,7 @@ Result KPageTable::MakePageGroup(KPageGroup& pg, VAddr addr, size_t num_pages) {
// Iterate, adding to group as we go. // Iterate, adding to group as we go.
const auto& memory_layout = m_system.Kernel().MemoryLayout(); const auto& memory_layout = m_system.Kernel().MemoryLayout();
while (tot_size < size) { while (tot_size < size) {
R_UNLESS(m_page_table_impl.ContinueTraversal(next_entry, context), R_UNLESS(m_page_table_impl->ContinueTraversal(next_entry, context),
ResultInvalidCurrentMemory); ResultInvalidCurrentMemory);
if (next_entry.phys_addr != (cur_addr + cur_size)) { if (next_entry.phys_addr != (cur_addr + cur_size)) {
@ -588,7 +593,7 @@ bool KPageTable::IsValidPageGroup(const KPageGroup& pg_ll, VAddr addr, size_t nu
// Begin traversal. // Begin traversal.
Common::PageTable::TraversalContext context; Common::PageTable::TraversalContext context;
Common::PageTable::TraversalEntry next_entry; Common::PageTable::TraversalEntry next_entry;
if (!m_page_table_impl.BeginTraversal(next_entry, context, addr)) { if (!m_page_table_impl->BeginTraversal(next_entry, context, addr)) {
return false; return false;
} }
@ -599,7 +604,7 @@ bool KPageTable::IsValidPageGroup(const KPageGroup& pg_ll, VAddr addr, size_t nu
// Iterate, comparing expected to actual. // Iterate, comparing expected to actual.
while (tot_size < size) { while (tot_size < size) {
if (!m_page_table_impl.ContinueTraversal(next_entry, context)) { if (!m_page_table_impl->ContinueTraversal(next_entry, context)) {
return false; return false;
} }
@ -2042,7 +2047,7 @@ Result KPageTable::Operate(VAddr addr, size_t num_pages, const KPageGroup& page_
switch (operation) { switch (operation) {
case OperationType::MapGroup: case OperationType::MapGroup:
m_system.Memory().MapMemoryRegion(m_page_table_impl, addr, size, node.GetAddress()); m_system.Memory().MapMemoryRegion(*m_page_table_impl, addr, size, node.GetAddress());
break; break;
default: default:
ASSERT(false); ASSERT(false);
@ -2064,12 +2069,12 @@ Result KPageTable::Operate(VAddr addr, size_t num_pages, KMemoryPermission perm,
switch (operation) { switch (operation) {
case OperationType::Unmap: case OperationType::Unmap:
m_system.Memory().UnmapRegion(m_page_table_impl, addr, num_pages * PageSize); m_system.Memory().UnmapRegion(*m_page_table_impl, addr, num_pages * PageSize);
break; break;
case OperationType::Map: { case OperationType::Map: {
ASSERT(map_addr); ASSERT(map_addr);
ASSERT(Common::IsAligned(map_addr, PageSize)); ASSERT(Common::IsAligned(map_addr, PageSize));
m_system.Memory().MapMemoryRegion(m_page_table_impl, addr, num_pages * PageSize, map_addr); m_system.Memory().MapMemoryRegion(*m_page_table_impl, addr, num_pages * PageSize, map_addr);
break; break;
} }
case OperationType::ChangePermissions: case OperationType::ChangePermissions:

View file

@ -88,11 +88,11 @@ public:
KMemoryAttribute attr_mask, KMemoryAttribute attr); KMemoryAttribute attr_mask, KMemoryAttribute attr);
Common::PageTable& PageTableImpl() { Common::PageTable& PageTableImpl() {
return m_page_table_impl; return *m_page_table_impl;
} }
const Common::PageTable& PageTableImpl() const { const Common::PageTable& PageTableImpl() const {
return m_page_table_impl; return *m_page_table_impl;
} }
bool CanContain(VAddr addr, size_t size, KMemoryState state) const; bool CanContain(VAddr addr, size_t size, KMemoryState state) const;
@ -303,7 +303,7 @@ public:
return IsKernel() ? 1 : 4; return IsKernel() ? 1 : 4;
} }
PAddr GetPhysicalAddr(VAddr addr) const { PAddr GetPhysicalAddr(VAddr addr) const {
const auto backing_addr = m_page_table_impl.backing_addr[addr >> PageBits]; const auto backing_addr = m_page_table_impl->backing_addr[addr >> PageBits];
ASSERT(backing_addr); ASSERT(backing_addr);
return backing_addr + addr; return backing_addr + addr;
} }
@ -365,7 +365,7 @@ private:
KMemoryManager::Pool m_memory_pool{KMemoryManager::Pool::Application}; KMemoryManager::Pool m_memory_pool{KMemoryManager::Pool::Application};
KMemoryManager::Direction m_allocation_option{KMemoryManager::Direction::FromFront}; KMemoryManager::Direction m_allocation_option{KMemoryManager::Direction::FromFront};
Common::PageTable m_page_table_impl; std::unique_ptr<Common::PageTable> m_page_table_impl;
Core::System& m_system; Core::System& m_system;
}; };

View file

@ -72,6 +72,7 @@ Result KProcess::Initialize(KProcess* process, Core::System& system, std::string
process->name = std::move(process_name); process->name = std::move(process_name);
process->resource_limit = res_limit; process->resource_limit = res_limit;
process->system_resource_address = 0;
process->state = State::Created; process->state = State::Created;
process->program_id = 0; process->program_id = 0;
process->process_id = type == ProcessType::KernelInternal ? kernel.CreateNewKernelProcessID() process->process_id = type == ProcessType::KernelInternal ? kernel.CreateNewKernelProcessID()
@ -92,6 +93,7 @@ Result KProcess::Initialize(KProcess* process, Core::System& system, std::string
process->exception_thread = nullptr; process->exception_thread = nullptr;
process->is_suspended = false; process->is_suspended = false;
process->schedule_count = 0; process->schedule_count = 0;
process->is_handle_table_initialized = false;
// Open a reference to the resource limit. // Open a reference to the resource limit.
process->resource_limit->Open(); process->resource_limit->Open();
@ -121,9 +123,9 @@ void KProcess::DecrementRunningThreadCount() {
} }
} }
u64 KProcess::GetTotalPhysicalMemoryAvailable() const { u64 KProcess::GetTotalPhysicalMemoryAvailable() {
const u64 capacity{resource_limit->GetFreeValue(LimitableResource::PhysicalMemory) + const u64 capacity{resource_limit->GetFreeValue(LimitableResource::PhysicalMemory) +
page_table->GetNormalMemorySize() + GetSystemResourceSize() + image_size + page_table.GetNormalMemorySize() + GetSystemResourceSize() + image_size +
main_thread_stack_size}; main_thread_stack_size};
if (const auto pool_size = kernel.MemoryManager().GetSize(KMemoryManager::Pool::Application); if (const auto pool_size = kernel.MemoryManager().GetSize(KMemoryManager::Pool::Application);
capacity != pool_size) { capacity != pool_size) {
@ -135,16 +137,16 @@ u64 KProcess::GetTotalPhysicalMemoryAvailable() const {
return memory_usage_capacity; return memory_usage_capacity;
} }
u64 KProcess::GetTotalPhysicalMemoryAvailableWithoutSystemResource() const { u64 KProcess::GetTotalPhysicalMemoryAvailableWithoutSystemResource() {
return GetTotalPhysicalMemoryAvailable() - GetSystemResourceSize(); return GetTotalPhysicalMemoryAvailable() - GetSystemResourceSize();
} }
u64 KProcess::GetTotalPhysicalMemoryUsed() const { u64 KProcess::GetTotalPhysicalMemoryUsed() {
return image_size + main_thread_stack_size + page_table->GetNormalMemorySize() + return image_size + main_thread_stack_size + page_table.GetNormalMemorySize() +
GetSystemResourceSize(); GetSystemResourceSize();
} }
u64 KProcess::GetTotalPhysicalMemoryUsedWithoutSystemResource() const { u64 KProcess::GetTotalPhysicalMemoryUsedWithoutSystemResource() {
return GetTotalPhysicalMemoryUsed() - GetSystemResourceUsage(); return GetTotalPhysicalMemoryUsed() - GetSystemResourceUsage();
} }
@ -348,6 +350,9 @@ Result KProcess::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std:
system_resource_size = metadata.GetSystemResourceSize(); system_resource_size = metadata.GetSystemResourceSize();
image_size = code_size; image_size = code_size;
// We currently do not support process-specific system resource
UNIMPLEMENTED_IF(system_resource_size != 0);
KScopedResourceReservation memory_reservation(resource_limit, LimitableResource::PhysicalMemory, KScopedResourceReservation memory_reservation(resource_limit, LimitableResource::PhysicalMemory,
code_size + system_resource_size); code_size + system_resource_size);
if (!memory_reservation.Succeeded()) { if (!memory_reservation.Succeeded()) {
@ -356,7 +361,7 @@ Result KProcess::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std:
return ResultLimitReached; return ResultLimitReached;
} }
// Initialize proces address space // Initialize proces address space
if (const Result result{page_table->InitializeForProcess( if (const Result result{page_table.InitializeForProcess(
metadata.GetAddressSpaceType(), false, 0x8000000, code_size, metadata.GetAddressSpaceType(), false, 0x8000000, code_size,
&kernel.GetApplicationMemoryBlockManager(), KMemoryManager::Pool::Application)}; &kernel.GetApplicationMemoryBlockManager(), KMemoryManager::Pool::Application)};
result.IsError()) { result.IsError()) {
@ -364,7 +369,7 @@ Result KProcess::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std:
} }
// Map process code region // Map process code region
if (const Result result{page_table->MapProcessCode(page_table->GetCodeRegionStart(), if (const Result result{page_table.MapProcessCode(page_table.GetCodeRegionStart(),
code_size / PageSize, KMemoryState::Code, code_size / PageSize, KMemoryState::Code,
KMemoryPermission::None)}; KMemoryPermission::None)};
result.IsError()) { result.IsError()) {
@ -374,7 +379,7 @@ Result KProcess::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std:
// Initialize process capabilities // Initialize process capabilities
const auto& caps{metadata.GetKernelCapabilities()}; const auto& caps{metadata.GetKernelCapabilities()};
if (const Result result{ if (const Result result{
capabilities.InitializeForUserProcess(caps.data(), caps.size(), *page_table)}; capabilities.InitializeForUserProcess(caps.data(), caps.size(), page_table)};
result.IsError()) { result.IsError()) {
return result; return result;
} }
@ -384,12 +389,12 @@ Result KProcess::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std:
case FileSys::ProgramAddressSpaceType::Is32Bit: case FileSys::ProgramAddressSpaceType::Is32Bit:
case FileSys::ProgramAddressSpaceType::Is36Bit: case FileSys::ProgramAddressSpaceType::Is36Bit:
case FileSys::ProgramAddressSpaceType::Is39Bit: case FileSys::ProgramAddressSpaceType::Is39Bit:
memory_usage_capacity = page_table->GetHeapRegionEnd() - page_table->GetHeapRegionStart(); memory_usage_capacity = page_table.GetHeapRegionEnd() - page_table.GetHeapRegionStart();
break; break;
case FileSys::ProgramAddressSpaceType::Is32BitNoMap: case FileSys::ProgramAddressSpaceType::Is32BitNoMap:
memory_usage_capacity = page_table->GetHeapRegionEnd() - page_table->GetHeapRegionStart() + memory_usage_capacity = page_table.GetHeapRegionEnd() - page_table.GetHeapRegionStart() +
page_table->GetAliasRegionEnd() - page_table->GetAliasRegionStart(); page_table.GetAliasRegionEnd() - page_table.GetAliasRegionStart();
break; break;
default: default:
@ -397,7 +402,7 @@ Result KProcess::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std:
} }
// Create TLS region // Create TLS region
R_TRY(this->CreateThreadLocalRegion(std::addressof(tls_region_address))); R_TRY(this->CreateThreadLocalRegion(std::addressof(plr_address)));
memory_reservation.Commit(); memory_reservation.Commit();
return handle_table.Initialize(capabilities.GetHandleTableSize()); return handle_table.Initialize(capabilities.GetHandleTableSize());
@ -409,7 +414,7 @@ void KProcess::Run(s32 main_thread_priority, u64 stack_size) {
resource_limit->Reserve(LimitableResource::PhysicalMemory, main_thread_stack_size); resource_limit->Reserve(LimitableResource::PhysicalMemory, main_thread_stack_size);
const std::size_t heap_capacity{memory_usage_capacity - (main_thread_stack_size + image_size)}; const std::size_t heap_capacity{memory_usage_capacity - (main_thread_stack_size + image_size)};
ASSERT(!page_table->SetMaxHeapSize(heap_capacity).IsError()); ASSERT(!page_table.SetMaxHeapSize(heap_capacity).IsError());
ChangeState(State::Running); ChangeState(State::Running);
@ -437,8 +442,8 @@ void KProcess::PrepareForTermination() {
stop_threads(kernel.System().GlobalSchedulerContext().GetThreadList()); stop_threads(kernel.System().GlobalSchedulerContext().GetThreadList());
this->DeleteThreadLocalRegion(tls_region_address); this->DeleteThreadLocalRegion(plr_address);
tls_region_address = 0; plr_address = 0;
if (resource_limit) { if (resource_limit) {
resource_limit->Release(LimitableResource::PhysicalMemory, resource_limit->Release(LimitableResource::PhysicalMemory,
@ -474,7 +479,7 @@ void KProcess::Finalize() {
} }
// Finalize the page table. // Finalize the page table.
page_table.reset(); page_table.Finalize();
// Perform inherited finalization. // Perform inherited finalization.
KAutoObjectWithSlabHeapAndContainer<KProcess, KWorkerTask>::Finalize(); KAutoObjectWithSlabHeapAndContainer<KProcess, KWorkerTask>::Finalize();
@ -628,7 +633,7 @@ bool KProcess::RemoveWatchpoint(Core::System& system, VAddr addr, u64 size,
void KProcess::LoadModule(CodeSet code_set, VAddr base_addr) { void KProcess::LoadModule(CodeSet code_set, VAddr base_addr) {
const auto ReprotectSegment = [&](const CodeSet::Segment& segment, const auto ReprotectSegment = [&](const CodeSet::Segment& segment,
Svc::MemoryPermission permission) { Svc::MemoryPermission permission) {
page_table->SetProcessMemoryPermission(segment.addr + base_addr, segment.size, permission); page_table.SetProcessMemoryPermission(segment.addr + base_addr, segment.size, permission);
}; };
kernel.System().Memory().WriteBlock(*this, base_addr, code_set.memory.data(), kernel.System().Memory().WriteBlock(*this, base_addr, code_set.memory.data(),
@ -645,8 +650,7 @@ bool KProcess::IsSignaled() const {
} }
KProcess::KProcess(KernelCore& kernel_) KProcess::KProcess(KernelCore& kernel_)
: KAutoObjectWithSlabHeapAndContainer{kernel_}, page_table{std::make_unique<KPageTable>( : KAutoObjectWithSlabHeapAndContainer{kernel_}, page_table{kernel_.System()},
kernel_.System())},
handle_table{kernel_}, address_arbiter{kernel_.System()}, condition_var{kernel_.System()}, handle_table{kernel_}, address_arbiter{kernel_.System()}, condition_var{kernel_.System()},
state_lock{kernel_}, list_lock{kernel_} {} state_lock{kernel_}, list_lock{kernel_} {}
@ -668,11 +672,11 @@ Result KProcess::AllocateMainThreadStack(std::size_t stack_size) {
// The kernel always ensures that the given stack size is page aligned. // The kernel always ensures that the given stack size is page aligned.
main_thread_stack_size = Common::AlignUp(stack_size, PageSize); main_thread_stack_size = Common::AlignUp(stack_size, PageSize);
const VAddr start{page_table->GetStackRegionStart()}; const VAddr start{page_table.GetStackRegionStart()};
const std::size_t size{page_table->GetStackRegionEnd() - start}; const std::size_t size{page_table.GetStackRegionEnd() - start};
CASCADE_RESULT(main_thread_stack_top, CASCADE_RESULT(main_thread_stack_top,
page_table->AllocateAndMapMemory( page_table.AllocateAndMapMemory(
main_thread_stack_size / PageSize, PageSize, false, start, size / PageSize, main_thread_stack_size / PageSize, PageSize, false, start, size / PageSize,
KMemoryState::Stack, KMemoryPermission::UserReadWrite)); KMemoryState::Stack, KMemoryPermission::UserReadWrite));
@ -681,4 +685,12 @@ Result KProcess::AllocateMainThreadStack(std::size_t stack_size) {
return ResultSuccess; return ResultSuccess;
} }
void KProcess::FinalizeHandleTable() {
// Finalize the table.
handle_table.Finalize();
// Note that the table is finalized.
is_handle_table_initialized = false;
}
} // namespace Kernel } // namespace Kernel

View file

@ -13,6 +13,7 @@
#include "core/hle/kernel/k_auto_object.h" #include "core/hle/kernel/k_auto_object.h"
#include "core/hle/kernel/k_condition_variable.h" #include "core/hle/kernel/k_condition_variable.h"
#include "core/hle/kernel/k_handle_table.h" #include "core/hle/kernel/k_handle_table.h"
#include "core/hle/kernel/k_page_table.h"
#include "core/hle/kernel/k_synchronization_object.h" #include "core/hle/kernel/k_synchronization_object.h"
#include "core/hle/kernel/k_thread_local_page.h" #include "core/hle/kernel/k_thread_local_page.h"
#include "core/hle/kernel/k_worker_task.h" #include "core/hle/kernel/k_worker_task.h"
@ -31,7 +32,6 @@ class ProgramMetadata;
namespace Kernel { namespace Kernel {
class KernelCore; class KernelCore;
class KPageTable;
class KResourceLimit; class KResourceLimit;
class KThread; class KThread;
class KSharedMemoryInfo; class KSharedMemoryInfo;
@ -107,12 +107,12 @@ public:
/// Gets a reference to the process' page table. /// Gets a reference to the process' page table.
KPageTable& PageTable() { KPageTable& PageTable() {
return *page_table; return page_table;
} }
/// Gets const a reference to the process' page table. /// Gets const a reference to the process' page table.
const KPageTable& PageTable() const { const KPageTable& PageTable() const {
return *page_table; return page_table;
} }
/// Gets a reference to the process' handle table. /// Gets a reference to the process' handle table.
@ -150,9 +150,8 @@ public:
return address_arbiter.WaitForAddress(address, arb_type, value, timeout); return address_arbiter.WaitForAddress(address, arb_type, value, timeout);
} }
/// Gets the address to the process' dedicated TLS region. VAddr GetProcessLocalRegionAddress() const {
VAddr GetTLSRegionAddress() const { return plr_address;
return tls_region_address;
} }
/// Gets the current status of the process /// Gets the current status of the process
@ -279,18 +278,18 @@ public:
} }
/// Retrieves the total physical memory available to this process in bytes. /// Retrieves the total physical memory available to this process in bytes.
u64 GetTotalPhysicalMemoryAvailable() const; u64 GetTotalPhysicalMemoryAvailable();
/// Retrieves the total physical memory available to this process in bytes, /// Retrieves the total physical memory available to this process in bytes,
/// without the size of the personal system resource heap added to it. /// without the size of the personal system resource heap added to it.
u64 GetTotalPhysicalMemoryAvailableWithoutSystemResource() const; u64 GetTotalPhysicalMemoryAvailableWithoutSystemResource();
/// Retrieves the total physical memory used by this process in bytes. /// Retrieves the total physical memory used by this process in bytes.
u64 GetTotalPhysicalMemoryUsed() const; u64 GetTotalPhysicalMemoryUsed();
/// Retrieves the total physical memory used by this process in bytes, /// Retrieves the total physical memory used by this process in bytes,
/// without the size of the personal system resource heap added to it. /// without the size of the personal system resource heap added to it.
u64 GetTotalPhysicalMemoryUsedWithoutSystemResource() const; u64 GetTotalPhysicalMemoryUsedWithoutSystemResource();
/// Gets the list of all threads created with this process as their owner. /// Gets the list of all threads created with this process as their owner.
std::list<KThread*>& GetThreadList() { std::list<KThread*>& GetThreadList() {
@ -413,8 +412,10 @@ private:
/// Allocates the main thread stack for the process, given the stack size in bytes. /// Allocates the main thread stack for the process, given the stack size in bytes.
Result AllocateMainThreadStack(std::size_t stack_size); Result AllocateMainThreadStack(std::size_t stack_size);
void FinalizeHandleTable();
/// Memory manager for this process /// Memory manager for this process
std::unique_ptr<KPageTable> page_table; KPageTable page_table;
/// Current status of the process /// Current status of the process
State state{}; State state{};
@ -433,6 +434,8 @@ private:
/// Resource limit descriptor for this process /// Resource limit descriptor for this process
KResourceLimit* resource_limit{}; KResourceLimit* resource_limit{};
VAddr system_resource_address{};
/// The ideal CPU core for this process, threads are scheduled on this core by default. /// The ideal CPU core for this process, threads are scheduled on this core by default.
u8 ideal_core = 0; u8 ideal_core = 0;
@ -459,7 +462,7 @@ private:
KConditionVariable condition_var; KConditionVariable condition_var;
/// Address indicating the location of the process' dedicated TLS region. /// Address indicating the location of the process' dedicated TLS region.
VAddr tls_region_address = 0; VAddr plr_address = 0;
/// Random values for svcGetInfo RandomEntropy /// Random values for svcGetInfo RandomEntropy
std::array<u64, RANDOM_ENTROPY_SIZE> random_entropy{}; std::array<u64, RANDOM_ENTROPY_SIZE> random_entropy{};
@ -485,8 +488,12 @@ private:
/// Schedule count of this process /// Schedule count of this process
s64 schedule_count{}; s64 schedule_count{};
size_t memory_release_hint{};
bool is_signaled{}; bool is_signaled{};
bool is_suspended{}; bool is_suspended{};
bool is_immortal{};
bool is_handle_table_initialized{};
bool is_initialized{}; bool is_initialized{};
std::atomic<u16> num_running_threads{}; std::atomic<u16> num_running_threads{};

View file

@ -95,6 +95,15 @@ struct KernelCore::Impl {
} }
} }
void CloseCurrentProcess() {
(*current_process).Finalize();
// current_process->Close();
// TODO: The current process should be destroyed based on accurate ref counting after
// calling Close(). Adding a manual Destroy() call instead to avoid a memory leak.
(*current_process).Destroy();
current_process = nullptr;
}
void Shutdown() { void Shutdown() {
is_shutting_down.store(true, std::memory_order_relaxed); is_shutting_down.store(true, std::memory_order_relaxed);
SCOPE_EXIT({ is_shutting_down.store(false, std::memory_order_relaxed); }); SCOPE_EXIT({ is_shutting_down.store(false, std::memory_order_relaxed); });
@ -157,15 +166,7 @@ struct KernelCore::Impl {
} }
} }
// Shutdown all processes. CloseCurrentProcess();
if (current_process) {
(*current_process).Finalize();
// current_process->Close();
// TODO: The current process should be destroyed based on accurate ref counting after
// calling Close(). Adding a manual Destroy() call instead to avoid a memory leak.
(*current_process).Destroy();
current_process = nullptr;
}
// Track kernel objects that were not freed on shutdown // Track kernel objects that were not freed on shutdown
{ {
@ -870,6 +871,10 @@ const KProcess* KernelCore::CurrentProcess() const {
return impl->current_process; return impl->current_process;
} }
void KernelCore::CloseCurrentProcess() {
impl->CloseCurrentProcess();
}
const std::vector<KProcess*>& KernelCore::GetProcessList() const { const std::vector<KProcess*>& KernelCore::GetProcessList() const {
return impl->process_list; return impl->process_list;
} }

View file

@ -131,6 +131,9 @@ public:
/// Retrieves a const pointer to the current process. /// Retrieves a const pointer to the current process.
const KProcess* CurrentProcess() const; const KProcess* CurrentProcess() const;
/// Closes the current process.
void CloseCurrentProcess();
/// Retrieves the list of processes. /// Retrieves the list of processes.
const std::vector<KProcess*>& GetProcessList() const; const std::vector<KProcess*>& GetProcessList() const;

View file

@ -933,7 +933,7 @@ static Result GetInfo(Core::System& system, u64* result, u64 info_id, Handle han
return ResultSuccess; return ResultSuccess;
case GetInfoType::UserExceptionContextAddr: case GetInfoType::UserExceptionContextAddr:
*result = process->GetTLSRegionAddress(); *result = process->GetProcessLocalRegionAddress();
return ResultSuccess; return ResultSuccess;
case GetInfoType::TotalPhysicalMemoryAvailableWithoutSystemResource: case GetInfoType::TotalPhysicalMemoryAvailableWithoutSystemResource: