summaryrefslogtreecommitdiff
path: root/src/arch
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch')
-rw-r--r--src/arch/riscv/process.cc11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/arch/riscv/process.cc b/src/arch/riscv/process.cc
index 13038c17c..eeea5ee48 100644
--- a/src/arch/riscv/process.cc
+++ b/src/arch/riscv/process.cc
@@ -88,6 +88,7 @@ RiscvProcess::argsInit(int pageSize)
// Determine stack size and populate auxv
Addr stack_top = memState->getStackMin();
+ stack_top -= elfObject->programHeaderSize();
for (const string& arg: argv)
stack_top -= arg.size() + 1;
for (const string& env: envp)
@@ -113,6 +114,16 @@ RiscvProcess::argsInit(int pageSize)
allocateMem(roundDown(stack_top, pageSize),
roundUp(memState->getStackSize(), pageSize));
+ // Copy program headers to stack
+ memState->setStackMin(memState->getStackMin() -
+ elfObject->programHeaderSize());
+ uint8_t* phdr = new uint8_t[elfObject->programHeaderSize()];
+ initVirtMem.readBlob(elfObject->programHeaderTable(), phdr,
+ elfObject->programHeaderSize());
+ initVirtMem.writeBlob(memState->getStackMin(), phdr,
+ elfObject->programHeaderSize());
+ delete phdr;
+
// Copy argv to stack
vector<Addr> argPointers;
for (const string& arg: argv) {