X-Git-Url: http://git.megacz.com/?p=nestedvm.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fnestedvm%2Fsupport_aux.c;h=c3098993a3e54dd8959baf5ee771e063ffe65c72;hp=513434ef320f691f4dffecd5d579b39ce3fe67a0;hb=896193619af1e0534356ac622494ae77c7e42594;hpb=f26168c62381bad692b6ccd782ba73336bfce180 diff --git a/src/org/ibex/nestedvm/support_aux.c b/src/org/ibex/nestedvm/support_aux.c index 513434e..c309899 100644 --- a/src/org/ibex/nestedvm/support_aux.c +++ b/src/org/ibex/nestedvm/support_aux.c @@ -9,6 +9,10 @@ #include #include #include +#include +#include +#include +#include int _syscall_set_errno(struct _reent *ptr, int err) { ptr->_errno = -err; @@ -62,6 +66,16 @@ extern rt _##f##_r(struct _reent *ptr, t1 a, t2 b, t3 c, t4 d); \ 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 *) @@ -90,9 +104,21 @@ REENT_WRAPPER3(mknod,const char *,mode_t,dev_t) 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[]) { @@ -225,6 +251,67 @@ int closedir(DIR *dir) { } /* + * 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 2) + (void)close(fd); + } + return (0); +}