mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-18 01:46:47 +00:00
kern: fix resource leak bugs
This commit is contained in:
parent
11d5353827
commit
46935fea80
4 changed files with 7 additions and 2 deletions
|
@ -77,6 +77,7 @@ namespace ams::kern {
|
||||||
void InitializeOptimizedMemory() { std::memset(GetVoidPointer(this->metadata_region), 0, CalculateOptimizedProcessOverheadSize(this->heap.GetSize())); }
|
void InitializeOptimizedMemory() { std::memset(GetVoidPointer(this->metadata_region), 0, CalculateOptimizedProcessOverheadSize(this->heap.GetSize())); }
|
||||||
void TrackAllocationForOptimizedProcess(KVirtualAddress block, size_t num_pages);
|
void TrackAllocationForOptimizedProcess(KVirtualAddress block, size_t num_pages);
|
||||||
|
|
||||||
|
constexpr Pool GetPool() const { return this->pool; }
|
||||||
constexpr size_t GetSize() const { return this->heap.GetSize(); }
|
constexpr size_t GetSize() const { return this->heap.GetSize(); }
|
||||||
constexpr KVirtualAddress GetEndAddress() const { return this->heap.GetEndAddress(); }
|
constexpr KVirtualAddress GetEndAddress() const { return this->heap.GetEndAddress(); }
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,9 @@ namespace ams::kern {
|
||||||
KPageGroup pg(page_table->GetBlockInfoManager());
|
KPageGroup pg(page_table->GetBlockInfoManager());
|
||||||
R_TRY(page_table->LockForDeviceAddressSpace(std::addressof(pg), process_address, size, ConvertToKMemoryPermission(device_perm), is_aligned));
|
R_TRY(page_table->LockForDeviceAddressSpace(std::addressof(pg), process_address, size, ConvertToKMemoryPermission(device_perm), is_aligned));
|
||||||
|
|
||||||
|
/* Close the pages we opened when we're done with them. */
|
||||||
|
ON_SCOPE_EXIT { pg.Close(); };
|
||||||
|
|
||||||
/* Ensure that if we fail, we don't keep unmapped pages locked. */
|
/* Ensure that if we fail, we don't keep unmapped pages locked. */
|
||||||
ON_SCOPE_EXIT {
|
ON_SCOPE_EXIT {
|
||||||
if (*out_mapped_size != size) {
|
if (*out_mapped_size != size) {
|
||||||
|
|
|
@ -796,7 +796,7 @@ namespace ams::kern {
|
||||||
R_UNLESS(stack_size + this->code_size >= this->code_size, svc::ResultOutOfMemory());
|
R_UNLESS(stack_size + this->code_size >= this->code_size, svc::ResultOutOfMemory());
|
||||||
|
|
||||||
/* Place a tentative reservation of memory for our new stack. */
|
/* Place a tentative reservation of memory for our new stack. */
|
||||||
KScopedResourceReservation mem_reservation(this, ams::svc::LimitableResource_PhysicalMemoryMax);
|
KScopedResourceReservation mem_reservation(this, ams::svc::LimitableResource_PhysicalMemoryMax, stack_size);
|
||||||
R_UNLESS(mem_reservation.Succeeded(), svc::ResultLimitReached());
|
R_UNLESS(mem_reservation.Succeeded(), svc::ResultLimitReached());
|
||||||
|
|
||||||
/* Allocate and map our stack. */
|
/* Allocate and map our stack. */
|
||||||
|
|
|
@ -143,7 +143,7 @@ namespace ams::kern {
|
||||||
this->num_kernel_waiters = 0;
|
this->num_kernel_waiters = 0;
|
||||||
this->entrypoint = reinterpret_cast<uintptr_t>(func);
|
this->entrypoint = reinterpret_cast<uintptr_t>(func);
|
||||||
|
|
||||||
/* We don't need a release (probably), and we've spent no time on the cpu. */
|
/* We haven't released our resource limit hint, and we've spent no time on the cpu. */
|
||||||
this->resource_limit_release_hint = 0;
|
this->resource_limit_release_hint = 0;
|
||||||
this->cpu_time = 0;
|
this->cpu_time = 0;
|
||||||
|
|
||||||
|
@ -825,6 +825,7 @@ namespace ams::kern {
|
||||||
/* Release the thread resource hint from parent. */
|
/* Release the thread resource hint from parent. */
|
||||||
if (this->parent != nullptr) {
|
if (this->parent != nullptr) {
|
||||||
this->parent->ReleaseResource(ams::svc::LimitableResource_ThreadCountMax, 0, 1);
|
this->parent->ReleaseResource(ams::svc::LimitableResource_ThreadCountMax, 0, 1);
|
||||||
|
this->resource_limit_release_hint = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Perform termination. */
|
/* Perform termination. */
|
||||||
|
|
Loading…
Reference in a new issue