XThread free stack on destruction

This commit is contained in:
Dr. Chat 2015-12-14 14:34:44 -06:00 committed by Ben Vanik
parent 07d31862f1
commit 621d3f8abb
2 changed files with 15 additions and 1 deletions

View File

@ -89,6 +89,7 @@ XThread::~XThread() {
kernel_state()->memory()->SystemHeapFree(scratch_address_);
kernel_state()->memory()->SystemHeapFree(tls_address_);
kernel_state()->memory()->SystemHeapFree(pcr_address_);
FreeStack();
if (thread_) {
// TODO(benvanik): platform kill
@ -214,7 +215,7 @@ bool XThread::AllocateStack(uint32_t size) {
auto heap = memory()->LookupHeap(0x40000000);
auto alignment = heap->page_size();
auto padding = heap->page_size() * 2; // Guard pages
auto padding = heap->page_size() * 2; // Guard page size * 2
size = xe::round_up(size, alignment);
auto actual_size = size + padding;
@ -241,6 +242,18 @@ bool XThread::AllocateStack(uint32_t size) {
return true;
}
void XThread::FreeStack() {
if (stack_alloc_base_) {
auto heap = memory()->LookupHeap(0x40000000);
heap->Release(stack_alloc_base_);
stack_alloc_base_ = 0;
stack_alloc_size_ = 0;
stack_base_ = 0;
stack_limit_ = 0;
}
}
X_STATUS XThread::Create() {
// Thread kernel object.
if (!CreateNative<X_KTHREAD>()) {

View File

@ -196,6 +196,7 @@ class XThread : public XObject {
protected:
bool AllocateStack(uint32_t size);
void FreeStack();
void InitializeGuestObject();
bool StepToAddress(uint32_t pc);