sim: fix function for emulating dup()
authorNilay Vaish <nilay@cs.wisc.edu>
Mon, 13 Apr 2015 22:33:57 +0000 (17:33 -0500)
committerNilay Vaish <nilay@cs.wisc.edu>
Mon, 13 Apr 2015 22:33:57 +0000 (17:33 -0500)
The function was using the host fd to obtain the fd object from the simulated
process.

src/sim/syscall_emul.cc

index bf7efe210aa77f2b3d7fc7232331781e87e68f61..8f3d08cd7ddb9ba52de1ee730a05c1e3b8ae3c5f 100644 (file)
@@ -594,13 +594,14 @@ SyscallReturn
 dupFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc)
 {
     int index = 0;
-    int fd = process->sim_fd(process->getSyscallArg(tc, index));
-    if (fd < 0)
+    int tgt_fd = process->getSyscallArg(tc, index);
+    int sim_fd = process->sim_fd(tgt_fd);
+    if (sim_fd < 0)
         return -EBADF;
 
-    Process::FdMap *fdo = process->sim_fd_obj(fd);
+    Process::FdMap *fdo = process->sim_fd_obj(tgt_fd);
 
-    int result = dup(fd);
+    int result = dup(sim_fd);
     return (result == -1) ? -errno :
         process->alloc_fd(result, fdo->filename, fdo->flags, fdo->mode, false);
 }