118c118,119
< SETranslatingPortProxy::Always)
---
> SETranslatingPortProxy::Always),
> fd_map(new FdMap[NUM_FDS])
178c179
< for (int i = 3; i <= MAX_FD; ++i) {
---
> for (int i = 3; i < NUM_FDS; ++i) {
202a204
>
235,240c237,239
< int size = contextIds.size();
< ThreadContext *tc;
< for (int i = 0; i < size; ++i) {
< tc = system->getThreadContext(contextIds[i]);
< if (tc->status() == ThreadContext::Halted) {
< // inactive context, free to use
---
> for (int id : contextIds) {
> ThreadContext *tc = system->getThreadContext(id);
> if (tc->status() == ThreadContext::Halted)
242d240
< }
269,281d266
< // map simulator fd sim_fd to target fd tgt_fd
< void
< Process::dup_fd(int sim_fd, int tgt_fd)
< {
< if (tgt_fd < 0 || tgt_fd > MAX_FD)
< panic("Process::dup_fd tried to dup past MAX_FD (%d)", tgt_fd);
<
< Process::FdMap *fdo = &fd_map[tgt_fd];
< fdo->fd = sim_fd;
< }
<
<
< // generate new target fd for sim_fd
291c276
< for (int free_fd = 0; free_fd <= MAX_FD; ++free_fd) {
---
> for (int free_fd = 0; free_fd < NUM_FDS; ++free_fd) {
308,309d292
<
< // free target fd (e.g., after close)
311c294
< Process::free_fd(int tgt_fd)
---
> Process::free_fdmap_entry(int tgt_fd)
314,315c297
< if (fdo->fd == -1)
< warn("Process::free_fd: request to free unused fd %d", tgt_fd);
---
> assert(fd_map[tgt_fd].fd > -1);
327,328d308
<
< // look up simulator fd for given target fd
332,335c312,313
< if (tgt_fd < 0 || tgt_fd > MAX_FD)
< return -1;
<
< return fd_map[tgt_fd].fd;
---
> FdMap *obj = sim_fd_obj(tgt_fd);
> return obj ? obj->fd : -1;
341c319
< if (tgt_fd < 0 || tgt_fd > MAX_FD)
---
> if (tgt_fd < 0 || tgt_fd >= NUM_FDS)
343d320
<
346a324,332
> int
> Process::tgt_fd(int sim_fd)
> {
> for (int index = 0; index < NUM_FDS; ++index)
> if (fd_map[index].fd == sim_fd)
> return index;
> return -1;
> }
>
436c422
< for (int free_fd = 3; free_fd <= MAX_FD; ++free_fd) {
---
> for (int free_fd = 3; free_fd < NUM_FDS; ++free_fd) {
479c465
< for (int free_fd = 0; free_fd <= MAX_FD; ++free_fd) {
---
> for (int free_fd = 0; free_fd < NUM_FDS; ++free_fd) {
532c518
< for (int x = 0; x <= MAX_FD; x++) {
---
> for (int x = 0; x < NUM_FDS; x++) {
552c538
< for (int x = 0; x <= MAX_FD; x++) {
---
> for (int x = 0; x < NUM_FDS; x++) {
560c546
< // found.
---
> // found.