gcc's cc1 runs!
[nestedvm.git] / src / org / ibex / nestedvm / UnixRuntime.java
index 32a3c75..9b9a8cf 100644 (file)
@@ -33,7 +33,9 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
                 
         // FEATURE: Do the proper mangling for non-unix hosts
         String userdir = getSystemProperty("user.dir");
-        cwd = userdir != null && userdir.startsWith("/") && File.separatorChar == '/'  ? userdir.substring(1) : "";
+        cwd = 
+            userdir != null && userdir.startsWith("/") && File.separatorChar == '/' && HostFS.hostRootDir().getParent() == null  
+            ? userdir.substring(1) : "";
     }
     
     // NOTE: getDisplayName() is a Java2 function
@@ -101,6 +103,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 +437,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;
@@ -784,8 +796,14 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
         public File getRoot() { return root; }
         
         private static File hostRootDir() {
+            if(getSystemProperty("nestedvm.root") != null) {
+                File f = new File(getSystemProperty("nestedvm.root"));
+                if(f.isDirectory()) return f;
+                // fall through to case below
+            }
             String cwd = getSystemProperty("user.dir");
             File f = new File(cwd != null ? cwd : ".");
+            if(!f.exists()) throw new Error("Couldn't get File for cwd");
             f = new File(f.getAbsolutePath());
             while(f.getParent() != null) f = new File(f.getParent());
             return f;