process.cc (10559:62f5f7363197) | process.cc (10782:0a78638881d7) |
---|---|
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 | 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, string filename, int flags, int mode, bool pipe) | 275Process::alloc_fd(int sim_fd, const string& filename, int flags, int mode, 276 bool pipe) |
276{ 277 // in case open() returns an error, don't allocate a new fd 278 if (sim_fd == -1) 279 return -1; 280 281 // find first free target fd 282 for (int free_fd = 0; free_fd <= MAX_FD; ++free_fd) { 283 Process::FdMap *fdo = &fd_map[free_fd]; --- 95 unchanged lines hidden (view full) --- 379 string out = fdo_stdout->filename; 380 string err = fdo_stderr->filename; 381 382 // initialize file descriptors to default: same as simulator 383 int stdin_fd, stdout_fd, stderr_fd; 384 385 if (in == "stdin" || in == "cin") 386 stdin_fd = STDIN_FILENO; | 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; |
387 else if (in == "None") | 388 else if (in == "NULL") |
388 stdin_fd = -1; 389 else { 390 // open standard in and seek to the right location 391 stdin_fd = Process::openInputFile(in); 392 if (lseek(stdin_fd, fdo_stdin->fileOffset, SEEK_SET) < 0) 393 panic("Unable to seek to correct location in file: %s", in); 394 } 395 396 if (out == "stdout" || out == "cout") 397 stdout_fd = STDOUT_FILENO; 398 else if (out == "stderr" || out == "cerr") 399 stdout_fd = STDERR_FILENO; | 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; |
400 else if (out == "None") | 401 else if (out == "NULL") |
401 stdout_fd = -1; 402 else { 403 stdout_fd = Process::openOutputFile(out); 404 if (lseek(stdout_fd, fdo_stdout->fileOffset, SEEK_SET) < 0) 405 panic("Unable to seek to correct location in file: %s", out); 406 } 407 408 if (err == "stdout" || err == "cout") 409 stderr_fd = STDOUT_FILENO; 410 else if (err == "stderr" || err == "cerr") 411 stderr_fd = STDERR_FILENO; | 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; |
412 else if (err == "None") | 413 else if (err == "NULL") |
413 stderr_fd = -1; 414 else if (err == out) 415 stderr_fd = stdout_fd; 416 else { 417 stderr_fd = Process::openOutputFile(err); 418 if (lseek(stderr_fd, fdo_stderr->fileOffset, SEEK_SET) < 0) 419 panic("Unable to seek to correct location in file: %s", err); 420 } --- 30 unchanged lines hidden (view full) --- 451 //Open file 452 int fd = open(fdo->filename.c_str(), fdo->flags, fdo->mode); 453 454 if (fd == -1) 455 panic("Unable to open file: %s", fdo->filename); 456 fdo->fd = fd; 457 458 //Seek to correct location before checkpoint | 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 |
459 if (lseek(fd,fdo->fileOffset, SEEK_SET) < 0) | 460 if (lseek(fd, fdo->fileOffset, SEEK_SET) < 0) |
460 panic("Unable to seek to correct location in file: %s", 461 fdo->filename); 462 } 463 } 464 } 465} 466 467void 468Process::find_file_offsets() 469{ 470 for (int free_fd = 0; free_fd <= MAX_FD; ++free_fd) { 471 Process::FdMap *fdo = &fd_map[free_fd]; 472 if (fdo->fd != -1) { 473 fdo->fileOffset = lseek(fdo->fd, 0, SEEK_CUR); 474 } else { | 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 { |
475 fdo->filename = "NULL"; 476 fdo->fileOffset = 0; | 476 fdo->filename = "NULL"; 477 fdo->fileOffset = 0; |
477 } 478 } 479} 480 481void 482Process::setReadPipeSource(int read_pipe_fd, int source_fd) 483{ 484 Process::FdMap *fdo = &fd_map[read_pipe_fd]; --- 287 unchanged lines hidden --- | 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 --- |