more syscalls for gcc
[nestedvm.git] / src / org / ibex / nestedvm / UnixRuntime.java
index 32a3c75..a6847ee 100644 (file)
@@ -101,6 +101,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
             case SYS_fork: return sys_fork();
             case SYS_pipe: return sys_pipe(a);
             case SYS_dup2: return sys_dup2(a,b);
+            case SYS_dup: return sys_dup(a);
             case SYS_waitpid: return sys_waitpid(a,b,c);
             case SYS_stat: return sys_stat(a,b);
             case SYS_lstat: return sys_lstat(a,b);
@@ -434,6 +435,15 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
         return 0;
     }
     
+    private int sys_dup(int oldd) {
+        if(oldd < 0 || oldd >= OPEN_MAX) return -EBADFD;
+        if(fds[oldd] == null) return -EBADFD;
+        FD fd = fds[oldd].dup();
+        int newd = addFD(fd);
+        if(newd < 0) { fd.close(); return -ENFILE; }
+        return newd;
+    }
+    
     private int sys_stat(int cstring, int addr) throws FaultException, ErrnoException {
         FStat s = gs.stat(this,normalizePath(cstring(cstring)));
         if(s == null) return -ENOENT;