From 095d6d46361db8b4b69790305c0310ea114d3813 Mon Sep 17 00:00:00 2001 From: brian Date: Fri, 4 Jun 2004 15:53:43 -0700 Subject: [PATCH] make nestedvm work under SableVM darcs-hash:20040604225343-24bed-5508a9c7cf832fb8ab943fe1ee64ed3b30019f51.gz --- src/org/ibex/nestedvm/Runtime.java | 10 +--------- src/org/ibex/nestedvm/UnixRuntime.java | 22 ++++++++++++---------- src/org/ibex/nestedvm/util/Platform.java | 14 +++++++++++++- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/org/ibex/nestedvm/Runtime.java b/src/org/ibex/nestedvm/Runtime.java index 88c18b5..a54fbc2 100644 --- a/src/org/ibex/nestedvm/Runtime.java +++ b/src/org/ibex/nestedvm/Runtime.java @@ -158,7 +158,7 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable { } } - InputStream stdin = Boolean.valueOf(getSystemProperty("nestedvm.textstdin")).booleanValue() ? new TextInputStream(System.in) : System.in; + InputStream stdin = Boolean.valueOf(Platform.getProperty("nestedvm.textstdin")).booleanValue() ? new TextInputStream(System.in) : System.in; addFD(new TerminalFD(stdin)); addFD(new TerminalFD(System.out)); addFD(new TerminalFD(System.err)); @@ -1393,14 +1393,6 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable { return _byteBuf; } - static String getSystemProperty(String key) { - try { - return System.getProperty(key); - } catch(SecurityException e) { - return null; - } - } - /** Decode a packed string */ protected static final int[] decodeData(String s, int words) { if(s.length() % 8 != 0) throw new IllegalArgumentException("string length must be a multiple of 8"); diff --git a/src/org/ibex/nestedvm/UnixRuntime.java b/src/org/ibex/nestedvm/UnixRuntime.java index bee9c24..ec2b58b 100644 --- a/src/org/ibex/nestedvm/UnixRuntime.java +++ b/src/org/ibex/nestedvm/UnixRuntime.java @@ -37,9 +37,9 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { super(pageSize,totalPages); // FEATURE: Do the proper mangling for non-unix hosts - String userdir = getSystemProperty("user.dir"); + String userdir = Platform.getProperty("user.dir"); cwd = - userdir != null && userdir.startsWith("/") && File.separatorChar == '/' && getSystemProperty("nestedvm.root") == null + userdir != null && userdir.startsWith("/") && File.separatorChar == '/' && Platform.getProperty("nestedvm.root") == null ? userdir.substring(1) : ""; } @@ -68,10 +68,10 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { 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.home") != null) - defaults[n++] = "HOME=" + getSystemProperty("user.home"); + if(!envHas("USER",extra) && Platform.getProperty("user.name") != null) + defaults[n++] = "USER=" + Platform.getProperty("user.name"); + if(!envHas("HOME",extra) && Platform.getProperty("user.home") != null) + defaults[n++] = "HOME=" + Platform.getProperty("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(); @@ -1049,7 +1049,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { public synchronized Object exec(UnixRuntime r, String path) throws ErrnoException { // HACK: Hideous hack to make a standalone busybox possible - if(path.equals("bin/busybox") && Boolean.valueOf(getSystemProperty("nestedvm.busyboxhack")).booleanValue()) + if(path.equals("bin/busybox") && Boolean.valueOf(Platform.getProperty("nestedvm.busyboxhack")).booleanValue()) return r.getClass(); FStat fstat = stat(r,path); if(fstat == null) return null; @@ -1229,16 +1229,18 @@ 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(Platform.getProperty("nestedvm.root") != null) { + File f = new File(Platform.getProperty("nestedvm.root")); if(f.isDirectory()) return f; // fall through to case below } - String cwd = getSystemProperty("user.dir"); + String cwd = Platform.getProperty("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()); + // HACK: This works around a bug in some versions of ClassPath + if(f.getPath().length() == 0) f = new File("/"); return f; } diff --git a/src/org/ibex/nestedvm/util/Platform.java b/src/org/ibex/nestedvm/util/Platform.java index ed59627..55fe2f1 100644 --- a/src/org/ibex/nestedvm/util/Platform.java +++ b/src/org/ibex/nestedvm/util/Platform.java @@ -13,7 +13,10 @@ public abstract class Platform { static { float version; try { - version = Float.valueOf(System.getProperty("java.specification.version")).floatValue(); + if(getProperty("java.vm.name").equals("SableVM")) + version = 1.2f; + else + version = Float.valueOf(getProperty("java.specification.version")).floatValue(); } catch(Exception e) { System.err.println("WARNING: " + e + " while trying to find jvm version - assuming 1.1"); version = 1.1f; @@ -33,6 +36,15 @@ public abstract class Platform { } } + public static String getProperty(String key) { + try { + return System.getProperty(key); + } catch(SecurityException e) { + return null; + } + } + + abstract boolean _atomicCreateFile(File f) throws IOException; public static boolean atomicCreateFile(File f) throws IOException { return p._atomicCreateFile(f); } -- 1.7.10.4