From 2aca7b9e1e6255cf740afec5dd390d0e6726c1e3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 28 Mar 2019 18:24:56 -0400 Subject: kernel/process: Ensure that given stack size is always page-aligned The kernel always makes sure that the given stack size is aligned to page boundaries. --- src/core/hle/kernel/process.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/core/hle/kernel/process.cpp') diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 0d782e4ba..73b4ff961 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp @@ -5,6 +5,7 @@ #include #include #include +#include "common/alignment.h" #include "common/assert.h" #include "common/logging/log.h" #include "core/core.h" @@ -108,6 +109,9 @@ ResultCode Process::LoadFromMetadata(const FileSys::ProgramMetadata& metadata) { } void Process::Run(VAddr entry_point, s32 main_thread_priority, u32 stack_size) { + // The kernel always ensures that the given stack size is page aligned. + stack_size = Common::AlignUp(stack_size, Memory::PAGE_SIZE); + // Allocate and map the main thread stack // TODO(bunnei): This is heap area that should be allocated by the kernel and not mapped as part // of the user address space. -- cgit v1.2.3 From 427f1e3e3da5709e74bf4db674a019d9d79f2ed3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 28 Mar 2019 18:26:09 -0400 Subject: kernel/process: Make Run's stack size parameter a u64 This will make operating with the process-related SVC commands much nicer in the future (the parameter representing the stack size in svcStartProcess is a 64-bit value). --- src/core/hle/kernel/process.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/hle/kernel/process.cpp') diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 73b4ff961..f18789a60 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp @@ -108,7 +108,7 @@ ResultCode Process::LoadFromMetadata(const FileSys::ProgramMetadata& metadata) { return handle_table.SetSize(capabilities.GetHandleTableSize()); } -void Process::Run(VAddr entry_point, s32 main_thread_priority, u32 stack_size) { +void Process::Run(VAddr entry_point, s32 main_thread_priority, u64 stack_size) { // The kernel always ensures that the given stack size is page aligned. stack_size = Common::AlignUp(stack_size, Memory::PAGE_SIZE); -- cgit v1.2.3 From 5d4ab5ec2fe36fa06d3adccb66261a4a8077c74e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 28 Mar 2019 18:30:58 -0400 Subject: kernel/process: Store the main thread stack size to a data member This will be necessary in order to properly report memory usage within svcGetInfo. --- src/core/hle/kernel/process.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/core/hle/kernel/process.cpp') diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index f18789a60..bb2673732 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp @@ -110,15 +110,15 @@ ResultCode Process::LoadFromMetadata(const FileSys::ProgramMetadata& metadata) { void Process::Run(VAddr entry_point, s32 main_thread_priority, u64 stack_size) { // The kernel always ensures that the given stack size is page aligned. - stack_size = Common::AlignUp(stack_size, Memory::PAGE_SIZE); + main_thread_stack_size = Common::AlignUp(stack_size, Memory::PAGE_SIZE); // Allocate and map the main thread stack // TODO(bunnei): This is heap area that should be allocated by the kernel and not mapped as part // of the user address space. + const VAddr mapping_address = vm_manager.GetTLSIORegionEndAddress() - main_thread_stack_size; vm_manager - .MapMemoryBlock(vm_manager.GetTLSIORegionEndAddress() - stack_size, - std::make_shared>(stack_size, 0), 0, stack_size, - MemoryState::Stack) + .MapMemoryBlock(mapping_address, std::make_shared>(main_thread_stack_size), + 0, main_thread_stack_size, MemoryState::Stack) .Unwrap(); vm_manager.LogLayout(); -- cgit v1.2.3 From 2289e895aa63cdb391795c573b96b1880c31f097 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 28 Mar 2019 18:52:45 -0400 Subject: kernel/process: Store the total size of the code memory loaded This will be necessary to properly report the used memory size in svcGetInfo. --- src/core/hle/kernel/process.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/core/hle/kernel/process.cpp') diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index bb2673732..819d2cb0b 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp @@ -228,6 +228,8 @@ void Process::LoadModule(CodeSet module_, VAddr base_addr) { MapSegment(module_.RODataSegment(), VMAPermission::Read, MemoryState::CodeData); MapSegment(module_.DataSegment(), VMAPermission::ReadWrite, MemoryState::CodeData); + code_memory_size += module_.memory->size(); + // Clear instruction cache in CPU JIT system.InvalidateCpuInstructionCaches(); } -- cgit v1.2.3 From 3a846aa80f5d533a5061fcbef2736aaef8c38a66 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 28 Mar 2019 22:59:17 -0400 Subject: kernel/process: Report total physical memory used to svcGetInfo Reports the (mostly) correct size through svcGetInfo now for queries to total used physical memory. This still doesn't correctly handle memory allocated via svcMapPhysicalMemory, however, we don't currently handle that case anyways. --- src/core/hle/kernel/process.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/core/hle/kernel/process.cpp') diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 819d2cb0b..b0b7af76b 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp @@ -76,6 +76,10 @@ SharedPtr Process::GetResourceLimit() const { return resource_limit; } +u64 Process::GetTotalPhysicalMemoryUsed() const { + return vm_manager.GetCurrentHeapSize() + main_thread_stack_size + code_memory_size; +} + ResultCode Process::ClearSignalState() { if (status == ProcessStatus::Exited) { LOG_ERROR(Kernel, "called on a terminated process instance."); -- cgit v1.2.3