diff options
Diffstat (limited to 'src/arch')
-rw-r--r-- | src/arch/alpha/process.cc | 35 | ||||
-rw-r--r-- | src/arch/arm/process.cc | 70 | ||||
-rw-r--r-- | src/arch/mips/process.cc | 45 | ||||
-rw-r--r-- | src/arch/power/process.cc | 63 | ||||
-rw-r--r-- | src/arch/riscv/process.cc | 60 | ||||
-rw-r--r-- | src/arch/sparc/process.cc | 53 | ||||
-rw-r--r-- | src/arch/x86/process.cc | 78 |
7 files changed, 189 insertions, 215 deletions
diff --git a/src/arch/alpha/process.cc b/src/arch/alpha/process.cc index 00468bbc3..a7822a367 100644 --- a/src/arch/alpha/process.cc +++ b/src/arch/alpha/process.cc @@ -82,8 +82,7 @@ AlphaProcess::argsInit(int intSize, int pageSize) objFile->loadSections(initVirtMem); - typedef AuxVector<uint64_t> auxv_t; - std::vector<auxv_t> auxv; + std::vector<AuxVector<uint64_t>> auxv; ElfObject * elfObject = dynamic_cast<ElfObject *>(objFile); if (elfObject) @@ -96,20 +95,21 @@ AlphaProcess::argsInit(int intSize, int pageSize) // seem to be a problem. // check out _dl_aux_init() in glibc/elf/dl-support.c for details // --Lisa - auxv.push_back(auxv_t(M5_AT_PAGESZ, AlphaISA::PageBytes)); - auxv.push_back(auxv_t(M5_AT_CLKTCK, 100)); - auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable())); - DPRINTF(Loader, "auxv at PHDR %08p\n", elfObject->programHeaderTable()); - auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount())); + auxv.emplace_back(M5_AT_PAGESZ, AlphaISA::PageBytes); + auxv.emplace_back(M5_AT_CLKTCK, 100); + auxv.emplace_back(M5_AT_PHDR, elfObject->programHeaderTable()); + DPRINTF(Loader, "auxv at PHDR %08p\n", + elfObject->programHeaderTable()); + auxv.emplace_back(M5_AT_PHNUM, elfObject->programHeaderCount()); // This is the base address of the ELF interpreter; it should be // zero for static executables or contain the base address for // dynamic executables. - auxv.push_back(auxv_t(M5_AT_BASE, getBias())); - auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint())); - auxv.push_back(auxv_t(M5_AT_UID, uid())); - auxv.push_back(auxv_t(M5_AT_EUID, euid())); - auxv.push_back(auxv_t(M5_AT_GID, gid())); - auxv.push_back(auxv_t(M5_AT_EGID, egid())); + auxv.emplace_back(M5_AT_BASE, getBias()); + auxv.emplace_back(M5_AT_ENTRY, objFile->entryPoint()); + auxv.emplace_back(M5_AT_UID, uid()); + auxv.emplace_back(M5_AT_EUID, euid()); + auxv.emplace_back(M5_AT_GID, gid()); + auxv.emplace_back(M5_AT_EGID, egid()); } @@ -168,11 +168,10 @@ AlphaProcess::argsInit(int intSize, int pageSize) copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); //Copy the aux stuff - for (vector<auxv_t>::size_type x = 0; x < auxv.size(); x++) { - initVirtMem.writeBlob(auxv_array_base + x * 2 * intSize, - (uint8_t*)&(auxv[x].getAuxType()), intSize); - initVirtMem.writeBlob(auxv_array_base + (x * 2 + 1) * intSize, - (uint8_t*)&(auxv[x].getAuxVal()), intSize); + Addr auxv_array_end = auxv_array_base; + for (const auto &aux: auxv) { + initVirtMem.write(auxv_array_end, aux, GuestByteOrder); + auxv_array_end += sizeof(aux); } ThreadContext *tc = system->getThreadContext(contextIds[0]); diff --git a/src/arch/arm/process.cc b/src/arch/arm/process.cc index ba9fbfaa3..baa861fc8 100644 --- a/src/arch/arm/process.cc +++ b/src/arch/arm/process.cc @@ -257,8 +257,7 @@ ArmProcess::argsInit(int pageSize, IntRegIndex spIndex) { int intSize = sizeof(IntType); - typedef AuxVector<IntType> auxv_t; - std::vector<auxv_t> auxv; + std::vector<AuxVector<IntType>> auxv; string filename; if (argv.size() < 1) @@ -285,41 +284,41 @@ ArmProcess::argsInit(int pageSize, IntRegIndex spIndex) //Bits which describe the system hardware capabilities //XXX Figure out what these should be - auxv.push_back(auxv_t(M5_AT_HWCAP, features)); + auxv.emplace_back(M5_AT_HWCAP, features); //Frequency at which times() increments - auxv.push_back(auxv_t(M5_AT_CLKTCK, 0x64)); + auxv.emplace_back(M5_AT_CLKTCK, 0x64); //Whether to enable "secure mode" in the executable - auxv.push_back(auxv_t(M5_AT_SECURE, 0)); + auxv.emplace_back(M5_AT_SECURE, 0); // Pointer to 16 bytes of random data - auxv.push_back(auxv_t(M5_AT_RANDOM, 0)); + auxv.emplace_back(M5_AT_RANDOM, 0); //The filename of the program - auxv.push_back(auxv_t(M5_AT_EXECFN, 0)); + auxv.emplace_back(M5_AT_EXECFN, 0); //The string "v71" -- ARM v7 architecture - auxv.push_back(auxv_t(M5_AT_PLATFORM, 0)); + auxv.emplace_back(M5_AT_PLATFORM, 0); } //The system page size - auxv.push_back(auxv_t(M5_AT_PAGESZ, ArmISA::PageBytes)); - // For statically linked executables, this is the virtual address of the - // program header tables if they appear in the executable image - auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable())); + auxv.emplace_back(M5_AT_PAGESZ, ArmISA::PageBytes); + // For statically linked executables, this is the virtual address of + // the program header tables if they appear in the executable image + auxv.emplace_back(M5_AT_PHDR, elfObject->programHeaderTable()); // This is the size of a program header entry from the elf file. - auxv.push_back(auxv_t(M5_AT_PHENT, elfObject->programHeaderSize())); + auxv.emplace_back(M5_AT_PHENT, elfObject->programHeaderSize()); // This is the number of program headers from the original elf file. - auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount())); + auxv.emplace_back(M5_AT_PHNUM, elfObject->programHeaderCount()); // This is the base address of the ELF interpreter; it should be // zero for static executables or contain the base address for // dynamic executables. - auxv.push_back(auxv_t(M5_AT_BASE, getBias())); + auxv.emplace_back(M5_AT_BASE, getBias()); //XXX Figure out what this should be. - auxv.push_back(auxv_t(M5_AT_FLAGS, 0)); + auxv.emplace_back(M5_AT_FLAGS, 0); //The entry point to the program - auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint())); + auxv.emplace_back(M5_AT_ENTRY, objFile->entryPoint()); //Different user and group IDs - auxv.push_back(auxv_t(M5_AT_UID, uid())); - auxv.push_back(auxv_t(M5_AT_EUID, euid())); - auxv.push_back(auxv_t(M5_AT_GID, gid())); - auxv.push_back(auxv_t(M5_AT_EGID, egid())); + auxv.emplace_back(M5_AT_UID, uid()); + auxv.emplace_back(M5_AT_EUID, euid()); + auxv.emplace_back(M5_AT_GID, gid()); + auxv.emplace_back(M5_AT_EGID, egid()); } //Figure out how big the initial stack nedes to be @@ -421,31 +420,28 @@ ArmProcess::argsInit(int pageSize, IntRegIndex spIndex) //Fix up the aux vectors which point to other data for (int i = auxv.size() - 1; i >= 0; i--) { - if (auxv[i].getHostAuxType() == M5_AT_PLATFORM) { - auxv[i].setAuxVal(platform_base); + if (auxv[i].type == M5_AT_PLATFORM) { + auxv[i].val = platform_base; initVirtMem.writeString(platform_base, platform.c_str()); - } else if (auxv[i].getHostAuxType() == M5_AT_EXECFN) { - auxv[i].setAuxVal(aux_data_base); + } else if (auxv[i].type == M5_AT_EXECFN) { + auxv[i].val = aux_data_base; initVirtMem.writeString(aux_data_base, filename.c_str()); - } else if (auxv[i].getHostAuxType() == M5_AT_RANDOM) { - auxv[i].setAuxVal(aux_random_base); + } else if (auxv[i].type == M5_AT_RANDOM) { + auxv[i].val = aux_random_base; // Just leave the value 0, we don't want randomness } } //Copy the aux stuff - for (int x = 0; x < auxv.size(); x++) { - initVirtMem.writeBlob(auxv_array_base + x * 2 * intSize, - (uint8_t*)&(auxv[x].getAuxType()), - intSize); - initVirtMem.writeBlob(auxv_array_base + (x * 2 + 1) * intSize, - (uint8_t*)&(auxv[x].getAuxVal()), - intSize); + Addr auxv_array_end = auxv_array_base; + for (const auto &aux: auxv) { + initVirtMem.write(auxv_array_end, aux, GuestByteOrder); + auxv_array_end += sizeof(aux); } //Write out the terminating zeroed auxillary vector - const IntType zero[2] = {0, 0}; - initVirtMem.writeBlob(auxv_array_base + 2 * intSize * auxv.size(), - (uint8_t*)zero, 2 * intSize); + const AuxVector<IntType> zero(0, 0); + initVirtMem.write(auxv_array_end, zero); + auxv_array_end += sizeof(zero); copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); diff --git a/src/arch/mips/process.cc b/src/arch/mips/process.cc index 9b4b5bb3c..d8378725c 100644 --- a/src/arch/mips/process.cc +++ b/src/arch/mips/process.cc @@ -96,36 +96,36 @@ MipsProcess::argsInit(int pageSize) // load object file into target memory objFile->loadSections(initVirtMem); - typedef AuxVector<IntType> auxv_t; - std::vector<auxv_t> auxv; + std::vector<AuxVector<IntType>> auxv; ElfObject * elfObject = dynamic_cast<ElfObject *>(objFile); if (elfObject) { // Set the system page size - auxv.push_back(auxv_t(M5_AT_PAGESZ, MipsISA::PageBytes)); + auxv.emplace_back(M5_AT_PAGESZ, MipsISA::PageBytes); // Set the frequency at which time() increments - auxv.push_back(auxv_t(M5_AT_CLKTCK, 100)); + auxv.emplace_back(M5_AT_CLKTCK, 100); // For statically linked executables, this is the virtual // address of the program header tables if they appear in the // executable image. - auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable())); - DPRINTF(Loader, "auxv at PHDR %08p\n", elfObject->programHeaderTable()); + auxv.emplace_back(M5_AT_PHDR, elfObject->programHeaderTable()); + DPRINTF(Loader, "auxv at PHDR %08p\n", + elfObject->programHeaderTable()); // This is the size of a program header entry from the elf file. - auxv.push_back(auxv_t(M5_AT_PHENT, elfObject->programHeaderSize())); + auxv.emplace_back(M5_AT_PHENT, elfObject->programHeaderSize()); // This is the number of program headers from the original elf file. - auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount())); + auxv.emplace_back(M5_AT_PHNUM, elfObject->programHeaderCount()); // This is the base address of the ELF interpreter; it should be // zero for static executables or contain the base address for // dynamic executables. - auxv.push_back(auxv_t(M5_AT_BASE, getBias())); + auxv.emplace_back(M5_AT_BASE, getBias()); //The entry point to the program - auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint())); + auxv.emplace_back(M5_AT_ENTRY, objFile->entryPoint()); //Different user and group IDs - auxv.push_back(auxv_t(M5_AT_UID, uid())); - auxv.push_back(auxv_t(M5_AT_EUID, euid())); - auxv.push_back(auxv_t(M5_AT_GID, gid())); - auxv.push_back(auxv_t(M5_AT_EGID, egid())); + auxv.emplace_back(M5_AT_UID, uid()); + auxv.emplace_back(M5_AT_EUID, euid()); + auxv.emplace_back(M5_AT_GID, gid()); + auxv.emplace_back(M5_AT_EGID, egid()); } // Calculate how much space we need for arg & env & auxv arrays. @@ -177,19 +177,16 @@ MipsProcess::argsInit(int pageSize) copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); // Copy the aux vector - for (typename vector<auxv_t>::size_type x = 0; x < auxv.size(); x++) { - initVirtMem.writeBlob(auxv_array_base + x * 2 * intSize, - (uint8_t*)&(auxv[x].getAuxType()), intSize); - initVirtMem.writeBlob(auxv_array_base + (x * 2 + 1) * intSize, - (uint8_t*)&(auxv[x].getAuxVal()), intSize); + Addr auxv_array_end = auxv_array_base; + for (const auto &aux: auxv) { + initVirtMem.write(auxv_array_end, aux, GuestByteOrder); + auxv_array_end += sizeof(aux); } // Write out the terminating zeroed auxilliary vector - for (unsigned i = 0; i < 2; i++) { - const IntType zero = 0; - const Addr addr = auxv_array_base + 2 * intSize * (auxv.size() + i); - initVirtMem.writeBlob(addr, (uint8_t*)&zero, intSize); - } + const AuxVector<IntType> zero(0, 0); + initVirtMem.write(auxv_array_end, zero); + auxv_array_end += sizeof(zero); ThreadContext *tc = system->getThreadContext(contextIds[0]); diff --git a/src/arch/power/process.cc b/src/arch/power/process.cc index ee72ba71a..1d082c77e 100644 --- a/src/arch/power/process.cc +++ b/src/arch/power/process.cc @@ -85,8 +85,7 @@ PowerProcess::initState() void PowerProcess::argsInit(int intSize, int pageSize) { - typedef AuxVector<uint32_t> auxv_t; - std::vector<auxv_t> auxv; + std::vector<AuxVector<uint32_t>> auxv; string filename; if (argv.size() < 1) @@ -111,37 +110,37 @@ PowerProcess::argsInit(int intSize, int pageSize) //Bits which describe the system hardware capabilities //XXX Figure out what these should be - auxv.push_back(auxv_t(M5_AT_HWCAP, features)); + auxv.emplace_back(M5_AT_HWCAP, features); //The system page size - auxv.push_back(auxv_t(M5_AT_PAGESZ, PowerISA::PageBytes)); + auxv.emplace_back(M5_AT_PAGESZ, PowerISA::PageBytes); //Frequency at which times() increments - auxv.push_back(auxv_t(M5_AT_CLKTCK, 0x64)); - // For statically linked executables, this is the virtual address of the - // program header tables if they appear in the executable image - auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable())); + auxv.emplace_back(M5_AT_CLKTCK, 0x64); + // For statically linked executables, this is the virtual address of + // the program header tables if they appear in the executable image + auxv.emplace_back(M5_AT_PHDR, elfObject->programHeaderTable()); // This is the size of a program header entry from the elf file. - auxv.push_back(auxv_t(M5_AT_PHENT, elfObject->programHeaderSize())); + auxv.emplace_back(M5_AT_PHENT, elfObject->programHeaderSize()); // This is the number of program headers from the original elf file. - auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount())); + auxv.emplace_back(M5_AT_PHNUM, elfObject->programHeaderCount()); // This is the base address of the ELF interpreter; it should be // zero for static executables or contain the base address for // dynamic executables. - auxv.push_back(auxv_t(M5_AT_BASE, getBias())); + auxv.emplace_back(M5_AT_BASE, getBias()); //XXX Figure out what this should be. - auxv.push_back(auxv_t(M5_AT_FLAGS, 0)); + auxv.emplace_back(M5_AT_FLAGS, 0); //The entry point to the program - auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint())); + auxv.emplace_back(M5_AT_ENTRY, objFile->entryPoint()); //Different user and group IDs - auxv.push_back(auxv_t(M5_AT_UID, uid())); - auxv.push_back(auxv_t(M5_AT_EUID, euid())); - auxv.push_back(auxv_t(M5_AT_GID, gid())); - auxv.push_back(auxv_t(M5_AT_EGID, egid())); + auxv.emplace_back(M5_AT_UID, uid()); + auxv.emplace_back(M5_AT_EUID, euid()); + auxv.emplace_back(M5_AT_GID, gid()); + auxv.emplace_back(M5_AT_EGID, egid()); //Whether to enable "secure mode" in the executable - auxv.push_back(auxv_t(M5_AT_SECURE, 0)); + auxv.emplace_back(M5_AT_SECURE, 0); //The filename of the program - auxv.push_back(auxv_t(M5_AT_EXECFN, 0)); + auxv.emplace_back(M5_AT_EXECFN, 0); //The string "v51" with unknown meaning - auxv.push_back(auxv_t(M5_AT_PLATFORM, 0)); + auxv.emplace_back(M5_AT_PLATFORM, 0); } //Figure out how big the initial stack nedes to be @@ -239,27 +238,25 @@ PowerProcess::argsInit(int intSize, int pageSize) //Fix up the aux vectors which point to other data for (int i = auxv.size() - 1; i >= 0; i--) { - if (auxv[i].getHostAuxType() == M5_AT_PLATFORM) { - auxv[i].setAuxVal(platform_base); + if (auxv[i].type == M5_AT_PLATFORM) { + auxv[i].val = platform_base; initVirtMem.writeString(platform_base, platform.c_str()); - } else if (auxv[i].getHostAuxType() == M5_AT_EXECFN) { - auxv[i].setAuxVal(aux_data_base); + } else if (auxv[i].type == M5_AT_EXECFN) { + auxv[i].val = aux_data_base; initVirtMem.writeString(aux_data_base, filename.c_str()); } } //Copy the aux stuff - for (int x = 0; x < auxv.size(); x++) - { - initVirtMem.writeBlob(auxv_array_base + x * 2 * intSize, - (uint8_t*)&(auxv[x].getAuxType()), intSize); - initVirtMem.writeBlob(auxv_array_base + (x * 2 + 1) * intSize, - (uint8_t*)&(auxv[x].getAuxVal()), intSize); + Addr auxv_array_end = auxv_array_base; + for (const auto &aux: auxv) { + initVirtMem.write(auxv_array_end, aux, GuestByteOrder); + auxv_array_end += sizeof(aux); } //Write out the terminating zeroed auxilliary vector - const uint64_t zero = 0; - initVirtMem.writeBlob(auxv_array_base + 2 * intSize * auxv.size(), - (uint8_t*)&zero, 2 * intSize); + const AuxVector<uint64_t> zero(0, 0); + initVirtMem.write(auxv_array_end, zero); + auxv_array_end += sizeof(zero); copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); diff --git a/src/arch/riscv/process.cc b/src/arch/riscv/process.cc index 16d0dc7ff..ab8305257 100644 --- a/src/arch/riscv/process.cc +++ b/src/arch/riscv/process.cc @@ -139,17 +139,16 @@ RiscvProcess::argsInit(int pageSize) stack_top -= env.size() + 1; stack_top &= -addrSize; - typedef AuxVector<IntType> auxv_t; - vector<auxv_t> auxv; + vector<AuxVector<IntType>> auxv; if (elfObject != nullptr) { - auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint())); - auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount())); - auxv.push_back(auxv_t(M5_AT_PHENT, elfObject->programHeaderSize())); - auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable())); - auxv.push_back(auxv_t(M5_AT_PAGESZ, PageBytes)); - auxv.push_back(auxv_t(M5_AT_SECURE, 0)); - auxv.push_back(auxv_t(M5_AT_RANDOM, stack_top)); - auxv.push_back(auxv_t(M5_AT_NULL, 0)); + auxv.emplace_back(M5_AT_ENTRY, objFile->entryPoint()); + auxv.emplace_back(M5_AT_PHNUM, elfObject->programHeaderCount()); + auxv.emplace_back(M5_AT_PHENT, elfObject->programHeaderSize()); + auxv.emplace_back(M5_AT_PHDR, elfObject->programHeaderTable()); + auxv.emplace_back(M5_AT_PAGESZ, PageBytes); + auxv.emplace_back(M5_AT_SECURE, 0); + auxv.emplace_back(M5_AT_RANDOM, stack_top); + auxv.emplace_back(M5_AT_NULL, 0); } stack_top -= (1 + argv.size()) * addrSize + (1 + envp.size()) * addrSize + @@ -200,30 +199,30 @@ RiscvProcess::argsInit(int pageSize) ((1 + argv.size()) * addrSize + (1 + envp.size()) * addrSize + addrSize + 2 * sizeof(IntType) * auxv.size())); - memState->setStackMin(memState->getStackMin() & -2*addrSize); + memState->setStackMin(memState->getStackMin() & (-2 * addrSize)); Addr sp = memState->getStackMin(); const auto pushOntoStack = - [this, &sp](const uint8_t* data, const size_t size) { - initVirtMem.writeBlob(sp, data, size); - sp += size; + [this, &sp](IntType data) { + initVirtMem.write(sp, data, GuestByteOrder); + sp += sizeof(data); }; // Push argc and argv pointers onto stack - IntType argc = htog((IntType)argv.size()); - DPRINTF(Stack, "Wrote argc %d to address %p\n", - argv.size(), (void*)sp); - pushOntoStack((uint8_t*)&argc, sizeof(IntType)); + IntType argc = argv.size(); + DPRINTF(Stack, "Wrote argc %d to address %#x\n", argc, sp); + pushOntoStack(argc); + for (const Addr& argPointer: argPointers) { - DPRINTF(Stack, "Wrote argv pointer %p to address %p\n", - (void*)argPointer, (void*)sp); - pushOntoStack((uint8_t*)&argPointer, addrSize); + DPRINTF(Stack, "Wrote argv pointer %#x to address %#x\n", + argPointer, sp); + pushOntoStack(argPointer); } // Push env pointers onto stack for (const Addr& envPointer: envPointers) { - DPRINTF(Stack, "Wrote envp pointer %p to address %p\n", - (void*)envPointer, (void*)sp); - pushOntoStack((uint8_t*)&envPointer, addrSize); + DPRINTF(Stack, "Wrote envp pointer %#x to address %#x\n", + envPointer, sp); + pushOntoStack(envPointer); } // Push aux vector onto stack @@ -237,13 +236,12 @@ RiscvProcess::argsInit(int pageSize) {M5_AT_RANDOM, "M5_AT_RANDOM"}, {M5_AT_NULL, "M5_AT_NULL"} }; - for (const AuxVector<IntType>& aux: auxv) { - DPRINTF(Stack, "Wrote aux key %s to address %p\n", - aux_keys[aux.getAuxType()], (void*)sp); - pushOntoStack((uint8_t*)&aux.getAuxType(), sizeof(IntType)); - DPRINTF(Stack, "Wrote aux value %x to address %p\n", - aux.getAuxVal(), (void*)sp); - pushOntoStack((uint8_t*)&aux.getAuxVal(), sizeof(IntType)); + for (const auto &aux: auxv) { + DPRINTF(Stack, "Wrote aux key %s to address %#x\n", + aux_keys[aux.type], sp); + pushOntoStack(aux.type); + DPRINTF(Stack, "Wrote aux value %x to address %#x\n", aux.val, sp); + pushOntoStack(aux.val); } ThreadContext *tc = system->getThreadContext(contextIds[0]); diff --git a/src/arch/sparc/process.cc b/src/arch/sparc/process.cc index 6659a04fa..3419e0970 100644 --- a/src/arch/sparc/process.cc +++ b/src/arch/sparc/process.cc @@ -192,9 +192,7 @@ SparcProcess::argsInit(int pageSize) { int intSize = sizeof(IntType); - typedef AuxVector<IntType> auxv_t; - - std::vector<auxv_t> auxv; + std::vector<AuxVector<IntType>> auxv; string filename; if (argv.size() < 1) @@ -238,34 +236,34 @@ SparcProcess::argsInit(int pageSize) ElfObject * elfObject = dynamic_cast<ElfObject *>(objFile); if (elfObject) { // Bits which describe the system hardware capabilities - auxv.push_back(auxv_t(M5_AT_HWCAP, hwcap)); + auxv.emplace_back(M5_AT_HWCAP, hwcap); // The system page size - auxv.push_back(auxv_t(M5_AT_PAGESZ, SparcISA::PageBytes)); + auxv.emplace_back(M5_AT_PAGESZ, SparcISA::PageBytes); // Defined to be 100 in the kernel source. // Frequency at which times() increments - auxv.push_back(auxv_t(M5_AT_CLKTCK, 100)); - // For statically linked executables, this is the virtual address of the - // program header tables if they appear in the executable image - auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable())); + auxv.emplace_back(M5_AT_CLKTCK, 100); + // For statically linked executables, this is the virtual address of + // the program header tables if they appear in the executable image + auxv.emplace_back(M5_AT_PHDR, elfObject->programHeaderTable()); // This is the size of a program header entry from the elf file. - auxv.push_back(auxv_t(M5_AT_PHENT, elfObject->programHeaderSize())); + auxv.emplace_back(M5_AT_PHENT, elfObject->programHeaderSize()); // This is the number of program headers from the original elf file. - auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount())); + auxv.emplace_back(M5_AT_PHNUM, elfObject->programHeaderCount()); // This is the base address of the ELF interpreter; it should be // zero for static executables or contain the base address for // dynamic executables. - auxv.push_back(auxv_t(M5_AT_BASE, getBias())); + auxv.emplace_back(M5_AT_BASE, getBias()); // This is hardwired to 0 in the elf loading code in the kernel - auxv.push_back(auxv_t(M5_AT_FLAGS, 0)); + auxv.emplace_back(M5_AT_FLAGS, 0); // The entry point to the program - auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint())); + auxv.emplace_back(M5_AT_ENTRY, objFile->entryPoint()); // Different user and group IDs - auxv.push_back(auxv_t(M5_AT_UID, uid())); - auxv.push_back(auxv_t(M5_AT_EUID, euid())); - auxv.push_back(auxv_t(M5_AT_GID, gid())); - auxv.push_back(auxv_t(M5_AT_EGID, egid())); + auxv.emplace_back(M5_AT_UID, uid()); + auxv.emplace_back(M5_AT_EUID, euid()); + auxv.emplace_back(M5_AT_GID, gid()); + auxv.emplace_back(M5_AT_EGID, egid()); // Whether to enable "secure mode" in the executable - auxv.push_back(auxv_t(M5_AT_SECURE, 0)); + auxv.emplace_back(M5_AT_SECURE, 0); } // Figure out how big the initial stack needs to be @@ -373,19 +371,16 @@ SparcProcess::argsInit(int pageSize) initVirtMem.writeString(file_name_base, filename.c_str()); // Copy the aux stuff - for (int x = 0; x < auxv.size(); x++) { - initVirtMem.writeBlob(auxv_array_base + x * 2 * intSize, - (uint8_t*)&(auxv[x].getAuxType()), intSize); - initVirtMem.writeBlob(auxv_array_base + (x * 2 + 1) * intSize, - (uint8_t*)&(auxv[x].getAuxVal()), intSize); + Addr auxv_array_end = auxv_array_base; + for (const auto &aux: auxv) { + initVirtMem.write(auxv_array_end, aux, GuestByteOrder); + auxv_array_end += sizeof(aux); } // Write out the terminating zeroed auxilliary vector - const IntType zero = 0; - initVirtMem.writeBlob(auxv_array_base + intSize * 2 * auxv.size(), - (uint8_t*)&zero, intSize); - initVirtMem.writeBlob(auxv_array_base + intSize * (2 * auxv.size() + 1), - (uint8_t*)&zero, intSize); + const AuxVector<IntType> zero(0, 0); + initVirtMem.write(auxv_array_end, zero); + auxv_array_end += sizeof(zero); copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); diff --git a/src/arch/x86/process.cc b/src/arch/x86/process.cc index 9e34a7b5d..d01afbc25 100644 --- a/src/arch/x86/process.cc +++ b/src/arch/x86/process.cc @@ -762,8 +762,7 @@ X86Process::argsInit(int pageSize, { int intSize = sizeof(IntType); - typedef AuxVector<IntType> auxv_t; - std::vector<auxv_t> auxv = extraAuxvs; + std::vector<AuxVector<IntType>> auxv = extraAuxvs; string filename; if (argv.size() < 1) @@ -859,40 +858,40 @@ X86Process::argsInit(int pageSize, // Bits which describe the system hardware capabilities // XXX Figure out what these should be - auxv.push_back(auxv_t(M5_AT_HWCAP, features)); + auxv.emplace_back(M5_AT_HWCAP, features); // The system page size - auxv.push_back(auxv_t(M5_AT_PAGESZ, X86ISA::PageBytes)); + auxv.emplace_back(M5_AT_PAGESZ, X86ISA::PageBytes); // Frequency at which times() increments // Defined to be 100 in the kernel source. - auxv.push_back(auxv_t(M5_AT_CLKTCK, 100)); + auxv.emplace_back(M5_AT_CLKTCK, 100); // This is the virtual address of the program header tables if they // appear in the executable image. - auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable())); + auxv.emplace_back(M5_AT_PHDR, elfObject->programHeaderTable()); // This is the size of a program header entry from the elf file. - auxv.push_back(auxv_t(M5_AT_PHENT, elfObject->programHeaderSize())); + auxv.emplace_back(M5_AT_PHENT, elfObject->programHeaderSize()); // This is the number of program headers from the original elf file. - auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount())); + auxv.emplace_back(M5_AT_PHNUM, elfObject->programHeaderCount()); // This is the base address of the ELF interpreter; it should be // zero for static executables or contain the base address for // dynamic executables. - auxv.push_back(auxv_t(M5_AT_BASE, getBias())); + auxv.emplace_back(M5_AT_BASE, getBias()); // XXX Figure out what this should be. - auxv.push_back(auxv_t(M5_AT_FLAGS, 0)); + auxv.emplace_back(M5_AT_FLAGS, 0); // The entry point to the program - auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint())); + auxv.emplace_back(M5_AT_ENTRY, objFile->entryPoint()); // Different user and group IDs - auxv.push_back(auxv_t(M5_AT_UID, uid())); - auxv.push_back(auxv_t(M5_AT_EUID, euid())); - auxv.push_back(auxv_t(M5_AT_GID, gid())); - auxv.push_back(auxv_t(M5_AT_EGID, egid())); + auxv.emplace_back(M5_AT_UID, uid()); + auxv.emplace_back(M5_AT_EUID, euid()); + auxv.emplace_back(M5_AT_GID, gid()); + auxv.emplace_back(M5_AT_EGID, egid()); // Whether to enable "secure mode" in the executable - auxv.push_back(auxv_t(M5_AT_SECURE, 0)); + auxv.emplace_back(M5_AT_SECURE, 0); // The address of 16 "random" bytes. - auxv.push_back(auxv_t(M5_AT_RANDOM, 0)); + auxv.emplace_back(M5_AT_RANDOM, 0); // The name of the program - auxv.push_back(auxv_t(M5_AT_EXECFN, 0)); + auxv.emplace_back(M5_AT_EXECFN, 0); // The platform string - auxv.push_back(auxv_t(M5_AT_PLATFORM, 0)); + auxv.emplace_back(M5_AT_PLATFORM, 0); } // Figure out how big the initial stack needs to be @@ -1006,29 +1005,24 @@ X86Process::argsInit(int pageSize, initVirtMem.writeString(file_name_base, filename.c_str()); // Fix up the aux vectors which point to data - assert(auxv[auxv.size() - 3].getHostAuxType() == M5_AT_RANDOM); - auxv[auxv.size() - 3].setAuxVal(aux_data_base); - assert(auxv[auxv.size() - 2].getHostAuxType() == M5_AT_EXECFN); - auxv[auxv.size() - 2].setAuxVal(argv_array_base); - assert(auxv[auxv.size() - 1].getHostAuxType() == M5_AT_PLATFORM); - auxv[auxv.size() - 1].setAuxVal(aux_data_base + numRandomBytes); + assert(auxv[auxv.size() - 3].type == M5_AT_RANDOM); + auxv[auxv.size() - 3].val = aux_data_base; + assert(auxv[auxv.size() - 2].type == M5_AT_EXECFN); + auxv[auxv.size() - 2].val = argv_array_base; + assert(auxv[auxv.size() - 1].type == M5_AT_PLATFORM); + auxv[auxv.size() - 1].val = aux_data_base + numRandomBytes; // Copy the aux stuff - for (int x = 0; x < auxv.size(); x++) { - initVirtMem.writeBlob(auxv_array_base + x * 2 * intSize, - (uint8_t*)&(auxv[x].getAuxType()), - intSize); - initVirtMem.writeBlob(auxv_array_base + (x * 2 + 1) * intSize, - (uint8_t*)&(auxv[x].getAuxVal()), - intSize); + Addr auxv_array_end = auxv_array_base; + for (const auto &aux: auxv) { + initVirtMem.write(auxv_array_end, aux, GuestByteOrder); + auxv_array_end += sizeof(aux); } // Write out the terminating zeroed auxiliary vector - const uint64_t zero = 0; - initVirtMem.writeBlob(auxv_array_base + auxv.size() * 2 * intSize, - (uint8_t*)&zero, intSize); - initVirtMem.writeBlob(auxv_array_base + (auxv.size() * 2 + 1) * intSize, - (uint8_t*)&zero, intSize); + const AuxVector<uint64_t> zero(0, 0); + initVirtMem.write(auxv_array_end, zero); + auxv_array_end += sizeof(zero); initVirtMem.writeString(aux_data_base, platform.c_str()); @@ -1053,8 +1047,7 @@ void X86_64Process::argsInit(int pageSize) { std::vector<AuxVector<uint64_t> > extraAuxvs; - extraAuxvs.push_back(AuxVector<uint64_t>(M5_AT_SYSINFO_EHDR, - vsyscallPage.base)); + extraAuxvs.emplace_back(M5_AT_SYSINFO_EHDR, vsyscallPage.base); X86Process::argsInit<uint64_t>(pageSize, extraAuxvs); } @@ -1063,10 +1056,9 @@ I386Process::argsInit(int pageSize) { std::vector<AuxVector<uint32_t> > extraAuxvs; //Tell the binary where the vsyscall part of the vsyscall page is. - extraAuxvs.push_back(AuxVector<uint32_t>(M5_AT_SYSINFO, - vsyscallPage.base + vsyscallPage.vsyscallOffset)); - extraAuxvs.push_back(AuxVector<uint32_t>(M5_AT_SYSINFO_EHDR, - vsyscallPage.base)); + extraAuxvs.emplace_back(M5_AT_SYSINFO, + vsyscallPage.base + vsyscallPage.vsyscallOffset); + extraAuxvs.emplace_back(M5_AT_SYSINFO_EHDR, vsyscallPage.base); X86Process::argsInit<uint32_t>(pageSize, extraAuxvs); } |