75 const Addr stack_base = 0x7FFFFFFFFFFFFFFFL;
76 const Addr max_stack_size = 8 * 1024 * 1024;
77 const Addr next_thread_stack_base = stack_base - max_stack_size;
79 const Addr mmap_end = 0x4000000000000000L;
80 memState = std::make_shared<MemState>(
this, brk_point, stack_base,
81 max_stack_size, next_thread_stack_base, mmap_end);
136 const int RandomBytes = 16;
137 const int addrSize =
sizeof(IntType);
144 stack_top -= RandomBytes;
145 for (
const std::string& arg:
argv)
146 stack_top -= arg.size() + 1;
147 for (
const std::string& env:
envp)
148 stack_top -= env.size() + 1;
149 stack_top &= -addrSize;
152 if (elfObject !=
nullptr) {
162 stack_top -= (1 +
argv.size()) * addrSize +
163 (1 +
envp.size()) * addrSize +
164 addrSize + 2 *
sizeof(IntType) * auxv.size();
165 stack_top &= -2*addrSize;
172 uint8_t at_random[RandomBytes];
173 std::generate(std::begin(at_random), std::end(at_random),
174 [&]{
return rng->random(0, 0xFF); });
179 for (
const std::string& arg:
argv) {
182 argPointers.push_back(
memState->getStackMin());
185 initVirtMem->readString(wrote, argPointers.back());
186 DPRINTFN(
"Wrote arg \"%s\" to address %p\n",
187 wrote, (
void*)
memState->getStackMin());
190 argPointers.push_back(0);
194 for (
const std::string& env:
envp) {
197 envPointers.push_back(
memState->getStackMin());
198 DPRINTF(Stack,
"Wrote env \"%s\" to address %p\n",
199 env, (
void*)
memState->getStackMin());
201 envPointers.push_back(0);
208 ((1 +
argv.size()) * addrSize +
209 (1 +
envp.size()) * addrSize +
210 addrSize + 2 *
sizeof(IntType) * auxv.size()));
213 const auto pushOntoStack =
214 [
this, &
sp](IntType
data) {
220 IntType argc =
argv.size();
221 DPRINTF(Stack,
"Wrote argc %d to address %#x\n", argc,
sp);
224 for (
const Addr& argPointer: argPointers) {
225 DPRINTF(Stack,
"Wrote argv pointer %#x to address %#x\n",
227 pushOntoStack(argPointer);
231 for (
const Addr& envPointer: envPointers) {
232 DPRINTF(Stack,
"Wrote envp pointer %#x to address %#x\n",
234 pushOntoStack(envPointer);
238 std::map<IntType, std::string> aux_keys = {
248 for (
const auto &aux: auxv) {
249 DPRINTF(Stack,
"Wrote aux key %s to address %#x\n",
250 aux_keys[aux.type],
sp);
251 pushOntoStack(aux.type);
252 DPRINTF(Stack,
"Wrote aux value %x to address %#x\n", aux.val,
sp);
253 pushOntoStack(aux.val);
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual void setReg(const RegId ®, RegVal val)
virtual const PCStateBase & pcState() const =0
Declarations of a non-full system Page Table.