X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fnestedvm%2FRuntime.java;h=f28662078395080bbd32807501a4d52d2e0ee8de;hb=6d6d9f59a2e6fe3b9e5b3563efcf0124bea4a672;hp=af846192584c59416ae2c79d0ec78f67e53eafd0;hpb=bca50e30043fa5ec16c58bbc42fe527d9d425351;p=nestedvm.git diff --git a/src/org/ibex/nestedvm/Runtime.java b/src/org/ibex/nestedvm/Runtime.java index af84619..f286620 100644 --- a/src/org/ibex/nestedvm/Runtime.java +++ b/src/org/ibex/nestedvm/Runtime.java @@ -731,7 +731,6 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable { if((flags & ~(3|O_CREAT|O_EXCL|O_APPEND|O_TRUNC)) != 0) { if(STDERR_DIAG) System.err.println("WARNING: Unsupported flags passed to open(\"" + f + "\"): " + toHex(flags & ~(3|O_CREAT|O_EXCL|O_APPEND|O_TRUNC))); - throw new ErrnoException(ENOTSUP); } boolean write = (flags&3) != RD_ONLY; @@ -810,6 +809,17 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable { copyout(buf,addr,n); return n; } + + /** The ftruncate syscall */ + private int sys_ftruncate(int fdn, long length) { + if (fdn < 0 || fdn >= OPEN_MAX) return -EBADFD; + if (fds[fdn] == null) return -EBADFD; + + Seekable seekable = fds[fdn].seekable(); + if (length < 0 || seekable == null) return -EINVAL; + try { seekable.resize(length); } catch (IOException e) { return -EIO; } + return 0; + } /** The close syscall */ private int sys_close(int fdn) { @@ -1023,7 +1033,7 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable { return -ENOSYS; } } - + /** The syscall dispatcher. The should be called by subclasses when the syscall instruction is invoked. syscall should be the contents of V0 and a, b, c, and d should be @@ -1032,9 +1042,11 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable { protected final int syscall(int syscall, int a, int b, int c, int d, int e, int f) { try { int n = _syscall(syscall,a,b,c,d,e,f); - //if(n < 0) System.err.println("syscall: " + syscall + " returned " + n); + //if(n<0) throw new ErrnoException(-n); return n; } catch(ErrnoException ex) { + //System.err.println("While executing syscall: " + syscall + ":"); + //if(syscall == SYS_open) try { System.err.println("Failed to open " + cstring(a) + " errno " + ex.errno); } catch(Exception e2) { } //ex.printStackTrace(); return -ex.errno; } catch(FaultException ex) { @@ -1057,6 +1069,7 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable { case SYS_close: return sys_close(a); case SYS_read: return sys_read(a,b,c); case SYS_lseek: return sys_lseek(a,b,c); + case SYS_ftruncate: return sys_ftruncate(a,b); case SYS_getpid: return sys_getpid(); case SYS_calljava: return sys_calljava(a,b,c,d); case SYS_gettimeofday: return sys_gettimeofday(a,b); @@ -1292,7 +1305,7 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable { pos++; len--; pb = true; } int n = parent.read(buf,pos,len); - if(n == -1) return -1; + if(n == -1) return pb ? 1 : -1; for(int i=0;i