process.cc revision 6227
1/* 2 * Copyright (c) 2001-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; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Nathan Binkert 29 * Steve Reinhardt 30 * Ali Saidi 31 */ 32 33#include <unistd.h> 34#include <fcntl.h> 35#include <string> 36 37#include "arch/remote_gdb.hh" 38#include "base/intmath.hh" 39#include "base/loader/object_file.hh" 40#include "base/loader/symtab.hh" 41#include "base/statistics.hh" 42#include "config/full_system.hh" 43#include "cpu/thread_context.hh" 44#include "mem/page_table.hh" 45#include "mem/physical.hh" 46#include "mem/translating_port.hh" 47#include "params/Process.hh" 48#include "params/LiveProcess.hh" 49#include "sim/debug.hh" 50#include "sim/process.hh" 51#include "sim/process_impl.hh" 52#include "sim/stats.hh" 53#include "sim/syscall_emul.hh" 54#include "sim/system.hh" 55 56#include "arch/isa_specific.hh" 57#if THE_ISA == ALPHA_ISA 58#include "arch/alpha/linux/process.hh" 59#include "arch/alpha/tru64/process.hh" 60#elif THE_ISA == SPARC_ISA 61#include "arch/sparc/linux/process.hh" 62#include "arch/sparc/solaris/process.hh" 63#elif THE_ISA == MIPS_ISA 64#include "arch/mips/linux/process.hh" 65#elif THE_ISA == ARM_ISA 66#include "arch/arm/linux/process.hh" 67#elif THE_ISA == X86_ISA 68#include "arch/x86/linux/process.hh" 69#else 70#error "THE_ISA not set" 71#endif 72 73 74using namespace std; 75using namespace TheISA; 76 77// 78// The purpose of this code is to fake the loader & syscall mechanism 79// when there's no OS: thus there's no resone to use it in FULL_SYSTEM 80// mode when we do have an OS 81// 82#if FULL_SYSTEM 83#error "process.cc not compatible with FULL_SYSTEM" 84#endif 85 86// current number of allocated processes 87int num_processes = 0; 88 89template<class IntType> 90AuxVector<IntType>::AuxVector(IntType type, IntType val) 91{ 92 a_type = TheISA::htog(type); 93 a_val = TheISA::htog(val); 94} 95 96template class AuxVector<uint32_t>; 97template class AuxVector<uint64_t>; 98 99Process::Process(ProcessParams * params) 100 : SimObject(params), system(params->system), checkpointRestored(false), 101 max_stack_size(params->max_stack_size) 102{ 103 string in = params->input; 104 string out = params->output; 105 string err = params->errout; 106 107 // initialize file descriptors to default: same as simulator 108 int stdin_fd, stdout_fd, stderr_fd; 109 110 if (in == "stdin" || in == "cin") 111 stdin_fd = STDIN_FILENO; 112 else if (in == "None") 113 stdin_fd = -1; 114 else 115 stdin_fd = Process::openInputFile(in); 116 117 if (out == "stdout" || out == "cout") 118 stdout_fd = STDOUT_FILENO; 119 else if (out == "stderr" || out == "cerr") 120 stdout_fd = STDERR_FILENO; 121 else if (out == "None") 122 stdout_fd = -1; 123 else 124 stdout_fd = Process::openOutputFile(out); 125 126 if (err == "stdout" || err == "cout") 127 stderr_fd = STDOUT_FILENO; 128 else if (err == "stderr" || err == "cerr") 129 stderr_fd = STDERR_FILENO; 130 else if (err == "None") 131 stderr_fd = -1; 132 else if (err == out) 133 stderr_fd = stdout_fd; 134 else 135 stderr_fd = Process::openOutputFile(err); 136 137 M5_pid = system->allocatePID(); 138 // initialize first 3 fds (stdin, stdout, stderr) 139 Process::FdMap *fdo = &fd_map[STDIN_FILENO]; 140 fdo->fd = stdin_fd; 141 fdo->filename = in; 142 fdo->flags = O_RDONLY; 143 fdo->mode = -1; 144 fdo->fileOffset = 0; 145 146 fdo = &fd_map[STDOUT_FILENO]; 147 fdo->fd = stdout_fd; 148 fdo->filename = out; 149 fdo->flags = O_WRONLY | O_CREAT | O_TRUNC; 150 fdo->mode = 0774; 151 fdo->fileOffset = 0; 152 153 fdo = &fd_map[STDERR_FILENO]; 154 fdo->fd = stderr_fd; 155 fdo->filename = err; 156 fdo->flags = O_WRONLY; 157 fdo->mode = -1; 158 fdo->fileOffset = 0; 159 160 161 // mark remaining fds as free 162 for (int i = 3; i <= MAX_FD; ++i) { 163 Process::FdMap *fdo = &fd_map[i]; 164 fdo->fd = -1; 165 } 166 167 mmap_start = mmap_end = 0; 168 nxm_start = nxm_end = 0; 169 pTable = new PageTable(this); 170 // other parameters will be initialized when the program is loaded 171} 172 173 174void 175Process::regStats() 176{ 177 using namespace Stats; 178 179 num_syscalls 180 .name(name() + ".PROG:num_syscalls") 181 .desc("Number of system calls") 182 ; 183} 184 185// 186// static helper functions 187// 188int 189Process::openInputFile(const string &filename) 190{ 191 int fd = open(filename.c_str(), O_RDONLY); 192 193 if (fd == -1) { 194 perror(NULL); 195 cerr << "unable to open \"" << filename << "\" for reading\n"; 196 fatal("can't open input file"); 197 } 198 199 return fd; 200} 201 202 203int 204Process::openOutputFile(const string &filename) 205{ 206 int fd = open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0664); 207 208 if (fd == -1) { 209 perror(NULL); 210 cerr << "unable to open \"" << filename << "\" for writing\n"; 211 fatal("can't open output file"); 212 } 213 214 return fd; 215} 216 217ThreadContext * 218Process::findFreeContext() 219{ 220 int size = contextIds.size(); 221 ThreadContext *tc; 222 for (int i = 0; i < size; ++i) { 223 tc = system->getThreadContext(contextIds[i]); 224 if (tc->status() == ThreadContext::Halted) { 225 // inactive context, free to use 226 return tc; 227 } 228 } 229 return NULL; 230} 231 232void 233Process::startup() 234{ 235 if (contextIds.empty()) 236 fatal("Process %s is not associated with any HW contexts!\n", name()); 237 238 // first thread context for this process... initialize & enable 239 ThreadContext *tc = system->getThreadContext(contextIds[0]); 240 241 // mark this context as active so it will start ticking. 242 tc->activate(0); 243 244 Port *mem_port; 245 mem_port = system->physmem->getPort("functional"); 246 initVirtMem = new TranslatingPort("process init port", this, 247 TranslatingPort::Always); 248 mem_port->setPeer(initVirtMem); 249 initVirtMem->setPeer(mem_port); 250} 251 252// map simulator fd sim_fd to target fd tgt_fd 253void 254Process::dup_fd(int sim_fd, int tgt_fd) 255{ 256 if (tgt_fd < 0 || tgt_fd > MAX_FD) 257 panic("Process::dup_fd tried to dup past MAX_FD (%d)", tgt_fd); 258 259 Process::FdMap *fdo = &fd_map[tgt_fd]; 260 fdo->fd = sim_fd; 261} 262 263 264// generate new target fd for sim_fd 265int 266Process::alloc_fd(int sim_fd, string filename, int flags, int mode, bool pipe) 267{ 268 // in case open() returns an error, don't allocate a new fd 269 if (sim_fd == -1) 270 return -1; 271 272 // find first free target fd 273 for (int free_fd = 0; free_fd <= MAX_FD; ++free_fd) { 274 Process::FdMap *fdo = &fd_map[free_fd]; 275 if (fdo->fd == -1) { 276 fdo->fd = sim_fd; 277 fdo->filename = filename; 278 fdo->mode = mode; 279 fdo->fileOffset = 0; 280 fdo->flags = flags; 281 fdo->isPipe = pipe; 282 fdo->readPipeSource = 0; 283 return free_fd; 284 } 285 } 286 287 panic("Process::alloc_fd: out of file descriptors!"); 288} 289 290 291// free target fd (e.g., after close) 292void 293Process::free_fd(int tgt_fd) 294{ 295 Process::FdMap *fdo = &fd_map[tgt_fd]; 296 if (fdo->fd == -1) 297 warn("Process::free_fd: request to free unused fd %d", tgt_fd); 298 299 fdo->fd = -1; 300 fdo->filename = "NULL"; 301 fdo->mode = 0; 302 fdo->fileOffset = 0; 303 fdo->flags = 0; 304 fdo->isPipe = false; 305 fdo->readPipeSource = 0; 306} 307 308 309// look up simulator fd for given target fd 310int 311Process::sim_fd(int tgt_fd) 312{ 313 if (tgt_fd > MAX_FD) 314 return -1; 315 316 return fd_map[tgt_fd].fd; 317} 318 319Process::FdMap * 320Process::sim_fd_obj(int tgt_fd) 321{ 322 if (tgt_fd > MAX_FD) 323 panic("sim_fd_obj called in fd out of range."); 324 325 return &fd_map[tgt_fd]; 326} 327bool 328Process::checkAndAllocNextPage(Addr vaddr) 329{ 330 // if this is an initial write we might not have 331 if (vaddr >= stack_min && vaddr < stack_base) { 332 pTable->allocate(roundDown(vaddr, VMPageSize), VMPageSize); 333 return true; 334 } 335 336 // We've accessed the next page of the stack, so extend the stack 337 // to cover it. 338 if (vaddr < stack_min && vaddr >= stack_base - max_stack_size) { 339 while (vaddr < stack_min) { 340 stack_min -= TheISA::PageBytes; 341 if(stack_base - stack_min > max_stack_size) 342 fatal("Maximum stack size exceeded\n"); 343 if(stack_base - stack_min > 8*1024*1024) 344 fatal("Over max stack size for one thread\n"); 345 pTable->allocate(stack_min, TheISA::PageBytes); 346 inform("Increasing stack size by one page."); 347 }; 348 return true; 349 } 350 return false; 351} 352 353 // find all offsets for currently open files and save them 354void 355Process::fix_file_offsets() { 356 Process::FdMap *fdo_stdin = &fd_map[STDIN_FILENO]; 357 Process::FdMap *fdo_stdout = &fd_map[STDOUT_FILENO]; 358 Process::FdMap *fdo_stderr = &fd_map[STDERR_FILENO]; 359 string in = fdo_stdin->filename; 360 string out = fdo_stdout->filename; 361 string err = fdo_stderr->filename; 362 363 // initialize file descriptors to default: same as simulator 364 int stdin_fd, stdout_fd, stderr_fd; 365 366 if (in == "stdin" || in == "cin") 367 stdin_fd = STDIN_FILENO; 368 else if (in == "None") 369 stdin_fd = -1; 370 else{ 371 //OPEN standard in and seek to the right location 372 stdin_fd = Process::openInputFile(in); 373 if (lseek(stdin_fd, fdo_stdin->fileOffset, SEEK_SET) < 0) 374 panic("Unable to seek to correct location in file: %s", in); 375 } 376 377 if (out == "stdout" || out == "cout") 378 stdout_fd = STDOUT_FILENO; 379 else if (out == "stderr" || out == "cerr") 380 stdout_fd = STDERR_FILENO; 381 else if (out == "None") 382 stdout_fd = -1; 383 else{ 384 stdout_fd = Process::openOutputFile(out); 385 if (lseek(stdout_fd, fdo_stdout->fileOffset, SEEK_SET) < 0) 386 panic("Unable to seek to correct location in file: %s", out); 387 } 388 389 if (err == "stdout" || err == "cout") 390 stderr_fd = STDOUT_FILENO; 391 else if (err == "stderr" || err == "cerr") 392 stderr_fd = STDERR_FILENO; 393 else if (err == "None") 394 stderr_fd = -1; 395 else if (err == out) 396 stderr_fd = stdout_fd; 397 else { 398 stderr_fd = Process::openOutputFile(err); 399 if (lseek(stderr_fd, fdo_stderr->fileOffset, SEEK_SET) < 0) 400 panic("Unable to seek to correct location in file: %s", err); 401 } 402 403 fdo_stdin->fd = stdin_fd; 404 fdo_stdout->fd = stdout_fd; 405 fdo_stderr->fd = stderr_fd; 406 407 408 for (int free_fd = 3; free_fd <= MAX_FD; ++free_fd) { 409 Process::FdMap *fdo = &fd_map[free_fd]; 410 if (fdo->fd != -1) { 411 if (fdo->isPipe){ 412 if (fdo->filename == "PIPE-WRITE") 413 continue; 414 else { 415 assert (fdo->filename == "PIPE-READ"); 416 //create a new pipe 417 int fds[2]; 418 int pipe_retval = pipe(fds); 419 420 if (pipe_retval < 0) { 421 // error 422 panic("Unable to create new pipe."); 423 } 424 fdo->fd = fds[0]; //set read pipe 425 Process::FdMap *fdo_write = &fd_map[fdo->readPipeSource]; 426 if (fdo_write->filename != "PIPE-WRITE") 427 panic ("Couldn't find write end of the pipe"); 428 429 fdo_write->fd = fds[1];//set write pipe 430 } 431 } else { 432 //Open file 433 int fd = open(fdo->filename.c_str(), fdo->flags, fdo->mode); 434 435 if (fd == -1) 436 panic("Unable to open file: %s", fdo->filename); 437 fdo->fd = fd; 438 439 //Seek to correct location before checkpoint 440 if (lseek(fd,fdo->fileOffset, SEEK_SET) < 0) 441 panic("Unable to seek to correct location in file: %s", fdo->filename); 442 } 443 } 444 } 445} 446void 447Process::find_file_offsets(){ 448 for (int free_fd = 0; free_fd <= MAX_FD; ++free_fd) { 449 Process::FdMap *fdo = &fd_map[free_fd]; 450 if (fdo->fd != -1) { 451 fdo->fileOffset = lseek(fdo->fd, 0, SEEK_CUR); 452 } else { 453 fdo->filename = "NULL"; 454 fdo->fileOffset = 0; 455 } 456 } 457} 458 459void 460Process::setReadPipeSource(int read_pipe_fd, int source_fd){ 461 Process::FdMap *fdo = &fd_map[read_pipe_fd]; 462 fdo->readPipeSource = source_fd; 463} 464 465void 466Process::FdMap::serialize(std::ostream &os) 467{ 468 SERIALIZE_SCALAR(fd); 469 SERIALIZE_SCALAR(isPipe); 470 SERIALIZE_SCALAR(filename); 471 SERIALIZE_SCALAR(flags); 472 SERIALIZE_SCALAR(readPipeSource); 473 SERIALIZE_SCALAR(fileOffset); 474} 475 476void 477Process::FdMap::unserialize(Checkpoint *cp, const std::string §ion) 478{ 479 UNSERIALIZE_SCALAR(fd); 480 UNSERIALIZE_SCALAR(isPipe); 481 UNSERIALIZE_SCALAR(filename); 482 UNSERIALIZE_SCALAR(flags); 483 UNSERIALIZE_SCALAR(readPipeSource); 484 UNSERIALIZE_SCALAR(fileOffset); 485} 486 487void 488Process::serialize(std::ostream &os) 489{ 490 SERIALIZE_SCALAR(initialContextLoaded); 491 SERIALIZE_SCALAR(brk_point); 492 SERIALIZE_SCALAR(stack_base); 493 SERIALIZE_SCALAR(stack_size); 494 SERIALIZE_SCALAR(stack_min); 495 SERIALIZE_SCALAR(next_thread_stack_base); 496 SERIALIZE_SCALAR(mmap_start); 497 SERIALIZE_SCALAR(mmap_end); 498 SERIALIZE_SCALAR(nxm_start); 499 SERIALIZE_SCALAR(nxm_end); 500 find_file_offsets(); 501 pTable->serialize(os); 502 for (int x = 0; x <= MAX_FD; x++) { 503 nameOut(os, csprintf("%s.FdMap%d", name(), x)); 504 fd_map[x].serialize(os); 505 } 506 507} 508 509void 510Process::unserialize(Checkpoint *cp, const std::string §ion) 511{ 512 UNSERIALIZE_SCALAR(initialContextLoaded); 513 UNSERIALIZE_SCALAR(brk_point); 514 UNSERIALIZE_SCALAR(stack_base); 515 UNSERIALIZE_SCALAR(stack_size); 516 UNSERIALIZE_SCALAR(stack_min); 517 UNSERIALIZE_SCALAR(next_thread_stack_base); 518 UNSERIALIZE_SCALAR(mmap_start); 519 UNSERIALIZE_SCALAR(mmap_end); 520 UNSERIALIZE_SCALAR(nxm_start); 521 UNSERIALIZE_SCALAR(nxm_end); 522 pTable->unserialize(cp, section); 523 for (int x = 0; x <= MAX_FD; x++) { 524 fd_map[x].unserialize(cp, csprintf("%s.FdMap%d", section, x)); 525 } 526 fix_file_offsets(); 527 528 checkpointRestored = true; 529 530} 531 532 533//////////////////////////////////////////////////////////////////////// 534// 535// LiveProcess member definitions 536// 537//////////////////////////////////////////////////////////////////////// 538 539 540LiveProcess::LiveProcess(LiveProcessParams * params, ObjectFile *_objFile) 541 : Process(params), objFile(_objFile), 542 argv(params->cmd), envp(params->env), cwd(params->cwd) 543{ 544 __uid = params->uid; 545 __euid = params->euid; 546 __gid = params->gid; 547 __egid = params->egid; 548 __pid = params->pid; 549 __ppid = params->ppid; 550 551 prog_fname = params->cmd[0]; 552 553 // load up symbols, if any... these may be used for debugging or 554 // profiling. 555 if (!debugSymbolTable) { 556 debugSymbolTable = new SymbolTable(); 557 if (!objFile->loadGlobalSymbols(debugSymbolTable) || 558 !objFile->loadLocalSymbols(debugSymbolTable)) { 559 // didn't load any symbols 560 delete debugSymbolTable; 561 debugSymbolTable = NULL; 562 } 563 } 564} 565 566void 567LiveProcess::argsInit(int intSize, int pageSize) 568{ 569 Process::startup(); 570 571 // load object file into target memory 572 objFile->loadSections(initVirtMem); 573 574 // Calculate how much space we need for arg & env arrays. 575 int argv_array_size = intSize * (argv.size() + 1); 576 int envp_array_size = intSize * (envp.size() + 1); 577 int arg_data_size = 0; 578 for (vector<string>::size_type i = 0; i < argv.size(); ++i) { 579 arg_data_size += argv[i].size() + 1; 580 } 581 int env_data_size = 0; 582 for (vector<string>::size_type i = 0; i < envp.size(); ++i) { 583 env_data_size += envp[i].size() + 1; 584 } 585 586 int space_needed = 587 argv_array_size + envp_array_size + arg_data_size + env_data_size; 588 if (space_needed < 32*1024) 589 space_needed = 32*1024; 590 591 // set bottom of stack 592 stack_min = stack_base - space_needed; 593 // align it 594 stack_min = roundDown(stack_min, pageSize); 595 stack_size = stack_base - stack_min; 596 // map memory 597 pTable->allocate(stack_min, roundUp(stack_size, pageSize)); 598 599 // map out initial stack contents 600 Addr argv_array_base = stack_min + intSize; // room for argc 601 Addr envp_array_base = argv_array_base + argv_array_size; 602 Addr arg_data_base = envp_array_base + envp_array_size; 603 Addr env_data_base = arg_data_base + arg_data_size; 604 605 // write contents to stack 606 uint64_t argc = argv.size(); 607 if (intSize == 8) 608 argc = htog((uint64_t)argc); 609 else if (intSize == 4) 610 argc = htog((uint32_t)argc); 611 else 612 panic("Unknown int size"); 613 614 initVirtMem->writeBlob(stack_min, (uint8_t*)&argc, intSize); 615 616 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); 617 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); 618 619 ThreadContext *tc = system->getThreadContext(contextIds[0]); 620 621 setSyscallArg(tc, 0, argc); 622 setSyscallArg(tc, 1, argv_array_base); 623 tc->setIntReg(StackPointerReg, stack_min); 624 625 Addr prog_entry = objFile->entryPoint(); 626 tc->setPC(prog_entry); 627 tc->setNextPC(prog_entry + sizeof(MachInst)); 628 629#if THE_ISA != ALPHA_ISA //e.g. MIPS or Sparc 630 tc->setNextNPC(prog_entry + (2 * sizeof(MachInst))); 631#endif 632 633 num_processes++; 634} 635 636void 637LiveProcess::syscall(int64_t callnum, ThreadContext *tc) 638{ 639 num_syscalls++; 640 641 SyscallDesc *desc = getDesc(callnum); 642 if (desc == NULL) 643 fatal("Syscall %d out of range", callnum); 644 645 desc->doSyscall(callnum, this, tc); 646} 647 648LiveProcess * 649LiveProcess::create(LiveProcessParams * params) 650{ 651 LiveProcess *process = NULL; 652 653 string executable = 654 params->executable == "" ? params->cmd[0] : params->executable; 655 ObjectFile *objFile = createObjectFile(executable); 656 if (objFile == NULL) { 657 fatal("Can't load object file %s", executable); 658 } 659 660 if (objFile->isDynamic()) 661 fatal("Object file is a dynamic executable however only static " 662 "executables are supported!\n Please recompile your " 663 "executable as a static binary and try again.\n"); 664 665#if THE_ISA == ALPHA_ISA 666 if (objFile->getArch() != ObjectFile::Alpha) 667 fatal("Object file architecture does not match compiled ISA (Alpha)."); 668 669 switch (objFile->getOpSys()) { 670 case ObjectFile::Tru64: 671 process = new AlphaTru64Process(params, objFile); 672 break; 673 674 case ObjectFile::UnknownOpSys: 675 warn("Unknown operating system; assuming Linux."); 676 // fall through 677 case ObjectFile::Linux: 678 process = new AlphaLinuxProcess(params, objFile); 679 break; 680 681 default: 682 fatal("Unknown/unsupported operating system."); 683 } 684#elif THE_ISA == SPARC_ISA 685 if (objFile->getArch() != ObjectFile::SPARC64 && 686 objFile->getArch() != ObjectFile::SPARC32) 687 fatal("Object file architecture does not match compiled ISA (SPARC)."); 688 switch (objFile->getOpSys()) { 689 case ObjectFile::UnknownOpSys: 690 warn("Unknown operating system; assuming Linux."); 691 // fall through 692 case ObjectFile::Linux: 693 if (objFile->getArch() == ObjectFile::SPARC64) { 694 process = new Sparc64LinuxProcess(params, objFile); 695 } else { 696 process = new Sparc32LinuxProcess(params, objFile); 697 } 698 break; 699 700 701 case ObjectFile::Solaris: 702 process = new SparcSolarisProcess(params, objFile); 703 break; 704 705 default: 706 fatal("Unknown/unsupported operating system."); 707 } 708#elif THE_ISA == X86_ISA 709 if (objFile->getArch() != ObjectFile::X86_64 && 710 objFile->getArch() != ObjectFile::I386) 711 fatal("Object file architecture does not match compiled ISA (x86)."); 712 switch (objFile->getOpSys()) { 713 case ObjectFile::UnknownOpSys: 714 warn("Unknown operating system; assuming Linux."); 715 // fall through 716 case ObjectFile::Linux: 717 if (objFile->getArch() == ObjectFile::X86_64) { 718 process = new X86_64LinuxProcess(params, objFile); 719 } else { 720 process = new I386LinuxProcess(params, objFile); 721 } 722 break; 723 724 default: 725 fatal("Unknown/unsupported operating system."); 726 } 727#elif THE_ISA == MIPS_ISA 728 if (objFile->getArch() != ObjectFile::Mips) 729 fatal("Object file architecture does not match compiled ISA (MIPS)."); 730 switch (objFile->getOpSys()) { 731 case ObjectFile::UnknownOpSys: 732 warn("Unknown operating system; assuming Linux."); 733 // fall through 734 case ObjectFile::Linux: 735 process = new MipsLinuxProcess(params, objFile); 736 break; 737 738 default: 739 fatal("Unknown/unsupported operating system."); 740 } 741#elif THE_ISA == ARM_ISA 742 if (objFile->getArch() != ObjectFile::Arm) 743 fatal("Object file architecture does not match compiled ISA (ARM)."); 744 switch (objFile->getOpSys()) { 745 case ObjectFile::UnknownOpSys: 746 warn("Unknown operating system; assuming Linux."); 747 // fall through 748 case ObjectFile::Linux: 749 process = new ArmLinuxProcess(params, objFile); 750 break; 751 752 default: 753 fatal("Unknown/unsupported operating system."); 754 } 755#else 756#error "THE_ISA not set" 757#endif 758 759 760 if (process == NULL) 761 fatal("Unknown error creating process object."); 762 return process; 763} 764 765LiveProcess * 766LiveProcessParams::create() 767{ 768 return LiveProcess::create(this); 769} 770