mips: Add the AT_RANDOM aux vector to the initial stack.
This is blindly used by at least modern glibc-s
Change-Id: I8fb904d487d0cb5f7747d063a6ed84894ee6b905
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/26828
Reviewed-by: Gabe Black <gabeblack@google.com>
Maintainer: Gabe Black <gabeblack@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
diff --git a/src/arch/mips/process.cc b/src/arch/mips/process.cc
index c388087..539c7a5 100644
--- a/src/arch/mips/process.cc
+++ b/src/arch/mips/process.cc
@@ -115,6 +115,7 @@
auxv.emplace_back(M5_AT_EUID, euid());
auxv.emplace_back(M5_AT_GID, gid());
auxv.emplace_back(M5_AT_EGID, egid());
+ auxv.emplace_back(M5_AT_RANDOM, 0);
}
// Calculate how much space we need for arg & env & auxv arrays.
@@ -126,6 +127,10 @@
for (vector<string>::size_type i = 0; i < argv.size(); ++i) {
arg_data_size += argv[i].size() + 1;
}
+
+ const int numRandomBytes = 16;
+ int aux_data_size = numRandomBytes;
+
int env_data_size = 0;
for (vector<string>::size_type i = 0; i < envp.size(); ++i) {
env_data_size += envp[i].size() + 1;
@@ -136,6 +141,7 @@
envp_array_size +
auxv_array_size +
arg_data_size +
+ aux_data_size +
env_data_size;
// set bottom of stack
@@ -152,7 +158,8 @@
IntType envp_array_base = argv_array_base + argv_array_size;
IntType auxv_array_base = envp_array_base + envp_array_size;
IntType arg_data_base = auxv_array_base + auxv_array_size;
- IntType env_data_base = arg_data_base + arg_data_size;
+ IntType aux_data_base = arg_data_base - arg_data_size;
+ IntType env_data_base = aux_data_base + aux_data_size;
// write contents to stack
IntType argc = argv.size();
@@ -167,6 +174,12 @@
copyStringArray(envp, envp_array_base, env_data_base,
LittleEndianByteOrder, *initVirtMem);
+ // Fix up the aux vectors which point to data.
+ for (auto &aux: auxv) {
+ if (aux.type == M5_AT_RANDOM)
+ aux.val = aux_data_base;
+ }
+
// Copy the aux vector
Addr auxv_array_end = auxv_array_base;
for (const auto &aux: auxv) {