Deleted Added
sdiff udiff text old ( 5512:755fcaf7a4cf ) new ( 5514:9a903bf83a33 )
full compact
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;

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

87int num_processes = 0;
88
89Process::Process(ProcessParams * params)
90 : SimObject(params), system(params->system), checkpointRestored(false),
91 max_stack_size(params->max_stack_size)
92{
93 string in = params->input;
94 string out = params->output;
95
96 // initialize file descriptors to default: same as simulator
97 int stdin_fd, stdout_fd, stderr_fd;
98
99 if (in == "stdin" || in == "cin")
100 stdin_fd = STDIN_FILENO;
101 else if (in == "None")
102 stdin_fd = -1;

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

107 stdout_fd = STDOUT_FILENO;
108 else if (out == "stderr" || out == "cerr")
109 stdout_fd = STDERR_FILENO;
110 else if (out == "None")
111 stdout_fd = -1;
112 else
113 stdout_fd = Process::openOutputFile(out);
114
115 stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO;
116
117 M5_pid = system->allocatePID();
118 // initialize first 3 fds (stdin, stdout, stderr)
119 Process::FdMap *fdo = &fd_map[STDIN_FILENO];
120 fdo->fd = stdin_fd;
121 fdo->filename = in;
122 fdo->flags = O_RDONLY;
123 fdo->mode = -1;
124 fdo->fileOffset = 0;
125
126 fdo = &fd_map[STDOUT_FILENO];
127 fdo->fd = stdout_fd;
128 fdo->filename = out;
129 fdo->flags = O_WRONLY | O_CREAT | O_TRUNC;
130 fdo->mode = 0774;
131 fdo->fileOffset = 0;
132
133 fdo = &fd_map[STDERR_FILENO];
134 fdo->fd = stderr_fd;
135 fdo->filename = "STDERR";
136 fdo->flags = O_WRONLY;
137 fdo->mode = -1;
138 fdo->fileOffset = 0;
139
140
141 // mark remaining fds as free
142 for (int i = 3; i <= MAX_FD; ++i) {
143 Process::FdMap *fdo = &fd_map[i];

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

178
179 return fd;
180}
181
182
183int
184Process::openOutputFile(const string &filename)
185{
186 int fd = open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0774);
187
188 if (fd == -1) {
189 perror(NULL);
190 cerr << "unable to open \"" << filename << "\" for writing\n";
191 fatal("can't open output file");
192 }
193
194 return fd;

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

350 // find all offsets for currently open files and save them
351void
352Process::fix_file_offsets() {
353 Process::FdMap *fdo_stdin = &fd_map[STDIN_FILENO];
354 Process::FdMap *fdo_stdout = &fd_map[STDOUT_FILENO];
355 Process::FdMap *fdo_stderr = &fd_map[STDERR_FILENO];
356 string in = fdo_stdin->filename;
357 string out = fdo_stdout->filename;
358
359 // initialize file descriptors to default: same as simulator
360 int stdin_fd, stdout_fd, stderr_fd;
361
362 if (in == "stdin" || in == "cin")
363 stdin_fd = STDIN_FILENO;
364 else if (in == "None")
365 stdin_fd = -1;

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

373 if (out == "stdout" || out == "cout")
374 stdout_fd = STDOUT_FILENO;
375 else if (out == "stderr" || out == "cerr")
376 stdout_fd = STDERR_FILENO;
377 else if (out == "None")
378 stdout_fd = -1;
379 else{
380 stdout_fd = Process::openOutputFile(out);
381 if (lseek(stdin_fd, fdo_stdout->fileOffset, SEEK_SET) < 0)
382 panic("Unable to seek to correct in file: %s", out);
383 }
384
385 stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO;
386
387 fdo_stdin->fd = stdin_fd;
388 fdo_stdout->fd = stdout_fd;
389 fdo_stderr->fd = stderr_fd;
390
391
392 for (int free_fd = 3; free_fd <= MAX_FD; ++free_fd) {
393 Process::FdMap *fdo = &fd_map[free_fd];

--- 340 unchanged lines hidden ---