process.cc (5963:f541a09c5916) process.cc (5973:07444c3d0a07)
1/*
2 * Copyright (c) 2003-2006 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;

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

147 // Set pointer for next thread stack. Reserve 8M for main stack.
148 next_thread_stack_base = stack_base - (8 * 1024 * 1024);
149
150 // Set up region for mmaps. This was determined empirically and may not
151 // always be correct.
152 mmap_start = mmap_end = (Addr)0x2aaaaaaab000ULL;
153}
154
1/*
2 * Copyright (c) 2003-2006 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;

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

147 // Set pointer for next thread stack. Reserve 8M for main stack.
148 next_thread_stack_base = stack_base - (8 * 1024 * 1024);
149
150 // Set up region for mmaps. This was determined empirically and may not
151 // always be correct.
152 mmap_start = mmap_end = (Addr)0x2aaaaaaab000ULL;
153}
154
155void
156I386LiveProcess::syscall(int64_t callnum, ThreadContext *tc)
157{
158 Addr eip = tc->readPC();
159 if (eip >= vsyscallPage.base &&
160 eip < vsyscallPage.base + vsyscallPage.size) {
161 tc->setNextPC(vsyscallPage.base + vsyscallPage.vsysexitOffset);
162 }
163 X86LiveProcess::syscall(callnum, tc);
164}
165
166
155I386LiveProcess::I386LiveProcess(LiveProcessParams *params,
156 ObjectFile *objFile, SyscallDesc *_syscallDescs,
157 int _numSyscallDescs) :
158 X86LiveProcess(params, objFile, _syscallDescs, _numSyscallDescs)
159{
167I386LiveProcess::I386LiveProcess(LiveProcessParams *params,
168 ObjectFile *objFile, SyscallDesc *_syscallDescs,
169 int _numSyscallDescs) :
170 X86LiveProcess(params, objFile, _syscallDescs, _numSyscallDescs)
171{
160 stack_base = (Addr)0xffffe000ULL;
172 _gdtStart = 0x100000000;
173 _gdtSize = VMPageSize;
161
174
175 vsyscallPage.base = 0xffffe000ULL;
176 vsyscallPage.size = VMPageSize;
177 vsyscallPage.vsyscallOffset = 0x400;
178 vsyscallPage.vsysexitOffset = 0x410;
179
180 stack_base = vsyscallPage.base;
181
162 // Set pointer for next thread stack. Reserve 8M for main stack.
163 next_thread_stack_base = stack_base - (8 * 1024 * 1024);
164
165 // Set up region for mmaps. This was determined empirically and may not
166 // always be correct.
167 mmap_start = mmap_end = (Addr)0xf7ffd000ULL;
168}
169

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

250 return;
251
252 argsInit(sizeof(uint32_t), VMPageSize);
253
254 /*
255 * Set up a GDT for this process. The whole GDT wouldn't really be for
256 * this process, but the only parts we care about are.
257 */
182 // Set pointer for next thread stack. Reserve 8M for main stack.
183 next_thread_stack_base = stack_base - (8 * 1024 * 1024);
184
185 // Set up region for mmaps. This was determined empirically and may not
186 // always be correct.
187 mmap_start = mmap_end = (Addr)0xf7ffd000ULL;
188}
189

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

