Alec Roelke has uploaded this change for review. ( https://gem5-review.googlesource.com/6681

Change subject: arch-riscv: Define AT_RANDOM properly
......................................................................

arch-riscv: Define AT_RANDOM properly

According to the getauxval(3) man page, the AT_RANDOM aux value should
be a pointer to 16 random bytes.  In the initial implementation of
RISC-V, this was based on spike's program stack setup, which copied the
program header table there instead.  This patch changes the
implementation to use the proper 16 random bytes, making it compatible
with some RISC-V programs that use custom linker scripts.

Change-Id: Idaae7f19bf3ed3fd06d293e5e9c0b6f778270eb2
---
M src/arch/riscv/process.cc
1 file changed, 11 insertions(+), 10 deletions(-)



diff --git a/src/arch/riscv/process.cc b/src/arch/riscv/process.cc
index 371a8e4..5a0ee8c 100644
--- a/src/arch/riscv/process.cc
+++ b/src/arch/riscv/process.cc
@@ -35,7 +35,9 @@

 #include <algorithm>
 #include <cstddef>
+#include <cstdlib>
 #include <iostream>
+#include <iterator>
 #include <map>
 #include <string>
 #include <vector>
@@ -81,6 +83,8 @@
 template<class IntType> void
 RiscvProcess::argsInit(int pageSize)
 {
+    const int RandomBytes = 16;
+
     updateBias();
     objFile->loadSections(initVirtMem);
     ElfObject* elfObject = dynamic_cast<ElfObject*>(objFile);
@@ -88,7 +92,7 @@

     // Determine stack size and populate auxv
     Addr stack_top = memState->getStackMin();
-    stack_top -= elfObject->programHeaderSize();
+    stack_top -= RandomBytes;
     for (const string& arg: argv)
         stack_top -= arg.size() + 1;
     for (const string& env: envp)
@@ -114,15 +118,12 @@
     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 random bytes (for AT_RANDOM) to stack
+    memState->setStackMin(memState->getStackMin() - RandomBytes);
+    uint8_t at_random[RandomBytes];
+    srand(time(nullptr));
+    generate(begin(at_random), end(at_random), ::rand);
+    initVirtMem.writeBlob(memState->getStackMin(), at_random, RandomBytes);

     // Copy argv to stack
     vector<Addr> argPointers;

--
To view, visit https://gem5-review.googlesource.com/6681
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Idaae7f19bf3ed3fd06d293e5e9c0b6f778270eb2
Gerrit-Change-Number: 6681
Gerrit-PatchSet: 1
Gerrit-Owner: Alec Roelke <ar...@virginia.edu>
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to