udp support
authorbrian <brian@brianweb.net>
Wed, 9 Jun 2004 00:13:19 +0000 (17:13 -0700)
committerbrian <brian@brianweb.net>
Wed, 9 Jun 2004 00:13:19 +0000 (17:13 -0700)
darcs-hash:20040609001319-24bed-da5c2446c936cf45e0b9ef046203a2f1536bc7bd.gz

Makefile
src/org/ibex/nestedvm/UnixRuntime.java
src/org/ibex/nestedvm/UsermodeConstants.java
src/org/ibex/nestedvm/support.s
src/org/ibex/nestedvm/support_aux.c
src/org/ibex/nestedvm/syscalls.h
upstream/misc/extraheaders.sh
upstream/patches/busybox.patch

index b13301b..530aa03 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -247,7 +247,7 @@ rebuild-constants: $(tasks)/build_libc
        ( \
                cat \
                        src/org/ibex/nestedvm/syscalls.h \
-                       $(usr)/mips-uknown-elf/include/nestedvm/sockets.h \
+                       $(usr)/mips-unknown-elf/include/nestedvm/socket.h \
                        $(usr)/mips-unknown-elf/include/sys/{errno.h,unistd.h,syslimits.h,sysctl.h}; \
                $(MIPS_CC) -E -dM $(usr)/mips-unknown-elf/include/sys/fcntl.h | awk '$$2 ~ /^[OF]_/ { print; }'; \
        ) | ( \
index 8fb08f9..0b50ee3 100644 (file)
@@ -158,6 +158,9 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
             case SYS_accept: return sys_accept(a,b,c);
             case SYS_shutdown: return sys_shutdown(a,b);
             case SYS_sysctl: return sys_sysctl(a,b,c,d,e,f);
+            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);
 
             default: return super._syscall(syscall,a,b,c,d,e,f);
         }
@@ -558,8 +561,6 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
         return n;
     }
     
