X-Git-Url: http://git.megacz.com/?p=nestedvm.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fnestedvm%2FRuntime.java;h=55851c39cfea3626a172e7ae8834d1704ae9c294;hp=5c2cc6a271b57db0ff77284b4d1bff66f07e6227;hb=d1a9c17fc77be2e8f200b7be68c4f70c10e73f89;hpb=d309b21d2ee150a9f426c7d22a5ce6d392b59d26 diff --git a/src/org/ibex/nestedvm/Runtime.java b/src/org/ibex/nestedvm/Runtime.java index 5c2cc6a..55851c3 100644 --- a/src/org/ibex/nestedvm/Runtime.java +++ b/src/org/ibex/nestedvm/Runtime.java @@ -102,7 +102,7 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable { /** Subclasses should return the address of the symbol symbol or -1 it it doesn't exits in this method This method is only required if the call() function is used */ - protected int lookupSymbol(String symbol) { return -1; } + public int lookupSymbol(String symbol) { return -1; } /** Subclasses should populate a CPUState object representing the cpu state */ protected abstract void getCPUState(CPUState state); @@ -704,6 +704,20 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable { 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; + + // release all fcntl locks on this file + Seekable s = fds[fdn].seekable(); + if (s != null) { + try { + for (int i=0; i < LOCK_MAX; i++) { + if (locks[i] != null && s.equals(locks[i].seekable())) { + locks[i].release(); + locks[i] = null; + } + } + } catch (IOException e) { throw new RuntimeException(e); } + } + fds[fdn].close(); fds[fdn] = null; return true; @@ -1249,7 +1263,35 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable { } return addr; } - + + // TODO: less memory copying (custom utf-8 reader) + // or at least roll strlen() into copyin() + public final String utfstring(int addr) throws ReadFaultException { + if (addr == 0) return null; + + // determine length + int i=addr; + for(int word = 1; word != 0; i++) { + word = memRead(i&~3); + switch(i&3) { + case 0: word = (word>>>24)&0xff; break; + case 1: word = (word>>>16)&0xff; break; + case 2: word = (word>>> 8)&0xff; break; + case 3: word = (word>>> 0)&0xff; break; + } + } + if (i > addr) i--; // do not count null + + byte[] bytes = new byte[i-addr]; + copyin(addr, bytes, bytes.length); + + try { + return new String(bytes, "UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); // should never happen with UTF-8 + } + } + /** Helper function to read a cstring from main memory */ public final String cstring(int addr) throws ReadFaultException { if (addr == 0) return null; @@ -1589,7 +1631,7 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable { static byte[] getBytes(String s) { try { - return s.getBytes("ISO-8859-1"); + return s.getBytes("UTF-8"); } catch(UnsupportedEncodingException e) { return null; // should never happen }