package org.ibex.nestedvm;
import org.ibex.nestedvm.util.*;
+// FEATURE: This is ugly, this stuff needs to be in org.ibex.util or something
+import org.ibex.classgen.util.Sort;
import java.io.*;
import java.util.*;
import java.net.*;
}
return 0;
}
-
-
- /*public int sys_opensocket(int cstring, int port) throws FaultException, ErrnoException {
- String hostname = cstring(cstring);
- try {
- FD fd = new SocketFD(new Socket(hostname,port));
- int n = addFD(fd);
- if(n == -1) fd.close();
- return n;
- } catch(IOException e) {
- return -EIO;
- }
- }
-
- private static class ListenSocketFD extends FD {
- ServerSocket s;
- public ListenSocketFD(ServerSocket s) { this.s = s; }
- public int flags() { return 0; }
- // FEATURE: What should these be?
- public FStat _fstat() { return new FStat(); }
- public void _close() { try { s.close(); } catch(IOException e) { } }
- }
-
- public int sys_listensocket(int port) {
- try {
- ListenSocketFD fd = new ListenSocketFD(new ServerSocket(port));
- int n = addFD(fd);
- if(n == -1) fd.close();
- return n;
- } catch(IOException e) {
- return -EIO;
- }
- }
-
- public int sys_accept(int fdn) {
- if(fdn < 0 || fdn >= OPEN_MAX) return -EBADFD;
- if(fds[fdn] == null) return -EBADFD;
- if(!(fds[fdn] instanceof ListenSocketFD)) return -EBADFD;
- try {
- ServerSocket s = ((ListenSocketFD)fds[fdn]).s;
- SocketFD fd = new SocketFD(s.accept());
- int n = addFD(fd);
- if(n == -1) fd.close();
- return n;
- } catch(IOException e) {
- return -EIO;
- }
- }*/
// FEATURE: Run through the fork/wait stuff one more time
public static class GlobalState {
+++ /dev/null
-package org.ibex.nestedvm.util;
-
-public final class Sort {
- private Sort() { }
-
- public interface Comparable { public int compareTo(Object o); }
- public interface CompareFunc { public int compare(Object a, Object b); }
-
- private static final CompareFunc comparableCompareFunc = new CompareFunc() {
- public int compare(Object a,Object b) { return ((Comparable)a).compareTo(b); }
- };
-
- public static void sort(Comparable[] a) { sort(a,comparableCompareFunc); }
- public static void sort(Object[] a, CompareFunc c) { sort(a,c,0,a.length-1); }
-
- private static void sort(Object[] a, CompareFunc c, int start, int end) {
- Object tmp;
- if(start >= end) return;
- if(end-start <= 6) {
- for(int i=start+1;i<=end;i++) {
- tmp = a[i];
- int j;
- for(j=i-1;j>=start;j--) {
- if(c.compare(a[j],tmp) <= 0) break;
- a[j+1] = a[j];
- }
- a[j+1] = tmp;
- }
- return;
- }
-
- Object pivot = a[end];
- int lo = start - 1;
- int hi = end;
-
- do {
- while((lo < hi) && c.compare(a[++lo],pivot) < 0) { }
- while((hi > lo) && c.compare(a[--hi],pivot) > 0) { }
- tmp = a[lo]; a[lo] = a[hi]; a[hi] = tmp;
- } while(lo < hi);
-
- tmp = a[lo]; a[lo] = a[end]; a[end] = tmp;
-
- sort(a, c, start, lo-1);
- sort(a, c, lo+1, end);
- }
-}