49 #include "debug/Stack.hh"
51 #include "params/Process.hh"
61 using namespace RiscvISA;
76 const Addr stack_base = 0x7FFFFFFFFFFFFFFF
L;
77 const Addr max_stack_size = 8 * 1024 * 1024;
78 const Addr next_thread_stack_base = stack_base - max_stack_size;
80 const Addr mmap_end = 0x4000000000000000
L;
81 memState = std::make_shared<MemState>(
this, brk_point, stack_base,
82 max_stack_size, next_thread_stack_base, mmap_end);
89 const Addr stack_base = 0x7FFFFFFF;
90 const Addr max_stack_size = 8 * 1024 * 1024;
91 const Addr next_thread_stack_base = stack_base - max_stack_size;
93 const Addr mmap_end = 0x40000000
L;
94 memState = std::make_shared<MemState>(
this, brk_point, stack_base,
95 max_stack_size, next_thread_stack_base, mmap_end);
123 template<
class IntType>
void
126 const int RandomBytes = 16;
127 const int addrSize =
sizeof(IntType);
134 stack_top -= RandomBytes;
135 for (
const std::string& arg:
argv)
136 stack_top -= arg.size() + 1;
137 for (
const std::string& env:
envp)
138 stack_top -= env.size() + 1;
139 stack_top &= -addrSize;
142 if (elfObject !=
nullptr) {
152 stack_top -= (1 +
argv.size()) * addrSize +
153 (1 +
envp.size()) * addrSize +
154 addrSize + 2 *
sizeof(IntType) * auxv.size();
155 stack_top &= -2*addrSize;
162 uint8_t at_random[RandomBytes];
163 std::generate(std::begin(at_random), std::end(at_random),
169 for (
const std::string& arg:
argv) {
172 argPointers.push_back(
memState->getStackMin());
175 initVirtMem->readString(wrote, argPointers.back());
176 DPRINTFN(
"Wrote arg \"%s\" to address %p\n",
177 wrote, (
void*)
memState->getStackMin());
180 argPointers.push_back(0);
184 for (
const std::string& env:
envp) {
187 envPointers.push_back(
memState->getStackMin());
188 DPRINTF(Stack,
"Wrote env \"%s\" to address %p\n",
189 env, (
void*)
memState->getStackMin());
191 envPointers.push_back(0);
198 ((1 +
argv.size()) * addrSize +
199 (1 +
envp.size()) * addrSize +
200 addrSize + 2 *
sizeof(IntType) * auxv.size()));
203 const auto pushOntoStack =
204 [
this, &
sp](IntType
data) {
210 IntType argc =
argv.size();
211 DPRINTF(Stack,
"Wrote argc %d to address %#x\n", argc,
sp);
214 for (
const Addr& argPointer: argPointers) {
215 DPRINTF(Stack,
"Wrote argv pointer %#x to address %#x\n",
217 pushOntoStack(argPointer);
221 for (
const Addr& envPointer: envPointers) {
222 DPRINTF(Stack,
"Wrote envp pointer %#x to address %#x\n",
224 pushOntoStack(envPointer);
228 std::map<IntType, std::string> aux_keys = {
238 for (
const auto &aux: auxv) {
239 DPRINTF(Stack,
"Wrote aux key %s to address %#x\n",
240 aux_keys[aux.type],
sp);
241 pushOntoStack(aux.type);
242 DPRINTF(Stack,
"Wrote aux value %x to address %#x\n", aux.val,
sp);
243 pushOntoStack(aux.val);