echo "public interface UsermodeConstants {"; \
tr '\t' ' ' | sed -n ' \
s/ */ /g; \
- s/ *# *define \([A-Z_][A-Za-z0-9_]*\) \([0-9][0-9x]*\)/ public static final int \1 = \2;/p'; \
+ s/ *# *define \([A-Z_][A-Za-z0-9_]*\) \([0-9][0-9a-fA-Fx]*\)/ public static final int \1 = \2;/p'; \
echo "}"; \
) > src/org/ibex/nestedvm/UsermodeConstants.java
continue OUTER;
case 12: // SYSCALL
this.pc = pc;
- r[V0] = syscall(r[V0],r[A0],r[A1],r[A2],r[A3]);
+ r[V0] = syscall(r[V0],r[A0],r[A1],r[A2],r[A3],r[T0],r[T1]);
if(state != RUNNING) { this.pc = nextPC; break OUTER; }
break;
case 13: // BREAK
<i>syscall</i> should be the contents of V0 and <i>a</i>, <i>b</i>, <i>c</i>, and <i>d</i> should be
the contenst of A0, A1, A2, and A3. The call MAY change the state
@see Runtime#state state */
- protected final int syscall(int syscall, int a, int b, int c, int d) {
+ protected final int syscall(int syscall, int a, int b, int c, int d, int e, int f) {
try {
- return _syscall(syscall,a,b,c,d);
- } catch(ErrnoException e) {
- return -e.errno;
- } catch(FaultException e) {
+ int n = _syscall(syscall,a,b,c,d,e,f);
+ //if(n < 0) System.err.println("syscall: " + syscall + " returned " + n);
+ return n;
+ } catch(ErrnoException ex) {
+ //ex.printStackTrace();
+ return -ex.errno;
+ } catch(FaultException ex) {
return -EFAULT;
- } catch(RuntimeException e) {
- e.printStackTrace();
+ } catch(RuntimeException ex) {
+ ex.printStackTrace();
throw new Error("Internal Error in _syscall()");
}
}
- int _syscall(int syscall, int a, int b, int c, int d) throws ErrnoException, FaultException {
+ 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);
import org.ibex.nestedvm.util.*;
import java.io.*;
import java.util.*;
-import java.net.Socket;
-import java.net.ServerSocket;
+import java.net.*;
// FEATURE: vfork
}
}
- int _syscall(int syscall, int a, int b, int c, int d) throws ErrnoException, FaultException {
+ int _syscall(int syscall, int a, int b, int c, int d, int e, int f) throws ErrnoException, FaultException {
switch(syscall) {
case SYS_kill: return sys_kill(a,b);
case SYS_fork: return sys_fork();
case SYS_getdents: return sys_getdents(a,b,c,d);
case SYS_unlink: return sys_unlink(a);
case SYS_getppid: return sys_getppid();
- case SYS_opensocket: return sys_opensocket(a,b);
- case SYS_listensocket: return sys_listensocket(a);
- case SYS_accept: return sys_accept(a);
+ case SYS_socket: return sys_socket(a,b,c);
+ case SYS_connect: return sys_connect(a,b,c);
+ case SYS_resolve_hostname: return sys_resolve_hostname(a,b,c);
+ case SYS_setsockopt: return sys_setsockopt(a,b,c,d,e);
+ case SYS_getsockopt: return sys_getsockopt(a,b,c,d,e);
+ case SYS_bind: return sys_bind(a,b,c);
+ case SYS_listen: return sys_listen(a,b);
+ 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);
- default: return super._syscall(syscall,a,b,c,d);
+ default: return super._syscall(syscall,a,b,c,d,e,f);
}
}
case 28: // SIGWINCH
break;
default:
- return syscall(SYS_exit,128+signal,0,0,0);
+ // FEATURE: This is ugly, make a clean interface to sys_exit
+ return syscall(SYS_exit,128+signal,0,0,0,0,0);
}
return 0;
}
return n;
}
- private static class SocketFD extends InputOutputStreamFD {
- private final Socket s;
+ static class SocketFD extends FD {
+ public static final int TYPE_STREAM = 0;
+ public static final int TYPE_DGRAM = 1;
+ public static final int LISTEN = 2;
+ public int type() { return flags & 1; }
+ public boolean listen() { return (flags & 2) != 0; }
- public SocketFD(Socket s) throws IOException {
- super(s.getInputStream(),s.getOutputStream());
- this.s = s;
+ int flags;
+ int options;
+ Object o;
+ InetAddress bindAddr;
+ int bindPort = -1;
+ DatagramPacket dp;
+ InputStream is;
+ OutputStream os;
+
+ public SocketFD(int type) { flags = type; }
+
+ public void setOptions() {
+ try {
+ if(o != null && type() == TYPE_STREAM && !listen()) {
+ ((Socket)o).setKeepAlive((options & SO_KEEPALIVE) != 0);
+ }
+ } catch(SocketException e) {
+ if(STDERR_DIAG) e.printStackTrace();
+ }
}
- public void _close() { try { s.close(); } catch(IOException e) { } }
+ 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 */
+ }
+ }
+ }
+
+ 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 {
+ DatagramSocket ds = (DatagramSocket) o;
+ dp.setData(a,off,length);
+ try {
+ ds.receive(dp);
+ } catch(IOException e) {
+ throw new ErrnoException(EIO);
+ }
+ 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 {
+ DatagramSocket ds = (DatagramSocket) o;
+ dp.setData(a,off,length);
+ try {
+ ds.send(dp);
+ } catch(IOException e) {
+ throw new ErrnoException(EIO);
+ }
+ return dp.getLength();
+ }
+ }
+
+ // FEATURE: Check that these are correct
+ public int flags() {
+ if(is != null && os != null) return O_RDWR;
+ if(is != null) return O_RDONLY;
+ if(os != null) return O_WRONLY;
+ return 0;
+ }
+
+ // FEATURE: Populate this properly
+ public FStat _fstat() { return new FStat(); }
}
public int sys_opensocket(int cstring, int port) throws FaultException, ErrnoException {
} catch(IOException e) {
return -EIO;
}
- }
+ }*/
// FEATURE: Run through the fork/wait stuff one more time
public static class GlobalState {
public static final int SYS_usleep = 45;
public static final int SYS_getppid = 46;
public static final int SYS_mkfifo = 47;
- public static final int SYS_opensocket = 48;
- public static final int SYS_listensocket = 49;
- public static final int SYS_accept = 50;
+ public static final int SYS_klogctl = 51;
+ public static final int SYS_realpath = 52;
+ public static final int SYS_sysctl = 53;
+ public static final int SYS_setpriority = 54;
+ public static final int SYS_getpriority = 55;
+ public static final int SYS_socket = 56;
+ public static final int SYS_connect = 57;
+ public static final int SYS_resolve_hostname = 58;
+ public static final int SYS_accept = 59;
+ public static final int SYS_setsockopt = 60;
+ public static final int SYS_getsockopt = 61;
+ 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 AF_INET = 2;
+ public static final int SOCK_STREAM = 1;
+ public static final int SOCK_DGRAM = 2;
+ public static final int HOST_NOT_FOUND = 1;
+ public static final int TRY_AGAIN = 2;
+ public static final int NO_RECOVERY = 3;
+ public static final int NO_DATA = 4;
+ public static final int SOL_SOCKET = 0xffff;
+ public static final int SO_REUSEADDR = 0x0004;
+ public static final int SO_KEEPALIVE = 0x0008;
+ public static final int SHUT_RD = 0;
+ 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 */
#define a3 $7
#define t0 $8
#define t1 $9
+#define t2 $10
+#define t3 $11
+#define sp $29
#define ra $31
/* We intentionally don't take advantage of delay slots because
.end name;
#define SYSCALL_R(name) SYSCALL_R2(_##name##_r,SYS_##name)
+#define SYSCALL_R_LONG(name) SYSCALL_R2_LONG(_##name##_r,SYS_##name)
+
#define SYSCALL_R2(name,number) \
+ SYSCALL_R2_BEG(name,number) \
+ SYSCALL_R2_END(name)
+
+
+#define SYSCALL_R2_LONG(name,number) \
+ SYSCALL_R2_BEG(name,number) \
+ lw a3,16(sp); \
+ lw t0,20(sp); \
+ lw t1,24(sp); \
+ SYSCALL_R2_END(name)
+
+#define SYSCALL_R2_BEG(name,number) \
.section .text.name,"ax",@progbits; \
.align 2; \
.globl name; \
.ent name; \
name: \
li v0, number; \
- move t0, a0; \
+ move t2, a0; \
move a0, a1; \
move a1, a2; \
move a2, a3; \
+
+#define SYSCALL_R2_END(name) \
syscall; \
- addu t1,v0,255; \
- sltu t1,t1,255; \
- bne t1,zero,$L##name##_errno;\
+ addu t3,v0,255; \
+ sltu t3,t3,255; \
+ bne t3,zero,$L##name##_errno;\
nop; \
j ra; \
nop; \
$L##name##_errno: \
- move a0, t0; \
+ move a0, t2; \
move a1, v0; \
j _syscall_set_errno; \
nop; \
.globl _call_helper
.ent _call_helper
_call_helper:
- subu $sp,$sp,32
+ subu sp,sp,32
/* addr */
move $2,$4
move $7,$16
/* args 5 and 6 */
- sw $17,16($sp)
- sw $18,20($sp)
+ sw $17,16(sp)
+ sw $18,20(sp)
/* call the func */
jal $31,$2
SYSCALL_R(lstat)
SYSCALL_R(symlink)
SYSCALL_R(link)
-SYSCALL_R(getdents)
+SYSCALL_R_LONG(getdents)
/*SYSCALL(memcpy) */
/*SYSCALL(memset) */
SYSCALL_R(dup)
SYSCALL_R(usleep)
SYSCALL(getppid)
SYSCALL_R(mkfifo)
-SYSCALL_R2(__open_socket_r,SYS_opensocket)
-SYSCALL_R2(__listen_socket_r,SYS_listensocket)
-SYSCALL_R2(__accept_r,SYS_accept)
+SYSCALL_R(klogctl)
+SYSCALL_R(realpath)
+SYSCALL_R2_LONG(__sysctl_r,SYS_sysctl)
+SYSCALL_R(getpriority)
+SYSCALL_R(setpriority)
+SYSCALL_R(socket)
+SYSCALL_R(connect)
+SYSCALL_R2(__resolve_hostname_r,SYS_resolve_hostname)
+SYSCALL_R(accept)
+SYSCALL_R_LONG(setsockopt)
+SYSCALL_R_LONG(getsockopt)
+SYSCALL_R(listen)
+SYSCALL_R(bind)
+SYSCALL_R(shutdown)
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
+#include <sys/sysctl.h>
+#include <sys/utsname.h>
+#include <nestedvm/sockets.h>
+#include <paths.h>
int _syscall_set_errno(struct _reent *ptr, int err) {
ptr->_errno = -err;
rt f(t1 a, t2 b, t3 c, t4 d) { return _##f##_r(_REENT,a,b,c,d); }
#define REENT_WRAPPER4(f,t1,t2,t3,t4) REENT_WRAPPER4R(f,int,t1,t2,t3,t4)
+#define REENT_WRAPPER5R(f,rt,t1,t2,t3,t4,t5) \
+extern rt _##f##_r(struct _reent *ptr, t1 a, t2 b, t3 c, t4 d, t5 e); \
+rt f(t1 a, t2 b, t3 c, t4 d, t5 e) { return _##f##_r(_REENT,a,b,c,d,e); }
+#define REENT_WRAPPER5(f,t1,t2,t3,t4,t5) REENT_WRAPPER5R(f,int,t1,t2,t3,t4,t5)
+
+#define REENT_WRAPPER6R(f,rt,t1,t2,t3,t4,t5,t6) \
+extern rt _##f##_r(struct _reent *ptr, t1 a, t2 b, t3 c, t4 d, t5 e, t6 f); \
+rt f(t1 a, t2 b, t3 c, t4 d, t5 e, t6 f) { return _##f##_r(_REENT,a,b,c,d,e,f); }
+#define REENT_WRAPPER6(f,t1,t2,t3,t4,t5,t6) REENT_WRAPPER6R(f,int,t1,t2,t3,t4,t5,t6)
+
REENT_WRAPPER2(mkdir,const char *,mode_t)
REENT_WRAPPER2(access,const char *,int)
REENT_WRAPPER1(rmdir,const char *)
REENT_WRAPPER2(ftruncate,int,off_t)
REENT_WRAPPER1(usleep,unsigned int)
REENT_WRAPPER2(mkfifo,const char *, mode_t)
-REENT_WRAPPER2(_open_socket,const char *,int)
-REENT_WRAPPER1(_listen_socket,int)
-REENT_WRAPPER1(_accept,int)
+REENT_WRAPPER3(klogctl,int,char*,int)
+REENT_WRAPPER2R(realpath,char *,const char *,char *)
+REENT_WRAPPER6(_sysctl,int *,int, void *, size_t*, void *, size_t)
+REENT_WRAPPER6(sysctl,int *, int, void *, size_t*, void *, size_t)
+REENT_WRAPPER2(getpriority,int,int)
+REENT_WRAPPER3(setpriority,int,int,int)
+REENT_WRAPPER3(connect,int,const struct sockaddr *,socklen_t)
+REENT_WRAPPER3(socket,int,int,int)
+REENT_WRAPPER3(_resolve_hostname,const char *,char*,size_t*)
+REENT_WRAPPER3(accept,int,struct sockaddr *,socklen_t*)
+REENT_WRAPPER5(getsockopt,int,int,int,void*,socklen_t*)
+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)
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[]) {
}
/*
+ * Networking/Socket stuff
+ */
+
+/* This should really be part of the newlib _reent structure */
+int h_errno;
+
+char *inet_ntoa(struct in_addr in) {
+ static char buf[18];
+ const unsigned char *p = (void*) ∈
+ snprintf(buf,sizeof(buf),"%u.%u.%u.%u",p[0],p[1],p[2],p[3]);
+ return buf;
+}
+
+struct servent *getservbyname(const char *name,const char *proto) {
+ return NULL;
+}
+
+static const char *h_errlist[] = { "No Error","Unknown host", "Host name lookup failure","Unknown server error","No address associated with name" };
+
+const char *hstrerror(int err) {
+ if(err < 0 || err > 4) return "Unknown Error";
+ return h_errlist[err];
+}
+
+void herror(const char *string) {
+ fprintf(stderr,"%s: %s\n",string,hstrerror(h_errno));
+}
+
+extern int _resolve_hostname(const char *, char *buf, size_t *size);
+
+struct hostent *gethostbyname(const char *hostname) {
+#define MAX_ADDRS 256
+ static struct hostent hostent;
+ static char saved_hostname[128];
+ static char *addr_list[MAX_ADDRS+1];
+ static char addr_list_buf[MAX_ADDRS*sizeof(struct in_addr)];
+ static char *aliases[1];
+
+ unsigned char buf[MAX_ADDRS*sizeof(struct in_addr)];
+ size_t size = sizeof(buf);
+ int err,i,n=0;
+
+ err = _resolve_hostname(hostname,buf,&size);
+ if(err != 0) { h_errno = err; return NULL; }
+
+ memcpy(addr_list_buf,buf,size);
+ for(i=0;i<size;i += sizeof(struct in_addr)) addr_list[n++] = &addr_list_buf[i];
+ addr_list[n] = NULL;
+ strncpy(saved_hostname,hostname,sizeof(saved_hostname));
+ aliases[0] = NULL;
+
+ hostent.h_name = saved_hostname;
+ hostent.h_aliases = aliases;
+ hostent.h_addrtype = AF_INET;
+ hostent.h_length = sizeof(struct in_addr);
+ hostent.h_addr_list = addr_list;
+
+ return &hostent;
+}
+
+/*
* Other People's Code
*/
return(bname);
}
+
+/* FreeBSD's daemon() - modified for nestedvm */
+int
+daemon(nochdir, noclose)
+int nochdir, noclose;
+{
+ int fd;
+
+ switch (fork()) {
+ case -1:
+ return (-1);
+ case 0:
+ break;
+ default:
+ _exit(0);
+ }
+
+ /*if (setsid() == -1)
+ return (-1);*/
+
+ if (!nochdir)
+ (void)chdir("/");
+
+ if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
+ (void)dup2(fd, STDIN_FILENO);
+ (void)dup2(fd, STDOUT_FILENO);
+ (void)dup2(fd, STDERR_FILENO);
+ if (fd > 2)
+ (void)close(fd);
+ }
+ return (0);
+}
#define SYS_usleep 45
#define SYS_getppid 46
#define SYS_mkfifo 47
-#define SYS_opensocket 48
-#define SYS_listensocket 49
-#define SYS_accept 50
+#define SYS_klogctl 51
+#define SYS_realpath 52
+#define SYS_sysctl 53
+#define SYS_setpriority 54
+#define SYS_getpriority 55
+#define SYS_socket 56
+#define SYS_connect 57
+#define SYS_resolve_hostname 58
+#define SYS_accept 59
+#define SYS_setsockopt 60
+#define SYS_getsockopt 61
+#define SYS_listen 62
+#define SYS_bind 63
+#define SYS_shutdown 64
task.closeFD(0);
task.closeFD(1);
//task.closeFD(2);
- task.addFD(new Runtime.InputStreamFD(sock.getInputStream()));
- task.addFD(new Runtime.OutputStreamFD(sock.getOutputStream()));
+ task.addFD(new Runtime.InputOutputStreamFD(sock.getInputStream()));
+ task.addFD(new Runtime.InputOutputStreamFD(sock.getOutputStream()));
//task.dupFD(1);
int status = task.run(new String[]{"EchoHelper"} );