make Runtime._syscall() protected so it can be overridden from outside the package
[nestedvm.git] / src / org / ibex / nestedvm / Runtime.java
index 201fde9..d77ea85 100644 (file)
@@ -1,5 +1,5 @@
 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
-// Licensed under the Apache Public Source License 2.0 ("the License").
+// Licensed under the Apache License 2.0 ("the License").
 // You may not use this file except in compliance with the License.
 
 // Copyright 2003 Brian Alliet
@@ -698,18 +698,18 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable {
         return i;
     }
 
-    /** Hook for subclasses to do something when the process closes an FD */
-    void _closedFD(FD fd) {  }
+    /** Hooks for subclasses before and after the process closes an FD */
+    void _preCloseFD(FD fd) {  }
+    void _postCloseFD(FD fd) {  }
 
     /** Closes file descriptor <i>fdn</i> and removes it from the file descriptor table */
     public final boolean closeFD(int fdn) {
         if(state == EXITED || state == EXECED) throw new IllegalStateException("closeFD called in inappropriate state");
         if(fdn < 0 || fdn >= OPEN_MAX) return false;
         if(fds[fdn] == null) return false;
-
-        _closedFD(fds[fdn]);
-
+        _preCloseFD(fds[fdn]);
         fds[fdn].close();
+        _postCloseFD(fds[fdn]);
         fds[fdn] = null;        
         return true;
     }
@@ -767,10 +767,10 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable {
             return null;
         } catch(IOException e) { throw new ErrnoException(EIO); }
         
-        return new SeekableFD(sf,flags) { protected FStat _fstat() { return hostFStat(f,data); } };
+        return new SeekableFD(sf,flags) { protected FStat _fstat() { return hostFStat(f,sf,data); } };
     }
     
-    FStat hostFStat(File f, Object data) { return new HostFStat(f); }
+    FStat hostFStat(File f, Seekable.File sf, Object data) { return new HostFStat(f,sf); }
     
     FD hostFSDirFD(File f, Object data) { return null; }
     
@@ -1087,7 +1087,7 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable {
         }
     }
     
-    int _syscall(int syscall, int a, int b, int c, int d, int e, int f) throws ErrnoException, FaultException {
+    protected int _syscall(int syscall, int a, int b, int c, int d, int e, int f) throws ErrnoException, FaultException {
         switch(syscall) {
             case SYS_null: return 0;
             case SYS_exit: return sys_exit(a);
@@ -1209,6 +1209,14 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable {
     /** File Descriptor class */
     public static abstract class FD {
         private int refCount = 1;
+        private String normalizedPath = null;
+        private boolean deleteOnClose = false;
+
+        public void setNormalizedPath(String path) { normalizedPath = path; }
+        public String getNormalizedPath() { return normalizedPath; }
+
+        public void markDeleteOnClose() { deleteOnClose = true; }
+        public boolean isMarkedForDeleteOnClose() { return deleteOnClose; }
         
         /** Read some bytes. Should return the number of bytes read, 0 on EOF, or throw an IOException on error */
         public int read(byte[] a, int off, int length) throws ErrnoException { throw new ErrnoException(EBADFD); }
@@ -1413,10 +1421,13 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable {
     
     static class HostFStat extends FStat {
         private final File f;
+        private final Seekable.File sf;
         private final boolean executable; 
-        public HostFStat(File f) { this(f,false); }
-        public HostFStat(File f, boolean executable) {
+        public HostFStat(File f, Seekable.File sf) { this(f,sf,false); }
+        public HostFStat(File f, boolean executable) {this(f,null,executable);}
+        public HostFStat(File f, Seekable.File sf, boolean executable) {
             this.f = f;
+            this.sf = sf;
             this.executable = executable;
         }
         public int dev() { return 1; }
@@ -1431,7 +1442,13 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable {
             if(f.canWrite()) mode |= 0222;
             return mode;
         }
-        public int size() { return (int) f.length(); }
+        public int size() {
+          try {
+            return sf != null ? (int)sf.length() : (int)f.length();
+          } catch (Exception x) {
+            return (int)f.length();
+          }
+        }
         public int mtime() { return (int)(f.lastModified()/1000); }        
     }