X-Git-Url: http://git.megacz.com/?p=nestedvm.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fnestedvm%2FUnixRuntime.java;h=151699f8c4c35c20b955291830371011c752070e;hp=11d109368a93af49e8e9958709cb88f96c972928;hb=7e1e0dc49707b777e71e69c23c0a48e0a2665a4b;hpb=ba59dfdff778e2a1b0dbe38b19534a8e775f4a4b diff --git a/src/org/ibex/nestedvm/UnixRuntime.java b/src/org/ibex/nestedvm/UnixRuntime.java index 11d1093..151699f 100644 --- a/src/org/ibex/nestedvm/UnixRuntime.java +++ b/src/org/ibex/nestedvm/UnixRuntime.java @@ -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 @@ -64,7 +66,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { if(extra == null) extra = new String[0]; if(!envHas("USER",extra) && getSystemProperty("user.name") != null) defaults[n++] = "USER=" + getSystemProperty("user.name"); - if(!envHas("HOME",extra) && getSystemProperty("user.name") != null) + if(!envHas("HOME",extra) && getSystemProperty("user.home") != null) defaults[n++] = "HOME=" + getSystemProperty("user.home"); if(!envHas("SHELL",extra)) defaults[n++] = "SHELL=/bin/sh"; if(!envHas("TERM",extra)) defaults[n++] = "TERM=vt100"; @@ -85,10 +87,10 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { } else { int newpid = -1; int nextPID = gs.nextPID; - for(int i=nextPID;i " + r.pid + " tasks[" + r.pid + "] = " + gd.tasks[r.pid]); @@ -278,7 +281,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { public static int runAndExec(UnixRuntime r, String[] argv) { r.start(argv); return executeAndExec(r); } public static int executeAndExec(UnixRuntime r) { - for(;;) { + for(;;) { for(;;) { if(r.execute()) break; if(STDERR_DIAG) System.err.println("WARNING: Pause requested while executing runAndExec()"); @@ -289,7 +292,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { } private String[] readStringArray(int addr) throws ReadFaultException { - int count = 0; + int count = 0; for(int p=addr;memRead(p) != 0;p+=4) count++; String[] a = new String[count]; for(int i=0,p=addr;i= 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; @@ -498,7 +516,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { public GlobalState(int maxProcs, boolean defaultMounts) { tasks = new UnixRuntime[maxProcs+1]; if(defaultMounts) { - addMount("/",new HostFS()); + addMount("/",new HostFS()); addMount("/dev",new DevFS()); } } @@ -550,13 +568,13 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { public synchronized void removeMount(String path) { if(!path.startsWith("/")) throw new IllegalArgumentException("Mount point doesn't start with a /"); if(path.equals("/")) { - removeMount(-1); + removeMount(-1); } else { path = path.substring(1); int p; for(p=0;p 0 && pos < size();pos++){ switch(pos) { - case -2: + case -2: case -1: - ino = pos == -1 ? parentInode() : myInode(); + ino = pos == -1 ? parentInode() : myInode(); if(ino == -1) continue; reclen = 9 + (pos == -1 ? 2 : 1); if(reclen > len) break OUTER; @@ -987,7 +1011,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { public String name(int n) { switch(n) { - case 0: return "null"; + case 0: return "null"; case 1: return "zero"; case 2: return "fd"; default: return null;