include sourcename in runtime compiled binaries, more gc friendly runtime compiler
[nestedvm.git] / src / org / ibex / nestedvm / UnixRuntime.java
index ac1b595..c88cf24 100644 (file)
@@ -167,7 +167,14 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
             case SYS_sendto: return sys_sendto(a,b,c,d,e,f);
             case SYS_recvfrom: return sys_recvfrom(a,b,c,d,e,f);
             case SYS_select: return sys_select(a,b,c,d,e);
-
+            case SYS_access: return sys_access(a,b);
+            case SYS_realpath: return sys_realpath(a,b);
+            case SYS_chown: return sys_chown(a,b,c);
+            case SYS_lchown: return sys_chown(a,b,c);
+            case SYS_fchown: return sys_fchown(a,b,c);
+            case SYS_chmod: return sys_chmod(a,b,c);
+            case SYS_fchmod: return sys_fchmod(a,b,c);
+            
             default: return super._syscall(syscall,a,b,c,d,e,f);
         }
     }
@@ -179,6 +186,36 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
     private int sys_getppid() {
         return parent == null ? 1 : parent.pid;
     }
+    
+    private int sys_chown(int fileAddr, int uid, int gid) {
+        return 0;
+    }
+    private int sys_lchown(int fileAddr, int uid, int gid) {
+        return 0;
+    }
+    private int sys_fchown(int fd, int uid, int gid) {
+        return 0;
+    }
+    private int sys_chmod(int fileAddr, int uid, int gid) {
+        return 0;
+    }
+    private int sys_fchmod(int fd, int uid, int gid) {
+        return 0;
+    }
+    
+    
+    private int sys_access(int cstring, int mode) throws ErrnoException, ReadFaultException {
+        // FEATURE: sys_access
+        return gs.stat(this,cstring(cstring)) == null ? -ENOENT : 0;
+    }
+    
+    private int sys_realpath(int inAddr, int outAddr) throws FaultException {
+        String s = normalizePath(cstring(inAddr));
+        byte[] b = getNullTerminatedBytes(s);
+        if(b.length > PATH_MAX) return -ERANGE;
+        copyout(b,outAddr,b.length);
+        return 0;
+    }
 
     // FEATURE: Signal handling
     // check flag only on backwards jumps to basic blocks without compulsatory checks 
@@ -371,7 +408,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
     static {
         Method m;
         try {
-            m = Class.forName("org.ibex.nestedvm.RuntimeCompiler").getMethod("compile",new Class[]{Seekable.class,String.class});
+            m = Class.forName("org.ibex.nestedvm.RuntimeCompiler").getMethod("compile",new Class[]{Seekable.class,String.class,String.class});
         } catch(NoSuchMethodException e) {
             m = null;
         } catch(ClassNotFoundException e) {
@@ -380,14 +417,14 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
         runtimeCompilerCompile = m;
     }
             
-    public Class runtimeCompile(Seekable s) throws IOException {
+    public Class runtimeCompile(Seekable s, String sourceName) throws IOException {
         if(runtimeCompilerCompile == null) {
             if(STDERR_DIAG) System.err.println("WARNING: Exec attempted but RuntimeCompiler not found!");
             return null;
         }
         
         try {
-            return (Class) runtimeCompilerCompile.invoke(null,new Object[]{s,"unixruntime"});
+            return (Class) runtimeCompilerCompile.invoke(null,new Object[]{s,"unixruntime,maxinsnpermethod=256,lessconstants",sourceName});
         } catch(IllegalAccessException e) {
             e.printStackTrace();
             return null;
@@ -447,7 +484,9 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
                     if(n < 4) s.tryReadFully(buf,n,4-n);
                     if(buf[1] != 'E' || buf[2] != 'L' || buf[3] != 'F') return -ENOEXEC;
                     s.seek(0);
-                    Class c = runtimeCompile(s);
+                    if(STDERR_DIAG) System.err.println("Running RuntimeCompiler for " + path);
+                    Class c = runtimeCompile(s,path);
+                    if(STDERR_DIAG) System.err.println("RuntimeCompiler finished for " + path);
                     if(c == null) throw new ErrnoException(ENOEXEC);
                     gs.execCache.put(path,new GlobalState.CacheEnt(mtime,size,c));
                     return execClass(c,argv,envp);
@@ -1414,7 +1453,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
         
         private static File getParentFile(File f) {
             String p = f.getParent();
-            return p == null ? null : new File(f,p);
+            return p == null ? null : new File(p);
         }
         
         public class HostDirFD extends DirFD {