52 #include "debug/Stack.hh" 54 #include "params/Process.hh" 69 fatal_if(params->useArchPT,
"Arch page tables not implemented.");
75 const Addr stack_base = 0x7FFFFFFFFFFFFFFF
L;
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 = 0x4000000000000000
L;
80 memState = make_shared<MemState>(brk_point, stack_base, max_stack_size,
81 next_thread_stack_base, mmap_end);
87 const Addr stack_base = 0x7FFFFFFF;
88 const Addr max_stack_size = 8 * 1024 * 1024;
89 const Addr next_thread_stack_base = stack_base - max_stack_size;
91 const Addr mmap_end = 0x40000000
L;
92 memState = make_shared<MemState>(brk_point, stack_base, max_stack_size,
93 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) {
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());
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);
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Addr programHeaderTable()
const std::string & name()
virtual TheISA::PCState pcState() const =0
virtual RegVal readIntReg(RegIndex reg_idx) const =0
bool successful() const
Was the system call successful?
std::vector< ContextID > contextIds
void writeString(Addr addr, const char *str) const
Same as tryWriteString, but insists on success.
virtual void setMiscRegNoEffect(RegIndex misc_reg, RegVal val)=0
void allocateMem(Addr vaddr, int64_t size, bool clobber=false)
const std::vector< int > SyscallArgumentRegs
SETranslatingPortProxy initVirtMem
RiscvProcess(ProcessParams *params, ObjectFile *objFile)
Overload hash function for BasicBlockRange type.
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
T roundUp(const T &val, const U &align)
This function is used to align addresses in memory.
std::shared_ptr< MemState > memState
ThreadContext is the external interface to all thread state for anything outside of the CPU...
int64_t encodedValue() const
The encoded value (as described above)
const ByteOrder GuestByteOrder
std::enable_if< std::is_integral< T >::value, T >::type random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
ThreadContext * getThreadContext(ContextID tid) const
void setSyscallReturn(ThreadContext *tc, SyscallReturn return_value) override
void writeBlob(Addr addr, const void *p, int size) const
Same as tryWriteBlob, but insists on success.
const Params * params() const
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
const RegIndex StackPointerReg
T roundDown(const T &val, const U &align)
This function is used to align addresses in memory.
const RegIndex SyscallPseudoReturnReg
RiscvProcess32(ProcessParams *params, ObjectFile *objFile)
std::vector< std::string > envp
void argsInit(int pageSize)
virtual void setIntReg(RegIndex reg_idx, RegVal val)=0
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
int64_t returnValue() const
The return value.
uint16_t programHeaderSize()
RiscvProcess64(ProcessParams *params, ObjectFile *objFile)
void readString(std::string &str, Addr addr) const
Same as tryReadString, but insists on success.
Declarations of a non-full system Page Table.
uint16_t programHeaderCount()
void write(Addr address, const T &data) const
Write object T to address.
std::vector< std::string > argv
This class represents the return value from an emulated system call, including any errno setting...
RegVal getSyscallArg(ThreadContext *tc, int &i) override
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
int ContextID
Globally unique thread context ID.