From: John Hodge (sonata) Date: Wed, 28 Nov 2012 08:51:23 +0000 (+0800) Subject: Usermode - A few tweaks to POSIX emulation for dropbear X-Git-Tag: rel0.15~641 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=05c45f4a7cf476f6e5d76df2307710d15cd18eb9;p=tpg%2Facess2.git Usermode - A few tweaks to POSIX emulation for dropbear --- diff --git a/Usermode/Libraries/ld-acess.so_src/include_exp/acess/sys.h b/Usermode/Libraries/ld-acess.so_src/include_exp/acess/sys.h index 88502b04..b5d0f0cf 100644 --- a/Usermode/Libraries/ld-acess.so_src/include_exp/acess/sys.h +++ b/Usermode/Libraries/ld-acess.so_src/include_exp/acess/sys.h @@ -48,7 +48,7 @@ extern int kill(int pid, int sig); extern int _SysWaitEvent(int EventMask); extern int waittid(int id, int *status); extern int clone(int flags, void *stack); -extern int execve(char *path, char **argv, char **envp); +extern int execve(const char *path, char **argv, char **envp); extern int _SysSpawn(const char *Path, const char **argv, const char **envp, int nFDs, int *FDs, struct s_sys_spawninfo *info); extern int gettid(void); extern int getpid(void); diff --git a/Usermode/Libraries/ld-acess.so_src/include_exp/sys/types.h b/Usermode/Libraries/ld-acess.so_src/include_exp/sys/types.h index f71aed21..36d2dba6 100644 --- a/Usermode/Libraries/ld-acess.so_src/include_exp/sys/types.h +++ b/Usermode/Libraries/ld-acess.so_src/include_exp/sys/types.h @@ -5,6 +5,11 @@ #include "../acess/intdefs.h" +typedef signed int ssize_t; +//#ifdef __USE_BSD +typedef unsigned int u_int; +//#endif + typedef struct stat t_fstat; #define FD_SETSIZE 128 diff --git a/Usermode/Libraries/ld-acess.so_src/include_exp/unistd.h b/Usermode/Libraries/ld-acess.so_src/include_exp/unistd.h index e1fee2e8..54a68476 100644 --- a/Usermode/Libraries/ld-acess.so_src/include_exp/unistd.h +++ b/Usermode/Libraries/ld-acess.so_src/include_exp/unistd.h @@ -9,11 +9,16 @@ #define O_WRONLY OPENFLAG_WRITE #define O_TRUNC OPENFLAG_TRUNCATE #define O_APPEND OPENFLAG_APPEND - -//typedef intptr_t ssize_t; +#define O_NONBLOCK 0 // TODO: #include "acess/sys.h" +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 + +static inline int fork(void) { return clone(CLONE_VM, 0); } +static inline int execv(const char *b,char *v[]) { return execve(b,v,NULL); } #endif diff --git a/Usermode/Libraries/libc.so_src/include_exp/stdlib.h b/Usermode/Libraries/libc.so_src/include_exp/stdlib.h index dbe557f7..7676afef 100644 --- a/Usermode/Libraries/libc.so_src/include_exp/stdlib.h +++ b/Usermode/Libraries/libc.so_src/include_exp/stdlib.h @@ -20,8 +20,11 @@ /* --- StdLib --- */ extern void _exit(int code) __attribute__((noreturn)); /* NOTE: Also defined in acess/sys.h */ + extern long long strtoll(const char *ptr, char **end, int base); extern long strtol(const char *ptr, char **end, int base); +extern unsigned long long strtoull(const char *ptr, char **end, int base); +extern unsigned long strtoul(const char *ptr, char **end, int base); extern int atoi(const char *ptr); extern void exit(int status) __attribute__((noreturn)); extern void abort(void); diff --git a/Usermode/Libraries/libc.so_src/stdlib.c b/Usermode/Libraries/libc.so_src/stdlib.c index 469f51c9..e15f49b4 100644 --- a/Usermode/Libraries/libc.so_src/stdlib.c +++ b/Usermode/Libraries/libc.so_src/stdlib.c @@ -71,9 +71,8 @@ EXPORT void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void } } -EXPORT long long strtoll(const char *str, char **end, int base) +EXPORT unsigned long long strtoull(const char *str, char **end, int base) { - int neg = 0; long long ret = 0; if( !str || base < 0 || base > 36 || base == 1 ) { @@ -86,12 +85,6 @@ EXPORT long long strtoll(const char *str, char **end, int base) while( isspace(*str) ) str++; - // Check for negative (or positive) sign - if(*str == '-' || *str == '+') { - neg = (*str == '-'); - str++; - } - if( base == 0 || base == 16 ) { if( *str == '0' && str[1] == 'x' ) { str += 2; @@ -129,14 +122,50 @@ EXPORT long long strtoll(const char *str, char **end, int base) str ++; } - if( neg ) - ret = -ret; - if(end) *end = (char*)str; return ret; } +EXPORT unsigned long strtoul(const char *ptr, char **end, int base) +{ + unsigned long long tmp = strtoull(ptr, end, base); + + if( tmp > ULONG_MAX ) { + errno = ERANGE; + return ULONG_MAX; + } + + return tmp; +} + +EXPORT long long strtoll(const char *str, char **end, int base) +{ + int neg = 0; + unsigned long long ret; + + if( !str ) { + errno = EINVAL; + return 0; + } + + while( isspace(*str) ) + str++; + + // Check for negative (or positive) sign + if(*str == '-' || *str == '+') { + neg = (*str == '-'); + str++; + } + + ret = strtoull(str, end, base); + + if( neg ) + return -ret; + else + return ret; +} + EXPORT long strtol(const char *str, char **end, int base) { long long tmp = strtoll(str, end, base); diff --git a/Usermode/Libraries/libposix.so_src/include_exp/fcntl.h b/Usermode/Libraries/libposix.so_src/include_exp/fcntl.h index 5fee9a11..ded9ba1e 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/fcntl.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/fcntl.h @@ -22,5 +22,12 @@ // Acess doesn't implement lseek #define lseek(_1,_2,_3) (seek(_1,_2,_3),tell(_1)) +enum e_fcntl_cmds +{ + F_SETFL +}; + +int fcntl(int fd, int cmd, ...) { return -1; } + #endif diff --git a/Usermode/Libraries/libposix.so_src/include_exp/sys/resource.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/resource.h index f9a64cb2..90308f23 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/sys/resource.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/sys/resource.h @@ -29,6 +29,15 @@ struct rlimit rlim_t rlim_max; }; +enum +{ + RLIMIT_AS, // Address space size + RLIMIT_CORE, // Max core file size + RLIMIT_CPU, // CPU time limit in s (SIGXCPU when reached) + RLIMIT_DATA, + // TODO: More? +}; + struct rusage { struct timeval ru_time; diff --git a/Usermode/Libraries/libpsocket.so_src/include_exp/netinet/in.h b/Usermode/Libraries/libpsocket.so_src/include_exp/netinet/in.h index 8abf7664..33e78659 100644 --- a/Usermode/Libraries/libpsocket.so_src/include_exp/netinet/in.h +++ b/Usermode/Libraries/libpsocket.so_src/include_exp/netinet/in.h @@ -22,7 +22,7 @@ struct sockaddr_in // getsockopt/setsockopt(level) enum { - IPPROTO_IP, + IPPROTO_IP = 1, IPPROTO_ICMP, IPPROTO_TCP, IPPROTO_UDP diff --git a/Usermode/Libraries/libpsocket.so_src/include_exp/netinet/tcp.h b/Usermode/Libraries/libpsocket.so_src/include_exp/netinet/tcp.h new file mode 100644 index 00000000..20cb4d3c --- /dev/null +++ b/Usermode/Libraries/libpsocket.so_src/include_exp/netinet/tcp.h @@ -0,0 +1,21 @@ +/* + * Acess2 POSIX Sockets Emulation + * - By John Hodge (thePowersGang) + * + * netinet/tcp.h + * - TCP Options + */ +#ifndef _NETINET__TCP_H_ +#define _NETINET__TCP_H_ + + +/** + * \brief Values for \a option_name in setsockopt/getsockopt + */ +enum eSockOpts_TCP +{ + TCP_NODELAY +}; + +#endif + diff --git a/Usermode/Libraries/libpsocket.so_src/include_exp/sys/socket.h b/Usermode/Libraries/libpsocket.so_src/include_exp/sys/socket.h index adc5a871..dc44ec68 100644 --- a/Usermode/Libraries/libpsocket.so_src/include_exp/sys/socket.h +++ b/Usermode/Libraries/libpsocket.so_src/include_exp/sys/socket.h @@ -17,9 +17,11 @@ typedef enum { AF_UNSPEC = 0, AF_PACKET = 1, + AF_LOCAL = 2, AF_INET = 4, AF_INET6 = 6, } sa_family_t; +#define AF_UNIX AF_LOCAL struct sockaddr { @@ -71,6 +73,7 @@ enum eSocketTypes */ enum eSocketDomains { + PF_UNSPEC, PF_LOCAL, //!< Machine-local comms PF_INET, //!< IPv4 PF_INET6, //!< IPv6 @@ -78,6 +81,20 @@ enum eSocketDomains }; #define PF_UNIX PF_LOCAL +// getsockopt/setsockopt level +enum +{ + SOL_SOCKET +}; + + +// SOL_SOCKET getsockopt/setsockopt names +enum +{ + SO_REUSEADDR, + SO_LINGER +}; + /** * \brief Create a new socket descriptor * \param domain Address family @@ -112,5 +129,8 @@ extern int send(int sockfd, void *buffer, size_t length, int flags); extern int setsockopt(int socket, int level, int option_name, const void *option_value, socklen_t option_len); extern int getsockopt(int socket, int level, int option_name, void *option_value, socklen_t *option_len); +extern int getsockname(int socket, struct sockaddr *addr, socklen_t *addrlen); +extern int getpeername(int socket, struct sockaddr *addr, socklen_t *addrlen); + #endif