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; --- 313 unchanged lines hidden (view full) --- 322Process::FdMap * 323Process::sim_fd_obj(int tgt_fd) 324{ 325 if (tgt_fd > MAX_FD) 326 panic("sim_fd_obj called in fd out of range."); 327 328 return &fd_map[tgt_fd]; 329} |
330 |
331bool 332Process::checkAndAllocNextPage(Addr vaddr) 333{ 334 // if this is an initial write we might not have 335 if (vaddr >= stack_min && vaddr < stack_base) { 336 pTable->allocate(roundDown(vaddr, VMPageSize), VMPageSize); 337 return true; 338 } --- 10 unchanged lines hidden (view full) --- 349 pTable->allocate(stack_min, TheISA::PageBytes); 350 inform("Increasing stack size by one page."); 351 }; 352 return true; 353 } 354 return false; 355} 356 |
357// find all offsets for currently open files and save them |
358void |
359Process::fix_file_offsets() 360{ |
361 Process::FdMap *fdo_stdin = &fd_map[STDIN_FILENO]; 362 Process::FdMap *fdo_stdout = &fd_map[STDOUT_FILENO]; 363 Process::FdMap *fdo_stderr = &fd_map[STDERR_FILENO]; 364 string in = fdo_stdin->filename; 365 string out = fdo_stdout->filename; 366 string err = fdo_stderr->filename; 367 368 // initialize file descriptors to default: same as simulator 369 int stdin_fd, stdout_fd, stderr_fd; 370 371 if (in == "stdin" || in == "cin") 372 stdin_fd = STDIN_FILENO; 373 else if (in == "None") 374 stdin_fd = -1; |
375 else { 376 // open standard in and seek to the right location |
377 stdin_fd = Process::openInputFile(in); 378 if (lseek(stdin_fd, fdo_stdin->fileOffset, SEEK_SET) < 0) 379 panic("Unable to seek to correct location in file: %s", in); 380 } 381 382 if (out == "stdout" || out == "cout") 383 stdout_fd = STDOUT_FILENO; 384 else if (out == "stderr" || out == "cerr") 385 stdout_fd = STDERR_FILENO; 386 else if (out == "None") 387 stdout_fd = -1; |
388 else { |
389 stdout_fd = Process::openOutputFile(out); 390 if (lseek(stdout_fd, fdo_stdout->fileOffset, SEEK_SET) < 0) 391 panic("Unable to seek to correct location in file: %s", out); 392 } 393 394 if (err == "stdout" || err == "cout") 395 stderr_fd = STDOUT_FILENO; 396 else if (err == "stderr" || err == "cerr") --- 41 unchanged lines hidden (view full) --- 438 int fd = open(fdo->filename.c_str(), fdo->flags, fdo->mode); 439 440 if (fd == -1) 441 panic("Unable to open file: %s", fdo->filename); 442 fdo->fd = fd; 443 444 //Seek to correct location before checkpoint 445 if (lseek(fd,fdo->fileOffset, SEEK_SET) < 0) |
446 panic("Unable to seek to correct location in file: %s", 447 fdo->filename); |
448 } 449 } 450 } 451} |
452 |
453void |
454Process::find_file_offsets() 455{ |
456 for (int free_fd = 0; free_fd <= MAX_FD; ++free_fd) { 457 Process::FdMap *fdo = &fd_map[free_fd]; 458 if (fdo->fd != -1) { 459 fdo->fileOffset = lseek(fdo->fd, 0, SEEK_CUR); |
460 } else { |
461 fdo->filename = "NULL"; 462 fdo->fileOffset = 0; 463 } 464 } 465} 466 467void |
468Process::setReadPipeSource(int read_pipe_fd, int source_fd) 469{ |
470 Process::FdMap *fdo = &fd_map[read_pipe_fd]; 471 fdo->readPipeSource = source_fd; 472} 473 474void 475Process::FdMap::serialize(std::ostream &os) 476{ 477 SERIALIZE_SCALAR(fd); --- 49 unchanged lines hidden (view full) --- 527 UNSERIALIZE_SCALAR(next_thread_stack_base); 528 UNSERIALIZE_SCALAR(mmap_start); 529 UNSERIALIZE_SCALAR(mmap_end); 530 UNSERIALIZE_SCALAR(nxm_start); 531 UNSERIALIZE_SCALAR(nxm_end); 532 pTable->unserialize(cp, section); 533 for (int x = 0; x <= MAX_FD; x++) { 534 fd_map[x].unserialize(cp, csprintf("%s.FdMap%d", section, x)); |
535 } |
536 fix_file_offsets(); 537 UNSERIALIZE_OPT_SCALAR(M5_pid); 538 // The above returns a bool so that you could do something if you don't 539 // find the param in the checkpoint if you wanted to, like set a default 540 // but in this case we'll just stick with the instantianted value if not 541 // found. 542 543 checkpointRestored = true; --- 264 unchanged lines hidden --- |