48 #include "debug/Stack.hh"
50 #include "params/Process.hh"
73 const Addr stack_base = 0x7FFFFFFFFFFFFFFF
L;
74 const Addr max_stack_size = 8 * 1024 * 1024;
75 const Addr next_thread_stack_base = stack_base - max_stack_size;
77 const Addr mmap_end = 0x4000000000000000
L;
78 memState = make_shared<MemState>(
this, brk_point, stack_base,
79 max_stack_size, next_thread_stack_base, mmap_end);
86 const Addr stack_base = 0x7FFFFFFF;
87 const Addr max_stack_size = 8 * 1024 * 1024;
88 const Addr next_thread_stack_base = stack_base - max_stack_size;
90 const Addr mmap_end = 0x40000000
L;
91 memState = make_shared<MemState>(
this, brk_point, stack_base,
92 max_stack_size, next_thread_stack_base, mmap_end);
120 template<
class IntType>
void
123 const int RandomBytes = 16;
124 const int addrSize =
sizeof(IntType);
131 stack_top -= RandomBytes;
132 for (
const string& arg:
argv)
133 stack_top -= arg.size() + 1;
134 for (
const string& env:
envp)
135 stack_top -= env.size() + 1;
136 stack_top &= -addrSize;
139 if (elfObject !=
nullptr) {
141 auxv.emplace_back(
M5_AT_PHNUM, elfObject->programHeaderCount());
142 auxv.emplace_back(
M5_AT_PHENT, elfObject->programHeaderSize());
143 auxv.emplace_back(
M5_AT_PHDR, elfObject->programHeaderTable());
149 stack_top -= (1 +
argv.size()) * addrSize +
150 (1 +
envp.size()) * addrSize +
151 addrSize + 2 *
sizeof(IntType) * auxv.size();
152 stack_top &= -2*addrSize;
159 uint8_t at_random[RandomBytes];
160 generate(begin(at_random), end(at_random),
166 for (
const string& arg:
argv) {
169 argPointers.push_back(
memState->getStackMin());
172 initVirtMem->readString(wrote, argPointers.back());
173 DPRINTFN(
"Wrote arg \"%s\" to address %p\n",
174 wrote, (
void*)
memState->getStackMin());
177 argPointers.push_back(0);
181 for (
const string& env:
envp) {
184 envPointers.push_back(
memState->getStackMin());
185 DPRINTF(Stack,
"Wrote env \"%s\" to address %p\n",
186 env, (
void*)
memState->getStackMin());
188 envPointers.push_back(0);
195 ((1 +
argv.size()) * addrSize +
196 (1 +
envp.size()) * addrSize +
197 addrSize + 2 *
sizeof(IntType) * auxv.size()));
200 const auto pushOntoStack =
201 [
this, &
sp](IntType
data) {
207 IntType argc =
argv.size();
208 DPRINTF(Stack,
"Wrote argc %d to address %#x\n", argc,
sp);
211 for (
const Addr& argPointer: argPointers) {
212 DPRINTF(Stack,
"Wrote argv pointer %#x to address %#x\n",
214 pushOntoStack(argPointer);
218 for (
const Addr& envPointer: envPointers) {
219 DPRINTF(Stack,
"Wrote envp pointer %#x to address %#x\n",
221 pushOntoStack(envPointer);
225 std::map<IntType, string> aux_keys = {
235 for (
const auto &aux: auxv) {
236 DPRINTF(Stack,
"Wrote aux key %s to address %#x\n",
237 aux_keys[aux.type],
sp);
238 pushOntoStack(aux.type);
239 DPRINTF(Stack,
"Wrote aux value %x to address %#x\n", aux.val,
sp);
240 pushOntoStack(aux.val);
251 10, 11, 12, 13, 14, 15, 16