38 #include "debug/Stack.hh"
40 #include "params/Process.hh"
59 Addr stack_base = 0xbf000000
L;
61 Addr max_stack_size = 8 * 1024 * 1024;
64 Addr next_thread_stack_base = stack_base - max_stack_size;
67 Addr mmap_end = 0x70000000
L;
69 memState = std::make_shared<MemState>(
70 this, brk_point, stack_base, max_stack_size,
71 next_thread_stack_base, mmap_end);
104 uint32_t features = 0;
115 auxv.emplace_back(
M5_AT_PHDR, elfObject->programHeaderTable());
117 auxv.emplace_back(
M5_AT_PHENT, elfObject->programHeaderSize());
119 auxv.emplace_back(
M5_AT_PHNUM, elfObject->programHeaderCount());
146 int sentry_size = intSize;
148 std::string platform =
"v51";
149 int platform_size = platform.size() + 1;
155 int aux_data_size = filename.size() + 1;
157 const int numRandomBytes = 16;
158 aux_data_size += numRandomBytes;
160 int env_data_size = 0;
161 for (
int i = 0;
i <
envp.size(); ++
i) {
162 env_data_size +=
envp[
i].size() + 1;
164 int arg_data_size = 0;
165 for (
int i = 0;
i <
argv.size(); ++
i) {
166 arg_data_size +=
argv[
i].size() + 1;
169 int info_block_size =
170 sentry_size + env_data_size + arg_data_size +
171 aux_data_size + platform_size;
174 int aux_array_size = intSize * 2 * (auxv.size() + 1);
176 int envp_array_size = intSize * (
envp.size() + 1);
177 int argv_array_size = intSize * (
argv.size() + 1);
179 int argc_size = intSize;
191 int partial_size = frame_size;
192 int aligned_partial_size =
roundUp(partial_size,
align);
193 int aux_padding = aligned_partial_size - partial_size;
195 int space_needed = frame_size + aux_padding;
197 Addr stack_min =
memState->getStackBase() - space_needed;
207 uint32_t sentry_base =
memState->getStackBase() - sentry_size;
208 uint32_t aux_data_base = sentry_base - aux_data_size;
209 uint32_t env_data_base = aux_data_base - env_data_size;
210 uint32_t arg_data_base = env_data_base - arg_data_size;
211 uint32_t platform_base = arg_data_base - platform_size;
212 uint32_t auxv_array_base = platform_base - aux_array_size - aux_padding;
213 uint32_t envp_array_base = auxv_array_base - envp_array_size;
214 uint32_t argv_array_base = envp_array_base - argv_array_size;
215 uint32_t argc_base = argv_array_base - argc_size;
217 DPRINTF(Stack,
"The addresses of items on the initial stack:\n");
218 DPRINTF(Stack,
"0x%x - aux data\n", aux_data_base);
219 DPRINTF(Stack,
"0x%x - env data\n", env_data_base);
220 DPRINTF(Stack,
"0x%x - arg data\n", arg_data_base);
221 DPRINTF(Stack,
"0x%x - platform base\n", platform_base);
222 DPRINTF(Stack,
"0x%x - auxv array\n", auxv_array_base);
223 DPRINTF(Stack,
"0x%x - envp array\n", envp_array_base);
224 DPRINTF(Stack,
"0x%x - argv array\n", argv_array_base);
225 DPRINTF(Stack,
"0x%x - argc \n", argc_base);
226 DPRINTF(Stack,
"0x%x - stack min\n", stack_min);
231 uint32_t argc =
argv.size();
232 uint32_t guestArgc =
htobe(argc);
235 uint32_t sentry_NULL = 0;
236 initVirtMem->writeBlob(sentry_base, &sentry_NULL, sentry_size);
239 for (
int i = auxv.size() - 1;
i >= 0;
i--) {
241 auxv[
i].val = platform_base;
242 initVirtMem->writeString(platform_base, platform.c_str());
244 auxv[
i].val = aux_data_base + numRandomBytes;
245 initVirtMem->writeString(aux_data_base, filename.c_str());
247 auxv[
i].val = aux_data_base;
252 Addr auxv_array_end = auxv_array_base;
253 for (
const auto &aux: auxv) {
255 auxv_array_end +=
sizeof(aux);
260 auxv_array_end +=
sizeof(zero);
267 initVirtMem->writeBlob(argc_base, &guestArgc, intSize);