X-Git-Url: http://git.megacz.com/?p=nestedvm.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fnestedvm%2FUnixRuntime.java;h=0bed8ed27ef330538112c773149dacc134fec68d;hp=11d109368a93af49e8e9958709cb88f96c972928;hb=2db6b04d7557a26e3b9e7440e7968aaec262216f;hpb=ba59dfdff778e2a1b0dbe38b19534a8e775f4a4b diff --git a/src/org/ibex/nestedvm/UnixRuntime.java b/src/org/ibex/nestedvm/UnixRuntime.java index 11d1093..0bed8ed 100644 --- a/src/org/ibex/nestedvm/UnixRuntime.java +++ b/src/org/ibex/nestedvm/UnixRuntime.java @@ -4,6 +4,8 @@ import org.ibex.nestedvm.util.*; import java.io.*; import java.util.*; +// FEATURE: vfork + public abstract class UnixRuntime extends Runtime implements Cloneable { /** The pid of this "process" */ private int pid; @@ -33,7 +35,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 == '/' && getSystemProperty("nestedvm.root") == null + ? userdir.substring(1) : ""; } // NOTE: getDisplayName() is a Java2 function @@ -59,16 +63,17 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { } String[] createEnv(String[] extra) { - String[] defaults = new String[5]; + String[] defaults = new String[6]; int n=0; 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"; if(!envHas("TZ",extra)) defaults[n++] = "TZ=" + posixTZ(); + if(!envHas("PATH",extra)) defaults[n++] = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin"; String[] env = new String[extra.length+n]; for(int i=0;i " + r.pid + " tasks[" + r.pid + "] = " + gd.tasks[r.pid]); @@ -278,7 +297,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 +308,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; @@ -451,6 +485,11 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { return 0; } + private int sys_unlink(int cstring) throws FaultException, ErrnoException { + gs.unlink(this,normalizePath(cstring(cstring))); + return 0; + } + private int sys_getcwd(int addr, int size) throws FaultException, ErrnoException { byte[] b = getBytes(cwd); if(size == 0) return -EINVAL; @@ -486,6 +525,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { protected static final int STAT = 2; protected static final int LSTAT = 3; protected static final int MKDIR = 4; + protected static final int UNLINK = 5; final UnixRuntime[] tasks; int nextPID = 1; @@ -498,7 +538,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 +590,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 +1046,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; @@ -1019,6 +1078,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { return null; } - public void mkdir(UnixRuntime r, String path, int mode) throws ErrnoException { throw new ErrnoException(EACCES); } - } + public void mkdir(UnixRuntime r, String path, int mode) throws ErrnoException { throw new ErrnoException(EROFS); } + public void unlink(UnixRuntime r, String path) throws ErrnoException { throw new ErrnoException(EROFS); } + } }