process.cc (13648:27e2153a4ea5) process.cc (13894:8603648c1679)
1/*
2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
3 * Copyright (c) 2016 The University of Virginia
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright

--- 125 unchanged lines hidden (view full) ---

134 Addr stack_top = memState->getStackMin();
135 stack_top -= RandomBytes;
136 for (const string& arg: argv)
137 stack_top -= arg.size() + 1;
138 for (const string& env: envp)
139 stack_top -= env.size() + 1;
140 stack_top &= -addrSize;
141
1/*
2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
3 * Copyright (c) 2016 The University of Virginia
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright

--- 125 unchanged lines hidden (view full) ---

134 Addr stack_top = memState->getStackMin();
135 stack_top -= RandomBytes;
136 for (const string& arg: argv)
137 stack_top -= arg.size() + 1;
138 for (const string& env: envp)
139 stack_top -= env.size() + 1;
140 stack_top &= -addrSize;
141
142 typedef AuxVector<IntType> auxv_t;
143 vector<auxv_t> auxv;
142 vector<AuxVector<IntType>> auxv;
144 if (elfObject != nullptr) {
143 if (elfObject != nullptr) {
145 auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint()));
146 auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount()));
147 auxv.push_back(auxv_t(M5_AT_PHENT, elfObject->programHeaderSize()));
148 auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable()));
149 auxv.push_back(auxv_t(M5_AT_PAGESZ, PageBytes));
150 auxv.push_back(auxv_t(M5_AT_SECURE, 0));
151 auxv.push_back(auxv_t(M5_AT_RANDOM, stack_top));
152 auxv.push_back(auxv_t(M5_AT_NULL, 0));
144 auxv.emplace_back(M5_AT_ENTRY, objFile->entryPoint());
145 auxv.emplace_back(M5_AT_PHNUM, elfObject->programHeaderCount());
146 auxv.emplace_back(M5_AT_PHENT, elfObject->programHeaderSize());
147 auxv.emplace_back(M5_AT_PHDR, elfObject->programHeaderTable());
148 auxv.emplace_back(M5_AT_PAGESZ, PageBytes);
149 auxv.emplace_back(M5_AT_SECURE, 0);
150 auxv.emplace_back(M5_AT_RANDOM, stack_top);
151 auxv.emplace_back(M5_AT_NULL, 0);
153 }
154 stack_top -= (1 + argv.size()) * addrSize +
155 (1 + envp.size()) * addrSize +
156 addrSize + 2 * sizeof(IntType) * auxv.size();
157 stack_top &= -2*addrSize;
158 memState->setStackSize(memState->getStackBase() - stack_top);
159 allocateMem(roundDown(stack_top, pageSize),
160 roundUp(memState->getStackSize(), pageSize));

--- 34 unchanged lines hidden (view full) ---

195 // Align stack
196 memState->setStackMin(memState->getStackMin() & -addrSize);
197
198 // Calculate bottom of stack
199 memState->setStackMin(memState->getStackMin() -
200 ((1 + argv.size()) * addrSize +
201 (1 + envp.size()) * addrSize +
202 addrSize + 2 * sizeof(IntType) * auxv.size()));
152 }
153 stack_top -= (1 + argv.size()) * addrSize +
154 (1 + envp.size()) * addrSize +
155 addrSize + 2 * sizeof(IntType) * auxv.size();
156 stack_top &= -2*addrSize;
157 memState->setStackSize(memState->getStackBase() - stack_top);
158 allocateMem(roundDown(stack_top, pageSize),
159 roundUp(memState->getStackSize(), pageSize));

--- 34 unchanged lines hidden (view full) ---

194 // Align stack
195 memState->setStackMin(memState->getStackMin() & -addrSize);
196
197 // Calculate bottom of stack
198 memState->setStackMin(memState->getStackMin() -
199 ((1 + argv.size()) * addrSize +
200 (1 + envp.size()) * addrSize +
201 addrSize + 2 * sizeof(IntType) * auxv.size()));
203 memState->setStackMin(memState->getStackMin() & -2*addrSize);
202 memState->setStackMin(memState->getStackMin() & (-2 * addrSize));
204 Addr sp = memState->getStackMin();
205 const auto pushOntoStack =
203 Addr sp = memState->getStackMin();
204 const auto pushOntoStack =
206 [this, &sp](const uint8_t* data, const size_t size) {
207 initVirtMem.writeBlob(sp, data, size);
208 sp += size;
205 [this, &sp](IntType data) {
206 initVirtMem.write(sp, data, GuestByteOrder);
207 sp += sizeof(data);
209 };
210
211 // Push argc and argv pointers onto stack
208 };
209
210 // Push argc and argv pointers onto stack
212 IntType argc = htog((IntType)argv.size());
213 DPRINTF(Stack, "Wrote argc %d to address %p\n",
214 argv.size(), (void*)sp);
215 pushOntoStack((uint8_t*)&argc, sizeof(IntType));
211 IntType argc = argv.size();
212 DPRINTF(Stack, "Wrote argc %d to address %#x\n", argc, sp);
213 pushOntoStack(argc);
214
216 for (const Addr& argPointer: argPointers) {
215 for (const Addr& argPointer: argPointers) {
217 DPRINTF(Stack, "Wrote argv pointer %p to address %p\n",
218 (void*)argPointer, (void*)sp);
219 pushOntoStack((uint8_t*)&argPointer, addrSize);
216 DPRINTF(Stack, "Wrote argv pointer %#x to address %#x\n",
217 argPointer, sp);
218 pushOntoStack(argPointer);
220 }
221
222 // Push env pointers onto stack
223 for (const Addr& envPointer: envPointers) {
219 }
220
221 // Push env pointers onto stack
222 for (const Addr& envPointer: envPointers) {
224 DPRINTF(Stack, "Wrote envp pointer %p to address %p\n",
225 (void*)envPointer, (void*)sp);
226 pushOntoStack((uint8_t*)&envPointer, addrSize);
223 DPRINTF(Stack, "Wrote envp pointer %#x to address %#x\n",
224 envPointer, sp);
225 pushOntoStack(envPointer);
227 }
228
229 // Push aux vector onto stack
230 std::map<IntType, string> aux_keys = {
231 {M5_AT_ENTRY, "M5_AT_ENTRY"},
232 {M5_AT_PHNUM, "M5_AT_PHNUM"},
233 {M5_AT_PHENT, "M5_AT_PHENT"},
234 {M5_AT_PHDR, "M5_AT_PHDR"},
235 {M5_AT_PAGESZ, "M5_AT_PAGESZ"},
236 {M5_AT_SECURE, "M5_AT_SECURE"},
237 {M5_AT_RANDOM, "M5_AT_RANDOM"},
238 {M5_AT_NULL, "M5_AT_NULL"}
239 };
226 }
227
228 // Push aux vector onto stack
229 std::map<IntType, string> aux_keys = {
230 {M5_AT_ENTRY, "M5_AT_ENTRY"},
231 {M5_AT_PHNUM, "M5_AT_PHNUM"},
232 {M5_AT_PHENT, "M5_AT_PHENT"},
233 {M5_AT_PHDR, "M5_AT_PHDR"},
234 {M5_AT_PAGESZ, "M5_AT_PAGESZ"},
235 {M5_AT_SECURE, "M5_AT_SECURE"},
236 {M5_AT_RANDOM, "M5_AT_RANDOM"},
237 {M5_AT_NULL, "M5_AT_NULL"}
238 };
240 for (const AuxVector<IntType>& aux: auxv) {
241 DPRINTF(Stack, "Wrote aux key %s to address %p\n",
242 aux_keys[aux.getAuxType()], (void*)sp);
243 pushOntoStack((uint8_t*)&aux.getAuxType(), sizeof(IntType));
244 DPRINTF(Stack, "Wrote aux value %x to address %p\n",
245 aux.getAuxVal(), (void*)sp);
246 pushOntoStack((uint8_t*)&aux.getAuxVal(), sizeof(IntType));
239 for (const auto &aux: auxv) {
240 DPRINTF(Stack, "Wrote aux key %s to address %#x\n",
241 aux_keys[aux.type], sp);
242 pushOntoStack(aux.type);
243 DPRINTF(Stack, "Wrote aux value %x to address %#x\n", aux.val, sp);
244 pushOntoStack(aux.val);
247 }
248
249 ThreadContext *tc = system->getThreadContext(contextIds[0]);
250 tc->setIntReg(StackPointerReg, memState->getStackMin());
251 tc->pcState(getStartPC());
252
253 memState->setStackMin(roundDown(memState->getStackMin(), pageSize));
254}

--- 30 unchanged lines hidden ---
245 }
246
247 ThreadContext *tc = system->getThreadContext(contextIds[0]);
248 tc->setIntReg(StackPointerReg, memState->getStackMin());
249 tc->pcState(getStartPC());
250
251 memState->setStackMin(roundDown(memState->getStackMin(), pageSize));
252}

--- 30 unchanged lines hidden ---