diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/kernel/process.cpp | 18 | ||||
| -rw-r--r-- | src/core/hle/kernel/process.h | 11 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 8 |
3 files changed, 28 insertions, 9 deletions
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 0d782e4ba..b0b7af76b 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <memory> | 6 | #include <memory> |
| 7 | #include <random> | 7 | #include <random> |
| 8 | #include "common/alignment.h" | ||
| 8 | #include "common/assert.h" | 9 | #include "common/assert.h" |
| 9 | #include "common/logging/log.h" | 10 | #include "common/logging/log.h" |
| 10 | #include "core/core.h" | 11 | #include "core/core.h" |
| @@ -75,6 +76,10 @@ SharedPtr<ResourceLimit> Process::GetResourceLimit() const { | |||
| 75 | return resource_limit; | 76 | return resource_limit; |
| 76 | } | 77 | } |
| 77 | 78 | ||
| 79 | u64 Process::GetTotalPhysicalMemoryUsed() const { | ||
| 80 | return vm_manager.GetCurrentHeapSize() + main_thread_stack_size + code_memory_size; | ||
| 81 | } | ||
| 82 | |||
| 78 | ResultCode Process::ClearSignalState() { | 83 | ResultCode Process::ClearSignalState() { |
| 79 | if (status == ProcessStatus::Exited) { | 84 | if (status == ProcessStatus::Exited) { |
| 80 | LOG_ERROR(Kernel, "called on a terminated process instance."); | 85 | LOG_ERROR(Kernel, "called on a terminated process instance."); |
| @@ -107,14 +112,17 @@ ResultCode Process::LoadFromMetadata(const FileSys::ProgramMetadata& metadata) { | |||
| 107 | return handle_table.SetSize(capabilities.GetHandleTableSize()); | 112 | return handle_table.SetSize(capabilities.GetHandleTableSize()); |
| 108 | } | 113 | } |
| 109 | 114 | ||
| 110 | void Process::Run(VAddr entry_point, s32 main_thread_priority, u32 stack_size) { | 115 | void Process::Run(VAddr entry_point, s32 main_thread_priority, u64 stack_size) { |
| 116 | // The kernel always ensures that the given stack size is page aligned. | ||
| 117 | main_thread_stack_size = Common::AlignUp(stack_size, Memory::PAGE_SIZE); | ||
| 118 | |||
| 111 | // Allocate and map the main thread stack | 119 | // Allocate and map the main thread stack |
| 112 | // TODO(bunnei): This is heap area that should be allocated by the kernel and not mapped as part | 120 | // TODO(bunnei): This is heap area that should be allocated by the kernel and not mapped as part |
| 113 | // of the user address space. | 121 | // of the user address space. |
| 122 | const VAddr mapping_address = vm_manager.GetTLSIORegionEndAddress() - main_thread_stack_size; | ||
| 114 | vm_manager | 123 | vm_manager |
| 115 | .MapMemoryBlock(vm_manager.GetTLSIORegionEndAddress() - stack_size, | 124 | .MapMemoryBlock(mapping_address, std::make_shared<std::vector<u8>>(main_thread_stack_size), |
| 116 | std::make_shared<std::vector<u8>>(stack_size, 0), 0, stack_size, | 125 | 0, main_thread_stack_size, MemoryState::Stack) |
| 117 | MemoryState::Stack) | ||
| 118 | .Unwrap(); | 126 | .Unwrap(); |
| 119 | 127 | ||
| 120 | vm_manager.LogLayout(); | 128 | vm_manager.LogLayout(); |
| @@ -224,6 +232,8 @@ void Process::LoadModule(CodeSet module_, VAddr base_addr) { | |||
| 224 | MapSegment(module_.RODataSegment(), VMAPermission::Read, MemoryState::CodeData); | 232 | MapSegment(module_.RODataSegment(), VMAPermission::Read, MemoryState::CodeData); |
| 225 | MapSegment(module_.DataSegment(), VMAPermission::ReadWrite, MemoryState::CodeData); | 233 | MapSegment(module_.DataSegment(), VMAPermission::ReadWrite, MemoryState::CodeData); |
| 226 | 234 | ||
| 235 | code_memory_size += module_.memory->size(); | ||
| 236 | |||
| 227 | // Clear instruction cache in CPU JIT | 237 | // Clear instruction cache in CPU JIT |
| 228 | system.InvalidateCpuInstructionCaches(); | 238 | system.InvalidateCpuInstructionCaches(); |
| 229 | } | 239 | } |
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h index a0217d3d8..732d12170 100644 --- a/src/core/hle/kernel/process.h +++ b/src/core/hle/kernel/process.h | |||
| @@ -186,6 +186,9 @@ public: | |||
| 186 | return random_entropy.at(index); | 186 | return random_entropy.at(index); |
| 187 | } | 187 | } |
| 188 | 188 | ||
| 189 | /// Retrieves the total physical memory used by this process in bytes. | ||
| 190 | u64 GetTotalPhysicalMemoryUsed() const; | ||
| 191 | |||
| 189 | /// Clears the signaled state of the process if and only if it's signaled. | 192 | /// Clears the signaled state of the process if and only if it's signaled. |
| 190 | /// | 193 | /// |
| 191 | /// @pre The process must not be already terminated. If this is called on a | 194 | /// @pre The process must not be already terminated. If this is called on a |
| @@ -210,7 +213,7 @@ public: | |||
| 210 | /** | 213 | /** |
| 211 | * Applies address space changes and launches the process main thread. | 214 | * Applies address space changes and launches the process main thread. |
| 212 | */ | 215 | */ |
| 213 | void Run(VAddr entry_point, s32 main_thread_priority, u32 stack_size); | 216 | void Run(VAddr entry_point, s32 main_thread_priority, u64 stack_size); |
| 214 | 217 | ||
| 215 | /** | 218 | /** |
| 216 | * Prepares a process for termination by stopping all of its threads | 219 | * Prepares a process for termination by stopping all of its threads |
| @@ -247,6 +250,12 @@ private: | |||
| 247 | /// Memory manager for this process. | 250 | /// Memory manager for this process. |
| 248 | Kernel::VMManager vm_manager; | 251 | Kernel::VMManager vm_manager; |
| 249 | 252 | ||
| 253 | /// Size of the main thread's stack in bytes. | ||
| 254 | u64 main_thread_stack_size = 0; | ||
| 255 | |||
| 256 | /// Size of the loaded code memory in bytes. | ||
| 257 | u64 code_memory_size = 0; | ||
| 258 | |||
| 250 | /// Current status of the process | 259 | /// Current status of the process |
| 251 | ProcessStatus status; | 260 | ProcessStatus status; |
| 252 | 261 | ||
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 11796e5e5..c408d4e22 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -709,7 +709,7 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id) | |||
| 709 | HeapRegionBaseAddr = 4, | 709 | HeapRegionBaseAddr = 4, |
| 710 | HeapRegionSize = 5, | 710 | HeapRegionSize = 5, |
| 711 | TotalMemoryUsage = 6, | 711 | TotalMemoryUsage = 6, |
| 712 | TotalHeapUsage = 7, | 712 | TotalPhysicalMemoryUsed = 7, |
| 713 | IsCurrentProcessBeingDebugged = 8, | 713 | IsCurrentProcessBeingDebugged = 8, |
| 714 | RegisterResourceLimit = 9, | 714 | RegisterResourceLimit = 9, |
| 715 | IdleTickCount = 10, | 715 | IdleTickCount = 10, |
| @@ -745,7 +745,7 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id) | |||
| 745 | case GetInfoType::NewMapRegionBaseAddr: | 745 | case GetInfoType::NewMapRegionBaseAddr: |
| 746 | case GetInfoType::NewMapRegionSize: | 746 | case GetInfoType::NewMapRegionSize: |
| 747 | case GetInfoType::TotalMemoryUsage: | 747 | case GetInfoType::TotalMemoryUsage: |
| 748 | case GetInfoType::TotalHeapUsage: | 748 | case GetInfoType::TotalPhysicalMemoryUsed: |
| 749 | case GetInfoType::IsVirtualAddressMemoryEnabled: | 749 | case GetInfoType::IsVirtualAddressMemoryEnabled: |
| 750 | case GetInfoType::PersonalMmHeapUsage: | 750 | case GetInfoType::PersonalMmHeapUsage: |
| 751 | case GetInfoType::TitleId: | 751 | case GetInfoType::TitleId: |
| @@ -805,8 +805,8 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id) | |||
| 805 | *result = process->VMManager().GetTotalMemoryUsage(); | 805 | *result = process->VMManager().GetTotalMemoryUsage(); |
| 806 | return RESULT_SUCCESS; | 806 | return RESULT_SUCCESS; |
| 807 | 807 | ||
| 808 | case GetInfoType::TotalHeapUsage: | 808 | case GetInfoType::TotalPhysicalMemoryUsed: |
| 809 | *result = process->VMManager().GetCurrentHeapSize(); | 809 | *result = process->GetTotalPhysicalMemoryUsed(); |
| 810 | return RESULT_SUCCESS; | 810 | return RESULT_SUCCESS; |
| 811 | 811 | ||
| 812 | case GetInfoType::IsVirtualAddressMemoryEnabled: | 812 | case GetInfoType::IsVirtualAddressMemoryEnabled: |