-    // FEATURE: UDP is totally broken
-    
     static class SocketFD extends FD {
         public static final int TYPE_STREAM = 0;
         public static final int TYPE_DGRAM = 1;
@@ -569,19 +570,31 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
         
         int flags;
         int options;
-        Object o;
+        
+        Socket s;
+        ServerSocket ss;
+        DatagramSocket ds;
+        
         InetAddress bindAddr;
         int bindPort = -1;
+        InetAddress connectAddr;
+        int connectPort = -1;
+        
         DatagramPacket dp;
         InputStream is;
         OutputStream os; 
         
-        public SocketFD(int type) { flags = type; }
+        private static final byte[] EMPTY = new byte[0];
+        public SocketFD(int type) {
+               flags = type;
+               if(type == TYPE_DGRAM)
+                       dp = new DatagramPacket(EMPTY,0);
+        }
         
         public void setOptions() {
             try {
-                if(o != null && type() == TYPE_STREAM && !listen()) {
-                    Platform.socketSetKeepAlive((Socket)o,(options & SO_KEEPALIVE) != 0);
+                if(s != null && type() == TYPE_STREAM && !listen()) {
+                    Platform.socketSetKeepAlive(s,(options & SO_KEEPALIVE) != 0);
                 }
             } catch(SocketException e) {
                 if(STDERR_DIAG) e.printStackTrace();
@@ -589,65 +602,84 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
         }
         
         public void _close() {
-            if(o != null) {
-                try {
-                    if(type() == TYPE_STREAM) {
-                        if(listen()) ((ServerSocket)o).close();
-                        else ((Socket)o).close();
-                    } else {
-                        ((DatagramSocket)o).close();
-                    }
-                } catch(IOException e) {
-                    /* ignore */
-                }
+            try {
+               if(s != null) s.close();
+               if(ss != null) ss.close();
+               if(ds != null) ds.close();
+            } catch(IOException e) {
+                /* ignore */
             }
         }
         
         public int read(byte[] a, int off, int length) throws ErrnoException {
-            if(type() == TYPE_STREAM) {
-                if(is == null) throw new ErrnoException(EPIPE);
-                try {
-                    int n = is.read(a,off,length);
-                    return n < 0 ? 0 : n;
-                } catch(IOException e) {
-                    throw new ErrnoException(EIO);
-                }
-            } else {
-                if(off != 0) throw new IllegalArgumentException("off must be 0");
-                DatagramSocket ds = (DatagramSocket) o;
-                dp.setData(a);
-                dp.setLength(length);
-                try {
-                    ds.receive(dp);
-                } catch(IOException e) {
-                    throw new ErrnoException(EIO);
-                }
-                return dp.getLength();
+            if(type() == TYPE_DGRAM) return recvfrom(a,off,length,null,null);
+            if(is == null) throw new ErrnoException(EPIPE);
+            try {
+                int n = is.read(a,off,length);
+                return n < 0 ? 0 : n;
+            } catch(IOException e) {
+                throw new ErrnoException(EIO);
             }
         }    
         
+        public int recvfrom(byte[] a, int off, int length, InetAddress[] sockAddr, int[] port) throws ErrnoException {
+               if(type() == TYPE_STREAM) return read(a,off,length);
+               
+               if(off != 0) throw new IllegalArgumentException("off must be 0");
+               dp.setData(a);
+               dp.setLength(length);
+               try {
+                       if(ds == null) ds = new DatagramSocket();
+                       ds.receive(dp);
+               } catch(IOException e) {
+                       if(STDERR_DIAG) e.printStackTrace();
+                       throw new ErrnoException(EIO);
+               }
+               if(sockAddr != null) {
+                       sockAddr[0] = dp.getAddress();
+                       port[0] = dp.getPort();
+               }
+               return dp.getLength();
+        }
+        
         public int write(byte[] a, int off, int length) throws ErrnoException {
-            if(type() == TYPE_STREAM) {
-                if(os == null) throw new ErrnoException(EPIPE);
-                try {
-                    os.write(a,off,length);
-                    return length;
-                } catch(IOException e) {
-                    throw new ErrnoException(EIO);
-                }
-            } else {
-                if(off != 0) throw new IllegalArgumentException("off must be 0");
-                DatagramSocket ds = (DatagramSocket) o;
-                dp.setData(a);
-                dp.setLength(length);
-                try {
-                    ds.send(dp);
-                } catch(IOException e) {
-                    throw new ErrnoException(EIO);
-                }
-                return dp.getLength();
+            if(type() == TYPE_DGRAM) return  sendto(a,off,length,null,-1);
+
+            if(os == null) throw new ErrnoException(EPIPE);
+            try {
+                os.write(a,off,length);
+                return length;
+            } catch(IOException e) {
+                throw new ErrnoException(EIO);
             }
         }
+        
+        public int sendto(byte[] a, int off, int length, InetAddress destAddr, int destPort) throws ErrnoException {
+               if(off != 0) throw new IllegalArgumentException("off must be 0");
+               if(type() == TYPE_STREAM) return write(a,off,length);
+               
+               if(destAddr == null) {
+                       destAddr = connectAddr;
+                       destPort = connectPort;
+                       
+                       if(destAddr == null) throw new ErrnoException(ENOTCONN);
+               }
+               
+               dp.setAddress(destAddr);
+               dp.setPort(destPort);
+               dp.setData(a);
+               dp.setLength(length);
+               
+               try {
+                       if(ds == null) ds = new DatagramSocket();
+                       ds.send(dp);
+               } catch(IOException e) {
+                       if(STDERR_DIAG) e.printStackTrace();
+                       if("Network is unreachable".equals(e.getMessage())) throw new ErrnoException(EHOSTUNREACH);
+                       throw new ErrnoException(EIO);
+               }
+               return dp.getLength();
+        }
 
         public int flags() { return O_RDWR; }
         public FStat _fstat() { return new SocketFStat(); }
@@ -669,7 +701,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
     private int sys_connect(int fdn, int addr, int namelen) throws ErrnoException, FaultException {
         SocketFD fd = getSocketFD(fdn);
         
-        if(fd.type() == SocketFD.TYPE_STREAM && fd.o != null) return -EISCONN;
+        if(fd.type() == SocketFD.TYPE_STREAM && (fd.s != null || fd.ss != null)) return -EISCONN;
         int word1 = memRead(addr);
         if( ((word1 >>> 16)&0xff) != AF_INET) return -EAFNOSUPPORT;
         int port = word1 & 0xffff;
@@ -683,22 +715,21 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
             return -EADDRNOTAVAIL;
         }
         
+        fd.connectAddr = inetAddr;
+        fd.connectPort = port;
+        
         try {
             switch(fd.type()) {
                 case SocketFD.TYPE_STREAM: {
                     Socket s = new Socket(inetAddr,port);
-                    fd.o = s;
+                    fd.s = s;
                     fd.setOptions();
                     fd.is = s.getInputStream();
                     fd.os = s.getOutputStream();
                     break;
                 }
-                case SocketFD.TYPE_DGRAM: {
-                    if(fd.dp == null) fd.dp = new DatagramPacket(null,0);
-                    fd.dp.setAddress(inetAddr);
-                    fd.dp.setPort(port);
+                case SocketFD.TYPE_DGRAM:
                     break;
-                }
                 default:
                     throw new Error("should never happen");
             }
@@ -778,7 +809,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
     private int sys_bind(int fdn, int addr, int namelen) throws FaultException, ErrnoException {
         SocketFD fd = getSocketFD(fdn);
         
-        if(fd.type() == SocketFD.TYPE_STREAM && fd.o != null) return -EISCONN;
+        if(fd.type() == SocketFD.TYPE_STREAM && (fd.s != null || fd.ss != null)) return -EISCONN;
         int word1 = memRead(addr);
         if( ((word1 >>> 16)&0xff) != AF_INET) return -EAFNOSUPPORT;
         int port = word1 & 0xffff;
@@ -801,10 +832,9 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
                 return 0;
             }
             case SocketFD.TYPE_DGRAM: {
-                DatagramSocket s = (DatagramSocket) fd.o;
-                if(s != null) s.close();
+                if(fd.ds != null) fd.ds.close();
                 try {
-                    fd.o = inetAddr != null ? new DatagramSocket(port,inetAddr) : new DatagramSocket(port);
+                    fd.ds = inetAddr != null ? new DatagramSocket(port,inetAddr) : new DatagramSocket(port);
                 } catch(IOException e) {
                     return -EADDRINUSE;
                 }
@@ -818,11 +848,11 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
     private int sys_listen(int fdn, int backlog) throws ErrnoException {
         SocketFD fd = getSocketFD(fdn);
         if(fd.type() != SocketFD.TYPE_STREAM) return -EOPNOTSUPP;
-        if(fd.o != null) return -EISCONN;
+        if(fd.ss != null || fd.s != null) return -EISCONN;
         if(fd.bindPort < 0) return -EOPNOTSUPP;
         
         try {
-            fd.o = new ServerSocket(fd.bindPort,backlog,fd.bindAddr);
+            fd.ss = new ServerSocket(fd.bindPort,backlog,fd.bindAddr);
             fd.flags |= SocketFD.LISTEN;
             return 0;
         } catch(IOException e) {
@@ -838,7 +868,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
 
         int size = memRead(lenaddr);
         
-        ServerSocket s = (ServerSocket) fd.o;
+        ServerSocket s = fd.ss;
         Socket client;
         try {
             client = s.accept();
@@ -854,7 +884,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
         }
         
         SocketFD clientFD = new SocketFD(SocketFD.TYPE_STREAM);
-        clientFD.o = client;
+        clientFD.s = client;
         try {
             clientFD.is = client.getInputStream();
             clientFD.os = client.getOutputStream();
@@ -869,9 +899,9 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
     private int sys_shutdown(int fdn, int how) throws ErrnoException {
         SocketFD fd = getSocketFD(fdn);
         if(fd.type() != SocketFD.TYPE_STREAM || fd.listen()) return -EOPNOTSUPP;
-        if(fd.o == null) return -ENOTCONN;
+        if(fd.s == null) return -ENOTCONN;
         
-        Socket s = (Socket) fd.o;
+        Socket s = fd.s;
         
         try {
             if(how == SHUT_RD || how == SHUT_RDWR) Platform.socketHalfClose(s,false);
@@ -883,6 +913,58 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
         return 0;
     }
     
+    private int sys_sendto(int fdn, int addr, int count, int flags, int destAddr, int socklen) throws ErrnoException,ReadFaultException {
+       SocketFD fd = getSocketFD(fdn);
+       if(flags != 0) throw new ErrnoException(EINVAL);
+       
+       int word1 = memRead(destAddr);
+       if( ((word1 >>> 16)&0xff) != AF_INET) return -EAFNOSUPPORT;
+       int port = word1 & 0xffff;
+       InetAddress inetAddr;
+               byte[] ip = new byte[4];
+               copyin(destAddr+4,ip,4);
+               try {
+                       inetAddr = Platform.inetAddressFromBytes(ip);
+               } catch(UnknownHostException e) {
+                       return -EADDRNOTAVAIL;
+               }
+       
+       count = Math.min(count,MAX_CHUNK);
+       byte[] buf = byteBuf(count);
+       copyin(addr,buf,count);
+       try {
+               return fd.sendto(buf,0,count,inetAddr,port);
+       } catch(ErrnoException e) {
+               if(e.errno == EPIPE) exit(128+13,true);
+               throw e;
+       }
+    }
+    
+    private int sys_recvfrom(int fdn, int addr, int count, int flags, int sourceAddr, int socklenAddr) throws ErrnoException, FaultException {
+       SocketFD fd = getSocketFD(fdn);
+       if(flags != 0) throw new ErrnoException(EINVAL);
+       
+       InetAddress[] inetAddr = sourceAddr == 0 ? null : new InetAddress[1];
+       int[] port = sourceAddr == 0 ? null : new int[1];
+       
+       count = Math.min(count,MAX_CHUNK);
+       byte[] buf = byteBuf(count);
+       int n = fd.recvfrom(buf,0,count,inetAddr,port);
+       copyout(buf,addr,n);
+       
+       if(sourceAddr != 0) {
+               memWrite(sourceAddr,(AF_INET << 16) | port[0]);
+               byte[] ip = inetAddr[0].getAddress();
+               copyout(ip,sourceAddr+4,4);
+       }
+       
+       return n;
+    }
+    
+    private int sys_select(int n, int readFDs, int writeFDs, int exceptFDs, int timevalAddr) throws ReadFaultException, ErrnoException {
+       return -ENOSYS;
+    }
+    
     private static String hostName() {
         try {
             return InetAddress.getLocalHost().getHostName();
index 1341de1..c373b67 100644 (file)
@@ -64,6 +64,9 @@ public interface UsermodeConstants {
     public static final int SYS_listen = 62;
     public static final int SYS_bind = 63;
     public static final int SYS_shutdown = 64;
+    public static final int SYS_sendto = 65;
+    public static final int SYS_recvfrom = 66;
+    public static final int SYS_select = 67;
     public static final int AF_INET = 2;
     public static final int SOCK_STREAM = 1;
     public static final int SOCK_DGRAM = 2;
@@ -78,129 +81,6 @@ public interface UsermodeConstants {
     public static final int SHUT_WR = 1;
     public static final int SHUT_RDWR = 2;
     public static final int INADDR_ANY = 0;
-    public static final int CTL_MAXNAME = 12;
-    public static final int CTL_UNSPEC = 0; /* unused */
-    public static final int CTL_KERN = 1; /* "high kernel": proc, limits */
-    public static final int CTL_VM = 2; /* virtual memory */
-    public static final int CTL_VFS = 3; /* file system, mount type is next */
-    public static final int CTL_NET = 4; /* network, see socket.h */
-    public static final int CTL_DEBUG = 5; /* debugging parameters */
-    public static final int CTL_HW = 6; /* generic cpu/io */
-    public static final int CTL_MACHDEP = 7; /* machine dependent */
-    public static final int CTL_USER = 8; /* user-level */
-    public static final int CTL_P1003_1B = 9; /* POSIX 1003.1B */
-    public static final int CTL_MAXID = 10; /* number of valid top-level ids */
-    public static final int KERN_OSTYPE = 1; /* string: system version */
-    public static final int KERN_OSRELEASE = 2; /* string: system release */
-    public static final int KERN_OSREV = 3; /* int: system revision */
-    public static final int KERN_VERSION = 4; /* string: compile time info */
-    public static final int KERN_MAXVNODES = 5; /* int: max vnodes */
-    public static final int KERN_MAXPROC = 6; /* int: max processes */
-    public static final int KERN_MAXFILES = 7; /* int: max open files */
-    public static final int KERN_ARGMAX = 8; /* int: max arguments to exec */
-    public static final int KERN_SECURELVL = 9; /* int: system security level */
-    public static final int KERN_HOSTNAME = 10; /* string: hostname */
-    public static final int KERN_HOSTID = 11; /* int: host identifier */
-    public static final int KERN_CLOCKRATE = 12; /* struct: struct clockrate */
-    public static final int KERN_VNODE = 13; /* struct: vnode structures */
-    public static final int KERN_PROC = 14; /* struct: process entries */
-    public static final int KERN_FILE = 15; /* struct: file entries */
-    public static final int KERN_PROF = 16; /* node: kernel profiling info */
-    public static final int KERN_POSIX1 = 17; /* int: POSIX.1 version */
-    public static final int KERN_NGROUPS = 18; /* int: # of supplemental group ids */
-    public static final int KERN_JOB_CONTROL = 19; /* int: is job control available */
-    public static final int KERN_SAVED_IDS = 20; /* int: saved set-user/group-ID */
-    public static final int KERN_BOOTTIME = 21; /* struct: time kernel was booted */
-    public static final int KERN_NISDOMAINNAME = 22; /* string: YP domain name */
-    public static final int KERN_UPDATEINTERVAL = 23; /* int: update process sleep time */
-    public static final int KERN_OSRELDATE = 24; /* int: OS release date */
-    public static final int KERN_NTP_PLL = 25; /* node: NTP PLL control */
-    public static final int KERN_BOOTFILE = 26; /* string: name of booted kernel */
-    public static final int KERN_MAXFILESPERPROC = 27; /* int: max open files per proc */
-    public static final int KERN_MAXPROCPERUID = 28; /* int: max processes per uid */
-    public static final int KERN_DUMPDEV = 29; /* dev_t: device to dump on */
-    public static final int KERN_IPC = 30; /* node: anything related to IPC */
-    public static final int KERN_DUMMY = 31; /* unused */
-    public static final int KERN_PS_STRINGS = 32; /* int: address of PS_STRINGS */
-    public static final int KERN_USRSTACK = 33; /* int: address of USRSTACK */
-    public static final int KERN_LOGSIGEXIT = 34; /* int: do we log sigexit procs? */
-    public static final int KERN_MAXID = 35; /* number of valid kern ids */
-    public static final int KERN_PROC_ALL = 0; /* everything */
-    public static final int KERN_PROC_PID = 1; /* by process id */
-    public static final int KERN_PROC_PGRP = 2; /* by process group id */
-    public static final int KERN_PROC_SESSION = 3; /* by session of pid */
-    public static final int KERN_PROC_TTY = 4; /* by controlling tty */
-    public static final int KERN_PROC_UID = 5; /* by effective uid */
-    public static final int KERN_PROC_RUID = 6; /* by real uid */
-    public static final int KERN_PROC_ARGS = 7; /* get/set arguments/proctitle */
-    public static final int KIPC_MAXSOCKBUF = 1; /* int: max size of a socket buffer */
-    public static final int KIPC_SOCKBUF_WASTE = 2; /* int: wastage factor in sockbuf */
-    public static final int KIPC_SOMAXCONN = 3; /* int: max length of connection q */
-    public static final int KIPC_MAX_LINKHDR = 4; /* int: max length of link header */
-    public static final int KIPC_MAX_PROTOHDR = 5; /* int: max length of network header */
-    public static final int KIPC_MAX_HDR = 6; /* int: max total length of headers */
-    public static final int KIPC_MAX_DATALEN = 7; /* int: max length of data? */
-    public static final int KIPC_MBSTAT = 8; /* struct: mbuf usage statistics */
-    public static final int KIPC_NMBCLUSTERS = 9; /* int: maximum mbuf clusters */
-    public static final int HW_MACHINE = 1; /* string: machine class */
-    public static final int HW_MODEL = 2; /* string: specific machine model */
-    public static final int HW_NCPU = 3; /* int: number of cpus */
-    public static final int HW_BYTEORDER = 4; /* int: machine byte order */
-    public static final int HW_PHYSMEM = 5; /* int: total memory */
-    public static final int HW_USERMEM = 6; /* int: non-kernel memory */
-    public static final int HW_PAGESIZE = 7; /* int: software page size */
-    public static final int HW_DISKNAMES = 8; /* strings: disk drive names */
-    public static final int HW_DISKSTATS = 9; /* struct: diskstats[] */
-    public static final int HW_FLOATINGPT = 10; /* int: has HW floating point? */
-    public static final int HW_MACHINE_ARCH = 11; /* string: machine architecture */
-    public static final int HW_MAXID = 12; /* number of valid hw ids */
-    public static final int USER_CS_PATH = 1; /* string: _CS_PATH */
-    public static final int USER_BC_BASE_MAX = 2; /* int: BC_BASE_MAX */
-    public static final int USER_BC_DIM_MAX = 3; /* int: BC_DIM_MAX */
-    public static final int USER_BC_SCALE_MAX = 4; /* int: BC_SCALE_MAX */
-    public static final int USER_BC_STRING_MAX = 5; /* int: BC_STRING_MAX */
-    public static final int USER_COLL_WEIGHTS_MAX = 6; /* int: COLL_WEIGHTS_MAX */
-    public static final int USER_EXPR_NEST_MAX = 7; /* int: EXPR_NEST_MAX */
-    public static final int USER_LINE_MAX = 8; /* int: LINE_MAX */
-    public static final int USER_RE_DUP_MAX = 9; /* int: RE_DUP_MAX */
-    public static final int USER_POSIX2_VERSION = 10; /* int: POSIX2_VERSION */
-    public static final int USER_POSIX2_C_BIND = 11; /* int: POSIX2_C_BIND */
-    public static final int USER_POSIX2_C_DEV = 12; /* int: POSIX2_C_DEV */
-    public static final int USER_POSIX2_CHAR_TERM = 13; /* int: POSIX2_CHAR_TERM */
-    public static final int USER_POSIX2_FORT_DEV = 14; /* int: POSIX2_FORT_DEV */
-    public static final int USER_POSIX2_FORT_RUN = 15; /* int: POSIX2_FORT_RUN */
-    public static final int USER_POSIX2_LOCALEDEF = 16; /* int: POSIX2_LOCALEDEF */
-    public static final int USER_POSIX2_SW_DEV = 17; /* int: POSIX2_SW_DEV */
-    public static final int USER_POSIX2_UPE = 18; /* int: POSIX2_UPE */
-    public static final int USER_STREAM_MAX = 19; /* int: POSIX2_STREAM_MAX */
-    public static final int USER_TZNAME_MAX = 20; /* int: POSIX2_TZNAME_MAX */
-    public static final int USER_MAXID = 21; /* number of valid user ids */
-    public static final int CTL_P1003_1B_ASYNCHRONOUS_IO = 1; /* boolean */
-    public static final int CTL_P1003_1B_MAPPED_FILES = 2; /* boolean */
-    public static final int CTL_P1003_1B_MEMLOCK = 3; /* boolean */
-    public static final int CTL_P1003_1B_MEMLOCK_RANGE = 4; /* boolean */
-    public static final int CTL_P1003_1B_MEMORY_PROTECTION = 5; /* boolean */
-    public static final int CTL_P1003_1B_MESSAGE_PASSING = 6; /* boolean */
-    public static final int CTL_P1003_1B_PRIORITIZED_IO = 7; /* boolean */
-    public static final int CTL_P1003_1B_PRIORITY_SCHEDULING = 8; /* boolean */
-    public static final int CTL_P1003_1B_REALTIME_SIGNALS = 9; /* boolean */
-    public static final int CTL_P1003_1B_SEMAPHORES = 10; /* boolean */
-    public static final int CTL_P1003_1B_FSYNC = 11; /* boolean */
-    public static final int CTL_P1003_1B_SHARED_MEMORY_OBJECTS = 12; /* boolean */
-    public static final int CTL_P1003_1B_SYNCHRONIZED_IO = 13; /* boolean */
-    public static final int CTL_P1003_1B_TIMERS = 14; /* boolean */
-    public static final int CTL_P1003_1B_AIO_LISTIO_MAX = 15; /* int */
-    public static final int CTL_P1003_1B_AIO_MAX = 16; /* int */
-    public static final int CTL_P1003_1B_AIO_PRIO_DELTA_MAX = 17; /* int */
-    public static final int CTL_P1003_1B_DELAYTIMER_MAX = 18; /* int */
-    public static final int CTL_P1003_1B_MQ_OPEN_MAX = 19; /* int */
-    public static final int CTL_P1003_1B_PAGESIZE = 20; /* int */
-    public static final int CTL_P1003_1B_RTSIG_MAX = 21; /* int */
-    public static final int CTL_P1003_1B_SEM_NSEMS_MAX = 22; /* int */
-    public static final int CTL_P1003_1B_SEM_VALUE_MAX = 23; /* int */
-    public static final int CTL_P1003_1B_SIGQUEUE_MAX = 24; /* int */
-    public static final int CTL_P1003_1B_TIMER_MAX = 25; /* int */
-    public static final int CTL_P1003_1B_MAXID = 26;
     public static final int EPERM = 1; /* Not super-user */
     public static final int ENOENT = 2; /* No such file or directory */
     public static final int ESRCH = 3; /* No such process */
@@ -424,6 +304,129 @@ public interface UsermodeConstants {
     public static final int EXPR_NEST_MAX = 32; /* max expressions nested in expr(1) */
     public static final int LINE_MAX = 2048; /* max bytes in an input line */
     public static final int RE_DUP_MAX = 255; /* max RE's in interval notation */
+    public static final int CTL_MAXNAME = 12;
+    public static final int CTL_UNSPEC = 0; /* unused */
+    public static final int CTL_KERN = 1; /* "high kernel": proc, limits */
+    public static final int CTL_VM = 2; /* virtual memory */
+    public static final int CTL_VFS = 3; /* file system, mount type is next */
+    public static final int CTL_NET = 4; /* network, see socket.h */
+    public static final int CTL_DEBUG = 5; /* debugging parameters */
+    public static final int CTL_HW = 6; /* generic cpu/io */
+    public static final int CTL_MACHDEP = 7; /* machine dependent */
+    public static final int CTL_USER = 8; /* user-level */
+    public static final int CTL_P1003_1B = 9; /* POSIX 1003.1B */
+    public static final int CTL_MAXID = 10; /* number of valid top-level ids */
+    public static final int KERN_OSTYPE = 1; /* string: system version */
+    public static final int KERN_OSRELEASE = 2; /* string: system release */
+    public static final int KERN_OSREV = 3; /* int: system revision */
+    public static final int KERN_VERSION = 4; /* string: compile time info */
+    public static final int KERN_MAXVNODES = 5; /* int: max vnodes */
+    public static final int KERN_MAXPROC = 6; /* int: max processes */
+    public static final int KERN_MAXFILES = 7; /* int: max open files */
+    public static final int KERN_ARGMAX = 8; /* int: max arguments to exec */
+    public static final int KERN_SECURELVL = 9; /* int: system security level */
+    public static final int KERN_HOSTNAME = 10; /* string: hostname */
+    public static final int KERN_HOSTID = 11; /* int: host identifier */
+    public static final int KERN_CLOCKRATE = 12; /* struct: struct clockrate */
+    public static final int KERN_VNODE = 13; /* struct: vnode structures */
+    public static final int KERN_PROC = 14; /* struct: process entries */
+    public static final int KERN_FILE = 15; /* struct: file entries */
+    public static final int KERN_PROF = 16; /* node: kernel profiling info */
+    public static final int KERN_POSIX1 = 17; /* int: POSIX.1 version */
+    public static final int KERN_NGROUPS = 18; /* int: # of supplemental group ids */
+    public static final int KERN_JOB_CONTROL = 19; /* int: is job control available */
+    public static final int KERN_SAVED_IDS = 20; /* int: saved set-user/group-ID */
+    public static final int KERN_BOOTTIME = 21; /* struct: time kernel was booted */
+    public static final int KERN_NISDOMAINNAME = 22; /* string: YP domain name */
+    public static final int KERN_UPDATEINTERVAL = 23; /* int: update process sleep time */
+    public static final int KERN_OSRELDATE = 24; /* int: OS release date */
+    public static final int KERN_NTP_PLL = 25; /* node: NTP PLL control */
+    public static final int KERN_BOOTFILE = 26; /* string: name of booted kernel */
+    public static final int KERN_MAXFILESPERPROC = 27; /* int: max open files per proc */
+    public static final int KERN_MAXPROCPERUID = 28; /* int: max processes per uid */
+    public static final int KERN_DUMPDEV = 29; /* dev_t: device to dump on */
+    public static final int KERN_IPC = 30; /* node: anything related to IPC */
+    public static final int KERN_DUMMY = 31; /* unused */
+    public static final int KERN_PS_STRINGS = 32; /* int: address of PS_STRINGS */
+    public static final int KERN_USRSTACK = 33; /* int: address of USRSTACK */
+    public static final int KERN_LOGSIGEXIT = 34; /* int: do we log sigexit procs? */
+    public static final int KERN_MAXID = 35; /* number of valid kern ids */
+    public static final int KERN_PROC_ALL = 0; /* everything */
+    public static final int KERN_PROC_PID = 1; /* by process id */
+    public static final int KERN_PROC_PGRP = 2; /* by process group id */
+    public static final int KERN_PROC_SESSION = 3; /* by session of pid */
+    public static final int KERN_PROC_TTY = 4; /* by controlling tty */
+    public static final int KERN_PROC_UID = 5; /* by effective uid */
+    public static final int KERN_PROC_RUID = 6; /* by real uid */
+    public static final int KERN_PROC_ARGS = 7; /* get/set arguments/proctitle */
+    public static final int KIPC_MAXSOCKBUF = 1; /* int: max size of a socket buffer */
+    public static final int KIPC_SOCKBUF_WASTE = 2; /* int: wastage factor in sockbuf */
+    public static final int KIPC_SOMAXCONN = 3; /* int: max length of connection q */
+    public static final int KIPC_MAX_LINKHDR = 4; /* int: max length of link header */
+    public static final int KIPC_MAX_PROTOHDR = 5; /* int: max length of network header */
+    public static final int KIPC_MAX_HDR = 6; /* int: max total length of headers */
+    public static final int KIPC_MAX_DATALEN = 7; /* int: max length of data? */
+    public static final int KIPC_MBSTAT = 8; /* struct: mbuf usage statistics */
+    public static final int KIPC_NMBCLUSTERS = 9; /* int: maximum mbuf clusters */
+    public static final int HW_MACHINE = 1; /* string: machine class */
+    public static final int HW_MODEL = 2; /* string: specific machine model */
+    public static final int HW_NCPU = 3; /* int: number of cpus */
+    public static final int HW_BYTEORDER = 4; /* int: machine byte order */
+    public static final int HW_PHYSMEM = 5; /* int: total memory */
+    public static final int HW_USERMEM = 6; /* int: non-kernel memory */
+    public static final int HW_PAGESIZE = 7; /* int: software page size */
+    public static final int HW_DISKNAMES = 8; /* strings: disk drive names */
+    public static final int HW_DISKSTATS = 9; /* struct: diskstats[] */
+    public static final int HW_FLOATINGPT = 10; /* int: has HW floating point? */
+    public static final int HW_MACHINE_ARCH = 11; /* string: machine architecture */
+    public static final int HW_MAXID = 12; /* number of valid hw ids */
+    public static final int USER_CS_PATH = 1; /* string: _CS_PATH */
+    public static final int USER_BC_BASE_MAX = 2; /* int: BC_BASE_MAX */
+    public static final int USER_BC_DIM_MAX = 3; /* int: BC_DIM_MAX */
+    public static final int USER_BC_SCALE_MAX = 4; /* int: BC_SCALE_MAX */
+    public static final int USER_BC_STRING_MAX = 5; /* int: BC_STRING_MAX */
+    public static final int USER_COLL_WEIGHTS_MAX = 6; /* int: COLL_WEIGHTS_MAX */
+    public static final int USER_EXPR_NEST_MAX = 7; /* int: EXPR_NEST_MAX */
+    public static final int USER_LINE_MAX = 8; /* int: LINE_MAX */
+    public static final int USER_RE_DUP_MAX = 9; /* int: RE_DUP_MAX */
+    public static final int USER_POSIX2_VERSION = 10; /* int: POSIX2_VERSION */
+    public static final int USER_POSIX2_C_BIND = 11; /* int: POSIX2_C_BIND */
+    public static final int USER_POSIX2_C_DEV = 12; /* int: POSIX2_C_DEV */
+    public static final int USER_POSIX2_CHAR_TERM = 13; /* int: POSIX2_CHAR_TERM */
+    public static final int USER_POSIX2_FORT_DEV = 14; /* int: POSIX2_FORT_DEV */
+    public static final int USER_POSIX2_FORT_RUN = 15; /* int: POSIX2_FORT_RUN */
+    public static final int USER_POSIX2_LOCALEDEF = 16; /* int: POSIX2_LOCALEDEF */
+    public static final int USER_POSIX2_SW_DEV = 17; /* int: POSIX2_SW_DEV */
+    public static final int USER_POSIX2_UPE = 18; /* int: POSIX2_UPE */
+    public static final int USER_STREAM_MAX = 19; /* int: POSIX2_STREAM_MAX */
+    public static final int USER_TZNAME_MAX = 20; /* int: POSIX2_TZNAME_MAX */
+    public static final int USER_MAXID = 21; /* number of valid user ids */
+    public static final int CTL_P1003_1B_ASYNCHRONOUS_IO = 1; /* boolean */
+    public static final int CTL_P1003_1B_MAPPED_FILES = 2; /* boolean */
+    public static final int CTL_P1003_1B_MEMLOCK = 3; /* boolean */
+    public static final int CTL_P1003_1B_MEMLOCK_RANGE = 4; /* boolean */
+    public static final int CTL_P1003_1B_MEMORY_PROTECTION = 5; /* boolean */
+    public static final int CTL_P1003_1B_MESSAGE_PASSING = 6; /* boolean */
+    public static final int CTL_P1003_1B_PRIORITIZED_IO = 7; /* boolean */
+    public static final int CTL_P1003_1B_PRIORITY_SCHEDULING = 8; /* boolean */
+    public static final int CTL_P1003_1B_REALTIME_SIGNALS = 9; /* boolean */
+    public static final int CTL_P1003_1B_SEMAPHORES = 10; /* boolean */
+    public static final int CTL_P1003_1B_FSYNC = 11; /* boolean */
+    public static final int CTL_P1003_1B_SHARED_MEMORY_OBJECTS = 12; /* boolean */
+    public static final int CTL_P1003_1B_SYNCHRONIZED_IO = 13; /* boolean */
+    public static final int CTL_P1003_1B_TIMERS = 14; /* boolean */
+    public static final int CTL_P1003_1B_AIO_LISTIO_MAX = 15; /* int */
+    public static final int CTL_P1003_1B_AIO_MAX = 16; /* int */
+    public static final int CTL_P1003_1B_AIO_PRIO_DELTA_MAX = 17; /* int */
+    public static final int CTL_P1003_1B_DELAYTIMER_MAX = 18; /* int */
+    public static final int CTL_P1003_1B_MQ_OPEN_MAX = 19; /* int */
+    public static final int CTL_P1003_1B_PAGESIZE = 20; /* int */
+    public static final int CTL_P1003_1B_RTSIG_MAX = 21; /* int */
+    public static final int CTL_P1003_1B_SEM_NSEMS_MAX = 22; /* int */
+    public static final int CTL_P1003_1B_SEM_VALUE_MAX = 23; /* int */
+    public static final int CTL_P1003_1B_SIGQUEUE_MAX = 24; /* int */
+    public static final int CTL_P1003_1B_TIMER_MAX = 25; /* int */
+    public static final int CTL_P1003_1B_MAXID = 26;
     public static final int F_UNLKSYS = 4;
     public static final int F_CNVT = 12;
     public static final int F_SETFD = 2;
index 2783a2f..ae5e738 100644 (file)
@@ -169,3 +169,6 @@ SYSCALL_R_LONG(getsockopt)
 SYSCALL_R(listen)
 SYSCALL_R(bind)
 SYSCALL_R(shutdown)
+SYSCALL_R_LONG(sendto)
+SYSCALL_R_LONG(recvfrom)
+SYSCALL_R_LONG(select)
index 05c83e0..97be5d9 100644 (file)
@@ -120,6 +120,9 @@ REENT_WRAPPER5(setsockopt,int,int,int,const void*,socklen_t)
 REENT_WRAPPER3(bind,int,const struct sockaddr *,socklen_t)
 REENT_WRAPPER2(listen,int,int)
 REENT_WRAPPER2(shutdown,int,int)
+REENT_WRAPPER6(sendto,int,const void*,size_t,int,const struct sockaddr*,socklen_t)
+REENT_WRAPPER6(recvfrom,int,void*,size_t,int,struct sockaddr*,socklen_t*)
+REENT_WRAPPER5(select,int,fd_set*,fd_set*,fd_set*,struct timeval*)
 
 extern int __execve_r(struct _reent *ptr, const char *path, char *const argv[], char *const envp[]);
 int _execve(const char *path, char *const argv[], char *const envp[]) {
index c9ce7ca..b89e9b0 100644 (file)
@@ -59,3 +59,6 @@
 #define SYS_listen 62
 #define SYS_bind 63
 #define SYS_shutdown 64
+#define SYS_sendto 65
+#define SYS_recvfrom 66
+#define SYS_select 67
index 0f6605a..7550e07 100755 (executable)
@@ -370,6 +370,7 @@ cat <<__EOF__ > nestedvm/socket.h
 #define __NESTEDVM_SOCKETS_H
 
 #include <sys/types.h>
+#include <sys/time.h>
 
 static unsigned short htons(int x) { return x; }
 static unsigned long htonl(int x) { return x; }
@@ -445,6 +446,9 @@ int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
 int shutdown(int s, int how);
 int connect(int s, const struct sockaddr *name, socklen_t namelen);
 char *inet_ntoa(struct in_addr in);
+int recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen);
+int sendto(int s, const void *msg, size_t len, int flags, const struct sockaddr *to, socklen_t tolen);
+int select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
 
 int getsockopt(int s, int level, int name, void *val, socklen_t *len);
 int setsockopt(int s, int level, int name, const void *val, socklen_t len);
index 5ad4113..0e23b8f 100644 (file)
@@ -1118,3 +1118,32 @@ diff -ur ../busybox-1.00-pre9.orig/util-linux/more.c ./util-linux/more.c
 +# Debugging Options
 +#
 +# CONFIG_DEBUG is not set
+--- .config.old        2004-06-08 16:02:45.000000000 -0400
++++ .config    2004-06-08 16:05:23.000000000 -0400
+@@ -309,7 +309,11 @@
+ # CONFIG_ROUTE is not set
+ # CONFIG_TELNET is not set
+ # CONFIG_TELNETD is not set
+-# CONFIG_TFTP is not set
++CONFIG_TFTP=y
++CONFIG_FEATURE_TFTP_GET=y
++CONFIG_FEATURE_TFTP_PUT=y
++# CONFIG_FEATURE_TFTP_BLOCKSIZE is not set
++# CONFIG_FEATURE_TFTP_DEBUG is not set
+ # CONFIG_TRACEROUTE is not set
+ # CONFIG_VCONFIG is not set
+ CONFIG_WGET=y
+--- networking/tftp.c~ 2004-06-08 16:50:30.000000000 -0400
++++ networking/tftp.c  2004-06-08 16:50:30.000000000 -0400
+@@ -320,7 +320,11 @@
+                       FD_ZERO(&rfds);
+                       FD_SET(socketfd, &rfds);
++#ifdef NESTEDVM
++                      switch(1) {
++#else
+                       switch (select(FD_SETSIZE, &rfds, NULL, NULL, &tv)) {
++#endif
+                       case 1:
+                               len = recvfrom(socketfd, buf, tftp_bufsize, 0,
+                                               (struct sockaddr *) &from, &fromlen);