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

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

91 int intSize = sizeof(IntType);
92
93 // Patch the ld_bias for dynamic executables.
94 updateBias();
95
96 // load object file into target memory
97 objFile->loadSections(initVirtMem);
98
1/*
2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

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

91 int intSize = sizeof(IntType);
92
93 // Patch the ld_bias for dynamic executables.
94 updateBias();
95
96 // load object file into target memory
97 objFile->loadSections(initVirtMem);
98
99 typedef AuxVector<IntType> auxv_t;
100 std::vector<auxv_t> auxv;
99 std::vector<AuxVector<IntType>> auxv;
101
102 ElfObject * elfObject = dynamic_cast<ElfObject *>(objFile);
103 if (elfObject)
104 {
105 // Set the system page size
100
101 ElfObject * elfObject = dynamic_cast<ElfObject *>(objFile);
102 if (elfObject)
103 {
104 // Set the system page size
106 auxv.push_back(auxv_t(M5_AT_PAGESZ, MipsISA::PageBytes));
105 auxv.emplace_back(M5_AT_PAGESZ, MipsISA::PageBytes);
107 // Set the frequency at which time() increments
106 // Set the frequency at which time() increments
108 auxv.push_back(auxv_t(M5_AT_CLKTCK, 100));
107 auxv.emplace_back(M5_AT_CLKTCK, 100);
109 // For statically linked executables, this is the virtual
110 // address of the program header tables if they appear in the
111 // executable image.
108 // For statically linked executables, this is the virtual
109 // address of the program header tables if they appear in the
110 // executable image.
112 auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable()));
113 DPRINTF(Loader, "auxv at PHDR %08p\n", elfObject->programHeaderTable());
111 auxv.emplace_back(M5_AT_PHDR, elfObject->programHeaderTable());
112 DPRINTF(Loader, "auxv at PHDR %08p\n",
113 elfObject->programHeaderTable());
114 // This is the size of a program header entry from the elf file.
114 // This is the size of a program header entry from the elf file.
115 auxv.push_back(auxv_t(M5_AT_PHENT, elfObject->programHeaderSize()));
115 auxv.emplace_back(M5_AT_PHENT, elfObject->programHeaderSize());
116 // This is the number of program headers from the original elf file.
116 // This is the number of program headers from the original elf file.
117 auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount()));
117 auxv.emplace_back(M5_AT_PHNUM, elfObject->programHeaderCount());
118 // This is the base address of the ELF interpreter; it should be
119 // zero for static executables or contain the base address for
120 // dynamic executables.
118 // This is the base address of the ELF interpreter; it should be
119 // zero for static executables or contain the base address for
120 // dynamic executables.
121 auxv.push_back(auxv_t(M5_AT_BASE, getBias()));
121 auxv.emplace_back(M5_AT_BASE, getBias());
122 //The entry point to the program
122 //The entry point to the program
123 auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint()));
123 auxv.emplace_back(M5_AT_ENTRY, objFile->entryPoint());
124 //Different user and group IDs
124 //Different user and group IDs
125 auxv.push_back(auxv_t(M5_AT_UID, uid()));
126 auxv.push_back(auxv_t(M5_AT_EUID, euid()));
127 auxv.push_back(auxv_t(M5_AT_GID, gid()));
128 auxv.push_back(auxv_t(M5_AT_EGID, egid()));
125 auxv.emplace_back(M5_AT_UID, uid());
126 auxv.emplace_back(M5_AT_EUID, euid());
127 auxv.emplace_back(M5_AT_GID, gid());
128 auxv.emplace_back(M5_AT_EGID, egid());
129 }
130
131 // Calculate how much space we need for arg & env & auxv arrays.
132 int argv_array_size = intSize * (argv.size() + 1);
133 int envp_array_size = intSize * (envp.size() + 1);
134 int auxv_array_size = intSize * 2 * (auxv.size() + 1);
135
136 int arg_data_size = 0;

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

172
173 initVirtMem.writeBlob(memState->getStackMin(), (uint8_t*)&argc, intSize);
174
175 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem);
176
177 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem);
178
179 // Copy the aux vector
129 }
130
131 // Calculate how much space we need for arg & env & auxv arrays.
132 int argv_array_size = intSize * (argv.size() + 1);
133 int envp_array_size = intSize * (envp.size() + 1);
134 int auxv_array_size = intSize * 2 * (auxv.size() + 1);
135
136 int arg_data_size = 0;

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

172
173 initVirtMem.writeBlob(memState->getStackMin(), (uint8_t*)&argc, intSize);
174
175 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem);
176
177 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem);
178
179 // Copy the aux vector
180 for (typename vector<auxv_t>::size_type x = 0; x < auxv.size(); x++) {
181 initVirtMem.writeBlob(auxv_array_base + x * 2 * intSize,
182 (uint8_t*)&(auxv[x].getAuxType()), intSize);
183 initVirtMem.writeBlob(auxv_array_base + (x * 2 + 1) * intSize,
184 (uint8_t*)&(auxv[x].getAuxVal()), intSize);
180 Addr auxv_array_end = auxv_array_base;
181 for (const auto &aux: auxv) {
182 initVirtMem.write(auxv_array_end, aux, GuestByteOrder);
183 auxv_array_end += sizeof(aux);
185 }
186
187 // Write out the terminating zeroed auxilliary vector
184 }
185
186 // Write out the terminating zeroed auxilliary vector
188 for (unsigned i = 0; i < 2; i++) {
189 const IntType zero = 0;
190 const Addr addr = auxv_array_base + 2 * intSize * (auxv.size() + i);
191 initVirtMem.writeBlob(addr, (uint8_t*)&zero, intSize);
192 }
187 const AuxVector<IntType> zero(0, 0);
188 initVirtMem.write(auxv_array_end, zero);
189 auxv_array_end += sizeof(zero);
193
194 ThreadContext *tc = system->getThreadContext(contextIds[0]);
195
196 setSyscallArg(tc, 0, argc);
197 setSyscallArg(tc, 1, argv_array_base);
198 tc->setIntReg(StackPointerReg, memState->getStackMin());
199
200 tc->pcState(getStartPC());

--- 30 unchanged lines hidden ---
190
191 ThreadContext *tc = system->getThreadContext(contextIds[0]);
192
193 setSyscallArg(tc, 0, argc);
194 setSyscallArg(tc, 1, argv_array_base);
195 tc->setIntReg(StackPointerReg, memState->getStackMin());
196
197 tc->pcState(getStartPC());

--- 30 unchanged lines hidden ---