48 #include "debug/Stack.hh"
50 #include "params/Process.hh"
72 const Addr stack_base = 0x7FFFFFFFFFFFFFFF
L;
73 const Addr max_stack_size = 8 * 1024 * 1024;
74 const Addr next_thread_stack_base = stack_base - max_stack_size;
76 const Addr mmap_end = 0x4000000000000000
L;
77 memState = std::make_shared<MemState>(
this, brk_point, stack_base,
78 max_stack_size, next_thread_stack_base, mmap_end);
85 const Addr stack_base = 0x7FFFFFFF;
86 const Addr max_stack_size = 8 * 1024 * 1024;
87 const Addr next_thread_stack_base = stack_base - max_stack_size;
89 const Addr mmap_end = 0x40000000
L;
90 memState = std::make_shared<MemState>(
this, brk_point, stack_base,
91 max_stack_size, next_thread_stack_base, mmap_end);
119 template<
class IntType>
void
122 const int RandomBytes = 16;
123 const int addrSize =
sizeof(IntType);
130 stack_top -= RandomBytes;
131 for (
const std::string& arg:
argv)
132 stack_top -= arg.size() + 1;
133 for (
const std::string& env:
envp)
134 stack_top -= env.size() + 1;
135 stack_top &= -addrSize;
138 if (elfObject !=
nullptr) {
140 auxv.emplace_back(
M5_AT_PHNUM, elfObject->programHeaderCount());
141 auxv.emplace_back(
M5_AT_PHENT, elfObject->programHeaderSize());
142 auxv.emplace_back(
M5_AT_PHDR, elfObject->programHeaderTable());
148 stack_top -= (1 +
argv.size()) * addrSize +
149 (1 +
envp.size()) * addrSize +
150 addrSize + 2 *
sizeof(IntType) * auxv.size();
151 stack_top &= -2*addrSize;
158 uint8_t at_random[RandomBytes];
159 std::generate(std::begin(at_random), std::end(at_random),
165 for (
const std::string& arg:
argv) {
168 argPointers.push_back(
memState->getStackMin());
171 initVirtMem->readString(wrote, argPointers.back());
172 DPRINTFN(
"Wrote arg \"%s\" to address %p\n",
173 wrote, (
void*)
memState->getStackMin());
176 argPointers.push_back(0);
180 for (
const std::string& env:
envp) {
183 envPointers.push_back(
memState->getStackMin());
184 DPRINTF(Stack,
"Wrote env \"%s\" to address %p\n",
185 env, (
void*)
memState->getStackMin());
187 envPointers.push_back(0);
194 ((1 +
argv.size()) * addrSize +
195 (1 +
envp.size()) * addrSize +
196 addrSize + 2 *
sizeof(IntType) * auxv.size()));
199 const auto pushOntoStack =
200 [
this, &
sp](IntType
data) {
206 IntType argc =
argv.size();
207 DPRINTF(Stack,
"Wrote argc %d to address %#x\n", argc,
sp);
210 for (
const Addr& argPointer: argPointers) {
211 DPRINTF(Stack,
"Wrote argv pointer %#x to address %#x\n",
213 pushOntoStack(argPointer);
217 for (
const Addr& envPointer: envPointers) {
218 DPRINTF(Stack,
"Wrote envp pointer %#x to address %#x\n",
220 pushOntoStack(envPointer);
224 std::map<IntType, std::string> aux_keys = {
234 for (
const auto &aux: auxv) {
235 DPRINTF(Stack,
"Wrote aux key %s to address %#x\n",
236 aux_keys[aux.type],
sp);
237 pushOntoStack(aux.type);
238 DPRINTF(Stack,
"Wrote aux value %x to address %#x\n", aux.val,
sp);
239 pushOntoStack(aux.val);