process.cc (13798:51228a4c00a5) | process.cc (13894:8603648c1679) |
---|---|
1/* 2 * Copyright (c) 2010, 2012, 2017-2018 ARM Limited 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software --- 243 unchanged lines hidden (view full) --- 252} 253 254template <class IntType> 255void 256ArmProcess::argsInit(int pageSize, IntRegIndex spIndex) 257{ 258 int intSize = sizeof(IntType); 259 | 1/* 2 * Copyright (c) 2010, 2012, 2017-2018 ARM Limited 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software --- 243 unchanged lines hidden (view full) --- 252} 253 254template <class IntType> 255void 256ArmProcess::argsInit(int pageSize, IntRegIndex spIndex) 257{ 258 int intSize = sizeof(IntType); 259 |
260 typedef AuxVector<IntType> auxv_t; 261 std::vector<auxv_t> auxv; | 260 std::vector<AuxVector<IntType>> auxv; |
262 263 string filename; 264 if (argv.size() < 1) 265 filename = ""; 266 else 267 filename = argv[0]; 268 269 //We want 16 byte alignment --- 10 unchanged lines hidden (view full) --- 280 ElfObject * elfObject = dynamic_cast<ElfObject *>(objFile); 281 if (elfObject) { 282 283 if (objFile->getOpSys() == ObjectFile::Linux) { 284 IntType features = armHwcap<IntType>(); 285 286 //Bits which describe the system hardware capabilities 287 //XXX Figure out what these should be | 261 262 string filename; 263 if (argv.size() < 1) 264 filename = ""; 265 else 266 filename = argv[0]; 267 268 //We want 16 byte alignment --- 10 unchanged lines hidden (view full) --- 279 ElfObject * elfObject = dynamic_cast<ElfObject *>(objFile); 280 if (elfObject) { 281 282 if (objFile->getOpSys() == ObjectFile::Linux) { 283 IntType features = armHwcap<IntType>(); 284 285 //Bits which describe the system hardware capabilities 286 //XXX Figure out what these should be |
288 auxv.push_back(auxv_t(M5_AT_HWCAP, features)); | 287 auxv.emplace_back(M5_AT_HWCAP, features); |
289 //Frequency at which times() increments | 288 //Frequency at which times() increments |
290 auxv.push_back(auxv_t(M5_AT_CLKTCK, 0x64)); | 289 auxv.emplace_back(M5_AT_CLKTCK, 0x64); |
291 //Whether to enable "secure mode" in the executable | 290 //Whether to enable "secure mode" in the executable |
292 auxv.push_back(auxv_t(M5_AT_SECURE, 0)); | 291 auxv.emplace_back(M5_AT_SECURE, 0); |
293 // Pointer to 16 bytes of random data | 292 // Pointer to 16 bytes of random data |
294 auxv.push_back(auxv_t(M5_AT_RANDOM, 0)); | 293 auxv.emplace_back(M5_AT_RANDOM, 0); |
295 //The filename of the program | 294 //The filename of the program |
296 auxv.push_back(auxv_t(M5_AT_EXECFN, 0)); | 295 auxv.emplace_back(M5_AT_EXECFN, 0); |
297 //The string "v71" -- ARM v7 architecture | 296 //The string "v71" -- ARM v7 architecture |
298 auxv.push_back(auxv_t(M5_AT_PLATFORM, 0)); | 297 auxv.emplace_back(M5_AT_PLATFORM, 0); |
299 } 300 301 //The system page size | 298 } 299 300 //The system page size |
302 auxv.push_back(auxv_t(M5_AT_PAGESZ, ArmISA::PageBytes)); 303 // For statically linked executables, this is the virtual address of the 304 // program header tables if they appear in the executable image 305 auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable())); | 301 auxv.emplace_back(M5_AT_PAGESZ, ArmISA::PageBytes); 302 // For statically linked executables, this is the virtual address of 303 // the program header tables if they appear in the executable image 304 auxv.emplace_back(M5_AT_PHDR, elfObject->programHeaderTable()); |
306 // This is the size of a program header entry from the elf file. | 305 // This is the size of a program header entry from the elf file. |
307 auxv.push_back(auxv_t(M5_AT_PHENT, elfObject->programHeaderSize())); | 306 auxv.emplace_back(M5_AT_PHENT, elfObject->programHeaderSize()); |
308 // This is the number of program headers from the original elf file. | 307 // This is the number of program headers from the original elf file. |
309 auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount())); | 308 auxv.emplace_back(M5_AT_PHNUM, elfObject->programHeaderCount()); |
310 // This is the base address of the ELF interpreter; it should be 311 // zero for static executables or contain the base address for 312 // dynamic executables. | 309 // This is the base address of the ELF interpreter; it should be 310 // zero for static executables or contain the base address for 311 // dynamic executables. |
313 auxv.push_back(auxv_t(M5_AT_BASE, getBias())); | 312 auxv.emplace_back(M5_AT_BASE, getBias()); |
314 //XXX Figure out what this should be. | 313 //XXX Figure out what this should be. |
315 auxv.push_back(auxv_t(M5_AT_FLAGS, 0)); | 314 auxv.emplace_back(M5_AT_FLAGS, 0); |
316 //The entry point to the program | 315 //The entry point to the program |
317 auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint())); | 316 auxv.emplace_back(M5_AT_ENTRY, objFile->entryPoint()); |
318 //Different user and group IDs | 317 //Different user and group IDs |
319 auxv.push_back(auxv_t(M5_AT_UID, uid())); 320 auxv.push_back(auxv_t(M5_AT_EUID, euid())); 321 auxv.push_back(auxv_t(M5_AT_GID, gid())); 322 auxv.push_back(auxv_t(M5_AT_EGID, egid())); | 318 auxv.emplace_back(M5_AT_UID, uid()); 319 auxv.emplace_back(M5_AT_EUID, euid()); 320 auxv.emplace_back(M5_AT_GID, gid()); 321 auxv.emplace_back(M5_AT_EGID, egid()); |
323 } 324 325 //Figure out how big the initial stack nedes to be 326 327 // A sentry NULL void pointer at the top of the stack. 328 int sentry_size = intSize; 329 330 string platform = "v71"; --- 85 unchanged lines hidden (view full) --- 416 417 //Write out the sentry void * 418 IntType sentry_NULL = 0; 419 initVirtMem.writeBlob(sentry_base, 420 (uint8_t*)&sentry_NULL, sentry_size); 421 422 //Fix up the aux vectors which point to other data 423 for (int i = auxv.size() - 1; i >= 0; i--) { | 322 } 323 324 //Figure out how big the initial stack nedes to be 325 326 // A sentry NULL void pointer at the top of the stack. 327 int sentry_size = intSize; 328 329 string platform = "v71"; --- 85 unchanged lines hidden (view full) --- 415 416 //Write out the sentry void * 417 IntType sentry_NULL = 0; 418 initVirtMem.writeBlob(sentry_base, 419 (uint8_t*)&sentry_NULL, sentry_size); 420 421 //Fix up the aux vectors which point to other data 422 for (int i = auxv.size() - 1; i >= 0; i--) { |
424 if (auxv[i].getHostAuxType() == M5_AT_PLATFORM) { 425 auxv[i].setAuxVal(platform_base); | 423 if (auxv[i].type == M5_AT_PLATFORM) { 424 auxv[i].val = platform_base; |
426 initVirtMem.writeString(platform_base, platform.c_str()); | 425 initVirtMem.writeString(platform_base, platform.c_str()); |
427 } else if (auxv[i].getHostAuxType() == M5_AT_EXECFN) { 428 auxv[i].setAuxVal(aux_data_base); | 426 } else if (auxv[i].type == M5_AT_EXECFN) { 427 auxv[i].val = aux_data_base; |
429 initVirtMem.writeString(aux_data_base, filename.c_str()); | 428 initVirtMem.writeString(aux_data_base, filename.c_str()); |
430 } else if (auxv[i].getHostAuxType() == M5_AT_RANDOM) { 431 auxv[i].setAuxVal(aux_random_base); | 429 } else if (auxv[i].type == M5_AT_RANDOM) { 430 auxv[i].val = aux_random_base; |
432 // Just leave the value 0, we don't want randomness 433 } 434 } 435 436 //Copy the aux stuff | 431 // Just leave the value 0, we don't want randomness 432 } 433 } 434 435 //Copy the aux stuff |
437 for (int x = 0; x < auxv.size(); x++) { 438 initVirtMem.writeBlob(auxv_array_base + x * 2 * intSize, 439 (uint8_t*)&(auxv[x].getAuxType()), 440 intSize); 441 initVirtMem.writeBlob(auxv_array_base + (x * 2 + 1) * intSize, 442 (uint8_t*)&(auxv[x].getAuxVal()), 443 intSize); | 436 Addr auxv_array_end = auxv_array_base; 437 for (const auto &aux: auxv) { 438 initVirtMem.write(auxv_array_end, aux, GuestByteOrder); 439 auxv_array_end += sizeof(aux); |
444 } 445 //Write out the terminating zeroed auxillary vector | 440 } 441 //Write out the terminating zeroed auxillary vector |
446 const IntType zero[2] = {0, 0}; 447 initVirtMem.writeBlob(auxv_array_base + 2 * intSize * auxv.size(), 448 (uint8_t*)zero, 2 * intSize); | 442 const AuxVector<IntType> zero(0, 0); 443 initVirtMem.write(auxv_array_end, zero); 444 auxv_array_end += sizeof(zero); |
449 450 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); 451 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); 452 453 initVirtMem.writeBlob(argc_base, (uint8_t*)&guestArgc, intSize); 454 455 ThreadContext *tc = system->getThreadContext(contextIds[0]); 456 //Set the stack pointer register --- 117 unchanged lines hidden --- | 445 446 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); 447 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); 448 449 initVirtMem.writeBlob(argc_base, (uint8_t*)&guestArgc, intSize); 450 451 ThreadContext *tc = system->getThreadContext(contextIds[0]); 452 //Set the stack pointer register --- 117 unchanged lines hidden --- |