270 return;
271
272 argsInit(sizeof(uint32_t), VMPageSize);
273
274 /*
275 * Set up a GDT for this process. The whole GDT wouldn't really be for
276 * this process, but the only parts we care about are.
277 */
258 _gdtStart = stack_base;
259 _gdtSize = VMPageSize;
260 pTable->allocate(_gdtStart, _gdtSize);
261 uint64_t zero = 0;
262 assert(_gdtSize % sizeof(zero) == 0);
263 for (Addr gdtCurrent = _gdtStart;
264 gdtCurrent < _gdtStart + _gdtSize; gdtCurrent += sizeof(zero)) {
265 initVirtMem->write(gdtCurrent, zero);
266 }
267
278 pTable->allocate(_gdtStart, _gdtSize);
279 uint64_t zero = 0;
280 assert(_gdtSize % sizeof(zero) == 0);
281 for (Addr gdtCurrent = _gdtStart;
282 gdtCurrent < _gdtStart + _gdtSize; gdtCurrent += sizeof(zero)) {
283 initVirtMem->write(gdtCurrent, zero);
284 }
285
286 // Set up the vsyscall page for this process.
287 pTable->allocate(vsyscallPage.base, vsyscallPage.size);
288 uint8_t vsyscallBlob[] = {
289 0x51, // push %ecx
290 0x52, // push %edp
291 0x55, // push %ebp
292 0x89, 0xe5, // mov %esp, %ebp
293 0x0f, 0x34 // sysenter
294 };
295 initVirtMem->writeBlob(vsyscallPage.base + vsyscallPage.vsyscallOffset,
296 vsyscallBlob, sizeof(vsyscallBlob));
297
298 uint8_t vsysexitBlob[] = {
299 0x5d, // pop %ebp
300 0x5a, // pop %edx
301 0x59, // pop %ecx
302 0xc3 // ret
303 };
304 initVirtMem->writeBlob(vsyscallPage.base + vsyscallPage.vsysexitOffset,
305 vsysexitBlob, sizeof(vsysexitBlob));
306
268 for (int i = 0; i < contextIds.size(); i++) {
269 ThreadContext * tc = system->getThreadContext(contextIds[i]);
270
271 SegAttr dataAttr = 0;
272 dataAttr.writable = 1;
273 dataAttr.readable = 1;
274 dataAttr.expandDown = 0;
275 dataAttr.dpl = 3;

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

327 efer.svme = 0; // Disable svm support for now. It isn't implemented.
328 efer.ffxsr = 1; // Turn on fast fxsave and fxrstor.
329 tc->setMiscReg(MISCREG_EFER, efer);
330 }
331}
332
333template<class IntType>
334void
307 for (int i = 0; i < contextIds.size(); i++) {
308 ThreadContext * tc = system->getThreadContext(contextIds[i]);
309
310 SegAttr dataAttr = 0;
311 dataAttr.writable = 1;
312 dataAttr.readable = 1;
313 dataAttr.expandDown = 0;
314 dataAttr.dpl = 3;

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

366 efer.svme = 0; // Disable svm support for now. It isn't implemented.
367 efer.ffxsr = 1; // Turn on fast fxsave and fxrstor.
368 tc->setMiscReg(MISCREG_EFER, efer);
369 }
370}
371
372template<class IntType>
373void
335X86LiveProcess::argsInit(int pageSize)
374X86LiveProcess::argsInit(int pageSize,
375 std::vector<AuxVector<IntType> > extraAuxvs)
336{
337 int intSize = sizeof(IntType);
338
339 typedef AuxVector<IntType> auxv_t;
376{
377 int intSize = sizeof(IntType);
378
379 typedef AuxVector<IntType> auxv_t;
340 std::vector<auxv_t> auxv;
380 std::vector<auxv_t> auxv = extraAuxvs;
341
342 string filename;
343 if(argv.size() < 1)
344 filename = "";
345 else
346 filename = argv[0];
347
348 //We want 16 byte alignment

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

603 stack_min = roundDown(stack_min, pageSize);
604
605// num_processes++;
606}
607
608void
609X86_64LiveProcess::argsInit(int intSize, int pageSize)
610{
381
382 string filename;
383 if(argv.size() < 1)
384 filename = "";
385 else
386 filename = argv[0];
387
388 //We want 16 byte alignment

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

643 stack_min = roundDown(stack_min, pageSize);
644
645// num_processes++;
646}
647
648void
649X86_64LiveProcess::argsInit(int intSize, int pageSize)
650{
611 X86LiveProcess::argsInit<uint64_t>(pageSize);
651 std::vector<AuxVector<uint64_t> > extraAuxvs;
652 X86LiveProcess::argsInit<uint64_t>(pageSize, extraAuxvs);
612}
613
614void
615I386LiveProcess::argsInit(int intSize, int pageSize)
616{
653}
654
655void
656I386LiveProcess::argsInit(int intSize, int pageSize)
657{
617 X86LiveProcess::argsInit<uint32_t>(pageSize);
658 std::vector<AuxVector<uint32_t> > extraAuxvs;
659 //Tell the binary where the vsyscall part of the vsyscall page is.
660 extraAuxvs.push_back(AuxVector<uint32_t>(0x20,
661 vsyscallPage.base + vsyscallPage.vsyscallOffset));
662 extraAuxvs.push_back(AuxVector<uint32_t>(0x21, vsyscallPage.base));
663 X86LiveProcess::argsInit<uint32_t>(pageSize, extraAuxvs);
618}
619
620void
621X86LiveProcess::setSyscallReturn(ThreadContext *tc, SyscallReturn return_value)
622{
623 tc->setIntReg(INTREG_RAX, return_value.value());
624}
625

--- 27 unchanged lines hidden ---
664}
665
666void
667X86LiveProcess::setSyscallReturn(ThreadContext *tc, SyscallReturn return_value)
668{
669 tc->setIntReg(INTREG_RAX, return_value.value());
670}
671

--- 27 unchanged lines hidden ---