1/* 2 * Copyright (c) 2014 Advanced Micro Devices, Inc. 3 * Copyright (c) 2012 ARM Limited 4 * All rights reserved 5 * 6 * The license below extends only to copyright in the software and shall 7 * not be construed as granting a license to any other intellectual 8 * property including but not limited to intellectual property relating --- 258 unchanged lines hidden (view full) --- 267 268 Process::FdMap *fdo = &fd_map[tgt_fd]; 269 fdo->fd = sim_fd; 270} 271 272 273// generate new target fd for sim_fd 274int |
275Process::alloc_fd(int sim_fd, const string& filename, int flags, int mode, 276 bool pipe) |
277{ 278 // in case open() returns an error, don't allocate a new fd 279 if (sim_fd == -1) 280 return -1; 281 282 // find first free target fd 283 for (int free_fd = 0; free_fd <= MAX_FD; ++free_fd) { 284 Process::FdMap *fdo = &fd_map[free_fd]; --- 95 unchanged lines hidden (view full) --- 380 string out = fdo_stdout->filename; 381 string err = fdo_stderr->filename; 382 383 // initialize file descriptors to default: same as simulator 384 int stdin_fd, stdout_fd, stderr_fd; 385 386 if (in == "stdin" || in == "cin") 387 stdin_fd = STDIN_FILENO; |
388 else if (in == "NULL") |
389 stdin_fd = -1; 390 else { 391 // open standard in and seek to the right location 392 stdin_fd = Process::openInputFile(in); 393 if (lseek(stdin_fd, fdo_stdin->fileOffset, SEEK_SET) < 0) 394 panic("Unable to seek to correct location in file: %s", in); 395 } 396 397 if (out == "stdout" || out == "cout") 398 stdout_fd = STDOUT_FILENO; 399 else if (out == "stderr" || out == "cerr") 400 stdout_fd = STDERR_FILENO; |
401 else if (out == "NULL") |
402 stdout_fd = -1; 403 else { 404 stdout_fd = Process::openOutputFile(out); 405 if (lseek(stdout_fd, fdo_stdout->fileOffset, SEEK_SET) < 0) 406 panic("Unable to seek to correct location in file: %s", out); 407 } 408 409 if (err == "stdout" || err == "cout") 410 stderr_fd = STDOUT_FILENO; 411 else if (err == "stderr" || err == "cerr") 412 stderr_fd = STDERR_FILENO; |
413 else if (err == "NULL") |
414 stderr_fd = -1; 415 else if (err == out) 416 stderr_fd = stdout_fd; 417 else { 418 stderr_fd = Process::openOutputFile(err); 419 if (lseek(stderr_fd, fdo_stderr->fileOffset, SEEK_SET) < 0) 420 panic("Unable to seek to correct location in file: %s", err); 421 } --- 30 unchanged lines hidden (view full) --- 452 //Open file 453 int fd = open(fdo->filename.c_str(), fdo->flags, fdo->mode); 454 455 if (fd == -1) 456 panic("Unable to open file: %s", fdo->filename); 457 fdo->fd = fd; 458 459 //Seek to correct location before checkpoint |
460 if (lseek(fd, fdo->fileOffset, SEEK_SET) < 0) |
461 panic("Unable to seek to correct location in file: %s", 462 fdo->filename); 463 } 464 } 465 } 466} 467 468void 469Process::find_file_offsets() 470{ 471 for (int free_fd = 0; free_fd <= MAX_FD; ++free_fd) { 472 Process::FdMap *fdo = &fd_map[free_fd]; 473 if (fdo->fd != -1) { 474 fdo->fileOffset = lseek(fdo->fd, 0, SEEK_CUR); 475 } else { |
476 fdo->filename = "NULL"; 477 fdo->fileOffset = 0; |
478 } 479 } 480} 481 482void 483Process::setReadPipeSource(int read_pipe_fd, int source_fd) 484{ 485 Process::FdMap *fdo = &fd_map[read_pipe_fd]; --- 287 unchanged lines hidden --- |