X-Git-Url: http://git.megacz.com/?p=nestedvm.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fnestedvm%2FUnixRuntime.java;h=11d109368a93af49e8e9958709cb88f96c972928;hp=42541dd989111f457e7b8cefa74a4559ab244080;hb=ba59dfdff778e2a1b0dbe38b19534a8e775f4a4b;hpb=efbc1822d80a8fb04447731bb33d64d3537f8121 diff --git a/src/org/ibex/nestedvm/UnixRuntime.java b/src/org/ibex/nestedvm/UnixRuntime.java index 42541dd..11d1093 100644 --- a/src/org/ibex/nestedvm/UnixRuntime.java +++ b/src/org/ibex/nestedvm/UnixRuntime.java @@ -4,18 +4,18 @@ import org.ibex.nestedvm.util.*; import java.io.*; import java.util.*; -// FIXME: Make plain old "mips-unknown-elf-gcc -o foo foo.c" work (modify spec file or whatever) - -// FEATURE: Remove System.{out,err}.printlns and throw Errors where applicable - public abstract class UnixRuntime extends Runtime implements Cloneable { /** The pid of this "process" */ private int pid; private UnixRuntime parent; public final int getPid() { return pid; } - private static final GlobalState defaultGD = new GlobalState(); - private GlobalState gd = defaultGD; + private static final GlobalState defaultGS = new GlobalState(); + private GlobalState gs = defaultGS; + public void setGlobalState(GlobalState gs) { + if(state != STOPPED) throw new IllegalStateException("can't change GlobalState when running"); + this.gs = gs; + } /** proceses' current working directory - absolute path WITHOUT leading slash "" = root, "bin" = /bin "usr/bin" = /usr/bin */ @@ -78,18 +78,18 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { private static class ProcessTableFullExn extends RuntimeException { } void _started() { - UnixRuntime[] tasks = gd.tasks; - synchronized(gd) { + UnixRuntime[] tasks = gs.tasks; + synchronized(gs) { if(pid != 0) { if(tasks[pid] == null || tasks[pid].pid != pid) throw new Error("should never happen"); } else { int newpid = -1; - int nextPID = gd.nextPID; + int nextPID = gs.nextPID; for(int i=nextPID;i= gd.tasks.length)) return -ECHILD; + if(pid !=-1 && (pid <= 0 || pid >= gs.tasks.length)) return -ECHILD; if(children == null) return blocking ? -ECHILD : 0; UnixRuntime done = null; @@ -166,7 +165,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { if(pid == -1) { if(exitedChildren.size() > 0) done = (UnixRuntime)exitedChildren.remove(exitedChildren.size() - 1); } else if(pid > 0) { - UnixRuntime t = gd.tasks[pid]; + UnixRuntime t = gs.tasks[pid]; if(t.parent != this) return -ECHILD; if(t.state == EXITED) { if(!exitedChildren.remove(t)) throw new Error("should never happen"); @@ -179,9 +178,9 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { if(done == null) { if(!blocking) return 0; try { children.wait(); } catch(InterruptedException e) {} - System.err.println("waitpid woke up: " + exitedChildren.size()); + //System.err.println("waitpid woke up: " + exitedChildren.size()); } else { - gd.tasks[done.pid] = null; + gs.tasks[done.pid] = null; break; } } @@ -195,7 +194,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { if(children != null) synchronized(children) { for(Enumeration e = exitedChildren.elements(); e.hasMoreElements(); ) { UnixRuntime child = (UnixRuntime) e.nextElement(); - gd.tasks[child.pid] = null; + gs.tasks[child.pid] = null; } exitedChildren.clear(); for(Enumeration e = activeChildren.elements(); e.hasMoreElements(); ) { @@ -207,11 +206,11 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { UnixRuntime _parent = parent; if(_parent == null) { - gd.tasks[pid] = null; + gs.tasks[pid] = null; } else { synchronized(_parent.children) { if(parent == null) { - gd.tasks[pid] = null; + gs.tasks[pid] = null; } else { parent.activeChildren.remove(this); parent.exitedChildren.add(this); @@ -251,7 +250,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { return -ENOMEM; } - System.err.println("fork " + pid + " -> " + r.pid + " tasks[" + r.pid + "] = " + gd.tasks[r.pid]); + //System.err.println("fork " + pid + " -> " + r.pid + " tasks[" + r.pid + "] = " + gd.tasks[r.pid]); if(children == null) { children = new Object(); activeChildren = new Vector(); @@ -282,7 +281,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { for(;;) { for(;;) { if(r.execute()) break; - System.err.println("WARNING: Pause requested while executing runAndExec()"); + if(STDERR_DIAG) System.err.println("WARNING: Pause requested while executing runAndExec()"); } if(r.state != EXECED) return r.exitStatus(); r = r.execedRuntime; @@ -304,7 +303,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { private int exec(String normalizedPath, String[] argv, String[] envp) throws ErrnoException { if(argv.length == 0) argv = new String[]{""}; - Object o = gd.exec(this,normalizedPath); + Object o = gs.exec(this,normalizedPath); if(o == null) return -ENOENT; if(o instanceof Class) { @@ -330,7 +329,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { private int exec(UnixRuntime r, String[] argv, String[] envp) { - System.err.println("Execing " + r); + //System.err.println("Execing " + r); for(int i=0;i " + path + " pwd: " + cwd); - if(gd.stat(this,path).type() != FStat.S_IFDIR) return -ENOTDIR; + //System.err.println("Chdir: " + cstring(addr) + " -> " + path + " pwd: " + cwd); + if(gs.stat(this,path).type() != FStat.S_IFDIR) return -ENOTDIR; cwd = path; - System.err.println("Now: [" + cwd + "]"); + //System.err.println("Now: [" + cwd + "]"); return 0; } @@ -508,7 +555,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { path = path.substring(1); int p; for(p=0;p 0) outp--; while(outp > 0 && out[outp] != '/') outp--; - System.err.println("After ..: " + new String(out,0,outp)); + //System.err.println("After ..: " + new String(out,0,outp)); continue; } inp++;