diff --git a/.gitignore b/.gitignore index 53b1ce827..59dbfcbcd 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ agents/iguana agents/libcrypto777.a + +agents/iguana.exe diff --git a/README.md b/README.md index 1771d2364..8962b01e1 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,9 @@ Just make sure you have the dev versions of openssl and curl installed: ```sudo apt-get install libcurl4-gnutls-dev libssl-dev``` ##For native (win32, win64)## -This still needs to be ported, pthreads is the only non-native windows system functions being used. OS_portable.c and OS_nonportable.c have the few windows functions that are needed to be ported and also a compile/link process needs to be done. I think cygwin or even mingw would work, alternatively compiling the codebase with VS shouldnt be too much work. Until this is done the instructions below about m_win32 and m_win64 wont actually work. +TOOL_DIR := /usr/local/gcc-4.8.0-qt-4.8.4-for-mingw32/win32-gcc/bin +MINGW := i586-mingw32 +The above two definitions need to be changed to match the mingw install on your system. m_win32 and m_win64 just invokes the makefile in mingw32 and mingw64 ##For chrome app## You need to make sure the nacl sdk is properly installed and you are able to build the examples. diff --git a/crypto777/OS_nonportable.c b/crypto777/OS_nonportable.c index cebcd1ee2..42b8db96e 100755 --- a/crypto777/OS_nonportable.c +++ b/crypto777/OS_nonportable.c @@ -30,7 +30,6 @@ void *OS_nonportable_tmpalloc(char *dirname,char *name,struct OS_memspace *mem,l } #elif _WIN32 -#include #include #include #include @@ -38,7 +37,6 @@ void *OS_nonportable_tmpalloc(char *dirname,char *name,struct OS_memspace *mem,l #include #include #include -#include #include #include #include /* _O_BINARY */ @@ -49,6 +47,449 @@ void *OS_nonportable_tmpalloc(char *dirname,char *name,struct OS_memspace *mem,l #include #include +#include +#include +#include + +#include "../win/mman.h" + +#ifndef FILE_MAP_EXECUTE +#define FILE_MAP_EXECUTE 0x0020 +#endif /* FILE_MAP_EXECUTE */ + +static int __map_mman_error(const DWORD err, const int deferr) +{ + if (err == 0) + return 0; + //TODO: implement + return err; +} + +static DWORD __map_mmap_prot_page(const int prot) +{ + DWORD protect = 0; + + if (prot == PROT_NONE) + return protect; + + if ((prot & PROT_EXEC) != 0) + { + protect = ((prot & PROT_WRITE) != 0) ? + PAGE_EXECUTE_READWRITE : PAGE_EXECUTE_READ; + } + else + { + protect = ((prot & PROT_WRITE) != 0) ? + PAGE_READWRITE : PAGE_READONLY; + } + + return protect; +} + +static DWORD __map_mmap_prot_file(const int prot) +{ + DWORD desiredAccess = 0; + + if (prot == PROT_NONE) + return desiredAccess; + + if ((prot & PROT_READ) != 0) + desiredAccess |= FILE_MAP_READ; + if ((prot & PROT_WRITE) != 0) + desiredAccess |= FILE_MAP_WRITE; + if ((prot & PROT_EXEC) != 0) + desiredAccess |= FILE_MAP_EXECUTE; + + return desiredAccess; +} + +void* mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off) +{ + HANDLE fm, h; + + void * map = MAP_FAILED; + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4293) +#endif + + const DWORD dwFileOffsetLow = (sizeof(off_t) <= sizeof(DWORD)) ? + (DWORD)off : (DWORD)(off & 0xFFFFFFFFL); + const DWORD dwFileOffsetHigh = (sizeof(off_t) <= sizeof(DWORD)) ? + (DWORD)0 : (DWORD)((off >> 32) & 0xFFFFFFFFL); + const DWORD protect = __map_mmap_prot_page(prot); + const DWORD desiredAccess = __map_mmap_prot_file(prot); + + const off_t maxSize = off + (off_t)len; + + const DWORD dwMaxSizeLow = (sizeof(off_t) <= sizeof(DWORD)) ? + (DWORD)maxSize : (DWORD)(maxSize & 0xFFFFFFFFL); + const DWORD dwMaxSizeHigh = (sizeof(off_t) <= sizeof(DWORD)) ? + (DWORD)0 : (DWORD)((maxSize >> 32) & 0xFFFFFFFFL); + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + + errno = 0; + + if (len == 0 + /* Unsupported flag combinations */ + || (flags & MAP_FIXED) != 0 + /* Usupported protection combinations */ + || prot == PROT_EXEC) + { + errno = EINVAL; + return MAP_FAILED; + } + + h = ((flags & MAP_ANONYMOUS) == 0) ? + (HANDLE)_get_osfhandle(fildes) : INVALID_HANDLE_VALUE; + + if ((flags & MAP_ANONYMOUS) == 0 && h == INVALID_HANDLE_VALUE) + { + errno = EBADF; + return MAP_FAILED; + } + + fm = CreateFileMapping(h, NULL, protect, dwMaxSizeHigh, dwMaxSizeLow, NULL); + + if (fm == NULL) + { + errno = __map_mman_error(GetLastError(), EPERM); + return MAP_FAILED; + } + + map = MapViewOfFile(fm, desiredAccess, dwFileOffsetHigh, dwFileOffsetLow, len); + + CloseHandle(fm); + + if (map == NULL) + { + errno = __map_mman_error(GetLastError(), EPERM); + return MAP_FAILED; + } + + return map; +} + +int munmap(void *addr, size_t len) +{ + if (UnmapViewOfFile(addr)) + return 0; + + errno = __map_mman_error(GetLastError(), EPERM); + + return -1; +} + +int _mprotect(void *addr, size_t len, int prot) +{ + DWORD newProtect = __map_mmap_prot_page(prot); + DWORD oldProtect = 0; + + if (VirtualProtect(addr, len, newProtect, &oldProtect)) + return 0; + + errno = __map_mman_error(GetLastError(), EPERM); + + return -1; +} + +int msync(void *addr, size_t len, int flags) +{ + if (FlushViewOfFile(addr, len)) + return 0; + + errno = __map_mman_error(GetLastError(), EPERM); + + return -1; +} + +int mlock(const void *addr, size_t len) +{ + if (VirtualLock((LPVOID)addr, len)) + return 0; + + errno = __map_mman_error(GetLastError(), EPERM); + + return -1; +} + +int munlock(const void *addr, size_t len) +{ + if (VirtualUnlock((LPVOID)addr, len)) + return 0; + + errno = __map_mman_error(GetLastError(), EPERM); + + return -1; +} + +#undef socket +#undef connect +#undef accept +#undef shutdown + +#include +#include +#include + +int win32_poll(struct pollfd *fds, unsigned int nfds, int timo) +{ + struct timeval timeout, *toptr; + fd_set ifds, ofds, efds, *ip, *op; + unsigned int i, rc; + + /* Set up the file-descriptor sets in ifds, ofds and efds. */ + FD_ZERO(&ifds); + FD_ZERO(&ofds); + FD_ZERO(&efds); + for (i = 0, op = ip = 0; i < nfds; ++i) { + fds[i].revents = 0; + if(fds[i].events & (POLLIN|POLLPRI)) { + ip = &ifds; + FD_SET(fds[i].fd, ip); + } + if(fds[i].events & POLLOUT) { + op = &ofds; + FD_SET(fds[i].fd, op); + } + FD_SET(fds[i].fd, &efds); + } + + /* Set up the timeval structure for the timeout parameter */ + if(timo < 0) { + toptr = 0; + } else { + toptr = &timeout; + timeout.tv_sec = timo / 1000; + timeout.tv_usec = (timo - timeout.tv_sec * 1000) * 1000; + } + +#ifdef DEBUG_POLL + printf("Entering select() sec=%ld usec=%ld ip=%lx op=%lx\n", + (long)timeout.tv_sec, (long)timeout.tv_usec, (long)ip, (long)op); +#endif + rc = select(0, ip, op, &efds, toptr); +#ifdef DEBUG_POLL + printf("Exiting select rc=%d\n", rc); +#endif + + if(rc <= 0) + return rc; + + if(rc > 0) { + for ( i = 0; i < nfds; ++i) { + int fd = fds[i].fd; + if(fds[i].events & (POLLIN|POLLPRI) && FD_ISSET(fd, &ifds)) + fds[i].revents |= POLLIN; + if(fds[i].events & POLLOUT && FD_ISSET(fd, &ofds)) + fds[i].revents |= POLLOUT; + if(FD_ISSET(fd, &efds)) + /* Some error was detected ... should be some way to know. */ + fds[i].revents |= POLLHUP; +#ifdef DEBUG_POLL + printf("%d %d %d revent = %x\n", + FD_ISSET(fd, &ifds), FD_ISSET(fd, &ofds), FD_ISSET(fd, &efds), + fds[i].revents + ); +#endif + } + } + return rc; +} +static void +set_connect_errno(int winsock_err) +{ + switch(winsock_err) { + case WSAEINVAL: + case WSAEALREADY: + case WSAEWOULDBLOCK: + errno = EINPROGRESS; + break; + default: + errno = winsock_err; + break; + } +} + +static void +set_socket_errno(int winsock_err) +{ + switch(winsock_err) { + case WSAEWOULDBLOCK: + errno = EAGAIN; + break; + default: + errno = winsock_err; + break; + } +} +/* + * A wrapper around the socket() function. The purpose of this wrapper + * is to ensure that the global errno symbol is set if an error occurs, + * even if we are using winsock. + */ +SOCKET +win32_socket(int domain, int type, int protocol) +{ + SOCKET fd = socket(domain, type, protocol); + if(fd == INVALID_SOCKET) { + set_socket_errno(WSAGetLastError()); + } + return fd; +} +/* + * A wrapper around the connect() function. The purpose of this wrapper + * is to ensure that the global errno symbol is set if an error occurs, + * even if we are using winsock. + */ +int +win32_connect(SOCKET fd, struct sockaddr *addr, socklen_t addr_len) +{ + int rc = connect(fd, addr, addr_len); + assert(rc == 0 || rc == SOCKET_ERROR); + if(rc == SOCKET_ERROR) { + set_connect_errno(WSAGetLastError()); + } + return rc; +} + +/* + * A wrapper around the accept() function. The purpose of this wrapper + * is to ensure that the global errno symbol is set if an error occurs, + * even if we are using winsock. + */ +SOCKET +win32_accept(SOCKET fd, struct sockaddr *addr, socklen_t *addr_len) +{ + SOCKET newfd = accept(fd, addr, addr_len); + if(newfd == INVALID_SOCKET) { + set_socket_errno(WSAGetLastError()); + newfd = -1; + } + return newfd; +} + +/* + * A wrapper around the shutdown() function. The purpose of this wrapper + * is to ensure that the global errno symbol is set if an error occurs, + * even if we are using winsock. + */ +int +win32_shutdown(SOCKET fd, int mode) +{ + int rc = shutdown(fd, mode); + assert(rc == 0 || rc == SOCKET_ERROR); + if(rc == SOCKET_ERROR) { + set_socket_errno(WSAGetLastError()); + } + return rc; +} + +int win32_close_socket(SOCKET fd) +{ + int rc = closesocket(fd); + if(rc == SOCKET_ERROR) { + set_socket_errno(WSAGetLastError()); + } + return rc; +} + +ssize_t win32_write_socket(SOCKET fd, void *buf, int n) +{ + int rc = send(fd, buf, n, 0); + if(rc == SOCKET_ERROR) { + set_socket_errno(WSAGetLastError()); + } + return rc; +} + +ssize_t win32_read_socket(SOCKET fd, void *buf, int n) +{ + int rc = recv(fd, buf, n, 0); + if(rc == SOCKET_ERROR) { + set_socket_errno(WSAGetLastError()); + } + return rc; +} + + +char * win32_strtok_r(char *s, const char *delim, char **lasts) +{ + register char *spanp; + register int c, sc; + char *tok; + + + if (s == NULL && (s = *lasts) == NULL) + return (NULL); + + /* + * Skip (span) leading delimiters (s += strspn(s, delim), sort of). + */ +cont: + c = *s++; + for (spanp = (char *)delim; (sc = *spanp++) != 0;) { + if (c == sc) + goto cont; + } + + if (c == 0) { /* no non-delimiter characters */ + *lasts = NULL; + return (NULL); + } + tok = s - 1; + + /* + * Scan token (scan for delimiters: s += strcspn(s, delim), sort of). + * Note that delim must have one NUL; we stop if we see that, too. + */ + for (;;) { + c = *s++; + spanp = (char *)delim; + do { + if ((sc = *spanp++) == c) { + if (c == 0) + s = NULL; + else + s[-1] = 0; + *lasts = s; + return (tok); + } + } while (sc != 0); + } + /* NOTREACHED */ +} + +char *win32_strsep (char **stringp, const char *delim) +{ + register char *s; + register const char *spanp; + register int c, sc; + char *tok; + + if ((s = *stringp) == NULL) + return (NULL); + for (tok = s;;) { + c = *s++; + spanp = delim; + do { + if ((sc = *spanp++) == c) { + if (c == 0) + s = NULL; + else + s[-1] = 0; + *stringp = s; + return (tok); + } + } while (sc != 0); + } + /* NOTREACHED */ +} + char *OS_nonportable_path(char *str) { int32_t i; @@ -92,10 +533,10 @@ void *OS_nonportable_mapfile(char *fname,uint64_t *filesizep,int32_t enablewrite int32_t OS_nonportable_renamefile(char *fname,char *newfname) { char cmdstr[1024],tmp[512]; - strcpt(tmp,fname); + strcpy(tmp,fname); OS_nonportable_path(tmp); sprintf(cmdstr,"del %s",tmp); - if ( system() != 0 ) + if ( system(cmdstr) != 0 ) printf("error deleting file.(%s)\n",cmdstr); else return(1); } diff --git a/crypto777/OS_portable.c b/crypto777/OS_portable.c index fe1b63fe0..fd8bb8b4a 100755 --- a/crypto777/OS_portable.c +++ b/crypto777/OS_portable.c @@ -63,12 +63,18 @@ void OS_portable_randombytes(unsigned char *x,long xlen) int32_t OS_portable_truncate(char *fname,long filesize) { +#ifdef _WIN32 + printf("need to implement truncate()\n"); + return(-1); +#else return(truncate(fname,filesize)); +#endif } char *OS_portable_path(char *str) { #ifdef _WIN32 + char *OS_nonportable_path(char *str); return(OS_nonportable_path(str)); #else return(str); @@ -79,10 +85,10 @@ int32_t OS_portable_renamefile(char *fname,char *newfname) { #ifdef _WIN32 char cmdstr[1024],tmp[512]; - strcpt(tmp,fname); - iguana_compatible_path(tmp); + strcpy(tmp,fname); + OS_portable_path(tmp); sprintf(cmdstr,"del %s",tmp); - if ( system() != 0 ) + if ( system(cmdstr) != 0 ) printf("error deleting file.(%s)\n",cmdstr); else return(1); #else @@ -94,10 +100,10 @@ int32_t OS_portable_removefile(char *fname) { #ifdef _WIN32 char cmdstr[1024],tmp[512]; - strcpt(tmp,fname); - iguana_compatible_path(tmp); + strcpy(tmp,fname); + OS_portable_path(tmp); sprintf(cmdstr,"del %s",tmp); - if ( system() != 0 ) + if ( system(cmdstr) != 0 ) printf("error deleting file.(%s)\n",cmdstr); else return(1); #else @@ -108,7 +114,8 @@ int32_t OS_portable_removefile(char *fname) void *OS_portable_mapfile(char *fname,long *filesizep,int32_t enablewrite) { #ifdef _WIN32 - return(OS_nonportable_mapfile(fname,filesizep,enablewrite); + void *OS_nonportable_mapfile(char *fname,long *filesizep,int32_t enablewrite); + return(OS_nonportable_mapfile(fname,filesizep,enablewrite)); #else int32_t fd,rwflags,flags = MAP_FILE|MAP_SHARED; uint64_t filesize; diff --git a/crypto777/OS_portable.h b/crypto777/OS_portable.h index 011f1f6ac..b04c31840 100755 --- a/crypto777/OS_portable.h +++ b/crypto777/OS_portable.h @@ -24,19 +24,31 @@ #include #include #include -#include -#include #include -#include -#include +#include #include -#include #include + +#ifdef __MINGW +#define sleep(x) Sleep(1000*(x)) +#include "../win/mingw.h" +#include "../win/mman.h" + +#else +#include +#include +#include +#include #include +#include +#define closesocket close +#endif + #include "../includes/libgfshare.h" #include "../includes/utlist.h" #include "../includes/uthash.h" #include "../includes/curve25519.h" +#include "../includes/cJSON.h" #ifndef MAP_FILE #define MAP_FILE 0 diff --git a/crypto777/OS_time.c b/crypto777/OS_time.c index edb63b67e..a2e614da8 100755 --- a/crypto777/OS_time.c +++ b/crypto777/OS_time.c @@ -42,6 +42,10 @@ struct tm *gmtime_r(const time_t *timep,struct tm *result) return(p); } +struct tm *_gmtime32(const time_t *timep,struct tm *result) { return(gmtime_r(timep,result)); } +time_t _time32(struct tm *tm) { return(time(NULL)); } +time_t _localtime32(struct tm *tm) { return(time(NULL)); } + #include #include // portable: uint64_t MSVC: __int64 diff --git a/crypto777/hmac/tiger.c b/crypto777/hmac/tiger.c index 6958cf54d..714454692 100755 --- a/crypto777/hmac/tiger.c +++ b/crypto777/hmac/tiger.c @@ -37,7 +37,7 @@ const struct ltc_hash_descriptor tiger_desc = }; #define t1 (table) -#define t2 (table+256) +#define t256 (table+256) #define t3 (table+256*2) #define t4 (table+256*3) @@ -566,8 +566,8 @@ INLINE static void tiger_round(ulong64 *a, ulong64 *b, ulong64 *c, ulong64 x, in { ulong64 tmp; tmp = (*c ^= x); - *a -= t1[byte(tmp, 0)] ^ t2[byte(tmp, 2)] ^ t3[byte(tmp, 4)] ^ t4[byte(tmp, 6)]; - tmp = (*b += t4[byte(tmp, 1)] ^ t3[byte(tmp, 3)] ^ t2[byte(tmp,5)] ^ t1[byte(tmp,7)]); + *a -= t1[byte(tmp, 0)] ^ t256[byte(tmp, 2)] ^ t3[byte(tmp, 4)] ^ t4[byte(tmp, 6)]; + tmp = (*b += t4[byte(tmp, 1)] ^ t3[byte(tmp, 3)] ^ t256[byte(tmp,5)] ^ t1[byte(tmp,7)]); switch (mul) { case 5: *b = (tmp << 2) + tmp; break; case 7: *b = (tmp << 3) - tmp; break; diff --git a/crypto777/iguana_OS.c b/crypto777/iguana_OS.c index 3bea4383a..d840fcfaf 100755 --- a/crypto777/iguana_OS.c +++ b/crypto777/iguana_OS.c @@ -118,7 +118,7 @@ void *queueitem(char *str) } item->allocsize = (uint32_t)allocsize; item->type = type; - data = (void *)((uint64_t)item + sizeof(*item)); + data = (void *)(long)((long)item + sizeof(*item)); memcpy(data,str,n); //printf("(%c) queueitem.%p itemdata.%p n.%d allocsize.%d\n",type,item,data,n,allocsize); //portable_mutex_unlock(&MEMmutex); @@ -400,7 +400,7 @@ void *iguana_memalloc(struct OS_memspace *mem,long size,int32_t clearflag) #endif if ( (mem->used + size) <= mem->totalsize ) { - ptr = (void *)((uint64_t)mem->ptr + (uint64_t)mem->used); + ptr = (void *)(long)((long)(mem->ptr + mem->used)); mem->used += size; if ( size*clearflag != 0 ) memset(ptr,0,size); diff --git a/crypto777/inet.c b/crypto777/inet.c index f5c0f1777..ff0b486a6 100755 --- a/crypto777/inet.c +++ b/crypto777/inet.c @@ -16,34 +16,25 @@ */ -#ifdef DEFINES_ONLY #ifndef crypto777_inet_h #define crypto777_inet_h -#include -#include -#include -#include -#include -#include -#ifdef _WIN32 -#include -#else -#include "../includes/nonportable.h" -#endif -#include -#include -#include - -#endif -#else +#include "OS_portable.h" -#ifndef crypto777_system777_c -#define crypto777_system777_c +#ifdef _WIN32 +#include +#include +#include +#define in6_addr sockaddr +#define in_addr_t struct sockaddr_storage +#define EAFNOSUPPORT WSAEAFNOSUPPORT -#ifndef crypto777_system777_h -#define DEFINES_ONLY -#include "inet.c" -#undef DEFINES_ONLY +struct sockaddr_in6 { + short sin6_family; + u_short sin6_port; + u_long sin6_flowinfo; + struct in6_addr sin6_addr; + u_long sin6_scope_id; +}; #endif static int inet_ntop4(unsigned char *src, char *dst, size_t size); @@ -502,7 +493,7 @@ char *conv_ipv6(char *ipv6addr) char ipv4str[4096]; struct sockaddr_in6 ipv6sa; in_addr_t *ipv4bin; - unsigned char *bytes; + unsigned char *bytes = 0; int32_t isok; memset(IPV4CHECK,0,sizeof(IPV4CHECK)); strcpy(ipv4str,ipv6addr); @@ -511,7 +502,12 @@ char *conv_ipv6(char *ipv6addr) isok = portable_pton(AF_INET6,ipv6addr,&ipv6sa.sin6_addr); if ( isok == 0 ) { +#ifdef _WIN32 + printf("need to figure this out for win32\n"); + //bytes = ((struct sockaddr_in6 *)&ipv6sa)->sin6_addr.s6_addr; +#else bytes = ((struct sockaddr_in6 *)&ipv6sa)->sin6_addr.s6_addr; +#endif if ( memcmp(bytes,IPV4CHECK,sizeof(IPV4CHECK)) != 0 ) // check its IPV4 really { bytes += 12; @@ -601,5 +597,4 @@ uint16_t parse_endpoint(int32_t *ip6flagp,char *transport,char *ipbuf,char *retb } #endif -#endif diff --git a/libs/libcrypto.a b/crypto777/pnacl_libs/libcrypto.a similarity index 100% rename from libs/libcrypto.a rename to crypto777/pnacl_libs/libcrypto.a diff --git a/libs/libcurl.a b/crypto777/pnacl_libs/libcurl.a similarity index 100% rename from libs/libcurl.a rename to crypto777/pnacl_libs/libcurl.a diff --git a/libs/libnanomsg.a b/crypto777/pnacl_libs/libnanomsg.a similarity index 100% rename from libs/libnanomsg.a rename to crypto777/pnacl_libs/libnanomsg.a diff --git a/libs/libssl.a b/crypto777/pnacl_libs/libssl.a similarity index 100% rename from libs/libssl.a rename to crypto777/pnacl_libs/libssl.a diff --git a/libs/libz.a b/crypto777/pnacl_libs/libz.a similarity index 100% rename from libs/libz.a rename to crypto777/pnacl_libs/libz.a diff --git a/deprecated/iguana_recv.c b/deprecated/iguana_recv.c new file mode 100755 index 000000000..281fe6e05 --- /dev/null +++ b/deprecated/iguana_recv.c @@ -0,0 +1,887 @@ +/****************************************************************************** + * Copyright © 2014-2015 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#include "iguana777.h" + +// peer context, ie massively multithreaded -> bundlesQ + +struct iguana_bundlereq *iguana_bundlereq(struct iguana_info *coin,struct iguana_peer *addr,int32_t type,int32_t datalen) +{ + struct iguana_bundlereq *req; int32_t allocsize; + allocsize = (uint32_t)sizeof(*req) + datalen; + req = mycalloc(type,1,allocsize); + req->allocsize = allocsize; + req->datalen = datalen; + req->addr = addr; + req->coin = coin; + req->type = type; + return(req); +} + +/*struct iguana_block *iguana_blockrequest(struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2,uint32_t now,int32_t iamthreadsafe) +{ + struct iguana_block *block = 0; + if( bp != 0 && bundlei >= 0 && bundlei < bp->n ) + block = bp->blocks[bundlei]; + if ( block == 0 && iamthreadsafe != 0 ) + block = iguana_blockfind(coin,hash2); + if ( block != 0 ) + { + //block->issued = now; + if ( block->numrequests < 100 ) + block->numrequests++; + } + return(block); +}*/ + +int32_t iguana_sendblockreq(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2,int32_t iamthreadsafe) +{ + int32_t len; uint8_t serialized[sizeof(struct iguana_msghdr) + sizeof(uint32_t)*32 + sizeof(bits256)]; + char hexstr[65]; init_hexbytes_noT(hexstr,hash2.bytes,sizeof(hash2)); + if ( (len= iguana_getdata(coin,serialized,MSG_BLOCK,hexstr)) > 0 ) + { + iguana_send(coin,addr,serialized,len); + coin->numreqsent++; + addr->pendblocks++; + addr->pendtime = (uint32_t)time(NULL); + //iguana_blockrequest(coin,bp,bundlei,hash2,addr->pendtime,iamthreadsafe); + //printf("REQ.%s bundlei.%d hdrsi.%d\n",bits256_str(hexstr,hash2),bundlei,bp!=0?bp->hdrsi:-1); + } else printf("MSG_BLOCK null datalen.%d\n",len); + return(len); +} + +int32_t iguana_sendtxidreq(struct iguana_info *coin,struct iguana_peer *addr,bits256 hash2) +{ + uint8_t serialized[sizeof(struct iguana_msghdr) + sizeof(uint32_t)*32 + sizeof(bits256)]; + int32_t len,i,r,j; char hexstr[65]; init_hexbytes_noT(hexstr,hash2.bytes,sizeof(hash2)); + if ( (len= iguana_getdata(coin,serialized,MSG_TX,hexstr)) > 0 ) + { + if ( addr == 0 ) + { + r = rand(); + for (i=0; iMAXPEERS; i++) + { + j = (i + r) % coin->MAXPEERS; + addr = &coin->peers.active[j]; + if ( coin->peers.active[j].usock >= 0 && coin->peers.active[j].dead == 0 ) + { + iguana_send(coin,addr,serialized,len); + break; + } + } + } else iguana_send(coin,addr,serialized,len); + } else printf("MSG_TX null datalen.%d\n",len); + printf("send MSG_TX.%d\n",len); + return(len); +} + +int32_t iguana_txidreq(struct iguana_info *coin,char **retstrp,bits256 txid) +{ + int32_t i; + while ( coin->numreqtxids >= sizeof(coin->reqtxids)/sizeof(*coin->reqtxids) ) + { + printf("txidreq full, wait\n"); + sleep(1); + } + char str[65]; printf("txidreq.%s\n",bits256_str(str,txid)); + coin->reqtxids[coin->numreqtxids++] = txid; + for (i=0; iMAXPEERS; i++) + if ( coin->peers.active[i].usock >= 0 ) + iguana_sendtxidreq(coin,coin->peers.ranked[i],txid); + return(0); +} + +void iguana_gotunconfirmedM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_msgtx *tx,uint8_t *data,int32_t datalen) +{ + struct iguana_bundlereq *req; + char str[65]; printf("%s unconfirmed.%s\n",addr->ipaddr,bits256_str(str,tx->txid)); + req = iguana_bundlereq(coin,addr,'U',datalen); + req->datalen = datalen; + req->txid = tx->txid; + memcpy(req->serialized,data,datalen); + queue_enqueue("bundlesQ",&coin->bundlesQ,&req->DL,0); +} + +void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *origtxdata,struct iguana_msgtx *txarray,struct iguana_msghdr *H,uint8_t *data,int32_t recvlen) +{ + struct iguana_bundlereq *req; struct iguana_txblock *txdata = 0; int32_t i,j,copyflag; char fname[1024]; + if ( 0 ) + { + for (i=0; ispace[0]; i++) + if ( txdata->space[i] != 0 ) + break; + if ( i != txdata->space[0] ) + { + for (i=0; ispace[0]; i++) + printf("%02x ",txdata->space[i]); + printf("extra\n"); + } + } + if ( coin->numreqtxids > 0 ) + { + for (i=0; iblock.RO.txn_count; i++) + { + for (j=0; jnumreqtxids; j++) + { + if ( memcmp(coin->reqtxids[j].bytes,txarray[i].txid.bytes,sizeof(bits256)) == 0 ) + { + char str[65]; printf("i.%d j.%d found txid.%s\n",i,j,bits256_str(str,coin->reqtxids[j])); + } + } + } + } + copyflag = 1 * (strcmp(coin->symbol,"BTC") != 0); + req = iguana_bundlereq(coin,addr,'B',copyflag * recvlen); + req->recvlen = recvlen; + if ( copyflag != 0 && recvlen != 0 ) + { + //printf("copy %p serialized[%d]\n",req->serialized,req->recvlen); + req->H = *H; + memcpy(req->serialized,data,recvlen), req->copyflag = 1; + } + txdata = origtxdata; + if ( addr != 0 ) + { + if ( addr->pendblocks > 0 ) + addr->pendblocks--; + addr->lastblockrecv = (uint32_t)time(NULL); + addr->recvblocks += 1.; + addr->recvtotal += recvlen; + if ( iguana_ramchain_data(coin,addr,origtxdata,txarray,origtxdata->block.RO.txn_count,data,recvlen) >= 0 ) + { + txdata->block.fpipbits = addr->ipbits; + req->datalen = txdata->datalen; + req->ipbits = txdata->block.fpipbits; + if ( 0 ) + { + struct iguana_txblock *checktxdata; struct OS_memspace checkmem; int32_t checkbundlei; + memset(&checkmem,0,sizeof(checkmem)); + iguana_meminit(&checkmem,"checkmem",0,txdata->datalen + 4096,0); + if ( (checktxdata= iguana_peertxdata(coin,&checkbundlei,fname,&checkmem,addr->ipbits,txdata->block.RO.hash2)) != 0 ) + { + printf("check datalen.%d bundlei.%d T.%d U.%d S.%d P.%d X.%d\n",checktxdata->datalen,checkbundlei,checktxdata->numtxids,checktxdata->numunspents,checktxdata->numspends,checktxdata->numpkinds,checktxdata->numexternaltxids); + } + iguana_mempurge(&checkmem); + } + } + } + //printf("recvlen.%d\n",req->recvlen); + req->block = txdata->block; + req->block.RO.txn_count = req->numtx = txdata->block.RO.txn_count; + coin->recvcount++; + coin->recvtime = (uint32_t)time(NULL); + req->addr = addr; + queue_enqueue("bundlesQ",&coin->bundlesQ,&req->DL,0); +} + +void iguana_gottxidsM(struct iguana_info *coin,struct iguana_peer *addr,bits256 *txids,int32_t n) +{ + struct iguana_bundlereq *req; + printf("got %d txids from %s\n",n,addr->ipaddr); + req = iguana_bundlereq(coin,addr,'T',0); + req->hashes = txids, req->n = n; + queue_enqueue("bundlesQ",&coin->bundlesQ,&req->DL,0); +} + +void iguana_gotheadersM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_block *blocks,int32_t n) +{ + struct iguana_bundlereq *req; + if ( addr != 0 ) + { + addr->recvhdrs++; + if ( addr->pendhdrs > 0 ) + addr->pendhdrs--; + //printf("%s blocks[%d] ht.%d gotheaders pend.%d %.0f\n",addr->ipaddr,n,blocks[0].height,addr->pendhdrs,milliseconds()); + } + req = iguana_bundlereq(coin,addr,'H',0); + req->blocks = blocks, req->n = n; + queue_enqueue("bundlesQ",&coin->bundlesQ,&req->DL,0); +} + +void iguana_gotblockhashesM(struct iguana_info *coin,struct iguana_peer *addr,bits256 *blockhashes,int32_t n) +{ + struct iguana_bundlereq *req; + if ( addr != 0 ) + { + addr->recvhdrs++; + if ( addr->pendhdrs > 0 ) + addr->pendhdrs--; + } + req = iguana_bundlereq(coin,addr,'S',0); + req->hashes = blockhashes, req->n = n; + //printf("bundlesQ blockhashes.%p[%d]\n",blockhashes,n); + queue_enqueue("bundlesQ",&coin->bundlesQ,&req->DL,0); +} + +void iguana_patch(struct iguana_info *coin,struct iguana_block *block) +{ + int32_t i,j,origheight,height; struct iguana_block *prev,*next; struct iguana_bundle *bp; + prev = iguana_blockhashset(coin,-1,block->RO.prev_block,1); + block->hh.prev = prev; + if ( prev != 0 ) + { + if ( prev->mainchain != 0 ) + { + prev->hh.next = block; + if ( memcmp(block->RO.prev_block.bytes,coin->blocks.hwmchain.RO.hash2.bytes,sizeof(bits256)) == 0 ) + { + _iguana_chainlink(coin,block); + //printf("link block %d\n",block->height); + } + if ( (next= block->hh.next) != 0 && bits256_nonz(next->RO.hash2) > 0 ) + { + next->height = block->height + 1; + //printf("autoreq %d\n",next->height); + if ( 0 && strcmp(coin->symbol,"BTC") != 0 ) + iguana_blockQ(coin,coin->bundles[(block->height+1)/coin->chain->bundlesize],(block->height+1)%coin->chain->bundlesize,next->RO.hash2,0); + } + } + else if ( block->height < 0 ) + { + for (i=0; i<1; i++) + { + if ( (prev= prev->hh.prev) == 0 ) + break; + if ( prev->mainchain != 0 && prev->height >= 0 ) + { + j = i; + origheight = (prev->height + i + 2); + prev = block->hh.prev; + height = (origheight - 1); + while ( i > 0 && prev != 0 ) + { + if ( prev->mainchain != 0 && prev->height != height ) + { + printf("mainchain height mismatch j.%d at i.%d %d != %d\n",j,i,prev->height,height); + break; + } + prev = prev->hh.prev; + height--; + } + if ( i == 0 ) + { + //printf("SET HEIGHT.%d j.%d\n",origheight,j); + if ( (bp= coin->bundles[origheight / coin->chain->bundlesize]) != 0 ) + { + iguana_bundlehash2add(coin,0,bp,origheight % coin->chain->bundlesize,block->RO.hash2); + block->height = origheight; + block->mainchain = 1; + prev = block->hh.prev; + prev->hh.next = block; + } + } //else printf("break at i.%d for j.%d origheight.%d\n",i,j,origheight); + break; + } + } + } + } +} + +int32_t iguana_allhashcmp(struct iguana_info *coin,struct iguana_bundle *bp,bits256 *blockhashes,int32_t num) +{ + bits256 allhash; int32_t err,i,n; struct iguana_block *block; + if ( bits256_nonz(bp->allhash) > 0 && num >= coin->chain->bundlesize ) + { + for (i=0; in; i++) + if ( bits256_nonz(blockhashes[i]) == 0 ) + blockhashes[i] = bp->hashes[i]; + vcalc_sha256(0,allhash.bytes,blockhashes[0].bytes,coin->chain->bundlesize * sizeof(*blockhashes)); + if ( memcmp(allhash.bytes,bp->allhash.bytes,sizeof(allhash)) == 0 ) + { + for (i=n=0; ichain->bundlesize&&in; i++) + { + if ( (err= iguana_bundlehash2add(coin,0,bp,i,blockhashes[i])) < 0 ) + return(err); + if ( bp->emitfinish == 0 && (block= bp->blocks[i]) != 0 && (block->queued == 0 && block->fpipbits == 0) && block->numrequests < 3 ) + iguana_blockQ(coin,bp,i,block->RO.hash2,0), n++; + } + //printf("ALLHASHES FOUND! %d requested.%d\n",bp->bundleheight,n); + return(i); + } + } + return(-1); +} + +// main context, ie single threaded +struct iguana_bundle *iguana_bundleset(struct iguana_info *coin,struct iguana_block **blockp,int32_t *bundleip,struct iguana_block *origblock) +{ + struct iguana_block *block; bits256 zero; struct iguana_bundle *bp = 0; + int32_t bundlei = -2; + *bundleip = -2; *blockp = 0; + if ( origblock == 0 ) + return(0); + memset(zero.bytes,0,sizeof(zero)); + if ( (block= iguana_blockhashset(coin,-1,origblock->RO.hash2,1)) != 0 ) + { + if ( block != origblock ) + iguana_blockcopy(coin,block,origblock); + *blockp = block; + //if ( bits256_nonz(block->RO.prev_block) > 0 ) + // iguana_patch(coin,block); + if ( (bp= iguana_bundlefind(coin,&bp,&bundlei,block->RO.hash2)) != 0 ) + { + if ( bundlei < coin->chain->bundlesize ) + { + block->bundlei = bundlei; + block->hdrsi = bp->hdrsi; + //iguana_hash2set(coin,"blockadd",bp,block->bundlei,block->hash2); + iguana_bundlehash2add(coin,0,bp,bundlei,block->RO.hash2); + if ( bundlei > 0 ) + { + //char str[65],str2[65]; printf("call hash2add %d:[%d -1] %s prev.%s\n",bp->hdrsi,bundlei,bits256_str(str2,block->RO.hash2),bits256_str(str,block->RO.prev_block)); + iguana_bundlehash2add(coin,0,bp,bundlei-1,block->RO.prev_block); + } + else if ( bp->hdrsi > 0 && (bp= coin->bundles[bp->hdrsi-1]) != 0 ) + iguana_bundlehash2add(coin,0,bp,coin->chain->bundlesize-1,block->RO.prev_block); + } + } + if ( (bp= iguana_bundlefind(coin,&bp,&bundlei,block->RO.prev_block)) != 0 ) + { + //printf("found prev.%d\n",bp->bundleheight+bundlei); + if ( bundlei < coin->chain->bundlesize ) + { + if ( bundlei == coin->chain->bundlesize-1 ) + { + //if ( coin->bundlescount < bp->hdrsi+1 ) + { + //char str[65]; printf("autoextend CREATE.%d new bundle.%s\n",bp->bundleheight + coin->chain->bundlesize,bits256_str(str,block->RO.hash2)); + iguana_bundlecreate(coin,&bundlei,bp->bundleheight + coin->chain->bundlesize,block->RO.hash2,zero,1); + } + } + else if ( bundlei < coin->chain->bundlesize-1 ) + iguana_bundlehash2add(coin,0,bp,bundlei+1,block->RO.hash2); + } + } + //char str[65]; printf("iguana_recvblock (%s) %d %d[%d] %p\n",bits256_str(str,block->hash2),block->havebundle,block->hdrsi,bundlei,bp); + } else printf("iguana_bundleset: error adding blockhash\n"); + return(iguana_bundlefind(coin,&bp,bundleip,origblock->RO.hash2)); +} + +struct iguana_bundlereq *iguana_recvblockhdrs(struct iguana_info *coin,struct iguana_bundlereq *req,struct iguana_block *blocks,int32_t n,int32_t *newhwmp) +{ + int32_t i,bundlei; struct iguana_block *block; struct iguana_bundle *bp; + if ( blocks == 0 ) + { + printf("iguana_recvblockhdrs null blocks?\n"); + return(req); + } + if ( blocks != 0 && n > 0 ) + { + for (i=0; ihdrsi < IGUANA_MAXACTIVEBUNDLES ) + { + //if ( 0 && i < bp->n && bp->requests[i] == 0 ) + // iguana_blockQ(coin,bp,bundlei,blocks[i].RO.hash2,0); + } + } + } + return(req); +} + +struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct iguana_bundlereq *req,bits256 *blockhashes,int32_t num) +{ + int32_t bundlei,i,n = 0; struct iguana_block *block; struct iguana_bundle *bp;// char str[65]; + bp = 0, bundlei = -2, iguana_bundlefind(coin,&bp,&bundlei,blockhashes[1]); + if ( bp != 0 ) + { + blockhashes[0] = bp->hashes[0]; + if ( num >= coin->chain->bundlesize ) + { + bp->hdrtime = (uint32_t)time(NULL); + if ( iguana_allhashcmp(coin,bp,blockhashes,num) == 0 ) + return(req); + } + for (i=0; i 0 && (block= iguana_blockhashset(coin,-1,blockhashes[i],1)) != 0 ) + { + if ( block->hdrsi == bp->hdrsi && block->bundlei == i ) + n++; + } + } + //printf("got [%d] num.%d matched hashes\n",n,num); + } + else + { + //char str[65]; printf("blockhashes[%d] %s\n",num,bits256_str(str,blockhashes[1])); + iguana_blockQ(coin,0,-1,blockhashes[1],1); + } + //iguana_blockQ(coin,0,-1,blockhashes[num-1],1); + /*if ( (block= iguana_blockhashset(coin,-1,blockhashes[1],1)) != 0 && num > 2 ) + { + if ( block->rawdata != 0 ) + { + if ( block->copyflag != 0 ) + myfree(block->rawdata,block->RO.recvlen), block->copyflag = 0; + else myfree(block->rawdata,block->numhashes * sizeof(bits256)); + } + //char str[65]; printf("got %d unmatched hashes %d:%d %s\n",num,bp==0?-1:bp->bundleheight,bundlei,bits256_str(str,blockhashes[1])); + block->rawdata = blockhashes, block->numhashes = num, block->havehashes = 1; + req->hashes = 0; + } + if ( 0 && num >= coin->chain->bundlesize+1 ) + { + char str[65]; bits256_str(str,blockhashes[coin->chain->bundlesize]); + queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(str),1); + }*/ + return(req); +} + +struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_bundlereq *req,struct iguana_block *origblock,int32_t numtx,int32_t datalen,int32_t recvlen,int32_t *newhwmp) +{ + struct iguana_bundle *prevbp=0,*bp=0; int32_t prevbundlei=-2,bundlei = -2; struct iguana_block *prevblock,*block; + bp = iguana_bundleset(coin,&block,&bundlei,origblock); + //char str[65]; printf("RECV %s [%d:%d] block.%p\n",bits256_str(str,origblock->RO.hash2),bp!=0?bp->hdrsi:-1,bundlei,block); + iguana_bundlefind(coin,&prevbp,&prevbundlei,origblock->RO.prev_block); + if ( prevbp != 0 && prevbundlei >= 0 && prevbp->blocks[prevbundlei] == 0 && (prevblock= iguana_blockfind(coin,origblock->RO.prev_block)) != 0 ) + { + prevbp->blocks[prevbundlei] = prevblock; + //printf("PREV %s prevbp.%p[%d]\n",bits256_str(str,origblock->RO.prev_block),prevbp,prevbundlei); + } + if ( block != 0 ) + { + if ( bp != 0 && bundlei >= 0 ) + bp->blocks[bundlei] = block; + block->RO.recvlen = recvlen; + if ( req->copyflag != 0 && block->queued == 0 )//block->rawdata == 0 ) + { + //char str[65]; printf("%s copyflag.%d %d data %d %d\n",bits256_str(str,block->RO.hash2),req->copyflag,block->height,req->recvlen,recvlen); + //block->rawdata = mycalloc('n',1,block->RO.recvlen); + //memcpy(block->rawdata,req->serialized,block->RO.recvlen); + //block->copyflag = 1; + coin->numcached++; + block->queued = 1; + queue_enqueue("cacheQ",&coin->cacheQ,&req->DL,0); + return(0); + } + //printf("datalen.%d ipbits.%x\n",datalen,req->ipbits); + } else printf("cant create block.%llx block.%p bp.%p bundlei.%d\n",(long long)origblock->RO.hash2.txid,block,bp,bundlei); + return(req); +} + +struct iguana_bundlereq *iguana_recvtxids(struct iguana_info *coin,struct iguana_bundlereq *req,bits256 *txids,int32_t n) +{ + return(req); +} + +struct iguana_bundlereq *iguana_recvunconfirmed(struct iguana_info *coin,struct iguana_bundlereq *req,uint8_t *data,int32_t datalen) +{ + int32_t i; + for (i=0; inumreqtxids; i++) + { + if ( memcmp(req->txid.bytes,coin->reqtxids[i].bytes,sizeof(req->txid)) == 0 ) + { + char str[65]; printf("got reqtxid.%s datalen.%d | numreqs.%d\n",bits256_str(str,req->txid),req->datalen,coin->numreqtxids); + coin->reqtxids[i] = coin->reqtxids[--coin->numreqtxids]; + } + } + return(req); +} + +int32_t iguana_processbundlesQ(struct iguana_info *coin,int32_t *newhwmp) // single threaded +{ + int32_t flag = 0; struct iguana_bundlereq *req; + *newhwmp = 0; + while ( flag < IGUANA_BUNDLELOOP && (req= queue_dequeue(&coin->bundlesQ,0)) != 0 ) + { + //printf("%s bundlesQ.%p type.%c n.%d\n",req->addr != 0 ? req->addr->ipaddr : "0",req,req->type,req->n); + if ( req->type == 'B' ) // one block with all txdata + req = iguana_recvblock(coin,req->addr,req,&req->block,req->numtx,req->datalen,req->recvlen,newhwmp); + else if ( req->type == 'H' ) // blockhdrs (doesnt have txn_count!) + { + if ( (req= iguana_recvblockhdrs(coin,req,req->blocks,req->n,newhwmp)) != 0 ) + { + if ( req->blocks != 0 ) + myfree(req->blocks,sizeof(*req->blocks) * req->n), req->blocks = 0; + } + } + else if ( req->type == 'S' ) // blockhashes + { + if ( (req= iguana_recvblockhashes(coin,req,req->hashes,req->n)) != 0 && req->hashes != 0 ) + myfree(req->hashes,sizeof(*req->hashes) * req->n), req->hashes = 0; + } + else if ( req->type == 'U' ) // unconfirmed tx + req = iguana_recvunconfirmed(coin,req,req->serialized,req->datalen); + else if ( req->type == 'T' ) // txids from inv + { + if ( (req= iguana_recvtxids(coin,req,req->hashes,req->n)) != 0 ) + myfree(req->hashes,(req->n+1) * sizeof(*req->hashes)), req->hashes = 0; + } + else printf("iguana_updatebundles unknown type.%c\n",req->type); + flag++; + //printf("done %s bundlesQ.%p type.%c n.%d\n",req->addr != 0 ? req->addr->ipaddr : "0",req,req->type,req->n); + if ( req != 0 ) + myfree(req,req->allocsize), req = 0; + } + return(flag); +} + +int32_t iguana_needhdrs(struct iguana_info *coin) +{ + if ( coin->longestchain == 0 || coin->blocks.hashblocks < coin->longestchain-coin->chain->bundlesize ) + return(1); + else return(0); +} + +int32_t iguana_reqhdrs(struct iguana_info *coin) +{ + int32_t i,lag,n = 0; struct iguana_bundle *bp; char hashstr[65]; + if ( iguana_needhdrs(coin) > 0 && queue_size(&coin->hdrsQ) == 0 ) + { + if ( coin->zcount++ > 1 ) + { + for (i=0; ibundlescount; i++) + { + if ( (bp= coin->bundles[i]) != 0 && bp->emitfinish < coin->startutc ) + { + if ( i == coin->bundlescount-1 ) + lag = 5; + else lag = 30 + (rand() % 30); + if ( i < coin->bundlescount-1 && (bp->numhashes >= (rand() % bp->n) || time(NULL) < bp->hdrtime+lag) ) + continue; + if ( bp->numhashes < bp->n && bp->bundleheight+bp->numhashes < coin->longestchain && time(NULL) > bp->issuetime+lag ) + { + //printf("LAG.%ld hdrsi.%d numhashes.%d:%d needhdrs.%d qsize.%d zcount.%d\n",time(NULL)-bp->hdrtime,i,bp->numhashes,bp->n,iguana_needhdrs(coin),queue_size(&coin->hdrsQ),coin->zcount); + if ( bp->issuetime == 0 ) + coin->numpendings++; + char str[65]; + bits256_str(str,bp->hashes[0]); + //printf("(%s %d).%d ",str,bp->bundleheight,i); + //printf("%d ",bp->bundleheight); + init_hexbytes_noT(hashstr,bp->hashes[0].bytes,sizeof(bits256)); + queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(hashstr),1); + /*if ( strcmp(coin->symbol,"BTC") != 0 && bits256_nonz(bp->hashes[1]) > 0 ) + { + if ( (block= iguana_blockfind(coin,bp->hashes[1])) != 0 ) + { + if ( block->havehashes != 0 && block->rawdata != 0 ) + iguana_allhashcmp(coin,bp,block->rawdata,block->numhashes); + //iguana_blockQ(coin,bp,1,bp->hashes[1],1); + } + }*/ + n++; + bp->hdrtime = bp->issuetime = (uint32_t)time(NULL); + } + } + } + if ( n > 0 ) + printf("REQ HDRS pending.%d\n",n); + coin->zcount = 0; + } + } else coin->zcount = 0; + return(n); +} + +struct iguana_blockreq { struct queueitem DL; bits256 hash2,*blockhashes; struct iguana_bundle *bp; int32_t n,height,bundlei; }; + +int32_t iguana_blockQ(struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2,int32_t priority) +{ + queue_t *Q; char *str; struct iguana_blockreq *req; struct iguana_block *block = 0; + if ( bits256_nonz(hash2) == 0 ) + { + printf("cant queue zerohash bundlei.%d\n",bundlei); + return(-1); + } + if ( (bp != 0 && (block= iguana_blockfind(coin,bp->hashes[bundlei])) == 0) || priority != 0 || bp == 0 ) + { + if ( block != 0 ) + { + if ( block->fpipbits != 0 || block->queued != 0 ) + return(0); + /*if ( block->rawdata != 0 && block->RO.recvlen != 0 ) + { + printf("free cached copy recvlen.%d need to process it here\n",block->RO.recvlen); + myfree(block->rawdata,block->RO.recvlen); + block->rawdata = 0; + block->RO.recvlen = 0; + }*/ + } + if ( priority != 0 ) + str = "priorityQ", Q = &coin->priorityQ; + else str = "blocksQ", Q = &coin->blocksQ; + if ( Q != 0 ) + { + req = mycalloc('r',1,sizeof(*req)); + req->hash2 = hash2; + req->bp = bp; + req->bundlei = bundlei; + if ( bp != 0 && bundlei >= 0 && bundlei < bp->n ) + { + //bp->issued[bundlei] = (uint32_t)time(NULL); + if ( bp->bundleheight >= 0 ) + req->height = (bp->bundleheight + bundlei); + } + char str[65]; + bits256_str(str,hash2); + if ( 0 && (bundlei % 250) == 0 ) + printf("%s %d %s recv.%d numranked.%d qsize.%d\n",str,req->height,str,coin->blocks.recvblocks,coin->peers.numranked,queue_size(Q)); + queue_enqueue(str,Q,&req->DL,0); + return(1); + } else printf("null Q\n"); + } //else printf("queueblock skip priority.%d bundlei.%d\n",bundlei,priority); + return(0); +} + +int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr) +{ + uint8_t serialized[sizeof(struct iguana_msghdr) + sizeof(uint32_t)*32 + sizeof(bits256)]; + char *hashstr=0; bits256 hash2; uint32_t now; struct iguana_block *block; struct iguana_blockreq *req=0; + int32_t i,r,diff,j,k,n,m; double metric,bestmetric = -1.; struct iguana_bundle *bp,*bestbp = 0; + int32_t limit,refbundlei,height=-1,incr,datalen,flag = 0; double val; + now = (uint32_t)time(NULL); + if ( iguana_needhdrs(coin) != 0 && addr->pendhdrs < IGUANA_MAXPENDHDRS ) + { + //printf("%s check hdrsQ\n",addr->ipaddr); + if ( (hashstr= queue_dequeue(&coin->hdrsQ,1)) != 0 ) + { + if ( (datalen= iguana_gethdrs(coin,serialized,coin->chain->gethdrsmsg,hashstr)) > 0 ) + { + decode_hex(hash2.bytes,sizeof(hash2),hashstr); + if ( bits256_nonz(hash2) > 0 ) + { + //printf("%s request hdr.(%s)\n",addr!=0?addr->ipaddr:"local",hashstr); + iguana_send(coin,addr,serialized,datalen); + addr->pendhdrs++; + flag++; + } + free_queueitem(hashstr); + return(flag); + } else printf("datalen.%d from gethdrs\n",datalen); + free_queueitem(hashstr); + hashstr = 0; + } + } + if ( (limit= addr->recvblocks) > coin->MAXPENDING ) + limit = coin->MAXPENDING; + if ( limit < 1 ) + limit = 1; + //if ( addr->pendblocks >= limit ) + // printf("%s %d overlimit.%d\n",addr->ipaddr,addr->pendblocks,limit); + if ( coin->bundlescount > 0 && (req= queue_dequeue(&coin->priorityQ,0)) == 0 && addr->pendblocks < limit )//&& now > addr->lastpoll ) + { + if ( 1 )//strcmp("BTC",coin->symbol) != 0 ) + { + int32_t bundlei; + incr = coin->peers.numranked == 0 ? coin->MAXPEERS : coin->peers.numranked; + if ( (rand() % 100) < 50 ) + height = addr->rank * _IGUANA_MAXPENDING; + else if ( (rand() % 100) < 50 ) + height = addr->addrind + (addr->rank * (coin->longestchain - coin->blocks.hwmchain.height) / (coin->peers.numranked+1)); + else if ( (rand() % 100) < 50 ) + { + height = (addr->lastheight + 1); + if ( height >= coin->longestchain-coin->chain->bundlesize ) + height = addr->rank*incr*_IGUANA_MAXPENDING; + } + else + { + height = coin->longestchain - (rand() % incr) * 1000; + if ( height < 0 ) + height = coin->blocks.hwmchain.height; + } + for (; heightbundlescount*coin->chain->bundlesize; height+=incr) + { + if ( height > coin->longestchain ) + height = addr->rank*incr*_IGUANA_MAXPENDING; + if ( height > addr->lastheight ) + addr->lastheight = height; + if ( (bp= coin->bundles[height/coin->chain->bundlesize]) != 0 && bp->emitfinish == 0 ) + { + bundlei = (height % coin->chain->bundlesize); + if ( bundlei < bp->n && bits256_nonz(bp->hashes[bundlei]) > 0 && (block= bp->blocks[bundlei]) != 0 && block->numrequests <= bp->minrequests && block->fpipbits == 0 )//&& block->queued == 0 )//(bp->issued[bundlei] == 0 || now > bp->issued[bundlei]+10) ) + { + if ( block->numrequests < 100 ) + block->numrequests++; + //block->issued = (uint32_t)time(NULL);; + if ( 0 && (rand() % 100) == 0 ) + printf("%s Send auto blockreq.%d [%d] minreq.%d\n",addr->ipaddr,bp->bundleheight+bundlei,block->numrequests,bp->minrequests); + iguana_sendblockreq(coin,addr,bp,bundlei,bp->hashes[bundlei],0); + return(1); + } + } + } + } + else + { + //printf("%s lastpoll.%u %u\n",addr->ipaddr,addr->lastpoll,now); + addr->lastpoll = now; + for (i=n=0; ibundlescount; i++) + if ( coin->bundles[i] != 0 && coin->bundles[i]->emitfinish == 0 ) + n++; + if ( n >= coin->bundlescount-(coin->bundlescount>>3) || (addr->ipbits % 10) < 5 ) + refbundlei = (addr->ipbits % coin->bundlescount); + else + { + if ( n*2 < coin->bundlescount ) + { + for (i=refbundlei=0; iusock == coin->peers.active[i].usock ) + break; + if ( coin->peers.active[i].usock >= 0 ) + refbundlei++; + } + //printf("half done\n"); + } else refbundlei = ((addr->addrind*100) % coin->bundlescount); + } + for (i=0; ibundlescount; i++) + { + if ( (diff= (i - refbundlei)) < 0 ) + diff = -diff; + if ( (bp= coin->bundles[i]) != 0 && bp->emitfinish == 0 ) + { + metric = (1 + diff * ((addr->addrind&1) == 0 ? 1 : 1) * (1. + bp->metric));// / (i*((addr->addrind&1) != 0 ? 1 : i) + 1); + //printf("%f ",bp->metric); + if ( bestmetric < 0. || metric < bestmetric ) + bestmetric = metric, bestbp = bp; + } + } + if ( bestbp != 0 && bp->emitfinish == 0 ) + { + for (k=0; kbundlescount; k++) + { + i = (bestbp->hdrsi + k) % coin->bundlescount; + if ( (bp= coin->bundles[i]) == 0 || bp->emitfinish != 0 ) + continue; + printf("%.15f ref.%d addrind.%d bestbp.%d\n",bestmetric,refbundlei,addr->addrind,bp->hdrsi); + m = coin->chain->bundlesize; + if ( bp->n < m ) + m = bp->n; + j = (addr->addrind*3 + 0) % m; + val = (bp->threshold / 1000.); + for (r=0; r= m ) + j = 0; + if ( (block= bp->blocks[j]) != 0 && block->fpipbits == 0 && block->queued == 0 && block->numrequests <= bp->minrequests ) + { + if ( block->numrequests < 100 ) + block->numrequests++; + //block->issued = (uint32_t)time(NULL);; + printf("%s Send auto blockreq.%d\n",addr->ipaddr,bp->bundleheight+j); + iguana_sendblockreq(coin,addr,bp,j,hash2,0); + return(1); + } + } + } + } + } + } + int32_t priority; + if ( addr->rank != 1 && req == 0 ) + { + priority = 0; + req = queue_dequeue(&coin->blocksQ,0); + } else priority = 1; + if ( req != 0 ) + { + hash2 = req->hash2; + height = req->height; + block = 0; + if ( priority == 0 && (bp= req->bp) != 0 && req->bundlei >= 0 && req->bundlei < bp->n && req->bundlei < coin->chain->bundlesize && (block= bp->blocks[req->bundlei]) != 0 && (block->fpipbits != 0 || block->queued != 0) ) + { + //if ( 0 && priority != 0 ) + printf("SKIP %p[%d] %d\n",bp,bp!=0?bp->bundleheight:-1,req->bundlei); + } + else + { + char str[65]; + if ( 0 && priority != 0 ) + printf(" issue.%s\n",bits256_str(str,hash2)); + if ( block != 0 && block->numrequests < 100 ) + block->numrequests++; + iguana_sendblockreq(coin,addr,req->bp,req->bundlei,hash2,0); + } + flag++; + myfree(req,sizeof(*req)); + } + return(flag); +} + +int32_t iguana_processrecv(struct iguana_info *coin) // single threaded +{ + int32_t newhwm = 0,h,lflag,bundlei,flag = 0; bits256 hash2; struct iguana_block *next,*block; struct iguana_bundle *bp; + //printf("process bundlesQ\n"); + flag += iguana_processbundlesQ(coin,&newhwm); + flag += iguana_reqhdrs(coin); + lflag = 1; + while ( lflag != 0 ) + { + lflag = 0; + h = coin->blocks.hwmchain.height / coin->chain->bundlesize; + if ( (next= iguana_blockfind(coin,iguana_blockhash(coin,coin->blocks.hwmchain.height+1))) == 0 ) + { + if ( (block= iguana_blockfind(coin,coin->blocks.hwmchain.RO.hash2)) != 0 ) + next = block->hh.next, block->mainchain = 1; + } + if ( next != 0 ) + { + //printf("have next\n"); + if ( memcmp(next->RO.prev_block.bytes,coin->blocks.hwmchain.RO.hash2.bytes,sizeof(bits256)) == 0 ) + { + if ( _iguana_chainlink(coin,next) != 0 ) + lflag++; + //else printf("chainlink error for %d\n",coin->blocks.hwmchain.height+1); + } + else if ( 1 ) + { + double threshold,lag = OS_milliseconds() - coin->backstopmillis; + threshold = (10 + coin->longestchain - coin->blocksrecv); + if ( threshold < 1 ) + threshold = 1.; + if ( (bp= coin->bundles[(coin->blocks.hwmchain.height+1)/coin->chain->bundlesize]) != 0 ) + threshold = (bp->avetime + coin->avetime) * .5; + else threshold = coin->avetime; + threshold *= 100. * sqrt(threshold) * .000777; + if ( strcmp(coin->symbol,"BTC") != 0 ) + threshold = 400; + else threshold = 1000; + if ( coin->blocks.hwmchain.height+1 < coin->longestchain && (coin->backstop != coin->blocks.hwmchain.height+1 || lag > threshold) ) + { + coin->backstop = coin->blocks.hwmchain.height+1; + hash2 = iguana_blockhash(coin,coin->backstop); + if ( bits256_nonz(hash2) > 0 ) + { + bp = coin->bundles[(coin->blocks.hwmchain.height+1)/coin->chain->bundlesize]; + bundlei = (coin->blocks.hwmchain.height+1) % coin->chain->bundlesize; + if ( bp != 0 ) + { + coin->backstopmillis = OS_milliseconds(); + iguana_blockQ(coin,bp,bundlei,iguana_blockhash(coin,coin->backstop),1); + //iguana_blockrequest(coin,bp,bundlei,hash2,(uint32_t)time(NULL),1); + /*if ( (bp= coin->bundles[(coin->blocks.hwmchain.height+1)/coin->chain->bundlesize]) == 0 || bp->fpos[bundlei] >= 0 ) + { + if ( bp != 0 && coin->backstop == coin->blocks.hwmchain.height+1 ) + { + iguana_bundleiclear(coin,bp,bundlei); + } + iguana_blockQ(coin,bp,bundlei,next->RO.hash2,1); + }*/ + if ( (rand() % 100) == 0 ) + printf("MAINCHAIN.%d threshold %.3f %.3f lag %.3f\n",coin->blocks.hwmchain.height+1,threshold,coin->backstopmillis,lag); + } + } + } + else if ( 0 && bits256_nonz(next->RO.prev_block) > 0 ) + printf("next prev cmp error nonz.%d\n",bits256_nonz(next->RO.prev_block)); + } + } + if ( h != coin->blocks.hwmchain.height / coin->chain->bundlesize ) + iguana_savehdrs(coin); + } + return(flag); +} diff --git a/iguana/iguana777.c b/iguana/iguana777.c index 4fbcfa338..0c5e8da7d 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -182,7 +182,7 @@ int32_t iguana_peermetrics(struct iguana_info *coin) void *iguana_kviAddriterator(struct iguana_info *coin,struct iguanakv *kv,struct iguana_kvitem *item,uint64_t args,void *key,void *value,int32_t valuesize) { - char ipaddr[64]; int32_t i; FILE *fp = (FILE *)args; struct iguana_peer *addr; struct iguana_iAddr *iA = value; + char ipaddr[64]; int32_t i; FILE *fp = (FILE *)(long)args; struct iguana_peer *addr; struct iguana_iAddr *iA = value; if ( fp != 0 && iA != 0 && iA->numconnects > 0 && iA->lastconnect > time(NULL)-IGUANA_RECENTPEER ) { for (i=0; ipeers.numranked; i++) diff --git a/iguana/iguana777.h b/iguana/iguana777.h index 193d47c94..af93f461c 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -72,19 +72,18 @@ struct iguana_txdatabits { uint64_t addrind:IGUANA_LOG2MAXPEERS,filecount:10,fpo #endif -#include "../includes/cJSON.h" #ifdef __PNACL -void PostMessage(const char* format, ...); +void PNACL_message(const char* format, ...); #endif extern int32_t IGUANA_NUMHELPERS; #ifdef __PNACL -#define printf PostMessage +#define printf PNACL_message #define MS_ASYNC 1 /* Sync memory asynchronously. */ #define MS_SYNC 4 /* Synchronous memory sync. */ #else -#define PostMessage printf +#define PNACL_message printf #endif #ifndef MSG_NOSIGNAL diff --git a/iguana/iguana_peers.c b/iguana/iguana_peers.c index fb5b6b7a7..e952f664f 100755 --- a/iguana/iguana_peers.c +++ b/iguana/iguana_peers.c @@ -228,7 +228,7 @@ void iguana_iAkill(struct iguana_info *coin,struct iguana_peer *addr,int32_t mar rank = addr->rank; strcpy(ipaddr,addr->ipaddr); if ( addr->usock >= 0 ) - close(addr->usock), addr->usock = -1; + closesocket(addr->usock), addr->usock = -1; if ( addr == coin->peers.localaddr ) coin->peers.localaddr = 0; //printf("iAkill.(%s)\n",addr->ipaddr); @@ -256,7 +256,7 @@ void iguana_iAkill(struct iguana_info *coin,struct iguana_peer *addr,int32_t mar int32_t opt; struct sockaddr_in addr; socklen_t addrlen = sizeof(addr); struct hostent* hostent = gethostbyname(hostname); if (hostent == NULL) { - PostMessage("gethostbyname() returned error: %d", errno); + PNACL_message("gethostbyname() returned error: %d", errno); return -1; } addr.sin_family = AF_INET; @@ -278,7 +278,7 @@ void iguana_iAkill(struct iguana_info *coin,struct iguana_peer *addr,int32_t mar int result = bind(sock, (struct sockaddr*)&addr, addrlen); if (result != 0) { printf("bind() failed: %s", strerror(errno)); - close(sock); + closesocket(sock); return -1; } return(sock); @@ -333,14 +333,14 @@ int32_t iguana_socket(int32_t bindflag,char *hostname,uint16_t port) if ( errno != ECONNRESET && errno != ENOTCONN && errno != ECONNREFUSED && errno != ETIMEDOUT && errno != EHOSTUNREACH ) printf("connect(%s) port.%d failed: %s sock.%d. errno.%d\n",hostname,port,strerror(errno),sock,errno); if ( sock >= 0 ) - close(sock); + closesocket(sock); return(-1); } if ( bindflag != 0 && listen(sock,128) != 0 ) { printf("listen(%s) port.%d failed: %s sock.%d. errno.%d\n",hostname,port,strerror(errno),sock,errno); if ( sock >= 0 ) - close(sock); + closesocket(sock); return(-1); } return(sock); diff --git a/iguana/iguana_pubkeys.c b/iguana/iguana_pubkeys.c index e2537afa4..46b89c7bb 100755 --- a/iguana/iguana_pubkeys.c +++ b/iguana/iguana_pubkeys.c @@ -15,11 +15,11 @@ #include "iguana777.h" #include -#include -#include -#include -#include -#include +#include "../includes/openssl/ec.h" +#include "../includes/openssl/ecdsa.h" +#include "../includes/openssl/obj_mac.h" +//#include "../includes/openssl/ripemd.h" +//#include "../includes/openssl/sha.h" #define SCRIPT_OP_IF 0x63 #define SCRIPT_OP_ELSE 0x67 diff --git a/iguana/iguana_ramchain.c b/iguana/iguana_ramchain.c index f823cd3fa..e61262dac 100755 --- a/iguana/iguana_ramchain.c +++ b/iguana/iguana_ramchain.c @@ -155,7 +155,7 @@ uint32_t iguana_sparseadd(uint8_t *bits,uint32_t ind,int32_t width,uint32_t tabl sparsemax = i; return(setind); } - else if ( memcmp((void *)((long)refdata + x*refsize),key,keylen) == 0 ) + else if ( memcmp((void *)(long)((long)refdata + x*refsize),key,keylen) == 0 ) { if ( setind == 0 ) sparsehits++; @@ -205,8 +205,8 @@ struct iguana_txid *iguana_txidfind(struct iguana_info *coin,int32_t *heightp,st ramchain = &bp->ramchain; if ( ramchain->H.data != 0 ) { - TXbits = (void *)((long)ramchain->H.data + ramchain->H.data->TXoffset); - T = (void *)((long)ramchain->H.data + ramchain->H.data->Toffset); + TXbits = (void *)(long)((long)ramchain->H.data + ramchain->H.data->TXoffset); + T = (void *)(long)((long)ramchain->H.data + ramchain->H.data->Toffset); //printf("search bp.%p TXbits.%p T.%p %d %d\n",bp,TXbits,T,(int32_t)ramchain->H.data->TXoffset,(int32_t)ramchain->H.data->Toffset); if ( (txidind= iguana_sparseaddtx(TXbits,ramchain->H.data->txsparsebits,ramchain->H.data->numtxsparse,txid,T,0)) > 0 ) { @@ -233,8 +233,8 @@ struct iguana_pkhash *iguana_pkhashfind(struct iguana_info *coin,struct iguana_p if ( (bp= coin->bundles[i]) != 0 ) { ramchain = &bp->ramchain; - PKbits = (void *)((long)ramchain->H.data + ramchain->H.data->PKoffset); - P = (void *)((long)ramchain->H.data + ramchain->H.data->Poffset); + PKbits = (void *)(long)((long)ramchain->H.data + ramchain->H.data->PKoffset); + P = (void *)(long)((long)ramchain->H.data + ramchain->H.data->Poffset); if ( (pkind= iguana_sparseaddpk(PKbits,ramchain->H.data->pksparsebits,ramchain->H.data->numpksparse,rmd160,P,0)) > 0 ) { *p = P[pkind]; @@ -594,17 +594,17 @@ int64_t iguana_hashmemsize(uint32_t numtxids,uint32_t numunspents,uint32_t numsp void _iguana_ramchain_setptrs(RAMCHAIN_PTRPS,struct iguana_ramchaindata *rdata) { - *B = (void *)((long)rdata + (long)rdata->Boffset); - *T = (void *)((long)rdata + (long)rdata->Toffset); + *B = (void *)(long)((long)rdata + (long)rdata->Boffset); + *T = (void *)(long)((long)rdata + (long)rdata->Toffset); if ( ramchain->expanded != 0 ) { - *Ux = (void *)((long)rdata + (long)rdata->Uoffset); - *Sx = (void *)((long)rdata + (long)rdata->Soffset); - *P = (void *)((long)rdata + (long)rdata->Poffset); - *X = (void *)((long)rdata + (long)rdata->Xoffset); - //ramchain->roU2 = (void *)((long)rdata + (long)rdata->U2offset); - //ramchain->roP2 = (void *)((long)rdata + (long)rdata->P2offset); - ramchain->roA = (void *)((long)rdata + (long)rdata->Aoffset); + *Ux = (void *)(long)((long)rdata + (long)rdata->Uoffset); + *Sx = (void *)(long)((long)rdata + (long)rdata->Soffset); + *P = (void *)(long)((long)rdata + (long)rdata->Poffset); + *X = (void *)(long)((long)rdata + (long)rdata->Xoffset); + //ramchain->roU2 = (void *)(long)((long)rdata + (long)rdata->U2offset); + //ramchain->roP2 = (void *)(long)((long)rdata + (long)rdata->P2offset); + ramchain->roA = (void *)(long)(long)((long)rdata + (long)rdata->Aoffset); //if ( (*U2= ramchain->U2) == 0 ) // *U2 = ramchain->U2 = ramchain->roU2; //if ( (*P2= ramchain->P2) == 0 ) @@ -612,21 +612,21 @@ void _iguana_ramchain_setptrs(RAMCHAIN_PTRPS,struct iguana_ramchaindata *rdata) if ( (*A= ramchain->A) == 0 ) *A = ramchain->A = ramchain->roA; //printf("T.%p Ux.%p Sx.%p P.%p\n",*T,*Ux,*Sx,*P); - *TXbits = (void *)((long)rdata + (long)rdata->TXoffset); - *PKbits = (void *)((long)rdata + (long)rdata->PKoffset); + *TXbits = (void *)(long)((long)rdata + (long)rdata->TXoffset); + *PKbits = (void *)(long)((long)rdata + (long)rdata->PKoffset); *U = 0, *S = 0; } else { - *U = (void *)((long)rdata + (long)rdata->Uoffset); - *S = (void *)((long)rdata + (long)rdata->Soffset); + *U = (void *)(long)((long)rdata + (long)rdata->Uoffset); + *S = (void *)(long)((long)rdata + (long)rdata->Soffset); *Ux = 0, *Sx = 0, *P = 0, *X = 0, *A = 0, *TXbits = 0, *PKbits = 0; //*U2 = 0, *P2 = 0, } } void *iguana_ramchain_offset(void *dest,uint8_t *lhash,FILE *fp,uint64_t fpos,void *srcptr,uint64_t *offsetp,uint64_t len,uint64_t srcsize) { - void *destptr = (void *)((long)dest + *offsetp); + void *destptr = (void *)(long)((long)dest + *offsetp); if ( (lhash != 0 || fp != 0) && (*offsetp + len) > srcsize ) { printf("ramchain_offset overflow (%p %p) offset.%ld + len.%ld %ld > %ld srcsize\n",fp,lhash,(long)*offsetp,(long)len,(long)(*offsetp + len),(long)srcsize); @@ -644,7 +644,7 @@ void *iguana_ramchain_offset(void *dest,uint8_t *lhash,FILE *fp,uint64_t fpos,vo //else printf("fp.(%ld <- %d) ",ftell(fp),(int32_t)len); } (*offsetp) += len; - return((void *)((long)destptr + fpos)); + return((void *)(long)((long)destptr + fpos)); } int64_t _iguana_rdata_action(FILE *fp,bits256 lhashes[IGUANA_NUMLHASHES],void *destptr,uint64_t fpos,uint32_t expanded,uint32_t numtxids,uint32_t numunspents,uint32_t numspends,uint32_t numpkinds,uint32_t numexternaltxids,uint32_t txsparsebits,uint64_t numtxsparse,uint32_t pksparsebits,uint64_t numpksparse,uint64_t srcsize,RAMCHAIN_FUNC,int32_t numblocks) @@ -1124,7 +1124,7 @@ struct iguana_ramchain *iguana_ramchain_map(struct iguana_info *coin,char *fname if ( ramchain->fileptr != 0 && ramchain->filesize > 0 ) { // verify hashes - ramchain->H.data = (void *)((long)ramchain->fileptr + fpos); + ramchain->H.data = (void *)(long)((long)ramchain->fileptr + fpos); ramchain->H.ROflag = 1; ramchain->expanded = expanded; ramchain->numblocks = (bp == 0) ? 1 : bp->n; @@ -1503,7 +1503,7 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru mapchain->fileptr = 0, mapchain->filesize = 0; iguana_ramchain_free(mapchain,1); memset(&R,0,sizeof(R)); - R.H.data = (void *)((long)ptr + fpos), R.filesize = fsize; + R.H.data = (void *)(long)((long)ptr + fpos), R.filesize = fsize; iguana_ramchain_link(&R,origtxdata->block.RO.hash2,origtxdata->block.RO.hash2,bp->hdrsi,bp->bundleheight+bundlei,bundlei,1,firsti,1); } if ( (err= iguana_ramchain_cmp(ramchain,&R,0)) != 0 ) @@ -1695,8 +1695,8 @@ struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana { iguana_ramchain_link(mapchain,bp->hashes[0],bp->ramchain.lasthash2,bp->hdrsi,bp->bundleheight,0,bp->ramchain.numblocks,firsti,1); //char str[65]; printf("bp.%d: T.%d U.%d S.%d P%d X.%d MAPPED %s %p\n",bp->hdrsi,bp->ramchain.H.data->numtxids,bp->ramchain.H.data->numunspents,bp->ramchain.H.data->numspends,bp->ramchain.H.data->numpkinds,bp->ramchain.H.data->numexternaltxids,mbstr(str,bp->ramchain.H.data->allocsize),bp->ramchain.H.data); - B = (void *)((long)mapchain->H.data + mapchain->H.data->Boffset); - T = (void *)((long)mapchain->H.data + mapchain->H.data->Toffset); + B = (void *)(long)((long)mapchain->H.data + mapchain->H.data->Boffset); + T = (void *)(long)((long)mapchain->H.data + mapchain->H.data->Toffset); for (i=0; in; i++) { if ( (block= bp->blocks[i]) != 0 || (block= iguana_blockhashset(coin,bp->bundleheight+i,bp->hashes[i],1)) != 0 ) @@ -1767,7 +1767,7 @@ int32_t iguana_bundlesaveHT(struct iguana_info *coin,struct OS_memspace *mem,str } mapchain->fileptr = ptr; mapchain->filesize = filesize; - mapchain->H.data = (void *)((long)ptr + fpos); + mapchain->H.data = (void *)(long)((long)ptr + fpos); mapchain->H.ROflag = 1; if ( fpos+mapchain->H.data->allocsize > filesize || iguana_ramchain_size(MAPCHAIN_ARG,1) != mapchain->H.data->allocsize ) { diff --git a/iguana/iguana_rpc.c b/iguana/iguana_rpc.c index 266ee1d55..f03fc9833 100755 --- a/iguana/iguana_rpc.c +++ b/iguana/iguana_rpc.c @@ -185,9 +185,9 @@ void iguana_vinset(struct iguana_info *coin,int32_t height,struct iguana_msgvin memset(vin,0,sizeof(*vin)); if ( height >= 0 && height < coin->chain->bundlesize*coin->bundlescount && (bp= coin->bundles[height / coin->chain->bundlesize]) != 0 && (rdata= bp->ramchain.H.data) != 0 ) { - S = (void *)((long)rdata + rdata->Soffset); - X = (void *)((long)rdata + rdata->Xoffset); - T = (void *)((long)rdata + rdata->Toffset); + S = (void *)(long)((long)rdata + rdata->Soffset); + X = (void *)(long)((long)rdata + rdata->Xoffset); + T = (void *)(long)((long)rdata + rdata->Toffset); spendind = (tx->firstvin + i); s = &S[spendind]; if ( s->diffsequence == 0 ) @@ -204,8 +204,8 @@ int32_t iguana_voutset(struct iguana_info *coin,uint8_t *scriptspace,char *asmst memset(vout,0,sizeof(*vout)); if ( height >= 0 && height < coin->chain->bundlesize*coin->bundlescount && (bp= coin->bundles[height / coin->chain->bundlesize]) != 0 && (rdata= bp->ramchain.H.data) != 0 ) { - U = (void *)((long)rdata + rdata->Uoffset); - P = (void *)((long)rdata + rdata->Poffset); + U = (void *)(long)((long)rdata + rdata->Uoffset); + P = (void *)(long)((long)rdata + rdata->Poffset); unspentind = (tx->firstvout + i); u = &U[unspentind]; if ( u->txidind != tx->txidind || u->vout != i || u->hdrsi != height / coin->chain->bundlesize ) diff --git a/iguana/m_win32 b/iguana/m_win32 index e45cfad34..b587ba2b0 100755 --- a/iguana/m_win32 +++ b/iguana/m_win32 @@ -1 +1,2 @@ -echo do equivalent of: gcc -o ../agents/iguana -O2 *.c ../agents/libcrypto777.a -lssl -lcrypto -lpthread -lm +make -f mingw32 + diff --git a/iguana/mingw b/iguana/mingw new file mode 100755 index 000000000..51992ea6d --- /dev/null +++ b/iguana/mingw @@ -0,0 +1,14 @@ +SOURCES := iguana_pubkeys.c iguana_recv.c iguana_bundles.c iguana_msg.c iguana_rpc.c iguana777.c iguana_chains.c iguana_peers.c iguana_accept.c iguana_html.c iguana_bitmap.c iguana_init.c iguana_ramchain.c iguana_blocks.c iguana_json.c ../crypto777/cJSON.c ../crypto777/iguana_utils.c ../crypto777/OS_nonportable.c ../crypto777/curve25519-donna.c ../crypto777/inet.c ../crypto777/OS_portable.c ../crypto777/curve25519.c ../crypto777/libgfshare.c ../crypto777/OS_time.c ../crypto777/hmac_sha512.c ../crypto777/ramcoder.c ../crypto777/SaM.c ../crypto777/iguana_OS.c ../crypto777/iguana_serdes.c ../crypto777/jpeg/jaricom.c ../crypto777/jpeg/jcapimin.c ../crypto777/jpeg/jcapistd.c ../crypto777/jpeg/jcarith.c ../crypto777/jpeg/jccoefct.c ../crypto777/jpeg/jccolor.c \ + ../crypto777/jpeg/jcdctmgr.c ../crypto777/jpeg/jchuff.c ../crypto777/jpeg/jcinit.c ../crypto777/jpeg/jcmainct.c ../crypto777/jpeg/jcmarker.c ../crypto777/jpeg/jcmaster.c \ + ../crypto777/jpeg/jcomapi.c ../crypto777/jpeg/jcparam.c ../crypto777/jpeg/jcprepct.c ../crypto777/jpeg/jcsample.c ../crypto777/jpeg/jctrans.c ../crypto777/jpeg/jdapimin.c \ + ../crypto777/jpeg/jdapistd.c ../crypto777/jpeg/jdarith.c ../crypto777/jpeg/jdatadst.c ../crypto777/jpeg/jdatasrc.c ../crypto777/jpeg/jdcoefct.c ../crypto777/jpeg/jdcolor.c \ + ../crypto777/jpeg/jddctmgr.c ../crypto777/jpeg/jdhuff.c ../crypto777/jpeg/jdinput.c ../crypto777/jpeg/jdmainct.c ../crypto777/jpeg/jdmarker.c ../crypto777/jpeg/jdmaster.c \ + ../crypto777/jpeg/jdmerge.c ../crypto777/jpeg/jdpostct.c ../crypto777/jpeg/jdsample.c ../crypto777/jpeg/jdtrans.c ../crypto777/jpeg/jerror.c ../crypto777/jpeg/jfdctflt.c \ + ../crypto777/jpeg/jfdctfst.c ../crypto777/jpeg/jfdctint.c ../crypto777/jpeg/jidctflt.c ../crypto777/jpeg/jidctfst.c ../crypto777/jpeg/jidctint.c ../crypto777/jpeg/jquant1.c \ + ../crypto777/jpeg/jquant2.c ../crypto777/jpeg/jutils.c ../crypto777/jpeg/jmemmgr.c ../crypto777/jpeg/jmemnobs.c main.c + + +all: + $(TOOL_DIR)/$(MINGW)-gcc -o ../agents/iguana.exe -D __MINGW $(SOURCES) $(LIBS) + $(TOOL_DIR)/$(MINGW)-strip --strip-all ../agents/iguana.exe + diff --git a/iguana/mingw32 b/iguana/mingw32 new file mode 100755 index 000000000..ed5309db4 --- /dev/null +++ b/iguana/mingw32 @@ -0,0 +1,9 @@ +TOOL_DIR := /usr/local/gcc-4.8.0-qt-4.8.4-for-mingw32/win32-gcc/bin +MINGW := i586-mingw32 +LIBS := ../win/libcrypto.a ../win/libssl.a ../win/libpthreadGC2.a -lws2_32 -lgdi32 + +include mingw + +all: + $(TOOL_DIR)/$(MINGW)-gcc -o ../agents/iguana.exe -D __MINGW $(SOURCES) $(LIBS) + $(TOOL_DIR)/$(MINGW)-strip --strip-all ../agents/iguana.exe diff --git a/iguana/mingw64 b/iguana/mingw64 new file mode 100755 index 000000000..b5f314e5f --- /dev/null +++ b/iguana/mingw64 @@ -0,0 +1,9 @@ +TOOL_DIR := /usr/local/gcc-4.8.0-qt-4.8.4-for-mingw64/win64-gcc/bin +MINGW := i686-mingw64 +LIBS := ../win/libcrypto.a ../win/libs/libssl.a ../win/libpthreadGC2_64.a -lws2_64 -lgdi64 + +include mingw + +all: + $(TOOL_DIR)/$(MINGW)-gcc -o ../agents/iguana.exe -D __MINGW $(SOURCES) $(LIBS) + $(TOOL_DIR)/$(MINGW)-strip --strip-all ../agents/iguana.exe diff --git a/includes/nonportable.h b/includes/nonportable.h index 077ebc613..66c97a362 100755 --- a/includes/nonportable.h +++ b/includes/nonportable.h @@ -1,4 +1,4 @@ -// MIT license +/* #ifndef _NONPORTABLELINUX_H #define _NONPORTABLELINUX_H @@ -8,4 +8,4 @@ #include #include -#endif +#endif*/ diff --git a/libs/include/aes.h b/includes/openssl/aes.h similarity index 99% rename from libs/include/aes.h rename to includes/openssl/aes.h index 031abf01b..7d4a150e8 100644 --- a/libs/include/aes.h +++ b/includes/openssl/aes.h @@ -52,7 +52,7 @@ #ifndef HEADER_AES_H #define HEADER_AES_H -#include +#include "opensslconf.h" #ifdef OPENSSL_NO_AES #error AES is disabled. diff --git a/libs/include/asn1.h b/includes/openssl/asn1.h similarity index 99% rename from libs/include/asn1.h rename to includes/openssl/asn1.h index 220a0c8c6..629b7d2ba 100644 --- a/libs/include/asn1.h +++ b/includes/openssl/asn1.h @@ -60,18 +60,18 @@ #define HEADER_ASN1_H #include -#include +#include "e_os2.h" #ifndef OPENSSL_NO_BIO -#include +#include "bio.h" #endif -#include -#include +#include "stack.h" +#include "safestack.h" -#include +#include "symhacks.h" -#include +#include "ossl_typ.h" #ifndef OPENSSL_NO_DEPRECATED -#include +#include "bn.h" #endif #ifdef OPENSSL_BUILD_SHLIBCRYPTO diff --git a/libs/include/asn1_mac.h b/includes/openssl/asn1_mac.h similarity index 99% rename from libs/include/asn1_mac.h rename to includes/openssl/asn1_mac.h index 87bd0e9e1..e8929d045 100644 --- a/libs/include/asn1_mac.h +++ b/includes/openssl/asn1_mac.h @@ -59,7 +59,7 @@ #ifndef HEADER_ASN1_MAC_H #define HEADER_ASN1_MAC_H -#include +#include "asn1.h" #ifdef __cplusplus extern "C" { diff --git a/libs/include/asn1t.h b/includes/openssl/asn1t.h similarity index 99% rename from libs/include/asn1t.h rename to includes/openssl/asn1t.h index d230e4bf7..eb78f4c3c 100644 --- a/libs/include/asn1t.h +++ b/includes/openssl/asn1t.h @@ -59,8 +59,8 @@ #define HEADER_ASN1T_H #include -#include -#include +#include "e_os2.h" +#include "asn1.h" #ifdef OPENSSL_BUILD_SHLIBCRYPTO # undef OPENSSL_EXTERN diff --git a/libs/include/bio.h b/includes/openssl/bio.h similarity index 99% rename from libs/include/bio.h rename to includes/openssl/bio.h index 05699ab21..ccbc8c349 100644 --- a/libs/include/bio.h +++ b/includes/openssl/bio.h @@ -59,14 +59,14 @@ #ifndef HEADER_BIO_H #define HEADER_BIO_H -#include +#include "e_os2.h" #ifndef OPENSSL_NO_FP_API # include #endif #include -#include +#include "crypto.h" #ifndef OPENSSL_NO_SCTP # ifndef OPENSSL_SYS_VMS diff --git a/libs/include/blowfish.h b/includes/openssl/blowfish.h similarity index 99% rename from libs/include/blowfish.h rename to includes/openssl/blowfish.h index 4b6c8920a..698a92465 100644 --- a/libs/include/blowfish.h +++ b/includes/openssl/blowfish.h @@ -59,7 +59,7 @@ #ifndef HEADER_BLOWFISH_H #define HEADER_BLOWFISH_H -#include +#include "e_os2.h" #ifdef __cplusplus extern "C" { diff --git a/libs/include/bn.h b/includes/openssl/bn.h similarity index 99% rename from libs/include/bn.h rename to includes/openssl/bn.h index 21a1a3fe3..7cfd5dff5 100644 --- a/libs/include/bn.h +++ b/includes/openssl/bn.h @@ -125,12 +125,12 @@ #ifndef HEADER_BN_H #define HEADER_BN_H -#include +#include "e_os2.h" #ifndef OPENSSL_NO_FP_API #include /* FILE */ #endif -#include -#include +#include "ossl_typ.h" +#include "crypto.h" #ifdef __cplusplus extern "C" { diff --git a/libs/include/buffer.h b/includes/openssl/buffer.h similarity index 99% rename from libs/include/buffer.h rename to includes/openssl/buffer.h index f8da32b48..cde2668ee 100644 --- a/libs/include/buffer.h +++ b/includes/openssl/buffer.h @@ -59,7 +59,7 @@ #ifndef HEADER_BUFFER_H #define HEADER_BUFFER_H -#include +#include "ossl_typ.h" #ifdef __cplusplus extern "C" { diff --git a/libs/include/camellia.h b/includes/openssl/camellia.h similarity index 99% rename from libs/include/camellia.h rename to includes/openssl/camellia.h index 67911e0ad..11f2f052f 100644 --- a/libs/include/camellia.h +++ b/includes/openssl/camellia.h @@ -52,7 +52,7 @@ #ifndef HEADER_CAMELLIA_H #define HEADER_CAMELLIA_H -#include +#include "opensslconf.h" #ifdef OPENSSL_NO_CAMELLIA #error CAMELLIA is disabled. diff --git a/libs/include/cast.h b/includes/openssl/cast.h similarity index 99% rename from libs/include/cast.h rename to includes/openssl/cast.h index 203922ea2..0a2a52c18 100644 --- a/libs/include/cast.h +++ b/includes/openssl/cast.h @@ -63,7 +63,7 @@ extern "C" { #endif -#include +#include "opensslconf.h" #ifdef OPENSSL_NO_CAST #error CAST is disabled. diff --git a/libs/include/cmac.h b/includes/openssl/cmac.h similarity index 99% rename from libs/include/cmac.h rename to includes/openssl/cmac.h index 712e92dce..9ab0d2520 100644 --- a/libs/include/cmac.h +++ b/includes/openssl/cmac.h @@ -59,7 +59,7 @@ extern "C" { #endif -#include +#include "evp.h" /* Opaque */ typedef struct CMAC_CTX_st CMAC_CTX; diff --git a/libs/include/cms.h b/includes/openssl/cms.h similarity index 99% rename from libs/include/cms.h rename to includes/openssl/cms.h index 36994fa6a..321139fb7 100644 --- a/libs/include/cms.h +++ b/includes/openssl/cms.h @@ -55,7 +55,7 @@ #ifndef HEADER_CMS_H #define HEADER_CMS_H -#include +#include "x509.h" #ifdef OPENSSL_NO_CMS #error CMS is disabled. diff --git a/libs/include/comp.h b/includes/openssl/comp.h similarity index 98% rename from libs/include/comp.h rename to includes/openssl/comp.h index 4b405c7d4..306da3f74 100644 --- a/libs/include/comp.h +++ b/includes/openssl/comp.h @@ -2,7 +2,7 @@ #ifndef HEADER_COMP_H #define HEADER_COMP_H -#include +#include "crypto.h" #ifdef __cplusplus extern "C" { diff --git a/libs/include/conf.h b/includes/openssl/conf.h similarity index 98% rename from libs/include/conf.h rename to includes/openssl/conf.h index c2199978a..57f513768 100644 --- a/libs/include/conf.h +++ b/includes/openssl/conf.h @@ -59,13 +59,13 @@ #ifndef HEADER_CONF_H #define HEADER_CONF_H -#include -#include -#include -#include -#include +#include "bio.h" +#include "lhash.h" +#include "stack.h" +#include "safestack.h" +#include "e_os2.h" -#include +#include "ossl_typ.h" #ifdef __cplusplus extern "C" { diff --git a/libs/include/conf_api.h b/includes/openssl/conf_api.h similarity index 98% rename from libs/include/conf_api.h rename to includes/openssl/conf_api.h index 87a954aff..2efea8882 100644 --- a/libs/include/conf_api.h +++ b/includes/openssl/conf_api.h @@ -59,8 +59,8 @@ #ifndef HEADER_CONF_API_H #define HEADER_CONF_API_H -#include -#include +#include "lhash.h" +#include "conf.h" #ifdef __cplusplus extern "C" { diff --git a/libs/include/crypto.h b/includes/openssl/crypto.h similarity index 99% rename from libs/include/crypto.h rename to includes/openssl/crypto.h index f92fc5182..7f542395c 100644 --- a/libs/include/crypto.h +++ b/includes/openssl/crypto.h @@ -119,24 +119,24 @@ #include -#include +#include "e_os2.h" #ifndef OPENSSL_NO_FP_API #include #endif -#include -#include -#include -#include +#include "stack.h" +#include "safestack.h" +#include "opensslv.h" +#include "ossl_typ.h" #ifdef CHARSET_EBCDIC -#include +#include "ebcdic.h" #endif /* Resolve problems on some operating systems with symbol names that clash one way or another */ -#include +#include "symhacks.h" #ifdef __cplusplus extern "C" { diff --git a/libs/include/curl.h b/includes/openssl/curl.h similarity index 100% rename from libs/include/curl.h rename to includes/openssl/curl.h diff --git a/libs/include/curlbuild.h b/includes/openssl/curlbuild.h similarity index 100% rename from libs/include/curlbuild.h rename to includes/openssl/curlbuild.h diff --git a/libs/include/curlrules.h b/includes/openssl/curlrules.h similarity index 100% rename from libs/include/curlrules.h rename to includes/openssl/curlrules.h diff --git a/libs/include/curlver.h b/includes/openssl/curlver.h similarity index 100% rename from libs/include/curlver.h rename to includes/openssl/curlver.h diff --git a/libs/include/des.h b/includes/openssl/des.h similarity index 99% rename from libs/include/des.h rename to includes/openssl/des.h index 1eaedcbd2..7508952b6 100644 --- a/libs/include/des.h +++ b/includes/openssl/des.h @@ -59,7 +59,7 @@ #ifndef HEADER_NEW_DES_H #define HEADER_NEW_DES_H -#include /* OPENSSL_EXTERN, OPENSSL_NO_DES, +#include "e_os2.h" /* OPENSSL_EXTERN, OPENSSL_NO_DES, DES_LONG (via openssl/opensslconf.h */ #ifdef OPENSSL_NO_DES diff --git a/libs/include/des_old.h b/includes/openssl/des_old.h similarity index 99% rename from libs/include/des_old.h rename to includes/openssl/des_old.h index 2b2c37235..0f594966f 100644 --- a/libs/include/des_old.h +++ b/includes/openssl/des_old.h @@ -91,7 +91,7 @@ #ifndef HEADER_DES_H #define HEADER_DES_H -#include /* OPENSSL_EXTERN, OPENSSL_NO_DES, DES_LONG */ +#include "e_os2.h" /* OPENSSL_EXTERN, OPENSSL_NO_DES, DES_LONG */ #ifdef OPENSSL_NO_DES #error DES is disabled. @@ -105,7 +105,7 @@ #error replaces . #endif -#include +#include "symhacks.h" #ifdef OPENSSL_BUILD_SHLIBCRYPTO # undef OPENSSL_EXTERN @@ -441,6 +441,6 @@ void _ossl_096_des_random_seed(des_cblock *key); #endif /* for DES_read_pw_string et al */ -#include +#include "ui_compat.h" #endif diff --git a/libs/include/dh.h b/includes/openssl/dh.h similarity index 98% rename from libs/include/dh.h rename to includes/openssl/dh.h index ea59e610e..1e5ab4cb6 100644 --- a/libs/include/dh.h +++ b/includes/openssl/dh.h @@ -59,18 +59,18 @@ #ifndef HEADER_DH_H #define HEADER_DH_H -#include +#include "e_os2.h" #ifdef OPENSSL_NO_DH #error DH is disabled. #endif #ifndef OPENSSL_NO_BIO -#include +#include "bio.h" #endif -#include +#include "ossl_typ.h" #ifndef OPENSSL_NO_DEPRECATED -#include +#include "bn.h" #endif #ifndef OPENSSL_DH_MAX_MODULUS_BITS diff --git a/libs/include/dsa.h b/includes/openssl/dsa.h similarity index 98% rename from libs/include/dsa.h rename to includes/openssl/dsa.h index a6f6d0b0b..f7a3bb0ac 100644 --- a/libs/include/dsa.h +++ b/includes/openssl/dsa.h @@ -65,22 +65,22 @@ #ifndef HEADER_DSA_H #define HEADER_DSA_H -#include +#include "e_os2.h" #ifdef OPENSSL_NO_DSA #error DSA is disabled. #endif #ifndef OPENSSL_NO_BIO -#include +#include "bio.h" #endif -#include -#include +#include "crypto.h" +#include "ossl_typ.h" #ifndef OPENSSL_NO_DEPRECATED -#include +#include "bn.h" #ifndef OPENSSL_NO_DH -# include +#include "dh.h" #endif #endif diff --git a/libs/include/dso.h b/includes/openssl/dso.h similarity index 99% rename from libs/include/dso.h rename to includes/openssl/dso.h index 839f2e061..e89c73c21 100644 --- a/libs/include/dso.h +++ b/includes/openssl/dso.h @@ -59,7 +59,7 @@ #ifndef HEADER_DSO_H #define HEADER_DSO_H -#include +#include "crypto.h" #ifdef __cplusplus extern "C" { diff --git a/libs/include/dtls1.h b/includes/openssl/dtls1.h similarity index 99% rename from libs/include/dtls1.h rename to includes/openssl/dtls1.h index e65d50119..8d229f3bf 100644 --- a/libs/include/dtls1.h +++ b/includes/openssl/dtls1.h @@ -60,8 +60,8 @@ #ifndef HEADER_DTLS1_H #define HEADER_DTLS1_H -#include -#include +#include "buffer.h" +#include "pqueue.h" #ifdef OPENSSL_SYS_VMS #include #include diff --git a/includes/openssl/e_os.h b/includes/openssl/e_os.h new file mode 100644 index 000000000..6a0aad1de --- /dev/null +++ b/includes/openssl/e_os.h @@ -0,0 +1,741 @@ +/* e_os.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_E_OS_H +#define HEADER_E_OS_H + +#include + +#include +/* contains what we can justify to make visible + * to the outside; this file e_os.h is not part of the exported + * interface. */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Used to checking reference counts, most while doing perl5 stuff :-) */ +#ifdef REF_PRINT +#undef REF_PRINT +#define REF_PRINT(a,b) fprintf(stderr,"%08X:%4d:%s\n",(int)b,b->references,a) +#endif + +#ifndef DEVRANDOM +/* set this to a comma-separated list of 'random' device files to try out. + * My default, we will try to read at least one of these files */ +#define DEVRANDOM "/dev/urandom","/dev/random","/dev/srandom" +#endif +#ifndef DEVRANDOM_EGD +/* set this to a comma-seperated list of 'egd' sockets to try out. These + * sockets will be tried in the order listed in case accessing the device files + * listed in DEVRANDOM did not return enough entropy. */ +#define DEVRANDOM_EGD "/var/run/egd-pool","/dev/egd-pool","/etc/egd-pool","/etc/entropy" +#endif + +#if defined(OPENSSL_SYS_VXWORKS) +# define NO_SYS_PARAM_H +# define NO_CHMOD +# define NO_SYSLOG +#endif + +#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) +# if macintosh==1 +# ifndef MAC_OS_GUSI_SOURCE +# define MAC_OS_pre_X +# define NO_SYS_TYPES_H +# endif +# define NO_SYS_PARAM_H +# define NO_CHMOD +# define NO_SYSLOG +# undef DEVRANDOM +# define GETPID_IS_MEANINGLESS +# endif +#endif + +/******************************************************************** + The Microsoft section + ********************************************************************/ +/* The following is used because of the small stack in some + * Microsoft operating systems */ +#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYSNAME_WIN32) +# define MS_STATIC static +#else +# define MS_STATIC +#endif + +#if defined(OPENSSL_SYS_WIN32) && !defined(WIN32) +# define WIN32 +#endif +#if defined(OPENSSL_SYS_WINDOWS) && !defined(WINDOWS) +# define WINDOWS +#endif +#if defined(OPENSSL_SYS_MSDOS) && !defined(MSDOS) +# define MSDOS +#endif + +#if defined(MSDOS) && !defined(GETPID_IS_MEANINGLESS) +# define GETPID_IS_MEANINGLESS +#endif + +#ifdef WIN32 +#define get_last_sys_error() GetLastError() +#define clear_sys_error() SetLastError(0) +#if !defined(WINNT) +#define WIN_CONSOLE_BUG +#endif +#else +#define get_last_sys_error() errno +#define clear_sys_error() errno=0 +#endif + +#if defined(WINDOWS) +#define get_last_socket_error() WSAGetLastError() +#define clear_socket_error() WSASetLastError(0) +#define readsocket(s,b,n) recv((s),(b),(n),0) +#define writesocket(s,b,n) send((s),(b),(n),0) +#elif defined(__DJGPP__) +#define WATT32 +#define get_last_socket_error() errno +#define clear_socket_error() errno=0 +#define closesocket(s) close_s(s) +#define readsocket(s,b,n) read_s(s,b,n) +#define writesocket(s,b,n) send(s,b,n,0) +#elif defined(MAC_OS_pre_X) +#define get_last_socket_error() errno +#define clear_socket_error() errno=0 +#define closesocket(s) MacSocket_close(s) +#define readsocket(s,b,n) MacSocket_recv((s),(b),(n),true) +#define writesocket(s,b,n) MacSocket_send((s),(b),(n)) +#elif defined(OPENSSL_SYS_VMS) +#define get_last_socket_error() errno +#define clear_socket_error() errno=0 +#define ioctlsocket(a,b,c) ioctl(a,b,c) +#define closesocket(s) close(s) +#define readsocket(s,b,n) recv((s),(b),(n),0) +#define writesocket(s,b,n) send((s),(b),(n),0) +#elif defined(OPENSSL_SYS_VXWORKS) +#define get_last_socket_error() errno +#define clear_socket_error() errno=0 +#define ioctlsocket(a,b,c) ioctl((a),(b),(int)(c)) +#define closesocket(s) close(s) +#define readsocket(s,b,n) read((s),(b),(n)) +#define writesocket(s,b,n) write((s),(char *)(b),(n)) +#elif defined(OPENSSL_SYS_BEOS_R5) +#define get_last_socket_error() errno +#define clear_socket_error() errno=0 +#define FIONBIO SO_NONBLOCK +#define ioctlsocket(a,b,c) setsockopt((a),SOL_SOCKET,(b),(c),sizeof(*(c))) +#define readsocket(s,b,n) recv((s),(b),(n),0) +#define writesocket(s,b,n) send((s),(b),(n),0) +#elif defined(OPENSSL_SYS_NETWARE) +#if defined(NETWARE_BSDSOCK) +#define get_last_socket_error() errno +#define clear_socket_error() errno=0 +#define closesocket(s) close(s) +#define ioctlsocket(a,b,c) ioctl(a,b,c) +#if defined(NETWARE_LIBC) +#define readsocket(s,b,n) recv((s),(b),(n),0) +#define writesocket(s,b,n) send((s),(b),(n),0) +#else +#define readsocket(s,b,n) recv((s),(char*)(b),(n),0) +#define writesocket(s,b,n) send((s),(char*)(b),(n),0) +#endif +#else +#define get_last_socket_error() WSAGetLastError() +#define clear_socket_error() WSASetLastError(0) +#define readsocket(s,b,n) recv((s),(b),(n),0) +#define writesocket(s,b,n) send((s),(b),(n),0) +#endif +#else +#define get_last_socket_error() errno +#define clear_socket_error() errno=0 +#define ioctlsocket(a,b,c) ioctl(a,b,c) +#define closesocket(s) close(s) +#define readsocket(s,b,n) read((s),(b),(n)) +#define writesocket(s,b,n) write((s),(b),(n)) +#endif + +#ifdef WIN16 /* never the case */ +# define MS_CALLBACK _far _loadds +# define MS_FAR _far +#else +# define MS_CALLBACK +# define MS_FAR +#endif + +#ifdef OPENSSL_NO_STDIO +# undef OPENSSL_NO_FP_API +# define OPENSSL_NO_FP_API +#endif + +#if (defined(WINDOWS) || defined(MSDOS)) + +# ifdef __DJGPP__ +# include +# include +# include +# include +# include +# define _setmode setmode +# define _O_TEXT O_TEXT +# define _O_BINARY O_BINARY +# undef DEVRANDOM +# define DEVRANDOM "/dev/urandom\x24" +# endif /* __DJGPP__ */ + +# ifndef S_IFDIR +# define S_IFDIR _S_IFDIR +# endif + +# ifndef S_IFMT +# define S_IFMT _S_IFMT +# endif + +# if !defined(WINNT) && !defined(__DJGPP__) +# define NO_SYSLOG +# endif +# define NO_DIRENT + +# ifdef WINDOWS +# if !defined(_WIN32_WCE) && !defined(_WIN32_WINNT) + /* + * Defining _WIN32_WINNT here in e_os.h implies certain "discipline." + * Most notably we ought to check for availability of each specific + * routine with GetProcAddress() and/or guard NT-specific calls with + * GetVersion() < 0x80000000. One can argue that in latter "or" case + * we ought to /DELAYLOAD some .DLLs in order to protect ourselves + * against run-time link errors. This doesn't seem to be necessary, + * because it turned out that already Windows 95, first non-NT Win32 + * implementation, is equipped with at least NT 3.51 stubs, dummy + * routines with same name, but which do nothing. Meaning that it's + * apparently sufficient to guard "vanilla" NT calls with GetVersion + * alone, while NT 4.0 and above interfaces ought to be linked with + * GetProcAddress at run-time. + */ +# define _WIN32_WINNT 0x0400 +# endif +# if !defined(OPENSSL_NO_SOCK) && defined(_WIN32_WINNT) + /* + * Just like defining _WIN32_WINNT including winsock2.h implies + * certain "discipline" for maintaining [broad] binary compatibility. + * As long as structures are invariant among Winsock versions, + * it's sufficient to check for specific Winsock2 API availability + * at run-time [DSO_global_lookup is recommended]... + */ +# include +# include + /* yes, they have to be #included prior to */ +# endif +# include +# include +# include +# include +# include +# ifdef _WIN64 +# define strlen(s) _strlen31(s) +/* cut strings to 2GB */ +static unsigned int _strlen31(const char *str) + { + unsigned int len=0; + while (*str && len<0x80000000U) str++, len++; + return len&0x7FFFFFFF; + } +# endif +# include +# if defined(_MSC_VER) && _MSC_VER<=1200 && defined(_MT) && defined(isspace) + /* compensate for bug in VC6 ctype.h */ +# undef isspace +# undef isdigit +# undef isalnum +# undef isupper +# undef isxdigit +# endif +# if defined(_MSC_VER) && !defined(_DLL) && defined(stdin) +# if _MSC_VER>=1300 +# undef stdin +# undef stdout +# undef stderr + FILE *__iob_func(); +# define stdin (&__iob_func()[0]) +# define stdout (&__iob_func()[1]) +# define stderr (&__iob_func()[2]) +# elif defined(I_CAN_LIVE_WITH_LNK4049) +# undef stdin +# undef stdout +# undef stderr + /* pre-1300 has __p__iob(), but it's available only in msvcrt.lib, + * or in other words with /MD. Declaring implicit import, i.e. + * with _imp_ prefix, works correctly with all compiler options, + * but without /MD results in LINK warning LNK4049: + * 'locally defined symbol "__iob" imported'. + */ + extern FILE *_imp___iob; +# define stdin (&_imp___iob[0]) +# define stdout (&_imp___iob[1]) +# define stderr (&_imp___iob[2]) +# endif +# endif +# endif +# include +# include + +# ifdef OPENSSL_SYS_WINCE +# define OPENSSL_NO_POSIX_IO +# endif + +# if defined (__BORLANDC__) +# define _setmode setmode +# define _O_TEXT O_TEXT +# define _O_BINARY O_BINARY +# define _int64 __int64 +# define _kbhit kbhit +# endif + +# define EXIT(n) exit(n) +# define LIST_SEPARATOR_CHAR ';' +# ifndef X_OK +# define X_OK 0 +# endif +# ifndef W_OK +# define W_OK 2 +# endif +# ifndef R_OK +# define R_OK 4 +# endif +# define OPENSSL_CONF "openssl.cnf" +# define SSLEAY_CONF OPENSSL_CONF +# define NUL_DEV "nul" +# define RFILE ".rnd" +# ifdef OPENSSL_SYS_WINCE +# define DEFAULT_HOME "" +# else +# define DEFAULT_HOME "C:" +# endif + +/* Avoid Windows 8 SDK GetVersion deprecated problems */ +#if defined(_MSC_VER) && _MSC_VER>=1800 +# define check_winnt() (1) +#else +# define check_winnt() (GetVersion() < 0x80000000) +#endif + +#else /* The non-microsoft world */ + +# ifdef OPENSSL_SYS_VMS +# define VMS 1 + /* some programs don't include stdlib, so exit() and others give implicit + function warnings */ +# include +# if defined(__DECC) +# include +# else +# include +# endif +# define OPENSSL_CONF "openssl.cnf" +# define SSLEAY_CONF OPENSSL_CONF +# define RFILE ".rnd" +# define LIST_SEPARATOR_CHAR ',' +# define NUL_DEV "NLA0:" + /* We don't have any well-defined random devices on VMS, yet... */ +# undef DEVRANDOM + /* We need to do this since VMS has the following coding on status codes: + + Bits 0-2: status type: 0 = warning, 1 = success, 2 = error, 3 = info ... + The important thing to know is that odd numbers are considered + good, while even ones are considered errors. + Bits 3-15: actual status number + Bits 16-27: facility number. 0 is considered "unknown" + Bits 28-31: control bits. If bit 28 is set, the shell won't try to + output the message (which, for random codes, just looks ugly) + + So, what we do here is to change 0 to 1 to get the default success status, + and everything else is shifted up to fit into the status number field, and + the status is tagged as an error, which I believe is what is wanted here. + -- Richard Levitte + */ +# define EXIT(n) do { int __VMS_EXIT = n; \ + if (__VMS_EXIT == 0) \ + __VMS_EXIT = 1; \ + else \ + __VMS_EXIT = (n << 3) | 2; \ + __VMS_EXIT |= 0x10000000; \ + exit(__VMS_EXIT); } while(0) +# define NO_SYS_PARAM_H + +# elif defined(OPENSSL_SYS_NETWARE) +# include +# include +# define NO_SYS_TYPES_H +# undef DEVRANDOM +# ifdef NETWARE_CLIB +# define getpid GetThreadID + extern int GetThreadID(void); +/* # include */ + extern int kbhit(void); +# else +# include +# endif +# define NO_SYSLOG +# define _setmode setmode +# define _kbhit kbhit +# define _O_TEXT O_TEXT +# define _O_BINARY O_BINARY +# define OPENSSL_CONF "openssl.cnf" +# define SSLEAY_CONF OPENSSL_CONF +# define RFILE ".rnd" +# define LIST_SEPARATOR_CHAR ';' +# define EXIT(n) { if (n) printf("ERROR: %d\n", (int)n); exit(n); } + +# else + /* !defined VMS */ +# ifdef OPENSSL_SYS_MPE +# define NO_SYS_PARAM_H +# endif +# ifdef OPENSSL_UNISTD +# include OPENSSL_UNISTD +# else +# include +# endif +# ifndef NO_SYS_TYPES_H +# include +# endif +# if defined(NeXT) || defined(OPENSSL_SYS_NEWS4) +# define pid_t int /* pid_t is missing on NEXTSTEP/OPENSTEP + * (unless when compiling with -D_POSIX_SOURCE, + * which doesn't work for us) */ +# endif +# ifdef OPENSSL_SYS_NEWS4 /* setvbuf is missing on mips-sony-bsd */ +# define setvbuf(a, b, c, d) setbuffer((a), (b), (d)) + typedef unsigned long clock_t; +# endif +# ifdef OPENSSL_SYS_WIN32_CYGWIN +# include +# include +# endif + +# define OPENSSL_CONF "openssl.cnf" +# define SSLEAY_CONF OPENSSL_CONF +# define RFILE ".rnd" +# define LIST_SEPARATOR_CHAR ':' +# define NUL_DEV "/dev/null" +# define EXIT(n) exit(n) +# endif + +# define SSLeay_getpid() getpid() + +#endif + + +/*************/ + +#ifdef USE_SOCKETS +# if defined(WINDOWS) || defined(MSDOS) + /* windows world */ + +# ifdef OPENSSL_NO_SOCK +# define SSLeay_Write(a,b,c) (-1) +# define SSLeay_Read(a,b,c) (-1) +# define SHUTDOWN(fd) close(fd) +# define SHUTDOWN2(fd) close(fd) +# elif !defined(__DJGPP__) +# if defined(_WIN32_WCE) && _WIN32_WCE<410 +# define getservbyname _masked_declaration_getservbyname +# endif +# if !defined(IPPROTO_IP) + /* winsock[2].h was included already? */ +# include +# endif +# ifdef getservbyname +# undef getservbyname + /* this is used to be wcecompat/include/winsock_extras.h */ + struct servent* PASCAL getservbyname(const char*,const char*); +# endif + +# ifdef _WIN64 +/* + * Even though sizeof(SOCKET) is 8, it's safe to cast it to int, because + * the value constitutes an index in per-process table of limited size + * and not a real pointer. + */ +# define socket(d,t,p) ((int)socket(d,t,p)) +# define accept(s,f,l) ((int)accept(s,f,l)) +# endif +# define SSLeay_Write(a,b,c) send((a),(b),(c),0) +# define SSLeay_Read(a,b,c) recv((a),(b),(c),0) +# define SHUTDOWN(fd) { shutdown((fd),0); closesocket(fd); } +# define SHUTDOWN2(fd) { shutdown((fd),2); closesocket(fd); } +# else +# define SSLeay_Write(a,b,c) write_s(a,b,c,0) +# define SSLeay_Read(a,b,c) read_s(a,b,c) +# define SHUTDOWN(fd) close_s(fd) +# define SHUTDOWN2(fd) close_s(fd) +# endif + +# elif defined(MAC_OS_pre_X) + +# include "MacSocket.h" +# define SSLeay_Write(a,b,c) MacSocket_send((a),(b),(c)) +# define SSLeay_Read(a,b,c) MacSocket_recv((a),(b),(c),true) +# define SHUTDOWN(fd) MacSocket_close(fd) +# define SHUTDOWN2(fd) MacSocket_close(fd) + +# elif defined(OPENSSL_SYS_NETWARE) + /* NetWare uses the WinSock2 interfaces by default, but can be configured for BSD + */ +# if defined(NETWARE_BSDSOCK) +# include +# include +# include +# if defined(NETWARE_CLIB) +# include +# else +# include +# endif +# define INVALID_SOCKET (int)(~0) +# else +# include +# endif +# define SSLeay_Write(a,b,c) send((a),(b),(c),0) +# define SSLeay_Read(a,b,c) recv((a),(b),(c),0) +# define SHUTDOWN(fd) { shutdown((fd),0); closesocket(fd); } +# define SHUTDOWN2(fd) { shutdown((fd),2); closesocket(fd); } + +# else + +# ifndef NO_SYS_PARAM_H +# include +# endif +# ifdef OPENSSL_SYS_VXWORKS +# include +# elif !defined(OPENSSL_SYS_MPE) +# include /* Needed under linux for FD_XXX */ +# endif + +# include +# if defined(OPENSSL_SYS_VMS_NODECC) +# include +# include +# include +# else +# include +# ifdef FILIO_H +# include /* Added for FIONBIO under unixware */ +# endif +# include +# if !defined(OPENSSL_SYS_BEOS_R5) +# include +# endif +# endif + +# if defined(NeXT) || defined(_NEXT_SOURCE) +# include +# include +# endif + +# ifdef OPENSSL_SYS_AIX +# include +# endif + +# ifdef __QNX__ +# include +# endif + +# if defined(sun) +# include +# else +# ifndef VMS +# include +# else + /* ioctl is only in VMS > 7.0 and when socketshr is not used */ +# if !defined(TCPIP_TYPE_SOCKETSHR) && defined(__VMS_VER) && (__VMS_VER > 70000000) +# include +# endif +# endif +# endif + +# ifdef VMS +# include +# if defined(TCPIP_TYPE_SOCKETSHR) +# include +# endif +# endif + +# define SSLeay_Read(a,b,c) read((a),(b),(c)) +# define SSLeay_Write(a,b,c) write((a),(b),(c)) +# define SHUTDOWN(fd) { shutdown((fd),0); closesocket((fd)); } +# define SHUTDOWN2(fd) { shutdown((fd),2); closesocket((fd)); } +# ifndef INVALID_SOCKET +# define INVALID_SOCKET (-1) +# endif /* INVALID_SOCKET */ +# endif + +/* Some IPv6 implementations are broken, disable them in known bad + * versions. + */ +# if !defined(OPENSSL_USE_IPV6) +# if defined(AF_INET6) && !defined(OPENSSL_SYS_BEOS_BONE) && !defined(NETWARE_CLIB) +# define OPENSSL_USE_IPV6 1 +# else +# define OPENSSL_USE_IPV6 0 +# endif +# endif + +#endif + +#if defined(sun) && !defined(__svr4__) && !defined(__SVR4) + /* include headers first, so our defines don't break it */ +#include +#include + /* bcopy can handle overlapping moves according to SunOS 4.1.4 manpage */ +# define memmove(s1,s2,n) bcopy((s2),(s1),(n)) +# define strtoul(s,e,b) ((unsigned long int)strtol((s),(e),(b))) +extern char *sys_errlist[]; extern int sys_nerr; +# define strerror(errnum) \ + (((errnum)<0 || (errnum)>=sys_nerr) ? NULL : sys_errlist[errnum]) + /* Being signed SunOS 4.x memcpy breaks ASN1_OBJECT table lookup */ +#include "crypto/o_str.h" +# define memcmp OPENSSL_memcmp +#endif + +#ifndef OPENSSL_EXIT +# if defined(MONOLITH) && !defined(OPENSSL_C) +# define OPENSSL_EXIT(n) return(n) +# else +# define OPENSSL_EXIT(n) do { EXIT(n); return(n); } while(0) +# endif +#endif + +/***********************************************/ + +#define DG_GCC_BUG /* gcc < 2.6.3 on DGUX */ + +#ifdef sgi +#define IRIX_CC_BUG /* all version of IRIX I've tested (4.* 5.*) */ +#endif +#ifdef OPENSSL_SYS_SNI +#define IRIX_CC_BUG /* CDS++ up to V2.0Bsomething suffered from the same bug.*/ +#endif + +#if defined(OPENSSL_SYS_WINDOWS) +# define strcasecmp _stricmp +# define strncasecmp _strnicmp +#elif defined(OPENSSL_SYS_VMS) +/* VMS below version 7.0 doesn't have strcasecmp() */ +# include "o_str.h" +# define strcasecmp OPENSSL_strcasecmp +# define strncasecmp OPENSSL_strncasecmp +# define OPENSSL_IMPLEMENTS_strncasecmp +#elif defined(OPENSSL_SYS_OS2) && defined(__EMX__) +# define strcasecmp stricmp +# define strncasecmp strnicmp +#elif defined(OPENSSL_SYS_NETWARE) +# include +# if defined(NETWARE_CLIB) +# define strcasecmp stricmp +# define strncasecmp strnicmp +# endif /* NETWARE_CLIB */ +#endif + +#if defined(OPENSSL_SYS_OS2) && defined(__EMX__) +# include +# include +# define NO_SYSLOG +#endif + +/* vxworks */ +#if defined(OPENSSL_SYS_VXWORKS) +#include +#include +#include + +#define TTY_STRUCT int + +#define sleep(a) taskDelay((a) * sysClkRateGet()) + +#include +#include +#include + +#define getpid taskIdSelf + +/* NOTE: these are implemented by helpers in database app! + * if the database is not linked, we need to implement them + * elswhere */ +struct hostent *gethostbyname(const char *name); +struct hostent *gethostbyaddr(const char *addr, int length, int type); +struct servent *getservbyname(const char *name, const char *proto); + +#endif +/* end vxworks */ + +/* beos */ +#if defined(OPENSSL_SYS_BEOS_R5) +#define SO_ERROR 0 +#define NO_SYS_UN +#define IPPROTO_IP 0 +#include +#endif + + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/libs/include/e_os2.h b/includes/openssl/e_os2.h similarity index 99% rename from libs/include/e_os2.h rename to includes/openssl/e_os2.h index d22c0368f..836099768 100644 --- a/libs/include/e_os2.h +++ b/includes/openssl/e_os2.h @@ -53,7 +53,7 @@ * */ -#include +#include "opensslconf.h" #ifndef HEADER_E_OS2_H #define HEADER_E_OS2_H diff --git a/libs/include/easy.h b/includes/openssl/easy.h similarity index 100% rename from libs/include/easy.h rename to includes/openssl/easy.h diff --git a/libs/include/ebcdic.h b/includes/openssl/ebcdic.h similarity index 100% rename from libs/include/ebcdic.h rename to includes/openssl/ebcdic.h diff --git a/libs/include/ec.h b/includes/openssl/ec.h similarity index 99% rename from libs/include/ec.h rename to includes/openssl/ec.h index dfe8710d3..bb5499c5a 100644 --- a/libs/include/ec.h +++ b/includes/openssl/ec.h @@ -76,16 +76,16 @@ #ifndef HEADER_EC_H #define HEADER_EC_H -#include +#include "opensslconf.h" #ifdef OPENSSL_NO_EC #error EC is disabled. #endif -#include -#include +#include "asn1.h" +#include "symhacks.h" #ifndef OPENSSL_NO_DEPRECATED -#include +#include "bn.h" #endif #ifdef __cplusplus diff --git a/libs/include/ecdh.h b/includes/openssl/ecdh.h similarity index 97% rename from libs/include/ecdh.h rename to includes/openssl/ecdh.h index 8887102c0..5a401bde7 100644 --- a/libs/include/ecdh.h +++ b/includes/openssl/ecdh.h @@ -69,16 +69,16 @@ #ifndef HEADER_ECDH_H #define HEADER_ECDH_H -#include +#include "opensslconf.h" #ifdef OPENSSL_NO_ECDH #error ECDH is disabled. #endif -#include -#include +#include "ec.h" +#include "ossl_typ.h" #ifndef OPENSSL_NO_DEPRECATED -#include +#include "bn.h" #endif #ifdef __cplusplus diff --git a/libs/include/ecdsa.h b/includes/openssl/ecdsa.h similarity index 98% rename from libs/include/ecdsa.h rename to includes/openssl/ecdsa.h index 7fb5254b6..2edf0f8fc 100644 --- a/libs/include/ecdsa.h +++ b/includes/openssl/ecdsa.h @@ -59,16 +59,16 @@ #ifndef HEADER_ECDSA_H #define HEADER_ECDSA_H -#include +#include "opensslconf.h" #ifdef OPENSSL_NO_ECDSA #error ECDSA is disabled. #endif -#include -#include +#include "ec.h" +#include "ossl_typ.h" #ifndef OPENSSL_NO_DEPRECATED -#include +#include "bn.h" #endif #ifdef __cplusplus diff --git a/libs/include/engine.h b/includes/openssl/engine.h similarity index 99% rename from libs/include/engine.h rename to includes/openssl/engine.h index f8be49772..70cf34316 100644 --- a/libs/include/engine.h +++ b/includes/openssl/engine.h @@ -64,38 +64,38 @@ #ifndef HEADER_ENGINE_H #define HEADER_ENGINE_H -#include +#include "opensslconf.h" #ifdef OPENSSL_NO_ENGINE #error ENGINE is disabled. #endif #ifndef OPENSSL_NO_DEPRECATED -#include +#include "bn.h" #ifndef OPENSSL_NO_RSA -#include +#include "rsa.h" #endif #ifndef OPENSSL_NO_DSA -#include +#include "dsa.h" #endif #ifndef OPENSSL_NO_DH -#include +#include "dh.h" #endif #ifndef OPENSSL_NO_ECDH -#include +#include "ecdh.h" #endif #ifndef OPENSSL_NO_ECDSA -#include +#include "ecdsa.h" #endif -#include -#include -#include +#include "rand.h" +#include "ui.h" +#include "err.h" #endif -#include -#include +#include "ossl_typ.h" +#include "symhacks.h" -#include +#include "x509.h" #ifdef __cplusplus extern "C" { diff --git a/libs/include/err.h b/includes/openssl/err.h similarity index 99% rename from libs/include/err.h rename to includes/openssl/err.h index 974cc9cc6..8fd9850b7 100644 --- a/libs/include/err.h +++ b/includes/openssl/err.h @@ -112,19 +112,19 @@ #ifndef HEADER_ERR_H #define HEADER_ERR_H -#include +#include "e_os2.h" #ifndef OPENSSL_NO_FP_API #include #include #endif -#include +#include "ossl_typ.h" #ifndef OPENSSL_NO_BIO -#include +#include "bio.h" #endif #ifndef OPENSSL_NO_LHASH -#include +#include "lhash.h" #endif #ifdef __cplusplus diff --git a/libs/include/evp.h b/includes/openssl/evp.h similarity index 99% rename from libs/include/evp.h rename to includes/openssl/evp.h index faeb3c24e..29d55a6f0 100644 --- a/libs/include/evp.h +++ b/includes/openssl/evp.h @@ -60,19 +60,19 @@ #define HEADER_ENVELOPE_H #ifdef OPENSSL_ALGORITHM_DEFINES -# include +#include "opensslconf.h" #else # define OPENSSL_ALGORITHM_DEFINES -# include +#include "opensslconf.h" # undef OPENSSL_ALGORITHM_DEFINES #endif -#include +#include "ossl_typ.h" -#include +#include "symhacks.h" #ifndef OPENSSL_NO_BIO -#include +#include "bio.h" #endif /* @@ -91,7 +91,7 @@ /* Default PKCS#5 iteration count */ #define PKCS5_DEFAULT_ITER 2048 -#include +#include "objects.h" #define EVP_PK_RSA 0x0001 #define EVP_PK_DSA 0x0002 diff --git a/libs/include/hmac.h b/includes/openssl/hmac.h similarity index 98% rename from libs/include/hmac.h rename to includes/openssl/hmac.h index 1be002219..fb00c7711 100644 --- a/libs/include/hmac.h +++ b/includes/openssl/hmac.h @@ -58,13 +58,13 @@ #ifndef HEADER_HMAC_H #define HEADER_HMAC_H -#include +#include "opensslconf.h" #ifdef OPENSSL_NO_HMAC #error HMAC is disabled. #endif -#include +#include "evp.h" #define HMAC_MAX_MD_CBLOCK 128 /* largest known is SHA512 */ diff --git a/libs/include/idea.h b/includes/openssl/idea.h similarity index 98% rename from libs/include/idea.h rename to includes/openssl/idea.h index e9a1e7f1a..523bf9153 100644 --- a/libs/include/idea.h +++ b/includes/openssl/idea.h @@ -59,7 +59,7 @@ #ifndef HEADER_IDEA_H #define HEADER_IDEA_H -#include /* IDEA_INT, OPENSSL_NO_IDEA */ +#include "opensslconf.h" /* IDEA_INT, OPENSSL_NO_IDEA */ #ifdef OPENSSL_NO_IDEA #error IDEA is disabled. diff --git a/libs/include/krb5_asn.h b/includes/openssl/krb5_asn.h similarity index 99% rename from libs/include/krb5_asn.h rename to includes/openssl/krb5_asn.h index 41725d0dc..fada9a8f6 100644 --- a/libs/include/krb5_asn.h +++ b/includes/openssl/krb5_asn.h @@ -63,7 +63,7 @@ /* #include */ -#include +#include "safestack.h" #ifdef __cplusplus extern "C" { diff --git a/libs/include/kssl.h b/includes/openssl/kssl.h similarity index 99% rename from libs/include/kssl.h rename to includes/openssl/kssl.h index e4df84307..7b7d738da 100644 --- a/libs/include/kssl.h +++ b/includes/openssl/kssl.h @@ -63,7 +63,7 @@ #ifndef KSSL_H #define KSSL_H -#include +#include "opensslconf.h" #ifndef OPENSSL_NO_KRB5 diff --git a/libs/include/lhash.h b/includes/openssl/lhash.h similarity index 99% rename from libs/include/lhash.h rename to includes/openssl/lhash.h index e7d876359..f9c10d527 100644 --- a/libs/include/lhash.h +++ b/includes/openssl/lhash.h @@ -63,13 +63,13 @@ #ifndef HEADER_LHASH_H #define HEADER_LHASH_H -#include +#include "e_os2.h" #ifndef OPENSSL_NO_FP_API #include #endif #ifndef OPENSSL_NO_BIO -#include +#include "bio.h" #endif #ifdef __cplusplus diff --git a/libs/include/md4.h b/includes/openssl/md4.h similarity index 99% rename from libs/include/md4.h rename to includes/openssl/md4.h index a55368a79..d8dd5c21f 100644 --- a/libs/include/md4.h +++ b/includes/openssl/md4.h @@ -59,7 +59,7 @@ #ifndef HEADER_MD4_H #define HEADER_MD4_H -#include +#include "e_os2.h" #include #ifdef __cplusplus diff --git a/libs/include/md5.h b/includes/openssl/md5.h similarity index 99% rename from libs/include/md5.h rename to includes/openssl/md5.h index 541cc925f..57ba303f1 100644 --- a/libs/include/md5.h +++ b/includes/openssl/md5.h @@ -59,7 +59,7 @@ #ifndef HEADER_MD5_H #define HEADER_MD5_H -#include +#include "e_os2.h" #include #ifdef __cplusplus diff --git a/libs/include/mdc2.h b/includes/openssl/mdc2.h similarity index 99% rename from libs/include/mdc2.h rename to includes/openssl/mdc2.h index f3e8e579d..29cea12ea 100644 --- a/libs/include/mdc2.h +++ b/includes/openssl/mdc2.h @@ -59,7 +59,7 @@ #ifndef HEADER_MDC2_H #define HEADER_MDC2_H -#include +#include "des.h" #ifdef __cplusplus extern "C" { diff --git a/libs/include/modes.h b/includes/openssl/modes.h similarity index 100% rename from libs/include/modes.h rename to includes/openssl/modes.h diff --git a/libs/include/mprintf.h b/includes/openssl/mprintf.h similarity index 100% rename from libs/include/mprintf.h rename to includes/openssl/mprintf.h diff --git a/libs/include/multi.h b/includes/openssl/multi.h similarity index 100% rename from libs/include/multi.h rename to includes/openssl/multi.h diff --git a/libs/include/obj_mac.h b/includes/openssl/obj_mac.h similarity index 100% rename from libs/include/obj_mac.h rename to includes/openssl/obj_mac.h diff --git a/libs/include/objects.h b/includes/openssl/objects.h similarity index 99% rename from libs/include/objects.h rename to includes/openssl/objects.h index bd0ee52fe..965773827 100644 --- a/libs/include/objects.h +++ b/includes/openssl/objects.h @@ -62,7 +62,7 @@ #define USE_OBJ_MAC #ifdef USE_OBJ_MAC -#include +#include "obj_mac.h" #else #define SN_undef "UNDEF" #define LN_undef "undefined" @@ -956,8 +956,8 @@ #define OBJ_OCSP_sign OBJ_id_kp,9L #endif /* USE_OBJ_MAC */ -#include -#include +#include "bio.h" +#include "asn1.h" #define OBJ_NAME_TYPE_UNDEF 0x00 #define OBJ_NAME_TYPE_MD_METH 0x01 diff --git a/libs/include/ocsp.h b/includes/openssl/ocsp.h similarity index 99% rename from libs/include/ocsp.h rename to includes/openssl/ocsp.h index 31e45744b..bb14c215b 100644 --- a/libs/include/ocsp.h +++ b/includes/openssl/ocsp.h @@ -64,10 +64,10 @@ #ifndef HEADER_OCSP_H #define HEADER_OCSP_H -#include -#include -#include -#include +#include "ossl_typ.h" +#include "x509.h" +#include "x509v3.h" +#include "safestack.h" #ifdef __cplusplus extern "C" { diff --git a/libs/include/opensslconf.h b/includes/openssl/opensslconf.h similarity index 100% rename from libs/include/opensslconf.h rename to includes/openssl/opensslconf.h diff --git a/libs/include/opensslv.h b/includes/openssl/opensslv.h similarity index 100% rename from libs/include/opensslv.h rename to includes/openssl/opensslv.h diff --git a/libs/include/ossl_typ.h b/includes/openssl/ossl_typ.h similarity index 99% rename from libs/include/ossl_typ.h rename to includes/openssl/ossl_typ.h index ea9227f6f..5d02d1864 100644 --- a/libs/include/ossl_typ.h +++ b/includes/openssl/ossl_typ.h @@ -55,7 +55,7 @@ #ifndef HEADER_OPENSSL_TYPES_H #define HEADER_OPENSSL_TYPES_H -#include +#include "e_os2.h" #ifdef NO_ASN1_TYPEDEFS #define ASN1_INTEGER ASN1_STRING diff --git a/libs/include/pem.h b/includes/openssl/pem.h similarity index 99% rename from libs/include/pem.h rename to includes/openssl/pem.h index 8a6ababe3..90ec1ec5b 100644 --- a/libs/include/pem.h +++ b/includes/openssl/pem.h @@ -59,16 +59,16 @@ #ifndef HEADER_PEM_H #define HEADER_PEM_H -#include +#include "e_os2.h" #ifndef OPENSSL_NO_BIO -#include +#include "bio.h" #endif #ifndef OPENSSL_NO_STACK -#include +#include "stack.h" #endif -#include -#include -#include +#include "evp.h" +#include "x509.h" +#include "pem2.h" #ifdef __cplusplus extern "C" { @@ -454,7 +454,7 @@ void PEM_proc_type(char *buf, int type); void PEM_dek_info(char *buf, const char *type, int len, char *str); -#include +#include "symhacks.h" DECLARE_PEM_rw(X509, X509) diff --git a/libs/include/pem2.h b/includes/openssl/pem2.h similarity index 100% rename from libs/include/pem2.h rename to includes/openssl/pem2.h diff --git a/libs/include/pkcs12.h b/includes/openssl/pkcs12.h similarity index 99% rename from libs/include/pkcs12.h rename to includes/openssl/pkcs12.h index b17eb9f42..3442059d0 100644 --- a/libs/include/pkcs12.h +++ b/includes/openssl/pkcs12.h @@ -59,8 +59,8 @@ #ifndef HEADER_PKCS12_H #define HEADER_PKCS12_H -#include -#include +#include "bio.h" +#include "x509.h" #ifdef __cplusplus extern "C" { diff --git a/libs/include/pkcs7.h b/includes/openssl/pkcs7.h similarity index 99% rename from libs/include/pkcs7.h rename to includes/openssl/pkcs7.h index e4d443193..f4111991d 100644 --- a/libs/include/pkcs7.h +++ b/includes/openssl/pkcs7.h @@ -59,12 +59,12 @@ #ifndef HEADER_PKCS7_H #define HEADER_PKCS7_H -#include -#include -#include +#include "asn1.h" +#include "bio.h" +#include "e_os2.h" -#include -#include +#include "symhacks.h" +#include "ossl_typ.h" #ifdef __cplusplus extern "C" { diff --git a/libs/include/pqueue.h b/includes/openssl/pqueue.h similarity index 100% rename from libs/include/pqueue.h rename to includes/openssl/pqueue.h diff --git a/libs/include/rand.h b/includes/openssl/rand.h similarity index 98% rename from libs/include/rand.h rename to includes/openssl/rand.h index bb5520e80..c66b3bf26 100644 --- a/libs/include/rand.h +++ b/includes/openssl/rand.h @@ -60,8 +60,8 @@ #define HEADER_RAND_H #include -#include -#include +#include "ossl_typ.h" +#include "e_os2.h" #if defined(OPENSSL_SYS_WINDOWS) #include diff --git a/libs/include/rc2.h b/includes/openssl/rc2.h similarity index 98% rename from libs/include/rc2.h rename to includes/openssl/rc2.h index e542ec94f..e8c5510b6 100644 --- a/libs/include/rc2.h +++ b/includes/openssl/rc2.h @@ -59,7 +59,7 @@ #ifndef HEADER_RC2_H #define HEADER_RC2_H -#include /* OPENSSL_NO_RC2, RC2_INT */ +#include "opensslconf.h" /* OPENSSL_NO_RC2, RC2_INT */ #ifdef OPENSSL_NO_RC2 #error RC2 is disabled. #endif diff --git a/libs/include/rc4.h b/includes/openssl/rc4.h similarity index 98% rename from libs/include/rc4.h rename to includes/openssl/rc4.h index 88ceb46bc..213ddc01f 100644 --- a/libs/include/rc4.h +++ b/includes/openssl/rc4.h @@ -59,7 +59,7 @@ #ifndef HEADER_RC4_H #define HEADER_RC4_H -#include /* OPENSSL_NO_RC4, RC4_INT */ +#include "opensslconf.h" /* OPENSSL_NO_RC4, RC4_INT */ #ifdef OPENSSL_NO_RC4 #error RC4 is disabled. #endif diff --git a/libs/include/ripemd.h b/includes/openssl/ripemd.h similarity index 99% rename from libs/include/ripemd.h rename to includes/openssl/ripemd.h index 189bd8c90..98fa7063b 100644 --- a/libs/include/ripemd.h +++ b/includes/openssl/ripemd.h @@ -59,7 +59,7 @@ #ifndef HEADER_RIPEMD_H #define HEADER_RIPEMD_H -#include +#include "e_os2.h" #include #ifdef __cplusplus diff --git a/libs/include/rsa.h b/includes/openssl/rsa.h similarity index 99% rename from libs/include/rsa.h rename to includes/openssl/rsa.h index 5f269e577..20dcb5dae 100644 --- a/libs/include/rsa.h +++ b/includes/openssl/rsa.h @@ -59,15 +59,15 @@ #ifndef HEADER_RSA_H #define HEADER_RSA_H -#include +#include "asn1.h" #ifndef OPENSSL_NO_BIO -#include +#include "bio.h" #endif -#include -#include +#include "crypto.h" +#include "ossl_typ.h" #ifndef OPENSSL_NO_DEPRECATED -#include +#include "bn.h" #endif #ifdef OPENSSL_NO_RSA diff --git a/libs/include/safestack.h b/includes/openssl/safestack.h similarity index 99% rename from libs/include/safestack.h rename to includes/openssl/safestack.h index ea3aa0d80..7c718090b 100644 --- a/libs/include/safestack.h +++ b/includes/openssl/safestack.h @@ -55,7 +55,7 @@ #ifndef HEADER_SAFESTACK_H #define HEADER_SAFESTACK_H -#include +#include "stack.h" #ifndef CHECKED_PTR_OF #define CHECKED_PTR_OF(type, p) \ diff --git a/libs/include/seed.h b/includes/openssl/seed.h similarity index 98% rename from libs/include/seed.h rename to includes/openssl/seed.h index c50fdd360..e5ba7860f 100644 --- a/libs/include/seed.h +++ b/includes/openssl/seed.h @@ -81,9 +81,9 @@ #ifndef HEADER_SEED_H #define HEADER_SEED_H -#include -#include -#include +#include "opensslconf.h" +#include "e_os2.h" +#include "crypto.h" #ifdef OPENSSL_NO_SEED #error SEED is disabled. diff --git a/libs/include/sha.h b/includes/openssl/sha.h similarity index 99% rename from libs/include/sha.h rename to includes/openssl/sha.h index 8a6bf4bbb..3a4227e71 100644 --- a/libs/include/sha.h +++ b/includes/openssl/sha.h @@ -59,7 +59,7 @@ #ifndef HEADER_SHA_H #define HEADER_SHA_H -#include +#include "e_os2.h" #include #ifdef __cplusplus diff --git a/libs/include/srp.h b/includes/openssl/srp.h similarity index 98% rename from libs/include/srp.h rename to includes/openssl/srp.h index 7ec7825ca..dba76ca89 100644 --- a/libs/include/srp.h +++ b/includes/openssl/srp.h @@ -68,9 +68,9 @@ extern "C" { #endif -#include -#include -#include +#include "safestack.h" +#include "bn.h" +#include "crypto.h" typedef struct SRP_gN_cache_st { diff --git a/libs/include/srtp.h b/includes/openssl/srtp.h similarity index 100% rename from libs/include/srtp.h rename to includes/openssl/srtp.h diff --git a/libs/include/ssl.h b/includes/openssl/ssl.h similarity index 99% rename from libs/include/ssl.h rename to includes/openssl/ssl.h index 7219a0e64..99fc0ada6 100644 --- a/libs/include/ssl.h +++ b/includes/openssl/ssl.h @@ -143,28 +143,28 @@ #ifndef HEADER_SSL_H #define HEADER_SSL_H -#include +#include "e_os2.h" #ifndef OPENSSL_NO_COMP -#include +#include "comp.h" #endif #ifndef OPENSSL_NO_BIO -#include +#include "bio.h" #endif #ifndef OPENSSL_NO_DEPRECATED #ifndef OPENSSL_NO_X509 -#include +#include "x509.h" #endif -#include -#include -#include +#include "crypto.h" +#include "lhash.h" +#include "buffer.h" #endif -#include -#include +#include "pem.h" +#include "hmac.h" -#include -#include -#include +#include "kssl.h" +#include "safestack.h" +#include "symhacks.h" #ifdef __cplusplus extern "C" { @@ -1369,12 +1369,12 @@ struct ssl_st } #endif -#include -#include -#include /* This is mostly sslv3 with a few tweaks */ -#include /* Datagram TLS */ -#include -#include /* Support for the use_srtp extension */ +#include "ssl2.h" +#include "ssl3.h" +#include "tls1.h" /* This is mostly sslv3 with a few tweaks */ +#include "dtls1.h" /* Datagram TLS */ +#include "ssl23.h" +#include "srtp.h" /* Support for the use_srtp extension */ #ifdef __cplusplus extern "C" { diff --git a/libs/include/ssl2.h b/includes/openssl/ssl2.h similarity index 100% rename from libs/include/ssl2.h rename to includes/openssl/ssl2.h diff --git a/libs/include/ssl23.h b/includes/openssl/ssl23.h similarity index 100% rename from libs/include/ssl23.h rename to includes/openssl/ssl23.h diff --git a/libs/include/ssl3.h b/includes/openssl/ssl3.h similarity index 99% rename from libs/include/ssl3.h rename to includes/openssl/ssl3.h index cb8b2492e..fb0cc7288 100644 --- a/libs/include/ssl3.h +++ b/includes/openssl/ssl3.h @@ -118,11 +118,11 @@ #define HEADER_SSL3_H #ifndef OPENSSL_NO_COMP -#include +#include "comp.h" #endif -#include -#include -#include +#include "buffer.h" +#include "evp.h" +#include "ssl.h" #ifdef __cplusplus extern "C" { diff --git a/libs/include/stack.h b/includes/openssl/stack.h similarity index 100% rename from libs/include/stack.h rename to includes/openssl/stack.h diff --git a/libs/include/stdcheaders.h b/includes/openssl/stdcheaders.h similarity index 100% rename from libs/include/stdcheaders.h rename to includes/openssl/stdcheaders.h diff --git a/libs/include/symhacks.h b/includes/openssl/symhacks.h similarity index 99% rename from libs/include/symhacks.h rename to includes/openssl/symhacks.h index bd2f000d5..ce702603a 100644 --- a/libs/include/symhacks.h +++ b/includes/openssl/symhacks.h @@ -55,7 +55,7 @@ #ifndef HEADER_SYMHACKS_H #define HEADER_SYMHACKS_H -#include +#include "e_os2.h" /* Hacks to solve the problem with linkers incapable of handling very long symbol names. In the case of VMS, the limit is 31 characters on VMS for diff --git a/libs/include/tls1.h b/includes/openssl/tls1.h similarity index 99% rename from libs/include/tls1.h rename to includes/openssl/tls1.h index c992091e3..b97b4a7a5 100644 --- a/libs/include/tls1.h +++ b/includes/openssl/tls1.h @@ -151,7 +151,7 @@ #ifndef HEADER_TLS1_H #define HEADER_TLS1_H -#include +#include "buffer.h" #ifdef __cplusplus extern "C" { diff --git a/libs/include/ts.h b/includes/openssl/ts.h similarity index 98% rename from libs/include/ts.h rename to includes/openssl/ts.h index c2448e3c3..884c70abd 100644 --- a/libs/include/ts.h +++ b/includes/openssl/ts.h @@ -59,31 +59,31 @@ #ifndef HEADER_TS_H #define HEADER_TS_H -#include -#include +#include "opensslconf.h" +#include "symhacks.h" #ifndef OPENSSL_NO_BUFFER -#include +#include "buffer.h" #endif #ifndef OPENSSL_NO_EVP -#include +#include "evp.h" #endif #ifndef OPENSSL_NO_BIO -#include +#include "bio.h" #endif -#include -#include -#include +#include "stack.h" +#include "asn1.h" +#include "safestack.h" #ifndef OPENSSL_NO_RSA -#include +#include "rsa.h" #endif #ifndef OPENSSL_NO_DSA -#include +#include "dsa.h" #endif #ifndef OPENSSL_NO_DH -#include +#include "dh.h" #endif #ifdef __cplusplus @@ -95,8 +95,8 @@ extern "C" { #undef X509_NAME #endif -#include -#include +#include "x509.h" +#include "x509v3.h" /* MessageImprint ::= SEQUENCE { diff --git a/libs/include/txt_db.h b/includes/openssl/txt_db.h similarity index 97% rename from libs/include/txt_db.h rename to includes/openssl/txt_db.h index 6abe435bc..7fda36197 100644 --- a/libs/include/txt_db.h +++ b/includes/openssl/txt_db.h @@ -59,12 +59,12 @@ #ifndef HEADER_TXT_DB_H #define HEADER_TXT_DB_H -#include +#include "opensslconf.h" #ifndef OPENSSL_NO_BIO -#include +#include "bio.h" #endif -#include -#include +#include "stack.h" +#include "lhash.h" #define DB_ERROR_OK 0 #define DB_ERROR_MALLOC 1 diff --git a/libs/include/typecheck-gcc.h b/includes/openssl/typecheck-gcc.h similarity index 100% rename from libs/include/typecheck-gcc.h rename to includes/openssl/typecheck-gcc.h diff --git a/libs/include/ui.h b/includes/openssl/ui.h similarity index 99% rename from libs/include/ui.h rename to includes/openssl/ui.h index bd78aa413..20c6034ec 100644 --- a/libs/include/ui.h +++ b/includes/openssl/ui.h @@ -60,10 +60,10 @@ #define HEADER_UI_H #ifndef OPENSSL_NO_DEPRECATED -#include +#include "crypto.h" #endif -#include -#include +#include "safestack.h" +#include "ossl_typ.h" #ifdef __cplusplus extern "C" { diff --git a/libs/include/ui_compat.h b/includes/openssl/ui_compat.h similarity index 98% rename from libs/include/ui_compat.h rename to includes/openssl/ui_compat.h index b35c9bb7f..d3ec71fe3 100644 --- a/libs/include/ui_compat.h +++ b/includes/openssl/ui_compat.h @@ -59,8 +59,8 @@ #ifndef HEADER_UI_COMPAT_H #define HEADER_UI_COMPAT_H -#include -#include +#include "opensslconf.h" +#include "ui.h" #ifdef __cplusplus extern "C" { diff --git a/libs/include/whrlpool.h b/includes/openssl/whrlpool.h similarity index 97% rename from libs/include/whrlpool.h rename to includes/openssl/whrlpool.h index 9e01f5b07..b63fcdace 100644 --- a/libs/include/whrlpool.h +++ b/includes/openssl/whrlpool.h @@ -1,7 +1,7 @@ #ifndef HEADER_WHRLPOOL_H #define HEADER_WHRLPOOL_H -#include +#include "e_os2.h" #include #ifdef __cplusplus diff --git a/libs/include/x509.h b/includes/openssl/x509.h similarity index 98% rename from libs/include/x509.h rename to includes/openssl/x509.h index 092dd7450..840358c6f 100644 --- a/libs/include/x509.h +++ b/includes/openssl/x509.h @@ -64,49 +64,49 @@ #ifndef HEADER_X509_H #define HEADER_X509_H -#include -#include +#include "e_os2.h" +#include "symhacks.h" #ifndef OPENSSL_NO_BUFFER -#include +#include "buffer.h" #endif #ifndef OPENSSL_NO_EVP -#include +#include "evp.h" #endif #ifndef OPENSSL_NO_BIO -#include +#include "bio.h" #endif -#include -#include -#include +#include "stack.h" +#include "asn1.h" +#include "safestack.h" #ifndef OPENSSL_NO_EC -#include +#include "ec.h" #endif #ifndef OPENSSL_NO_ECDSA -#include +#include "ecdsa.h" #endif #ifndef OPENSSL_NO_ECDH -#include +#include "ecdh.h" #endif #ifndef OPENSSL_NO_DEPRECATED #ifndef OPENSSL_NO_RSA -#include +#include "rsa.h" #endif #ifndef OPENSSL_NO_DSA -#include +#include "dsa.h" #endif #ifndef OPENSSL_NO_DH -#include +#include "dh.h" #endif #endif #ifndef OPENSSL_NO_SHA -#include +#include "sha.h" #endif -#include +#include "ossl_typ.h" #ifdef __cplusplus extern "C" { @@ -597,8 +597,8 @@ struct pkcs8_priv_key_info_st } #endif -#include -#include +#include "x509_vfy.h" +#include "pkcs7.h" #ifdef __cplusplus extern "C" { diff --git a/libs/include/x509_vfy.h b/includes/openssl/x509_vfy.h similarity index 99% rename from libs/include/x509_vfy.h rename to includes/openssl/x509_vfy.h index fe09b30aa..8d023d42e 100644 --- a/libs/include/x509_vfy.h +++ b/includes/openssl/x509_vfy.h @@ -57,7 +57,7 @@ */ #ifndef HEADER_X509_H -#include +#include "x509.h> /* openssl/x509.h ends up #include-ing this file at about the only * appropriate moment. */ #endif @@ -65,13 +65,13 @@ #ifndef HEADER_X509_VFY_H #define HEADER_X509_VFY_H -#include +#include "opensslconf.h" #ifndef OPENSSL_NO_LHASH -#include +#include "lhash.h" #endif -#include -#include -#include +#include "bio.h" +#include "crypto.h" +#include "symhacks.h" #ifdef __cplusplus extern "C" { diff --git a/libs/include/x509v3.h b/includes/openssl/x509v3.h similarity index 99% rename from libs/include/x509v3.h rename to includes/openssl/x509v3.h index b308abe7c..865ebd9df 100644 --- a/libs/include/x509v3.h +++ b/includes/openssl/x509v3.h @@ -58,9 +58,9 @@ #ifndef HEADER_X509V3_H #define HEADER_X509V3_H -#include -#include -#include +#include "bio.h" +#include "x509.h" +#include "conf.h" #ifdef __cplusplus extern "C" { diff --git a/libs/include/zconf.h b/includes/openssl/zconf.h similarity index 100% rename from libs/include/zconf.h rename to includes/openssl/zconf.h diff --git a/libs/include/zlib.h b/includes/openssl/zlib.h similarity index 100% rename from libs/include/zlib.h rename to includes/openssl/zlib.h diff --git a/pnacl_main.h b/pnacl_main.h index c97bd1c7a..77c11be6c 100644 --- a/pnacl_main.h +++ b/pnacl_main.h @@ -6,14 +6,21 @@ #include #include #include -#include #include +#ifdef _WIN32 +#include "win/pthread.h" +#include +//static inline void sleep(unsigned ms) { Sleep(ms*1000); } + +#else +#include +#endif static int initflag; #ifndef __PNACL -#define PostMessage printf +#define PNACL_message printf #else -void PostMessage(const char* format, ...); +void PNACL_message(const char* format, ...); #endif void OS_init(); @@ -31,8 +38,8 @@ void *CHROMEAPP_NAME(void *arg) arg = 0; #endif while ( initflag == 0 ) - sleep(1); - PostMessage("%s start.(%s)\n",CHROMEAPP_STR,(char *)arg); + usleep(1000000); + PNACL_message("%s start.(%s)\n",CHROMEAPP_STR,(char *)arg); CHROMEAPP_MAIN(arg); return(0); } @@ -135,7 +142,7 @@ struct PP_Var GetDictVar(struct PP_Var dict, const char* key) return value; } -void PostMessage(const char* format, ...) +void PNACL_message(const char* format, ...) { va_list args; va_start(args, format); @@ -172,7 +179,7 @@ static int ParseMessage(struct PP_Var message,const char **out_function,struct P *out_function = VarToCStr(cmd_value); g_ppb_var->Release(cmd_value); *out_params = GetDictVar(message, "args"); - PostMessage("Parse.(%s) cmd.(%s)\n",*out_function,VarToCStr(*out_params)); + PNACL_message("Parse.(%s) cmd.(%s)\n",*out_function,VarToCStr(*out_params)); if ( cmd_value.type != PP_VARTYPE_STRING ) return(1); if ( out_params->type != PP_VARTYPE_ARRAY ) @@ -201,13 +208,13 @@ static void HandleMessage(struct PP_Var message) const char *function_name,*error; struct PP_Var params,result_var; if ( ParseMessage(message, &function_name, ¶ms) != 0 ) { - PostMessage("Error: Unable to parse message"); + PNACL_message("Error: Unable to parse message"); return; } HandleFunc function = GetFunctionByName(function_name); if ( function == 0 ) { - PostMessage("Error: Unknown function \"%s\"", function_name); // Function name wasn't found. + PNACL_message("Error: Unknown function \"%s\"", function_name); // Function name wasn't found. return; } // Function name was found, call it. @@ -216,10 +223,10 @@ static void HandleMessage(struct PP_Var message) { if ( error != NULL ) { - PostMessage("Error: \"%s\" failed: %s.", function_name, error); + PNACL_message("Error: \"%s\" failed: %s.", function_name, error); free((void*)error); } - else PostMessage("Error: \"%s\" failed.", function_name); + else PNACL_message("Error: \"%s\" failed.", function_name); return; } // Function returned an output dictionary. Send it to JavaScript. @@ -266,7 +273,7 @@ int EnqueueMessage(struct PP_Var message) // We shouldn't block the main thread waiting for the queue to not be full, so just drop the message. if ( IsQueueFull() != 0) { - PostMessage("EnqueueMessage: full Q, drop message\n"); + PNACL_message("EnqueueMessage: full Q, drop message\n"); pthread_mutex_unlock(&g_queue_mutex); return(0); } @@ -341,7 +348,7 @@ static PP_Bool Instance_DidCreate(PP_Instance instance,uint32_t argc,const char* "httpfs", /* filesystemtype */ 0, /* mountflags */ ""); /* data */ - PostMessage("finished DidCreate %s\n",CHROMEAPP_STR); + PNACL_message("finished DidCreate %s\n",CHROMEAPP_STR); initflag = 1; return PP_TRUE; } @@ -362,7 +369,7 @@ static void Messaging_HandleMessage(PP_Instance instance,struct PP_Var message) { if ( message.type != PP_VARTYPE_DICTIONARY ) // Special case for jspipe input handling { - PostMessage("Got unexpected message type: %d\n", message.type); + PNACL_message("Got unexpected message type: %d\n", message.type); return; } struct PP_Var pipe_var = CStrToVar("pipe"); @@ -376,11 +383,11 @@ static void Messaging_HandleMessage(PP_Instance instance,struct PP_Var message) g_ppb_var->Release(pipe_name); if ( fd < 0 ) { - PostMessage("Warning: opening %s failed.", file_name); + PNACL_message("Warning: opening %s failed.", file_name); goto done; } //if ( ioctl(fd, NACL_IOC_HANDLEMESSAGE, &message) != 0 ) - // PostMessage("Error: ioctl on %s failed: %s", file_name, strerror(errno)); + // PNACL_message("Error: ioctl on %s failed: %s", file_name, strerror(errno)); close(fd); goto done; } @@ -388,7 +395,7 @@ static void Messaging_HandleMessage(PP_Instance instance,struct PP_Var message) if ( !EnqueueMessage(message) ) { g_ppb_var->Release(message); - PostMessage("Warning: dropped message because the queue was full."); + PNACL_message("Warning: dropped message because the queue was full."); } done: g_ppb_var->Release(pipe_name); @@ -596,7 +603,7 @@ int CHROMEAPP_HANDLER(struct PP_Var params,struct PP_Var *output,const char **ou { char *CHROMEAPP_JSON(char *); char *retstr; - PostMessage("inside Handle_%s\n",CHROMEAPP_STR); + PNACL_message("inside Handle_%s\n",CHROMEAPP_STR); CHECK_PARAM_COUNT(CHROMEAPP_NAME, 1); PARAM_STRING(0,jsonstr); retstr = CHROMEAPP_JSON(jsonstr); @@ -607,7 +614,7 @@ int CHROMEAPP_HANDLER(struct PP_Var params,struct PP_Var *output,const char **ou int example_main() { - PostMessage("Started %s example main.\n",CHROMEAPP_STR); + PNACL_message("Started %s example main.\n",CHROMEAPP_STR); while ( 1 ) { sleep(777); diff --git a/tools/m_pnacl b/tools/m_pnacl deleted file mode 100755 index eb967f793..000000000 --- a/tools/m_pnacl +++ /dev/null @@ -1,2 +0,0 @@ -git pull -make diff --git a/tools/m_unix b/tools/m_unix deleted file mode 100755 index 5456c5b80..000000000 --- a/tools/m_unix +++ /dev/null @@ -1,2 +0,0 @@ -git pull -gcc -o agent *.c libcrypto777.a diff --git a/win/libcrypto.a b/win/libcrypto.a new file mode 100644 index 000000000..62f2adfc8 Binary files /dev/null and b/win/libcrypto.a differ diff --git a/win/libpthreadGC2.a b/win/libpthreadGC2.a new file mode 100644 index 000000000..df211759f Binary files /dev/null and b/win/libpthreadGC2.a differ diff --git a/win/libpthreadGC2_64.a b/win/libpthreadGC2_64.a new file mode 100644 index 000000000..430162364 Binary files /dev/null and b/win/libpthreadGC2_64.a differ diff --git a/win/libssl.a b/win/libssl.a new file mode 100644 index 000000000..ac3e692a7 Binary files /dev/null and b/win/libssl.a differ diff --git a/win/mingw.c b/win/mingw.c new file mode 100644 index 000000000..d9f51c831 --- /dev/null +++ b/win/mingw.c @@ -0,0 +1,743 @@ +#ifdef __MINGW32__ + +#include "mingw.h" + +#undef socket +#undef connect +#undef accept +#undef shutdown + +#include +#include +#include + +int win32_poll(struct pollfd *fds, unsigned int nfds, int timo) +{ + struct timeval timeout, *toptr; + fd_set ifds, ofds, efds, *ip, *op; + unsigned int i, rc; + + /* Set up the file-descriptor sets in ifds, ofds and efds. */ + FD_ZERO(&ifds); + FD_ZERO(&ofds); + FD_ZERO(&efds); + for (i = 0, op = ip = 0; i < nfds; ++i) { + fds[i].revents = 0; + if(fds[i].events & (POLLIN|POLLPRI)) { + ip = &ifds; + FD_SET(fds[i].fd, ip); + } + if(fds[i].events & POLLOUT) { + op = &ofds; + FD_SET(fds[i].fd, op); + } + FD_SET(fds[i].fd, &efds); + } + + /* Set up the timeval structure for the timeout parameter */ + if(timo < 0) { + toptr = 0; + } else { + toptr = &timeout; + timeout.tv_sec = timo / 1000; + timeout.tv_usec = (timo - timeout.tv_sec * 1000) * 1000; + } + +#ifdef DEBUG_POLL + printf("Entering select() sec=%ld usec=%ld ip=%lx op=%lx\n", + (long)timeout.tv_sec, (long)timeout.tv_usec, (long)ip, (long)op); +#endif + rc = select(0, ip, op, &efds, toptr); +#ifdef DEBUG_POLL + printf("Exiting select rc=%d\n", rc); +#endif + + if(rc <= 0) + return rc; + + if(rc > 0) { + for ( i = 0; i < nfds; ++i) { + int fd = fds[i].fd; + if(fds[i].events & (POLLIN|POLLPRI) && FD_ISSET(fd, &ifds)) + fds[i].revents |= POLLIN; + if(fds[i].events & POLLOUT && FD_ISSET(fd, &ofds)) + fds[i].revents |= POLLOUT; + if(FD_ISSET(fd, &efds)) + /* Some error was detected ... should be some way to know. */ + fds[i].revents |= POLLHUP; +#ifdef DEBUG_POLL + printf("%d %d %d revent = %x\n", + FD_ISSET(fd, &ifds), FD_ISSET(fd, &ofds), FD_ISSET(fd, &efds), + fds[i].revents + ); +#endif + } + } + return rc; +} +static void +set_connect_errno(int winsock_err) +{ + switch(winsock_err) { + case WSAEINVAL: + case WSAEALREADY: + case WSAEWOULDBLOCK: + errno = EINPROGRESS; + break; + default: + errno = winsock_err; + break; + } +} + +static void +set_socket_errno(int winsock_err) +{ + switch(winsock_err) { + case WSAEWOULDBLOCK: + errno = EAGAIN; + break; + default: + errno = winsock_err; + break; + } +} +/* + * A wrapper around the socket() function. The purpose of this wrapper + * is to ensure that the global errno symbol is set if an error occurs, + * even if we are using winsock. + */ +SOCKET +win32_socket(int domain, int type, int protocol) +{ + SOCKET fd = socket(domain, type, protocol); + if(fd == INVALID_SOCKET) { + set_socket_errno(WSAGetLastError()); + } + return fd; +} +/* + * A wrapper around the connect() function. The purpose of this wrapper + * is to ensure that the global errno symbol is set if an error occurs, + * even if we are using winsock. + */ +int +win32_connect(SOCKET fd, struct sockaddr *addr, socklen_t addr_len) +{ + int rc = connect(fd, addr, addr_len); + assert(rc == 0 || rc == SOCKET_ERROR); + if(rc == SOCKET_ERROR) { + set_connect_errno(WSAGetLastError()); + } + return rc; +} + +/* + * A wrapper around the accept() function. The purpose of this wrapper + * is to ensure that the global errno symbol is set if an error occurs, + * even if we are using winsock. + */ +SOCKET +win32_accept(SOCKET fd, struct sockaddr *addr, socklen_t *addr_len) +{ + SOCKET newfd = accept(fd, addr, addr_len); + if(newfd == INVALID_SOCKET) { + set_socket_errno(WSAGetLastError()); + newfd = -1; + } + return newfd; +} + +/* + * A wrapper around the shutdown() function. The purpose of this wrapper + * is to ensure that the global errno symbol is set if an error occurs, + * even if we are using winsock. + */ +int +win32_shutdown(SOCKET fd, int mode) +{ + int rc = shutdown(fd, mode); + assert(rc == 0 || rc == SOCKET_ERROR); + if(rc == SOCKET_ERROR) { + set_socket_errno(WSAGetLastError()); + } + return rc; +} + +int win32_close_socket(SOCKET fd) +{ + int rc = closesocket(fd); + if(rc == SOCKET_ERROR) { + set_socket_errno(WSAGetLastError()); + } + return rc; +} + +ssize_t win32_write_socket(SOCKET fd, void *buf, int n) +{ + int rc = send(fd, buf, n, 0); + if(rc == SOCKET_ERROR) { + set_socket_errno(WSAGetLastError()); + } + return rc; +} + +ssize_t win32_read_socket(SOCKET fd, void *buf, int n) +{ + int rc = recv(fd, buf, n, 0); + if(rc == SOCKET_ERROR) { + set_socket_errno(WSAGetLastError()); + } + return rc; +} + + +char * win32_strtok_r(char *s, const char *delim, char **lasts) +{ + register char *spanp; + register int c, sc; + char *tok; + + + if (s == NULL && (s = *lasts) == NULL) + return (NULL); + + /* + * Skip (span) leading delimiters (s += strspn(s, delim), sort of). + */ +cont: + c = *s++; + for (spanp = (char *)delim; (sc = *spanp++) != 0;) { + if (c == sc) + goto cont; + } + + if (c == 0) { /* no non-delimiter characters */ + *lasts = NULL; + return (NULL); + } + tok = s - 1; + + /* + * Scan token (scan for delimiters: s += strcspn(s, delim), sort of). + * Note that delim must have one NUL; we stop if we see that, too. + */ + for (;;) { + c = *s++; + spanp = (char *)delim; + do { + if ((sc = *spanp++) == c) { + if (c == 0) + s = NULL; + else + s[-1] = 0; + *lasts = s; + return (tok); + } + } while (sc != 0); + } + /* NOTREACHED */ +} + +char *win32_strsep (char **stringp, const char *delim) +{ + register char *s; + register const char *spanp; + register int c, sc; + char *tok; + + if ((s = *stringp) == NULL) + return (NULL); + for (tok = s;;) { + c = *s++; + spanp = delim; + do { + if ((sc = *spanp++) == c) { + if (c == 0) + s = NULL; + else + s[-1] = 0; + *stringp = s; + return (tok); + } + } while (sc != 0); + } + /* NOTREACHED */ +} + +#ifdef noneed +/****************************************************************************** + time32.c -- extended time functions that use all 32 bits + + Author: Mark Baranowski + Email: requestXXX@els-software.org (remove XXX) + Download: http://els-software.org + + Last significant change: May 6, 2015 + + These functions are provided "as is" in the hopes that they might serve some + higher purpose. If you want these functions to serve some lower purpose, + then that too is all right. So as to keep these hopes alive you may + freely distribute these functions so long as this header remains intact. + You may also freely distribute modified versions of these functions so long + as you indicate that such versions are modified and so long as you + provide access to the unmodified original copy. + + Note: The most recent version of these functions may be obtained from + http://els-software.org + + The following functions support Unix time beyond Jan 19 03:14:08 2038 GMT, + assuming that the future standard will treat the 32-bits used by Unix's + present-day file system as unsigned. + + These functions work by mapping years within the region 2038-2106 down + into the region of 2010-2037. All fields of the "tm" structure, + including those fields dealing with day-of-week and daylight savings time + are correct! Bear in mind, however, that the definition of daylight + savings time changes with the whims of man, thus the notion of daylight + savings held during 2010-2037 may not be the same as the notion held + thereafter. + + See also: time(3) + + ****************************************************************************/ + +#include "sysdefs.h" + +#include "defs.h" +#include "time32.h" +#include "sysInfo.h" + +/*****************************************************************************/ +#if defined(HAVE_LONG_LONG_TIME) + +struct tm *localtime32_r(const time_t *clock, struct tm *res) +{return localtime_r(clock, res);} + +struct tm *gmtime32_r(const time_t *clock, struct tm *res) +{return gmtime_r(clock, res);} + +#ifdef USE_POSIX_TIME_R +char *asctime32_r(const struct tm *tm, char *buf) +{return asctime_r(tm, buf);} + +char *ctime32_r(const time_t *clock, char *buf) +{return ctime_r(clock, buf);} +#else +char *asctime32_r(const struct tm *tm, char *buf, int buflen) +{return asctime_r(tm, buf, buflen);} + +char *ctime32_r(const time_t *clock, char *buf, int buflen) +{return ctime_r(clock, buf, buflen);} +#endif + +struct tm *localtime32(const time_t *clock) +{return localtime(clock);} + +struct tm *gmtime32(const time_t *clock) +{return gmtime(clock);} + +size_t strftime32(char *str, size_t max, + const char *format, const struct tm *tm) +{return strftime(str, max, format, tm);} + +char *asctime32(const struct tm *tm) +{return asctime(tm);} + +char *ctime32(const time_t *clock) +{return ctime(clock);} + +#ifdef HAVE_MKTIME +time_t mktime32(const struct tm *tm) +{return mktime(tm);} +#endif + +#ifdef HAVE_TIMELOCAL +/* FreeBSD/Darwin do NOT declare these args as "const": */ +time_t timelocal32(struct tm *tm) +{return timelocal(tm);} + +time_t timegm32(struct tm *tm) +{return timegm(tm);} +#endif + +/*****************************************************************************/ +#else + +Local void mapclock32(time_t *clock, int *years); +Local void mapyears32(int *years, time_t *clock); + +#if !defined(HAVE_TIME_R) +struct tm *localtime_r(const time_t *clock, struct tm *xtime); +struct tm *gmtime_r(const time_t *clock, struct tm *xtime); +# ifdef USE_POSIX_TIME_R +char *asctime_r(const struct tm *tm, char *buf); +char *ctime_r(const time_t *clock, char *buf); +# else +char *asctime_r(const struct tm *tm, char *buf, int buflen); +char *ctime_r(const time_t *clock, char *buf, int buflen); +# endif +#endif /* !defined(HAVE_TIME_R) */ + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +struct tm *localtime32_r(const time_t *clock, struct tm *xtime) +{ + time_t xclock = *clock; + int xyears; + mapclock32(&xclock, &xyears); + localtime_r(&xclock, xtime); + xtime->tm_year += xyears; + return(xtime); +} + + +struct tm *localtime32(const time_t *clock) +{ + static struct tm xtime; /* return value must be static */ + return(localtime32_r(clock, &xtime)); +} + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +struct tm *gmtime32_r(const time_t *clock, struct tm *xtime) +{ + time_t xclock = *clock; + int xyears; + mapclock32(&xclock, &xyears); + gmtime_r(&xclock, xtime); + xtime->tm_year += xyears; + return(xtime); +} + + +struct tm *gmtime32(const time_t *clock) +{ + static struct tm xtime; /* return value must be static */ + return(gmtime32_r(clock, &xtime)); +} + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* NB: strftime32 will work correctly for all years > 2038 IF and only + IF the "tm" parameter given it was generated using one of the + time32 functions: localtime32(), localtime32_r(), gmtime32(), or + gmtime32_r(). */ +/* NB: strftime() is known to be in SunOS4/5, HPUX10/11, Linux2.2/4/6; + So far Only SunOS5 is known to have cftime() and ascftime() */ +size_t strftime32(char *str, size_t max, + const char *format, const struct tm *tm) +{ +#if defined(SUNOS) + /* SunOS 5.8, 5.9, 5.10 has a quirk where "strftime(..., ..., "%a", tm)" + corrupts tzname[0] and tzname[1] for certain values of tm_year, e.g. + "edate -C 0xd0700000" currupts tzname[], but "edate -C 0xd0800000" + doesn't. Setting tm_year within spec fixes this problem, but creates + a different problem if asked to print the year. All other OSes + including SunOS5.7 appear to take tm_year at face value. */ + if (osVersion == 0) osVersion = get_osVersion(); + if (osVersion >= 50800) + { + struct tm xtime = *tm; + time_t xclock = 0; + mapyears32(&xtime.tm_year, &xclock); + return(strftime(str, max, format, &xtime)); + } +#endif + /* Fall through for OS versions that take tm_year at face value: */ + return(strftime(str, max, format, tm)); +} + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* NB: asctime32() and asctime32_r() will work correctly for all years > 2038 + IF and only IF the "tm" parameter given it was generated using one of the + time32 functions: localtime32(), localtime32_r(), gmtime32(), or + gmtime32_r(). */ + +#ifdef USE_POSIX_TIME_R +char *asctime32_r(const struct tm *tm, char *buf) +{ + return(asctime_r(tm, buf)); +} +#else +char *asctime32_r(const struct tm *tm, char *buf, int buflen) +{ + return(asctime_r(tm, buf, buflen)); +} +#endif + + +char *asctime32(const struct tm *tm) +{ +# define BUF_SIZE (26+8) /* 8 bytes of slack */ + static char buf[BUF_SIZE]; /* return value must be static */ +#ifdef USE_POSIX_TIME_R + return(asctime32_r(tm, buf)); +#else + return(asctime32_r(tm, buf, BUF_SIZE)); +#endif +} + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifdef USE_POSIX_TIME_R +char *ctime32_r(const time_t *clock, char *buf) +{ + struct tm xtime; + return(asctime32_r(localtime32_r(clock, &xtime), buf)); +} +#else +char *ctime32_r(const time_t *clock, char *buf, int buflen) +{ + struct tm xtime; + return(asctime32_r(localtime32_r(clock, &xtime), buf, buflen)); +} +#endif + + +char *ctime32(const time_t *clock) +{ +# define BUF_SIZE (26+8) /* 8 bytes of slack */ + static char buf[BUF_SIZE]; /* return value must be static */ +#ifdef USE_POSIX_TIME_R + return(ctime32_r(clock, buf)); +#else + return(ctime32_r(clock, buf, BUF_SIZE)); +#endif +} + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* mktime is known to be supported by: HPUX 10+, SunOS5+, Linux2.2+, OSF1 + mktime is known to NOT be supported by: SunOS4 */ +#ifdef HAVE_MKTIME +time_t mktime32(const struct tm *tm) +{ + struct tm xtime = *tm; + time_t xclock; + mapyears32(&xtime.tm_year, &xclock); + return(mktime(&xtime) + xclock); +} +#endif /*HAVE_MKTIME*/ + + +/* timelocal and timegm are only known to be supported by SunOS4. Perhaps + older BSD-based OSes also support them, but POSIX based UNIXes do not. */ +#ifdef HAVE_TIMELOCAL +time_t timelocal32(struct tm *tm) +{ + struct tm xtime = *tm; + time_t xclock; + mapyears32(&xtime.tm_year, &xclock); + return(timelocal(&xtime) + xclock); +} + + +time_t timegm32(struct tm *tm) +{ + struct tm xtime = *tm; + time_t xclock; + mapyears32(&xtime.tm_year, &xclock); + return(timegm(&xtime) + xclock); +} +#endif /*HAVE_TIMELOCAL*/ + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#define _28_YEARS ( 28 * SECS_PER_YEAR) +#define _68_YEARS ( 68 * SECS_PER_YEAR) +#define _90_YEARS ( 88 * SECS_PER_YEAR + 2*365*SECS_PER_DAY) +#define _96_YEARS ( 96 * SECS_PER_YEAR) +#define JAN_1_2100 (128 * SECS_PER_YEAR + 2*365*SECS_PER_DAY) +#define JAN_1_2102 (JAN_1_2100 + 2*365*SECS_PER_DAY) /* leap year missing */ +#define JAN_1_2106 (JAN_1_2102 + 4*SECS_PER_YEAR) +#define TIME32 ((Ulong)0x80000000) + +Local void mapclock32(time_t *clock, int *years) +{ + Ulong xclock = (Ulong)*clock; + int xyears = 0; + + /* Prevent certain processors (e.g. DEC_ALPHA) from sign extending: */ + if (sizeof(Ulong) > 4) xclock &= 0xffffffff; + + /* Years from 1970 up until Jan 19 03:14:08 2038 GMT need no mapping. */ + + if (xclock >= TIME32) + { + /* Map years beyond Jan 19 03:14:08 2038 GMT: */ + if (xclock >= JAN_1_2100) + { + if (xclock < JAN_1_2102) + { + /* Map years 2100 and 2101: + (These two years must be contiguously mapped in order for + localtime(JAN_1_2101) to return the correct "tm_yday" value. + Hint: think about how Jan 1 2101, 00:00 GMT maps into + Dec 31 2100 LOCAL TIME). */ + + xclock -= _90_YEARS; + xyears = 90; + } + else if (xclock < JAN_1_2106) + { + /* Map years from 2102 up until 2106: */ + xclock -= _68_YEARS; + xclock += SECS_PER_DAY; /* Compensate for missing leap year in 2100! */ + xyears = 68; + } + else + { + /* Map years from Jan 1 2106 up until Feb 7 04:28:14 2106 GMT: */ + xclock -= _96_YEARS; + xclock += SECS_PER_DAY; /* Compensate for missing leap year in 2100! */ + xyears = 96; + } + } + else + { + /* Map years from 2038 up until 2100: */ + while (xclock >= TIME32) + { + xclock -= _28_YEARS; + xyears += 28; + } + } + } + + *clock = xclock; + *years = xyears; + return; +} + + +#define _1970 ( 70) +#define _2038 ( 68 + _1970) +#define _2100 (130 + _1970) +#define _2102 (132 + _1970) +#define _2106 (136 + _1970) + +Local void mapyears32(int *years, time_t *clock) +{ + Ulong xclock = 0; + int xyears = *years; + + /* Years from 1970 up until Jan 19 03:14:08 2038 GMT need no mapping. */ + + if (xyears >= _2038) + { + /* Map years beyond Jan 19 03:14:08 2038 GMT: */ + if (xyears >= _2100) + { + if (xyears < _2102) + { + /* Map years 2100 and 2101: + (These two years must be contiguously mapped in order for + localtime(JAN_1_2101) to return the correct "tm_yday" value. + Hint: think about how Jan 1 2101, 00:00 GMT maps into + Dec 31 2100 LOCAL TIME). */ + + xyears -= 90; + xclock = _90_YEARS; + } + else if (xyears < _2106) + { + /* Map years from 2102 up until 2106: */ + xyears -= 68; + xclock = _68_YEARS; + xclock -= SECS_PER_DAY; /* Compensate for missing leap year in 2100! */ + } + else + { + /* Map years from Jan 1 2106 up until Feb 7 04:28:14 2106 GMT: */ + xyears -= 96; + xclock = _96_YEARS; + xclock -= SECS_PER_DAY; /* Compensate for missing leap year in 2100! */ + } + } + else + { + /* Map years from 2038 up until 2100: */ + while (xyears >= _2038) + { + xyears -= 28; + xclock += _28_YEARS; + } + } + } + + *years = xyears; + *clock = xclock; + return; +} + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* The following ERSATZ *time_r() routines localtime_r(), gmtime_r(), + asctime_r(), and ctime_r() are provided here as cheap substitutes to be + used ONLY by those Unixes that are lacking these functions. Moreover, + when building on a Unix that has NATIVE support for the following ERSATZ + functions be sure to define HAVE_TIME_R so that the compiler will instead + make use of its NATIVE *time_r() routines. + + NOTE: If you must resort to using the following ERSATZ *time_r() routines + then as a consequence the *time32_r() functions in the previous section + will not be fully reentrant. HOWEVER, if you can AVOID using the + following routines and instead make use of your Unix's NATIVE *time_r() + routines then as a result the *time32_r() in the previous section will + also be reentrant! */ + +#if !defined(HAVE_TIME_R) + +struct tm *localtime_r(const time_t *clock, struct tm *xtime) +{ + *xtime = *localtime(clock); + return(xtime); +} +struct tm *gmtime_r(const time_t *clock, struct tm *xtime) +{ + *xtime = *gmtime(clock); + return(xtime); +} + +#include +# ifdef USE_POSIX_TIME_R +char *asctime_r(const struct tm *tm, char *buf) +{ + strcpy(buf, asctime(tm)); + return(buf); +} +char *ctime_r(const time_t *clock, char *buf) +{ + strcpy(buf, ctime(clock)); + return(buf); +} +# else +char *asctime_r(const struct tm *tm, char *buf, int buflen) +{ + strncpy(buf, asctime(tm), buflen); + return(buf); +} +char *ctime_r(const time_t *clock, char *buf, int buflen) +{ + strncpy(buf, ctime(clock), buflen); + return(buf); +} +# endif + +#endif /* !defined(HAVE_TIME_R) */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/*****************************************************************************/ +#endif /* !defined(HAVE_LONG_LONG_TIME) */ + +#endif +#endif + + diff --git a/win/mingw.h b/win/mingw.h new file mode 100644 index 000000000..a4da548cf --- /dev/null +++ b/win/mingw.h @@ -0,0 +1,75 @@ +#ifndef MINGW_H +#define MINGW_H + +#include + +#define _USE_W32_SOCKETS 1 +#include +#include "pthread.h" + +#define ENOTCONN WSAENOTCONN +#define EWOULDBLOCK WSAEWOULDBLOCK +#define ENOBUFS WSAENOBUFS +#define ECONNRESET WSAECONNRESET +#define ESHUTDOWN WSAESHUTDOWN +#define EAFNOSUPPORT WSAEAFNOSUPPORT +#define EPROTONOSUPPORT WSAEPROTONOSUPPORT +#define EINPROGRESS WSAEINPROGRESS +#define EISCONN WSAEISCONN +#define ECONNREFUSED WSAECONNREFUSED +#define EHOSTUNREACH WSAEHOSTUNREACH + +/* winsock doesn't feature poll(), so there is a version implemented + * in terms of select() in mingw.c. The following definitions + * are copied from linux man pages. A poll() macro is defined to + * call the version in mingw.c. + */ +#define POLLIN 0x0001 /* There is data to read */ +#define POLLPRI 0x0002 /* There is urgent data to read */ +#define POLLOUT 0x0004 /* Writing now will not block */ +#define POLLERR 0x0008 /* Error condition */ +#define POLLHUP 0x0010 /* Hung up */ +#define POLLNVAL 0x0020 /* Invalid request: fd not open */ +struct pollfd { + SOCKET fd; /* file descriptor */ + short events; /* requested events */ + short revents; /* returned events */ +}; +#define poll(x, y, z) win32_poll(x, y, z) + +/* These wrappers do nothing special except set the global errno variable if + * an error occurs (winsock doesn't do this by default). They set errno + * to unix-like values (i.e. WSAEWOULDBLOCK is mapped to EAGAIN), so code + * outside of this file "shouldn't" have to worry about winsock specific error + * handling. + */ +#define socket(x, y, z) win32_socket(x, y, z) +#define connect(x, y, z) win32_connect(x, y, z) +#define accept(x, y, z) win32_accept(x, y, z) +#define shutdown(x, y) win32_shutdown(x, y) +#define read(x, y, z) win32_read_socket(x, y, z) +#define write(x, y, z) win32_write_socket(x, y, z) + +/* Winsock uses int instead of the usual socklen_t */ +typedef int socklen_t; + +int win32_poll(struct pollfd *, unsigned int, int); +SOCKET win32_socket(int, int, int); +int win32_connect(SOCKET, struct sockaddr*, socklen_t); +SOCKET win32_accept(SOCKET, struct sockaddr*, socklen_t *); +int win32_shutdown(SOCKET, int); +int win32_close_socket(SOCKET fd); + +#define strtok_r(x, y, z) win32_strtok_r(x, y, z) +#define strsep(x,y) win32_strsep(x,y) + +char *win32_strtok_r(char *s, const char *delim, char **lasts); +char *win32_strsep(char **stringp, const char *delim); + +ssize_t win32_read_socket(SOCKET fd, void *buf, int n); +ssize_t win32_write_socket(SOCKET fd, void *buf, int n); + +//static inline void sleep(unsigned ms) { Sleep(ms*1000); } + +#endif + diff --git a/win/mman.h b/win/mman.h new file mode 100644 index 000000000..94337dac0 --- /dev/null +++ b/win/mman.h @@ -0,0 +1,51 @@ + +#ifndef _SYS_MMAN_H_ +#define _SYS_MMAN_H_ + +#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later. +#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows. +#endif + +/* All the headers include this file. */ +#ifndef _MSC_VER +#include <_mingw.h> +#endif + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define PROT_NONE 0 +#define PROT_READ 1 +#define PROT_WRITE 2 +#define PROT_EXEC 4 + +#define MAP_FILE 0 +#define MAP_SHARED 1 +#define MAP_PRIVATE 2 +#define MAP_TYPE 0xf +#define MAP_FIXED 0x10 +#define MAP_ANONYMOUS 0x20 +#define MAP_ANON MAP_ANONYMOUS + +#define MAP_FAILED ((void *)-1) + +/* Flags for msync. */ +#define MS_ASYNC 1 +#define MS_SYNC 2 +#define MS_INVALIDATE 4 + +void* mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off); +int munmap(void *addr, size_t len); +int _mprotect(void *addr, size_t len, int prot); +int msync(void *addr, size_t len, int flags); +int mlock(const void *addr, size_t len); +int munlock(const void *addr, size_t len); + +#ifdef __cplusplus +}; +#endif + +#endif diff --git a/win/pthread.h b/win/pthread.h new file mode 100644 index 000000000..7da6eb4b4 --- /dev/null +++ b/win/pthread.h @@ -0,0 +1,1368 @@ +/* This is an implementation of the threads API of POSIX 1003.1-2001. + * + * -------------------------------------------------------------------------- + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999,2005 Pthreads-win32 contributors + * + * Contact Email: rpj@callisto.canberra.edu.au + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#if !defined( PTHREAD_H ) +#define PTHREAD_H + +/* + * See the README file for an explanation of the pthreads-win32 version + * numbering scheme and how the DLL is named etc. + */ +#define PTW32_VERSION 2,9,1,0 +#define PTW32_VERSION_STRING "2, 9, 1, 0\0" + +/* There are three implementations of cancel cleanup. + * Note that pthread.h is included in both application + * compilation units and also internally for the library. + * The code here and within the library aims to work + * for all reasonable combinations of environments. + * + * The three implementations are: + * + * WIN32 SEH + * C + * C++ + * + * Please note that exiting a push/pop block via + * "return", "exit", "break", or "continue" will + * lead to different behaviour amongst applications + * depending upon whether the library was built + * using SEH, C++, or C. For example, a library built + * with SEH will call the cleanup routine, while both + * C++ and C built versions will not. + */ + +/* + * Define defaults for cleanup code. + * Note: Unless the build explicitly defines one of the following, then + * we default to standard C style cleanup. This style uses setjmp/longjmp + * in the cancelation and thread exit implementations and therefore won't + * do stack unwinding if linked to applications that have it (e.g. + * C++ apps). This is currently consistent with most/all commercial Unix + * POSIX threads implementations. + */ +#if !defined( __CLEANUP_SEH ) && !defined( __CLEANUP_CXX ) && !defined( __CLEANUP_C ) +# define __CLEANUP_C +#endif + +#if defined( __CLEANUP_SEH ) && ( !defined( _MSC_VER ) && !defined(PTW32_RC_MSC)) +#error ERROR [__FILE__, line __LINE__]: SEH is not supported for this compiler. +#endif + +/* + * Stop here if we are being included by the resource compiler. + */ +#if !defined(RC_INVOKED) + +#undef PTW32_LEVEL + +#if defined(_POSIX_SOURCE) +#define PTW32_LEVEL 0 +/* Early POSIX */ +#endif + +#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309 +#undef PTW32_LEVEL +#define PTW32_LEVEL 1 +/* Include 1b, 1c and 1d */ +#endif + +#if defined(INCLUDE_NP) +#undef PTW32_LEVEL +#define PTW32_LEVEL 2 +/* Include Non-Portable extensions */ +#endif + +#define PTW32_LEVEL_MAX 3 + +#if ( defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112 ) || !defined(PTW32_LEVEL) +#define PTW32_LEVEL PTW32_LEVEL_MAX +/* Include everything */ +#endif + +#if defined(_UWIN) +# define HAVE_STRUCT_TIMESPEC 1 +# define HAVE_SIGNAL_H 1 +# undef HAVE_PTW32_CONFIG_H +# pragma comment(lib, "pthread") +#endif + +/* + * ------------------------------------------------------------- + * + * + * Module: pthread.h + * + * Purpose: + * Provides an implementation of PThreads based upon the + * standard: + * + * POSIX 1003.1-2001 + * and + * The Single Unix Specification version 3 + * + * (these two are equivalent) + * + * in order to enhance code portability between Windows, + * various commercial Unix implementations, and Linux. + * + * See the ANNOUNCE file for a full list of conforming + * routines and defined constants, and a list of missing + * routines and constants not defined in this implementation. + * + * Authors: + * There have been many contributors to this library. + * The initial implementation was contributed by + * John Bossom, and several others have provided major + * sections or revisions of parts of the implementation. + * Often significant effort has been contributed to + * find and fix important bugs and other problems to + * improve the reliability of the library, which sometimes + * is not reflected in the amount of code which changed as + * result. + * As much as possible, the contributors are acknowledged + * in the ChangeLog file in the source code distribution + * where their changes are noted in detail. + * + * Contributors are listed in the CONTRIBUTORS file. + * + * As usual, all bouquets go to the contributors, and all + * brickbats go to the project maintainer. + * + * Maintainer: + * The code base for this project is coordinated and + * eventually pre-tested, packaged, and made available by + * + * Ross Johnson + * + * QA Testers: + * Ultimately, the library is tested in the real world by + * a host of competent and demanding scientists and + * engineers who report bugs and/or provide solutions + * which are then fixed or incorporated into subsequent + * versions of the library. Each time a bug is fixed, a + * test case is written to prove the fix and ensure + * that later changes to the code don't reintroduce the + * same error. The number of test cases is slowly growing + * and therefore so is the code reliability. + * + * Compliance: + * See the file ANNOUNCE for the list of implemented + * and not-implemented routines and defined options. + * Of course, these are all defined is this file as well. + * + * Web site: + * The source code and other information about this library + * are available from + * + * http://sources.redhat.com/pthreads-win32/ + * + * ------------------------------------------------------------- + */ + +/* Try to avoid including windows.h */ +#if (defined(__MINGW64__) || defined(__MINGW32__)) && defined(__cplusplus) +#define PTW32_INCLUDE_WINDOWS_H +#endif + +#if defined(PTW32_INCLUDE_WINDOWS_H) +#include +#endif + +#if defined(_MSC_VER) && _MSC_VER < 1300 || defined(__DMC__) +/* + * VC++6.0 or early compiler's header has no DWORD_PTR type. + */ +typedef unsigned long DWORD_PTR; +typedef unsigned long ULONG_PTR; +#endif +/* + * ----------------- + * autoconf switches + * ----------------- + */ + +#if defined(HAVE_PTW32_CONFIG_H) +#include "config.h" +#endif /* HAVE_PTW32_CONFIG_H */ + +#if !defined(NEED_FTIME) +#include +#else /* NEED_FTIME */ +/* use native WIN32 time API */ +#endif /* NEED_FTIME */ + +#if defined(HAVE_SIGNAL_H) +#include +#endif /* HAVE_SIGNAL_H */ + +#include + +/* + * Boolean values to make us independent of system includes. + */ +enum { + PTW32_FALSE = 0, + PTW32_TRUE = (! PTW32_FALSE) +}; + +/* + * This is a duplicate of what is in the autoconf config.h, + * which is only used when building the pthread-win32 libraries. + */ + +#if !defined(PTW32_CONFIG_H) +# if defined(WINCE) +# define NEED_ERRNO +# define NEED_SEM +# endif +# if defined(__MINGW64__) +# define HAVE_STRUCT_TIMESPEC +# define HAVE_MODE_T +# elif defined(_UWIN) || defined(__MINGW32__) +# define HAVE_MODE_T +# endif +#endif + +/* + * + */ + +#if PTW32_LEVEL >= PTW32_LEVEL_MAX +#if defined(NEED_ERRNO) +#include "need_errno.h" +#else +#include +#endif +#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ + +/* + * Several systems don't define some error numbers. + */ +#if !defined(ENOTSUP) +# define ENOTSUP 48 /* This is the value in Solaris. */ +#endif + +#if !defined(ETIMEDOUT) +# define ETIMEDOUT 10060 /* Same as WSAETIMEDOUT */ +#endif + +#if !defined(ENOSYS) +# define ENOSYS 140 /* Semi-arbitrary value */ +#endif + +#if !defined(EDEADLK) +# if defined(EDEADLOCK) +# define EDEADLK EDEADLOCK +# else +# define EDEADLK 36 /* This is the value in MSVC. */ +# endif +#endif + +/* POSIX 2008 - related to robust mutexes */ +#if !defined(EOWNERDEAD) +# define EOWNERDEAD 43 +#endif +#if !defined(ENOTRECOVERABLE) +# define ENOTRECOVERABLE 44 +#endif + +#include "sched.h" + +/* + * To avoid including windows.h we define only those things that we + * actually need from it. + */ +#if !defined(PTW32_INCLUDE_WINDOWS_H) +#if !defined(HANDLE) +# define PTW32__HANDLE_DEF +# define HANDLE void * +#endif +#if !defined(DWORD) +# define PTW32__DWORD_DEF +# define DWORD unsigned long +#endif +#endif + +#if !defined(HAVE_STRUCT_TIMESPEC) +#define HAVE_STRUCT_TIMESPEC +#if !defined(_TIMESPEC_DEFINED) +#define _TIMESPEC_DEFINED +struct timespec { + time_t tv_sec; + long tv_nsec; +}; +#endif /* _TIMESPEC_DEFINED */ +#endif /* HAVE_STRUCT_TIMESPEC */ + +#if !defined(SIG_BLOCK) +#define SIG_BLOCK 0 +#endif /* SIG_BLOCK */ + +#if !defined(SIG_UNBLOCK) +#define SIG_UNBLOCK 1 +#endif /* SIG_UNBLOCK */ + +#if !defined(SIG_SETMASK) +#define SIG_SETMASK 2 +#endif /* SIG_SETMASK */ + +#if defined(__cplusplus) +extern "C" +{ +#endif /* __cplusplus */ + +/* + * ------------------------------------------------------------- + * + * POSIX 1003.1-2001 Options + * ========================= + * + * Options are normally set in , which is not provided + * with pthreads-win32. + * + * For conformance with the Single Unix Specification (version 3), all of the + * options below are defined, and have a value of either -1 (not supported) + * or 200112L (supported). + * + * These options can neither be left undefined nor have a value of 0, because + * either indicates that sysconf(), which is not implemented, may be used at + * runtime to check the status of the option. + * + * _POSIX_THREADS (== 200112L) + * If == 200112L, you can use threads + * + * _POSIX_THREAD_ATTR_STACKSIZE (== 200112L) + * If == 200112L, you can control the size of a thread's + * stack + * pthread_attr_getstacksize + * pthread_attr_setstacksize + * + * _POSIX_THREAD_ATTR_STACKADDR (== -1) + * If == 200112L, you can allocate and control a thread's + * stack. If not supported, the following functions + * will return ENOSYS, indicating they are not + * supported: + * pthread_attr_getstackaddr + * pthread_attr_setstackaddr + * + * _POSIX_THREAD_PRIORITY_SCHEDULING (== -1) + * If == 200112L, you can use realtime scheduling. + * This option indicates that the behaviour of some + * implemented functions conforms to the additional TPS + * requirements in the standard. E.g. rwlocks favour + * writers over readers when threads have equal priority. + * + * _POSIX_THREAD_PRIO_INHERIT (== -1) + * If == 200112L, you can create priority inheritance + * mutexes. + * pthread_mutexattr_getprotocol + + * pthread_mutexattr_setprotocol + + * + * _POSIX_THREAD_PRIO_PROTECT (== -1) + * If == 200112L, you can create priority ceiling mutexes + * Indicates the availability of: + * pthread_mutex_getprioceiling + * pthread_mutex_setprioceiling + * pthread_mutexattr_getprioceiling + * pthread_mutexattr_getprotocol + + * pthread_mutexattr_setprioceiling + * pthread_mutexattr_setprotocol + + * + * _POSIX_THREAD_PROCESS_SHARED (== -1) + * If set, you can create mutexes and condition + * variables that can be shared with another + * process.If set, indicates the availability + * of: + * pthread_mutexattr_getpshared + * pthread_mutexattr_setpshared + * pthread_condattr_getpshared + * pthread_condattr_setpshared + * + * _POSIX_THREAD_SAFE_FUNCTIONS (== 200112L) + * If == 200112L you can use the special *_r library + * functions that provide thread-safe behaviour + * + * _POSIX_READER_WRITER_LOCKS (== 200112L) + * If == 200112L, you can use read/write locks + * + * _POSIX_SPIN_LOCKS (== 200112L) + * If == 200112L, you can use spin locks + * + * _POSIX_BARRIERS (== 200112L) + * If == 200112L, you can use barriers + * + * + These functions provide both 'inherit' and/or + * 'protect' protocol, based upon these macro + * settings. + * + * ------------------------------------------------------------- + */ + +/* + * POSIX Options + */ +#undef _POSIX_THREADS +#define _POSIX_THREADS 200809L + +#undef _POSIX_READER_WRITER_LOCKS +#define _POSIX_READER_WRITER_LOCKS 200809L + +#undef _POSIX_SPIN_LOCKS +#define _POSIX_SPIN_LOCKS 200809L + +#undef _POSIX_BARRIERS +#define _POSIX_BARRIERS 200809L + +#undef _POSIX_THREAD_SAFE_FUNCTIONS +#define _POSIX_THREAD_SAFE_FUNCTIONS 200809L + +#undef _POSIX_THREAD_ATTR_STACKSIZE +#define _POSIX_THREAD_ATTR_STACKSIZE 200809L + +/* + * The following options are not supported + */ +#undef _POSIX_THREAD_ATTR_STACKADDR +#define _POSIX_THREAD_ATTR_STACKADDR -1 + +#undef _POSIX_THREAD_PRIO_INHERIT +#define _POSIX_THREAD_PRIO_INHERIT -1 + +#undef _POSIX_THREAD_PRIO_PROTECT +#define _POSIX_THREAD_PRIO_PROTECT -1 + +/* TPS is not fully supported. */ +#undef _POSIX_THREAD_PRIORITY_SCHEDULING +#define _POSIX_THREAD_PRIORITY_SCHEDULING -1 + +#undef _POSIX_THREAD_PROCESS_SHARED +#define _POSIX_THREAD_PROCESS_SHARED -1 + + +/* + * POSIX 1003.1-2001 Limits + * =========================== + * + * These limits are normally set in , which is not provided with + * pthreads-win32. + * + * PTHREAD_DESTRUCTOR_ITERATIONS + * Maximum number of attempts to destroy + * a thread's thread-specific data on + * termination (must be at least 4) + * + * PTHREAD_KEYS_MAX + * Maximum number of thread-specific data keys + * available per process (must be at least 128) + * + * PTHREAD_STACK_MIN + * Minimum supported stack size for a thread + * + * PTHREAD_THREADS_MAX + * Maximum number of threads supported per + * process (must be at least 64). + * + * SEM_NSEMS_MAX + * The maximum number of semaphores a process can have. + * (must be at least 256) + * + * SEM_VALUE_MAX + * The maximum value a semaphore can have. + * (must be at least 32767) + * + */ +#undef _POSIX_THREAD_DESTRUCTOR_ITERATIONS +#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 + +#undef PTHREAD_DESTRUCTOR_ITERATIONS +#define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS + +#undef _POSIX_THREAD_KEYS_MAX +#define _POSIX_THREAD_KEYS_MAX 128 + +#undef PTHREAD_KEYS_MAX +#define PTHREAD_KEYS_MAX _POSIX_THREAD_KEYS_MAX + +#undef PTHREAD_STACK_MIN +#define PTHREAD_STACK_MIN 0 + +#undef _POSIX_THREAD_THREADS_MAX +#define _POSIX_THREAD_THREADS_MAX 64 + + /* Arbitrary value */ +#undef PTHREAD_THREADS_MAX +#define PTHREAD_THREADS_MAX 2019 + +#undef _POSIX_SEM_NSEMS_MAX +#define _POSIX_SEM_NSEMS_MAX 256 + + /* Arbitrary value */ +#undef SEM_NSEMS_MAX +#define SEM_NSEMS_MAX 1024 + +#undef _POSIX_SEM_VALUE_MAX +#define _POSIX_SEM_VALUE_MAX 32767 + +#undef SEM_VALUE_MAX +#define SEM_VALUE_MAX INT_MAX + + +#if defined(__GNUC__) && !defined(__declspec) +# error Please upgrade your GNU compiler to one that supports __declspec. +#endif + +/* + * When building the library, you should define PTW32_BUILD so that + * the variables/functions are exported correctly. When using the library, + * do NOT define PTW32_BUILD, and then the variables/functions will + * be imported correctly. + */ +#if !defined(PTW32_STATIC_LIB) +# if defined(PTW32_BUILD) +# define PTW32_DLLPORT __declspec (dllexport) +# else +# define PTW32_DLLPORT __declspec (dllimport) +# endif +#else +# define PTW32_DLLPORT +#endif + +/* + * The Open Watcom C/C++ compiler uses a non-standard calling convention + * that passes function args in registers unless __cdecl is explicitly specified + * in exposed function prototypes. + * + * We force all calls to cdecl even though this could slow Watcom code down + * slightly. If you know that the Watcom compiler will be used to build both + * the DLL and application, then you can probably define this as a null string. + * Remember that pthread.h (this file) is used for both the DLL and application builds. + */ +#define PTW32_CDECL __cdecl + +#if defined(_UWIN) && PTW32_LEVEL >= PTW32_LEVEL_MAX +# include +#else +/* + * Generic handle type - intended to extend uniqueness beyond + * that available with a simple pointer. It should scale for either + * IA-32 or IA-64. + */ +typedef struct { + void * p; /* Pointer to actual object */ + unsigned int x; /* Extra information - reuse count etc */ +} ptw32_handle_t; + +typedef ptw32_handle_t pthread_t; +typedef struct pthread_attr_t_ * pthread_attr_t; +typedef struct pthread_once_t_ pthread_once_t; +typedef struct pthread_key_t_ * pthread_key_t; +typedef struct pthread_mutex_t_ * pthread_mutex_t; +typedef struct pthread_mutexattr_t_ * pthread_mutexattr_t; +typedef struct pthread_cond_t_ * pthread_cond_t; +typedef struct pthread_condattr_t_ * pthread_condattr_t; +#endif +typedef struct pthread_rwlock_t_ * pthread_rwlock_t; +typedef struct pthread_rwlockattr_t_ * pthread_rwlockattr_t; +typedef struct pthread_spinlock_t_ * pthread_spinlock_t; +typedef struct pthread_barrier_t_ * pthread_barrier_t; +typedef struct pthread_barrierattr_t_ * pthread_barrierattr_t; + +/* + * ==================== + * ==================== + * POSIX Threads + * ==================== + * ==================== + */ + +enum { +/* + * pthread_attr_{get,set}detachstate + */ + PTHREAD_CREATE_JOINABLE = 0, /* Default */ + PTHREAD_CREATE_DETACHED = 1, + +/* + * pthread_attr_{get,set}inheritsched + */ + PTHREAD_INHERIT_SCHED = 0, + PTHREAD_EXPLICIT_SCHED = 1, /* Default */ + +/* + * pthread_{get,set}scope + */ + PTHREAD_SCOPE_PROCESS = 0, + PTHREAD_SCOPE_SYSTEM = 1, /* Default */ + +/* + * pthread_setcancelstate paramters + */ + PTHREAD_CANCEL_ENABLE = 0, /* Default */ + PTHREAD_CANCEL_DISABLE = 1, + +/* + * pthread_setcanceltype parameters + */ + PTHREAD_CANCEL_ASYNCHRONOUS = 0, + PTHREAD_CANCEL_DEFERRED = 1, /* Default */ + +/* + * pthread_mutexattr_{get,set}pshared + * pthread_condattr_{get,set}pshared + */ + PTHREAD_PROCESS_PRIVATE = 0, + PTHREAD_PROCESS_SHARED = 1, + +/* + * pthread_mutexattr_{get,set}robust + */ + PTHREAD_MUTEX_STALLED = 0, /* Default */ + PTHREAD_MUTEX_ROBUST = 1, + +/* + * pthread_barrier_wait + */ + PTHREAD_BARRIER_SERIAL_THREAD = -1 +}; + +/* + * ==================== + * ==================== + * Cancelation + * ==================== + * ==================== + */ +#define PTHREAD_CANCELED ((void *)(size_t) -1) + + +/* + * ==================== + * ==================== + * Once Key + * ==================== + * ==================== + */ +#define PTHREAD_ONCE_INIT { PTW32_FALSE, 0, 0, 0} + +struct pthread_once_t_ +{ + int done; /* indicates if user function has been executed */ + void * lock; + int reserved1; + int reserved2; +}; + + +/* + * ==================== + * ==================== + * Object initialisers + * ==================== + * ==================== + */ +#define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t)(size_t) -1) +#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER ((pthread_mutex_t)(size_t) -2) +#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER ((pthread_mutex_t)(size_t) -3) + +/* + * Compatibility with LinuxThreads + */ +#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP PTHREAD_RECURSIVE_MUTEX_INITIALIZER +#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP PTHREAD_ERRORCHECK_MUTEX_INITIALIZER + +#define PTHREAD_COND_INITIALIZER ((pthread_cond_t)(size_t) -1) + +#define PTHREAD_RWLOCK_INITIALIZER ((pthread_rwlock_t)(size_t) -1) + +#define PTHREAD_SPINLOCK_INITIALIZER ((pthread_spinlock_t)(size_t) -1) + + +/* + * Mutex types. + */ +enum +{ + /* Compatibility with LinuxThreads */ + PTHREAD_MUTEX_FAST_NP, + PTHREAD_MUTEX_RECURSIVE_NP, + PTHREAD_MUTEX_ERRORCHECK_NP, + PTHREAD_MUTEX_TIMED_NP = PTHREAD_MUTEX_FAST_NP, + PTHREAD_MUTEX_ADAPTIVE_NP = PTHREAD_MUTEX_FAST_NP, + /* For compatibility with POSIX */ + PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_FAST_NP, + PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP, + PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP, + PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL +}; + + +typedef struct ptw32_cleanup_t ptw32_cleanup_t; + +#if defined(_MSC_VER) +/* Disable MSVC 'anachronism used' warning */ +#pragma warning( disable : 4229 ) +#endif + +typedef void (* PTW32_CDECL ptw32_cleanup_callback_t)(void *); + +#if defined(_MSC_VER) +#pragma warning( default : 4229 ) +#endif + +struct ptw32_cleanup_t +{ + ptw32_cleanup_callback_t routine; + void *arg; + struct ptw32_cleanup_t *prev; +}; + +#if defined(__CLEANUP_SEH) + /* + * WIN32 SEH version of cancel cleanup. + */ + +#define pthread_cleanup_push( _rout, _arg ) \ + { \ + ptw32_cleanup_t _cleanup; \ + \ + _cleanup.routine = (ptw32_cleanup_callback_t)(_rout); \ + _cleanup.arg = (_arg); \ + __try \ + { \ + +#define pthread_cleanup_pop( _execute ) \ + } \ + __finally \ + { \ + if( _execute || AbnormalTermination()) \ + { \ + (*(_cleanup.routine))( _cleanup.arg ); \ + } \ + } \ + } + +#else /* __CLEANUP_SEH */ + +#if defined(__CLEANUP_C) + + /* + * C implementation of PThreads cancel cleanup + */ + +#define pthread_cleanup_push( _rout, _arg ) \ + { \ + ptw32_cleanup_t _cleanup; \ + \ + ptw32_push_cleanup( &_cleanup, (ptw32_cleanup_callback_t) (_rout), (_arg) ); \ + +#define pthread_cleanup_pop( _execute ) \ + (void) ptw32_pop_cleanup( _execute ); \ + } + +#else /* __CLEANUP_C */ + +#if defined(__CLEANUP_CXX) + + /* + * C++ version of cancel cleanup. + * - John E. Bossom. + */ + + class PThreadCleanup { + /* + * PThreadCleanup + * + * Purpose + * This class is a C++ helper class that is + * used to implement pthread_cleanup_push/ + * pthread_cleanup_pop. + * The destructor of this class automatically + * pops the pushed cleanup routine regardless + * of how the code exits the scope + * (i.e. such as by an exception) + */ + ptw32_cleanup_callback_t cleanUpRout; + void * obj; + int executeIt; + + public: + PThreadCleanup() : + cleanUpRout( 0 ), + obj( 0 ), + executeIt( 0 ) + /* + * No cleanup performed + */ + { + } + + PThreadCleanup( + ptw32_cleanup_callback_t routine, + void * arg ) : + cleanUpRout( routine ), + obj( arg ), + executeIt( 1 ) + /* + * Registers a cleanup routine for 'arg' + */ + { + } + + ~PThreadCleanup() + { + if ( executeIt && ((void *) cleanUpRout != (void *) 0) ) + { + (void) (*cleanUpRout)( obj ); + } + } + + void execute( int exec ) + { + executeIt = exec; + } + }; + + /* + * C++ implementation of PThreads cancel cleanup; + * This implementation takes advantage of a helper + * class who's destructor automatically calls the + * cleanup routine if we exit our scope weirdly + */ +#define pthread_cleanup_push( _rout, _arg ) \ + { \ + PThreadCleanup cleanup((ptw32_cleanup_callback_t)(_rout), \ + (void *) (_arg) ); + +#define pthread_cleanup_pop( _execute ) \ + cleanup.execute( _execute ); \ + } + +#else + +#error ERROR [__FILE__, line __LINE__]: Cleanup type undefined. + +#endif /* __CLEANUP_CXX */ + +#endif /* __CLEANUP_C */ + +#endif /* __CLEANUP_SEH */ + +/* + * =============== + * =============== + * Methods + * =============== + * =============== + */ + +/* + * PThread Attribute Functions + */ +PTW32_DLLPORT int PTW32_CDECL pthread_attr_init (pthread_attr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_destroy (pthread_attr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_getdetachstate (const pthread_attr_t * attr, + int *detachstate); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstackaddr (const pthread_attr_t * attr, + void **stackaddr); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstacksize (const pthread_attr_t * attr, + size_t * stacksize); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setdetachstate (pthread_attr_t * attr, + int detachstate); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstackaddr (pthread_attr_t * attr, + void *stackaddr); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstacksize (pthread_attr_t * attr, + size_t stacksize); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedparam (const pthread_attr_t *attr, + struct sched_param *param); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedparam (pthread_attr_t *attr, + const struct sched_param *param); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedpolicy (pthread_attr_t *, + int); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedpolicy (const pthread_attr_t *, + int *); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setinheritsched(pthread_attr_t * attr, + int inheritsched); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_getinheritsched(const pthread_attr_t * attr, + int * inheritsched); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setscope (pthread_attr_t *, + int); + +PTW32_DLLPORT int PTW32_CDECL pthread_attr_getscope (const pthread_attr_t *, + int *); + +/* + * PThread Functions + */ +PTW32_DLLPORT int PTW32_CDECL pthread_create (pthread_t * tid, + const pthread_attr_t * attr, + void *(PTW32_CDECL *start) (void *), + void *arg); + +PTW32_DLLPORT int PTW32_CDECL pthread_detach (pthread_t tid); + +PTW32_DLLPORT int PTW32_CDECL pthread_equal (pthread_t t1, + pthread_t t2); + +PTW32_DLLPORT void PTW32_CDECL pthread_exit (void *value_ptr); + +PTW32_DLLPORT int PTW32_CDECL pthread_join (pthread_t thread, + void **value_ptr); + +PTW32_DLLPORT pthread_t PTW32_CDECL pthread_self (void); + +PTW32_DLLPORT int PTW32_CDECL pthread_cancel (pthread_t thread); + +PTW32_DLLPORT int PTW32_CDECL pthread_setcancelstate (int state, + int *oldstate); + +PTW32_DLLPORT int PTW32_CDECL pthread_setcanceltype (int type, + int *oldtype); + +PTW32_DLLPORT void PTW32_CDECL pthread_testcancel (void); + +PTW32_DLLPORT int PTW32_CDECL pthread_once (pthread_once_t * once_control, + void (PTW32_CDECL *init_routine) (void)); + +#if PTW32_LEVEL >= PTW32_LEVEL_MAX +PTW32_DLLPORT ptw32_cleanup_t * PTW32_CDECL ptw32_pop_cleanup (int execute); + +PTW32_DLLPORT void PTW32_CDECL ptw32_push_cleanup (ptw32_cleanup_t * cleanup, + ptw32_cleanup_callback_t routine, + void *arg); +#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ + +/* + * Thread Specific Data Functions + */ +PTW32_DLLPORT int PTW32_CDECL pthread_key_create (pthread_key_t * key, + void (PTW32_CDECL *destructor) (void *)); + +PTW32_DLLPORT int PTW32_CDECL pthread_key_delete (pthread_key_t key); + +PTW32_DLLPORT int PTW32_CDECL pthread_setspecific (pthread_key_t key, + const void *value); + +PTW32_DLLPORT void * PTW32_CDECL pthread_getspecific (pthread_key_t key); + + +/* + * Mutex Attribute Functions + */ +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_init (pthread_mutexattr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_destroy (pthread_mutexattr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getpshared (const pthread_mutexattr_t + * attr, + int *pshared); + +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setpshared (pthread_mutexattr_t * attr, + int pshared); + +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_settype (pthread_mutexattr_t * attr, int kind); +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_gettype (const pthread_mutexattr_t * attr, int *kind); + +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setrobust( + pthread_mutexattr_t *attr, + int robust); +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getrobust( + const pthread_mutexattr_t * attr, + int * robust); + +/* + * Barrier Attribute Functions + */ +PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_init (pthread_barrierattr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_destroy (pthread_barrierattr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_getpshared (const pthread_barrierattr_t + * attr, + int *pshared); + +PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_setpshared (pthread_barrierattr_t * attr, + int pshared); + +/* + * Mutex Functions + */ +PTW32_DLLPORT int PTW32_CDECL pthread_mutex_init (pthread_mutex_t * mutex, + const pthread_mutexattr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_mutex_destroy (pthread_mutex_t * mutex); + +PTW32_DLLPORT int PTW32_CDECL pthread_mutex_lock (pthread_mutex_t * mutex); + +PTW32_DLLPORT int PTW32_CDECL pthread_mutex_timedlock(pthread_mutex_t * mutex, + const struct timespec *abstime); + +PTW32_DLLPORT int PTW32_CDECL pthread_mutex_trylock (pthread_mutex_t * mutex); + +PTW32_DLLPORT int PTW32_CDECL pthread_mutex_unlock (pthread_mutex_t * mutex); + +PTW32_DLLPORT int PTW32_CDECL pthread_mutex_consistent (pthread_mutex_t * mutex); + +/* + * Spinlock Functions + */ +PTW32_DLLPORT int PTW32_CDECL pthread_spin_init (pthread_spinlock_t * lock, int pshared); + +PTW32_DLLPORT int PTW32_CDECL pthread_spin_destroy (pthread_spinlock_t * lock); + +PTW32_DLLPORT int PTW32_CDECL pthread_spin_lock (pthread_spinlock_t * lock); + +PTW32_DLLPORT int PTW32_CDECL pthread_spin_trylock (pthread_spinlock_t * lock); + +PTW32_DLLPORT int PTW32_CDECL pthread_spin_unlock (pthread_spinlock_t * lock); + +/* + * Barrier Functions + */ +PTW32_DLLPORT int PTW32_CDECL pthread_barrier_init (pthread_barrier_t * barrier, + const pthread_barrierattr_t * attr, + unsigned int count); + +PTW32_DLLPORT int PTW32_CDECL pthread_barrier_destroy (pthread_barrier_t * barrier); + +PTW32_DLLPORT int PTW32_CDECL pthread_barrier_wait (pthread_barrier_t * barrier); + +/* + * Condition Variable Attribute Functions + */ +PTW32_DLLPORT int PTW32_CDECL pthread_condattr_init (pthread_condattr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_condattr_destroy (pthread_condattr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_condattr_getpshared (const pthread_condattr_t * attr, + int *pshared); + +PTW32_DLLPORT int PTW32_CDECL pthread_condattr_setpshared (pthread_condattr_t * attr, + int pshared); + +/* + * Condition Variable Functions + */ +PTW32_DLLPORT int PTW32_CDECL pthread_cond_init (pthread_cond_t * cond, + const pthread_condattr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_cond_destroy (pthread_cond_t * cond); + +PTW32_DLLPORT int PTW32_CDECL pthread_cond_wait (pthread_cond_t * cond, + pthread_mutex_t * mutex); + +PTW32_DLLPORT int PTW32_CDECL pthread_cond_timedwait (pthread_cond_t * cond, + pthread_mutex_t * mutex, + const struct timespec *abstime); + +PTW32_DLLPORT int PTW32_CDECL pthread_cond_signal (pthread_cond_t * cond); + +PTW32_DLLPORT int PTW32_CDECL pthread_cond_broadcast (pthread_cond_t * cond); + +/* + * Scheduling + */ +PTW32_DLLPORT int PTW32_CDECL pthread_setschedparam (pthread_t thread, + int policy, + const struct sched_param *param); + +PTW32_DLLPORT int PTW32_CDECL pthread_getschedparam (pthread_t thread, + int *policy, + struct sched_param *param); + +PTW32_DLLPORT int PTW32_CDECL pthread_setconcurrency (int); + +PTW32_DLLPORT int PTW32_CDECL pthread_getconcurrency (void); + +/* + * Read-Write Lock Functions + */ +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_init(pthread_rwlock_t *lock, + const pthread_rwlockattr_t *attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_destroy(pthread_rwlock_t *lock); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_tryrdlock(pthread_rwlock_t *); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_trywrlock(pthread_rwlock_t *); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_rdlock(pthread_rwlock_t *lock); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedrdlock(pthread_rwlock_t *lock, + const struct timespec *abstime); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_wrlock(pthread_rwlock_t *lock); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedwrlock(pthread_rwlock_t *lock, + const struct timespec *abstime); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_unlock(pthread_rwlock_t *lock); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_init (pthread_rwlockattr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_destroy (pthread_rwlockattr_t * attr); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_getpshared (const pthread_rwlockattr_t * attr, + int *pshared); + +PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_setpshared (pthread_rwlockattr_t * attr, + int pshared); + +#if PTW32_LEVEL >= PTW32_LEVEL_MAX - 1 + +/* + * Signal Functions. Should be defined in but MSVC and MinGW32 + * already have signal.h that don't define these. + */ +PTW32_DLLPORT int PTW32_CDECL pthread_kill(pthread_t thread, int sig); + +/* + * Non-portable functions + */ + +/* + * Compatibility with Linux. + */ +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setkind_np(pthread_mutexattr_t * attr, + int kind); +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getkind_np(pthread_mutexattr_t * attr, + int *kind); + +/* + * Possibly supported by other POSIX threads implementations + */ +PTW32_DLLPORT int PTW32_CDECL pthread_delay_np (struct timespec * interval); +PTW32_DLLPORT int PTW32_CDECL pthread_num_processors_np(void); +PTW32_DLLPORT unsigned __int64 PTW32_CDECL pthread_getunique_np(pthread_t thread); + +/* + * Useful if an application wants to statically link + * the lib rather than load the DLL at run-time. + */ +PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_attach_np(void); +PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_detach_np(void); +PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_attach_np(void); +PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_detach_np(void); + +/* + * Features that are auto-detected at load/run time. + */ +PTW32_DLLPORT int PTW32_CDECL pthread_win32_test_features_np(int); +enum ptw32_features { + PTW32_SYSTEM_INTERLOCKED_COMPARE_EXCHANGE = 0x0001, /* System provides it. */ + PTW32_ALERTABLE_ASYNC_CANCEL = 0x0002 /* Can cancel blocked threads. */ +}; + +/* + * Register a system time change with the library. + * Causes the library to perform various functions + * in response to the change. Should be called whenever + * the application's top level window receives a + * WM_TIMECHANGE message. It can be passed directly to + * pthread_create() as a new thread if desired. + */ +PTW32_DLLPORT void * PTW32_CDECL pthread_timechange_handler_np(void *); + +#endif /*PTW32_LEVEL >= PTW32_LEVEL_MAX - 1 */ + +#if PTW32_LEVEL >= PTW32_LEVEL_MAX + +/* + * Returns the Win32 HANDLE for the POSIX thread. + */ +PTW32_DLLPORT HANDLE PTW32_CDECL pthread_getw32threadhandle_np(pthread_t thread); +/* + * Returns the win32 thread ID for POSIX thread. + */ +PTW32_DLLPORT DWORD PTW32_CDECL pthread_getw32threadid_np (pthread_t thread); + + +/* + * Protected Methods + * + * This function blocks until the given WIN32 handle + * is signaled or pthread_cancel had been called. + * This function allows the caller to hook into the + * PThreads cancel mechanism. It is implemented using + * + * WaitForMultipleObjects + * + * on 'waitHandle' and a manually reset WIN32 Event + * used to implement pthread_cancel. The 'timeout' + * argument to TimedWait is simply passed to + * WaitForMultipleObjects. + */ +PTW32_DLLPORT int PTW32_CDECL pthreadCancelableWait (HANDLE waitHandle); +PTW32_DLLPORT int PTW32_CDECL pthreadCancelableTimedWait (HANDLE waitHandle, + DWORD timeout); + +#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ + +/* + * Thread-Safe C Runtime Library Mappings. + */ +#if !defined(_UWIN) +# if defined(NEED_ERRNO) + PTW32_DLLPORT int * PTW32_CDECL _errno( void ); +# else +# if !defined(errno) +# if (defined(_MT) || defined(_DLL)) + __declspec(dllimport) extern int * __cdecl _errno(void); +# define errno (*_errno()) +# endif +# endif +# endif +#endif + +/* + * Some compiler environments don't define some things. + */ +#if defined(__BORLANDC__) +# define _ftime ftime +# define _timeb timeb +#endif + +#if defined(__cplusplus) + +/* + * Internal exceptions + */ +class ptw32_exception {}; +class ptw32_exception_cancel : public ptw32_exception {}; +class ptw32_exception_exit : public ptw32_exception {}; + +#endif + +#if PTW32_LEVEL >= PTW32_LEVEL_MAX + +/* FIXME: This is only required if the library was built using SEH */ +/* + * Get internal SEH tag + */ +PTW32_DLLPORT DWORD PTW32_CDECL ptw32_get_exception_services_code(void); + +#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ + +#if !defined(PTW32_BUILD) + +#if defined(__CLEANUP_SEH) + +/* + * Redefine the SEH __except keyword to ensure that applications + * propagate our internal exceptions up to the library's internal handlers. + */ +#define __except( E ) \ + __except( ( GetExceptionCode() == ptw32_get_exception_services_code() ) \ + ? EXCEPTION_CONTINUE_SEARCH : ( E ) ) + +#endif /* __CLEANUP_SEH */ + +#if defined(__CLEANUP_CXX) + +/* + * Redefine the C++ catch keyword to ensure that applications + * propagate our internal exceptions up to the library's internal handlers. + */ +#if defined(_MSC_VER) + /* + * WARNING: Replace any 'catch( ... )' with 'PtW32CatchAll' + * if you want Pthread-Win32 cancelation and pthread_exit to work. + */ + +#if !defined(PtW32NoCatchWarn) + +#pragma message("Specify \"/DPtW32NoCatchWarn\" compiler flag to skip this message.") +#pragma message("------------------------------------------------------------------") +#pragma message("When compiling applications with MSVC++ and C++ exception handling:") +#pragma message(" Replace any 'catch( ... )' in routines called from POSIX threads") +#pragma message(" with 'PtW32CatchAll' or 'CATCHALL' if you want POSIX thread") +#pragma message(" cancelation and pthread_exit to work. For example:") +#pragma message("") +#pragma message(" #if defined(PtW32CatchAll)") +#pragma message(" PtW32CatchAll") +#pragma message(" #else") +#pragma message(" catch(...)") +#pragma message(" #endif") +#pragma message(" {") +#pragma message(" /* Catchall block processing */") +#pragma message(" }") +#pragma message("------------------------------------------------------------------") + +#endif + +#define PtW32CatchAll \ + catch( ptw32_exception & ) { throw; } \ + catch( ... ) + +#else /* _MSC_VER */ + +#define catch( E ) \ + catch( ptw32_exception & ) { throw; } \ + catch( E ) + +#endif /* _MSC_VER */ + +#endif /* __CLEANUP_CXX */ + +#endif /* ! PTW32_BUILD */ + +#if defined(__cplusplus) +} /* End of extern "C" */ +#endif /* __cplusplus */ + +#if defined(PTW32__HANDLE_DEF) +# undef HANDLE +#endif +#if defined(PTW32__DWORD_DEF) +# undef DWORD +#endif + +#undef PTW32_LEVEL +#undef PTW32_LEVEL_MAX + +#endif /* ! RC_INVOKED */ + +#endif /* PTHREAD_H */ diff --git a/win/sched.h b/win/sched.h new file mode 100644 index 000000000..f36a97a66 --- /dev/null +++ b/win/sched.h @@ -0,0 +1,183 @@ +/* + * Module: sched.h + * + * Purpose: + * Provides an implementation of POSIX realtime extensions + * as defined in + * + * POSIX 1003.1b-1993 (POSIX.1b) + * + * -------------------------------------------------------------------------- + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999,2005 Pthreads-win32 contributors + * + * Contact Email: rpj@callisto.canberra.edu.au + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ +#if !defined(_SCHED_H) +#define _SCHED_H + +#undef PTW32_SCHED_LEVEL + +#if defined(_POSIX_SOURCE) +#define PTW32_SCHED_LEVEL 0 +/* Early POSIX */ +#endif + +#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309 +#undef PTW32_SCHED_LEVEL +#define PTW32_SCHED_LEVEL 1 +/* Include 1b, 1c and 1d */ +#endif + +#if defined(INCLUDE_NP) +#undef PTW32_SCHED_LEVEL +#define PTW32_SCHED_LEVEL 2 +/* Include Non-Portable extensions */ +#endif + +#define PTW32_SCHED_LEVEL_MAX 3 + +#if ( defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112 ) || !defined(PTW32_SCHED_LEVEL) +#define PTW32_SCHED_LEVEL PTW32_SCHED_LEVEL_MAX +/* Include everything */ +#endif + + +#if defined(__GNUC__) && !defined(__declspec) +# error Please upgrade your GNU compiler to one that supports __declspec. +#endif + +/* + * When building the library, you should define PTW32_BUILD so that + * the variables/functions are exported correctly. When using the library, + * do NOT define PTW32_BUILD, and then the variables/functions will + * be imported correctly. + */ +#if !defined(PTW32_STATIC_LIB) +# if defined(PTW32_BUILD) +# define PTW32_DLLPORT __declspec (dllexport) +# else +# define PTW32_DLLPORT __declspec (dllimport) +# endif +#else +# define PTW32_DLLPORT +#endif + +/* + * This is a duplicate of what is in the autoconf config.h, + * which is only used when building the pthread-win32 libraries. + */ + +#if !defined(PTW32_CONFIG_H) +# if defined(WINCE) +# define NEED_ERRNO +# define NEED_SEM +# endif +# if defined(__MINGW64__) +# define HAVE_STRUCT_TIMESPEC +# define HAVE_MODE_T +# elif defined(_UWIN) || defined(__MINGW32__) +# define HAVE_MODE_T +# endif +#endif + +/* + * + */ + +#if PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX +#if defined(NEED_ERRNO) +#include "need_errno.h" +#else +#include +#endif +#endif /* PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX */ + +#if (defined(__MINGW64__) || defined(__MINGW32__)) || defined(_UWIN) +# if PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX +/* For pid_t */ +# include +/* Required by Unix 98 */ +# include +# else + typedef int pid_t; +# endif +#else + typedef int pid_t; +#endif + +/* Thread scheduling policies */ + +enum { + SCHED_OTHER = 0, + SCHED_FIFO, + SCHED_RR, + SCHED_MIN = SCHED_OTHER, + SCHED_MAX = SCHED_RR +}; + +struct sched_param { + int sched_priority; +}; + +#if defined(__cplusplus) +extern "C" +{ +#endif /* __cplusplus */ + +PTW32_DLLPORT int __cdecl sched_yield (void); + +PTW32_DLLPORT int __cdecl sched_get_priority_min (int policy); + +PTW32_DLLPORT int __cdecl sched_get_priority_max (int policy); + +PTW32_DLLPORT int __cdecl sched_setscheduler (pid_t pid, int policy); + +PTW32_DLLPORT int __cdecl sched_getscheduler (pid_t pid); + +/* + * Note that this macro returns ENOTSUP rather than + * ENOSYS as might be expected. However, returning ENOSYS + * should mean that sched_get_priority_{min,max} are + * not implemented as well as sched_rr_get_interval. + * This is not the case, since we just don't support + * round-robin scheduling. Therefore I have chosen to + * return the same value as sched_setscheduler when + * SCHED_RR is passed to it. + */ +#define sched_rr_get_interval(_pid, _interval) \ + ( errno = ENOTSUP, (int) -1 ) + + +#if defined(__cplusplus) +} /* End of extern "C" */ +#endif /* __cplusplus */ + +#undef PTW32_SCHED_LEVEL +#undef PTW32_SCHED_LEVEL_MAX + +#endif /* !_SCHED_H */ + diff --git a/win/semaphore.h b/win/semaphore.h new file mode 100644 index 000000000..c6e9407e2 --- /dev/null +++ b/win/semaphore.h @@ -0,0 +1,169 @@ +/* + * Module: semaphore.h + * + * Purpose: + * Semaphores aren't actually part of the PThreads standard. + * They are defined by the POSIX Standard: + * + * POSIX 1003.1b-1993 (POSIX.1b) + * + * -------------------------------------------------------------------------- + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999,2005 Pthreads-win32 contributors + * + * Contact Email: rpj@callisto.canberra.edu.au + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ +#if !defined( SEMAPHORE_H ) +#define SEMAPHORE_H + +#undef PTW32_SEMAPHORE_LEVEL + +#if defined(_POSIX_SOURCE) +#define PTW32_SEMAPHORE_LEVEL 0 +/* Early POSIX */ +#endif + +#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309 +#undef PTW32_SEMAPHORE_LEVEL +#define PTW32_SEMAPHORE_LEVEL 1 +/* Include 1b, 1c and 1d */ +#endif + +#if defined(INCLUDE_NP) +#undef PTW32_SEMAPHORE_LEVEL +#define PTW32_SEMAPHORE_LEVEL 2 +/* Include Non-Portable extensions */ +#endif + +#define PTW32_SEMAPHORE_LEVEL_MAX 3 + +#if !defined(PTW32_SEMAPHORE_LEVEL) +#define PTW32_SEMAPHORE_LEVEL PTW32_SEMAPHORE_LEVEL_MAX +/* Include everything */ +#endif + +#if defined(__GNUC__) && ! defined (__declspec) +# error Please upgrade your GNU compiler to one that supports __declspec. +#endif + +/* + * When building the library, you should define PTW32_BUILD so that + * the variables/functions are exported correctly. When using the library, + * do NOT define PTW32_BUILD, and then the variables/functions will + * be imported correctly. + */ +#if !defined(PTW32_STATIC_LIB) +# if defined(PTW32_BUILD) +# define PTW32_DLLPORT __declspec (dllexport) +# else +# define PTW32_DLLPORT __declspec (dllimport) +# endif +#else +# define PTW32_DLLPORT +#endif + +/* + * This is a duplicate of what is in the autoconf config.h, + * which is only used when building the pthread-win32 libraries. + */ + +#if !defined(PTW32_CONFIG_H) +# if defined(WINCE) +# define NEED_ERRNO +# define NEED_SEM +# endif +# if defined(__MINGW64__) +# define HAVE_STRUCT_TIMESPEC +# define HAVE_MODE_T +# elif defined(_UWIN) || defined(__MINGW32__) +# define HAVE_MODE_T +# endif +#endif + +/* + * + */ + +#if PTW32_SEMAPHORE_LEVEL >= PTW32_SEMAPHORE_LEVEL_MAX +#if defined(NEED_ERRNO) +#include "need_errno.h" +#else +#include +#endif +#endif /* PTW32_SEMAPHORE_LEVEL >= PTW32_SEMAPHORE_LEVEL_MAX */ + +#define _POSIX_SEMAPHORES + +#if defined(__cplusplus) +extern "C" +{ +#endif /* __cplusplus */ + +#if !defined(HAVE_MODE_T) +typedef unsigned int mode_t; +#endif + + +typedef struct sem_t_ * sem_t; + +PTW32_DLLPORT int __cdecl sem_init (sem_t * sem, + int pshared, + unsigned int value); + +PTW32_DLLPORT int __cdecl sem_destroy (sem_t * sem); + +PTW32_DLLPORT int __cdecl sem_trywait (sem_t * sem); + +PTW32_DLLPORT int __cdecl sem_wait (sem_t * sem); + +PTW32_DLLPORT int __cdecl sem_timedwait (sem_t * sem, + const struct timespec * abstime); + +PTW32_DLLPORT int __cdecl sem_post (sem_t * sem); + +PTW32_DLLPORT int __cdecl sem_post_multiple (sem_t * sem, + int count); + +PTW32_DLLPORT int __cdecl sem_open (const char * name, + int oflag, + mode_t mode, + unsigned int value); + +PTW32_DLLPORT int __cdecl sem_close (sem_t * sem); + +PTW32_DLLPORT int __cdecl sem_unlink (const char * name); + +PTW32_DLLPORT int __cdecl sem_getvalue (sem_t * sem, + int * sval); + +#if defined(__cplusplus) +} /* End of extern "C" */ +#endif /* __cplusplus */ + +#undef PTW32_SEMAPHORE_LEVEL +#undef PTW32_SEMAPHORE_LEVEL_MAX + +#endif /* !SEMAPHORE_H */