Add dup() support (from Antti Miettinen).
authorSteve Reinhardt <stever@eecs.umich.edu>
Mon, 28 Aug 2006 14:39:56 +0000 (07:39 -0700)
committerSteve Reinhardt <stever@eecs.umich.edu>
Mon, 28 Aug 2006 14:39:56 +0000 (07:39 -0700)
--HG--
extra : convert_revision : 72c834666afa3c353da026617ad5e7a762eb645f

src/arch/alpha/linux/process.cc
src/sim/syscall_emul.cc
src/sim/syscall_emul.hh

index 997c78ac9d38162ff7eab68210a9e4aabad2fbef..357ebdada4c36a3996f9435f3e5d53bbd4ce59a4 100644 (file)
@@ -162,7 +162,7 @@ SyscallDesc AlphaLinuxProcess::syscallDescs[] = {
     /* 38 */ SyscallDesc("osf_old_stat", unimplementedFunc),
     /* 39 */ SyscallDesc("setpgid", unimplementedFunc),
     /* 40 */ SyscallDesc("osf_old_lstat", unimplementedFunc),
-    /* 41 */ SyscallDesc("dup", unimplementedFunc),
+    /* 41 */ SyscallDesc("dup", dupFunc),
     /* 42 */ SyscallDesc("pipe", pipePseudoFunc),
     /* 43 */ SyscallDesc("osf_set_program_attributes", unimplementedFunc),
     /* 44 */ SyscallDesc("osf_profil", unimplementedFunc),
index e72890612d5b9f556718e5f5cf7cd421757aeeb6..cf90d8f84ca3400f095aafe13ed8a22dc3164fb5 100644 (file)
@@ -300,6 +300,19 @@ fchownFunc(SyscallDesc *desc, int num, Process *process, ThreadContext *tc)
 }
 
 
+SyscallReturn
+dupFunc(SyscallDesc *desc, int num, Process *process, ThreadContext *tc)
+{
+    int fd = process->sim_fd(tc->getSyscallArg(0));
+
+    if (fd < 0)
+        return -EBADF;
+
+    int result = dup(fd);
+    return (result == -1) ? -errno : process->alloc_fd(result);
+}
+
+
 SyscallReturn
 fcntlFunc(SyscallDesc *desc, int num, Process *process,
           ThreadContext *tc)
index a3ff006efbad33750df310314f1ef6963101ae44..69ef314216afcc1e58ce35d66b04845349e38033 100644 (file)
@@ -245,6 +245,10 @@ SyscallReturn chownFunc(SyscallDesc *desc, int num,
 SyscallReturn fchownFunc(SyscallDesc *desc, int num,
                          Process *p, ThreadContext *tc);
 
+/// Target dup() handler.
+SyscallReturn dupFunc(SyscallDesc *desc, int num,
+                      Process *process, ThreadContext *tc);
+
 /// Target fnctl() handler.
 SyscallReturn fcntlFunc(SyscallDesc *desc, int num,
                         Process *process, ThreadContext *tc);