Skip to content

Commit 2b3e998

Browse files
committed
Always allocate stack on heap
1 parent 6140db7 commit 2b3e998

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lib/tinykvm/machine_elf.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ void Machine::elf_loader(std::string_view binary, const MachineOptions& options)
9393
const auto* phdr = (Elf64_Phdr*) (binary.data() + elf->e_phoff);
9494
const auto program_begin = phdr->p_vaddr;
9595
this->m_start_address = this->m_image_base + elf->e_entry;
96-
this->m_stack_address = this->m_image_base + program_begin;
9796
this->m_heap_address = 0x0;
9897

9998
int seg = 0;
@@ -146,11 +145,11 @@ void Machine::elf_loader(std::string_view binary, const MachineOptions& options)
146145
this->m_brk_address = this->m_heap_address;
147146
this->m_mm = this->mmap_start();
148147

149-
/* If there is not enough room for stack, move it */
148+
/* Always allocate stack on heap, because we don't know where
149+
the kernel ends yet, and some run-times even depend on the
150+
stack being above the image base. */
150151
const uint32_t STACK_SIZE = (options.stack_size + PageMask()) & ~PageMask();
151-
if (this->m_stack_address < STACK_SIZE) {
152-
this->m_stack_address = this->mmap_allocate(STACK_SIZE) + STACK_SIZE;
153-
}
152+
this->m_stack_address = this->mmap_allocate(STACK_SIZE) + STACK_SIZE;
154153

155154
/* Dynamic executables require some extra work, like relocation */
156155
if (is_dynamic) {

0 commit comments

Comments
 (0)