process.cc (7447:3fc243687abb) process.cc (7487:2a5e4070155e)
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}
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
330bool
331Process::checkAndAllocNextPage(Addr vaddr)
332{
333 // if this is an initial write we might not have
334 if (vaddr >= stack_min && vaddr < stack_base) {
335 pTable->allocate(roundDown(vaddr, VMPageSize), VMPageSize);
336 return true;
337 }

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

348 pTable->allocate(stack_min, TheISA::PageBytes);
349 inform("Increasing stack size by one page.");
350 };
351 return true;
352 }
353 return false;
354}
355
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
356 // find all offsets for currently open files and save them
357// find all offsets for currently open files and save them
357void
358void
358Process::fix_file_offsets() {
359Process::fix_file_offsets()
360{
359 Process::FdMap *fdo_stdin = &fd_map[STDIN_FILENO];
360 Process::FdMap *fdo_stdout = &fd_map[STDOUT_FILENO];
361 Process::FdMap *fdo_stderr = &fd_map[STDERR_FILENO];
362 string in = fdo_stdin->filename;
363 string out = fdo_stdout->filename;
364 string err = fdo_stderr->filename;
365
366 // initialize file descriptors to default: same as simulator
367 int stdin_fd, stdout_fd, stderr_fd;
368
369 if (in == "stdin" || in == "cin")
370 stdin_fd = STDIN_FILENO;
371 else if (in == "None")
372 stdin_fd = -1;
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;
373 else{
374 //OPEN standard in and seek to the right location
375 else {
376 // open standard in and seek to the right location
375 stdin_fd = Process::openInputFile(in);
376 if (lseek(stdin_fd, fdo_stdin->fileOffset, SEEK_SET) < 0)
377 panic("Unable to seek to correct location in file: %s", in);
378 }
379
380 if (out == "stdout" || out == "cout")
381 stdout_fd = STDOUT_FILENO;
382 else if (out == "stderr" || out == "cerr")
383 stdout_fd = STDERR_FILENO;
384 else if (out == "None")
385 stdout_fd = -1;
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;
386 else{
388 else {
387 stdout_fd = Process::openOutputFile(out);
388 if (lseek(stdout_fd, fdo_stdout->fileOffset, SEEK_SET) < 0)
389 panic("Unable to seek to correct location in file: %s", out);
390 }
391
392 if (err == "stdout" || err == "cout")
393 stderr_fd = STDOUT_FILENO;
394 else if (err == "stderr" || err == "cerr")

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

436 int fd = open(fdo->filename.c_str(), fdo->flags, fdo->mode);
437
438 if (fd == -1)
439 panic("Unable to open file: %s", fdo->filename);
440 fdo->fd = fd;
441
442 //Seek to correct location before checkpoint
443 if (lseek(fd,fdo->fileOffset, SEEK_SET) < 0)
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)
444 panic("Unable to seek to correct location in file: %s", fdo->filename);
446 panic("Unable to seek to correct location in file: %s",
447 fdo->filename);
445 }
446 }
447 }
448}
448 }
449 }
450 }
451}
452
449void
453void
450Process::find_file_offsets(){
454Process::find_file_offsets()
455{
451 for (int free_fd = 0; free_fd <= MAX_FD; ++free_fd) {
452 Process::FdMap *fdo = &fd_map[free_fd];
453 if (fdo->fd != -1) {
454 fdo->fileOffset = lseek(fdo->fd, 0, SEEK_CUR);
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);
455 } else {
460 } else {
456 fdo->filename = "NULL";
457 fdo->fileOffset = 0;
458 }
459 }
460}
461
462void
461 fdo->filename = "NULL";
462 fdo->fileOffset = 0;
463 }
464 }
465}
466
467void
463Process::setReadPipeSource(int read_pipe_fd, int source_fd){
468Process::setReadPipeSource(int read_pipe_fd, int source_fd)
469{
464 Process::FdMap *fdo = &fd_map[read_pipe_fd];
465 fdo->readPipeSource = source_fd;
466}
467
468void
469Process::FdMap::serialize(std::ostream &os)
470{
471 SERIALIZE_SCALAR(fd);

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

521 UNSERIALIZE_SCALAR(next_thread_stack_base);
522 UNSERIALIZE_SCALAR(mmap_start);
523 UNSERIALIZE_SCALAR(mmap_end);
524 UNSERIALIZE_SCALAR(nxm_start);
525 UNSERIALIZE_SCALAR(nxm_end);
526 pTable->unserialize(cp, section);
527 for (int x = 0; x <= MAX_FD; x++) {
528 fd_map[x].unserialize(cp, csprintf("%s.FdMap%d", section, x));
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));
529 }
535 }
530 fix_file_offsets();
531 UNSERIALIZE_OPT_SCALAR(M5_pid);
532 // The above returns a bool so that you could do something if you don't
533 // find the param in the checkpoint if you wanted to, like set a default
534 // but in this case we'll just stick with the instantianted value if not
535 // found.
536
537 checkpointRestored = true;

--- 264 unchanged lines hidden ---
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 ---