diff --git a/build.log b/build.log deleted file mode 100644 index 56261d9..0000000 --- a/build.log +++ /dev/null @@ -1,33 +0,0 @@ -Using built-in specs. -COLLECT_GCC=gcc -COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper -OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa -OFFLOAD_TARGET_DEFAULT=1 -Target: x86_64-linux-gnu -Configured with: ../src/configure -v --with-pkgversion='Ubuntu 13.3.0-6ubuntu2~24.04' --with-bugurl=file:///usr/share/doc/gcc-13/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-13 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-13-fG75Ri/gcc-13-13.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-13-fG75Ri/gcc-13-13.3.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2 -Thread model: posix -Supported LTO compression algorithms: zlib zstd -gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04) -COLLECT_GCC_OPTIONS='-I' '../src' '-I' '../lib' '-I' '../tinycrypt/lib/include' '-I' '../tinycrypt/lib/source' '-g' '-O2' '-v' '-o' 'test_ll_queue_fixed' '-mtune=generic' '-march=x86-64' '-dumpdir' 'test_ll_queue_fixed-' - /usr/libexec/gcc/x86_64-linux-gnu/13/cc1 -quiet -v -I ../src -I ../lib -I ../tinycrypt/lib/include -I ../tinycrypt/lib/source -imultiarch x86_64-linux-gnu test_ll_queue_fixed.c -D_FORTIFY_SOURCE=3 -quiet -dumpdir test_ll_queue_fixed- -dumpbase test_ll_queue_fixed.c -dumpbase-ext .c -mtune=generic -march=x86-64 -g -O2 -version -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -o /tmp/ccZX9kaj.s -GNU C17 (Ubuntu 13.3.0-6ubuntu2~24.04) version 13.3.0 (x86_64-linux-gnu) - compiled by GNU C version 13.3.0, GMP version 6.3.0, MPFR version 4.2.1, MPC version 1.3.1, isl version isl-0.26-GMP - -GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 -ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" -ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/13/include-fixed/x86_64-linux-gnu" -ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/13/include-fixed" -ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include" -ignoring nonexistent directory "../src" -ignoring nonexistent directory "../lib" -ignoring nonexistent directory "../tinycrypt/lib/include" -ignoring nonexistent directory "../tinycrypt/lib/source" -#include "..." search starts here: -#include <...> search starts here: - /usr/lib/gcc/x86_64-linux-gnu/13/include - /usr/local/include - /usr/include/x86_64-linux-gnu - /usr/include -End of search list. -cc1: fatal error: test_ll_queue_fixed.c: Нет такого файла или каталога -compilation terminated. diff --git a/lib/Makefile.am b/lib/Makefile.am index 2f8bdce..d86c217 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -14,7 +14,8 @@ libuasync_a_SOURCES = \ sha256.c \ sha256.h \ socket_compat.c \ - socket_compat.h + socket_compat.h \ + platform_compat.h libuasync_a_CFLAGS = \ -D_ISOC99_SOURCE \ diff --git a/lib/debug_config.c b/lib/debug_config.c index 12faf10..2f058be 100644 --- a/lib/debug_config.c +++ b/lib/debug_config.c @@ -3,6 +3,7 @@ */ #include "debug_config.h" +#include "platform_compat.h" #include #include #include @@ -10,13 +11,6 @@ #include #include #include -#include -#include - -#include -#include -#include -#include void log_dump(const char* prefix, const uint8_t* data, size_t len) { // Build packet data as hex string for single-line output diff --git a/lib/platform_compat.h b/lib/platform_compat.h new file mode 100644 index 0000000..5a50d55 --- /dev/null +++ b/lib/platform_compat.h @@ -0,0 +1,156 @@ +/** + * Platform compatibility layer for POSIX functions on Windows + */ + +#ifndef PLATFORM_COMPAT_H +#define PLATFORM_COMPAT_H + +#ifdef _WIN32 + #include + #include + #include + #include + #include + + // POSIX functions missing on Windows + #define strcasecmp _stricmp + #define strncasecmp _strnicmp + + // poll() implementation for Windows + #ifndef POLLIN + #define POLLIN 0x0001 + #endif + #ifndef POLLOUT + #define POLLOUT 0x0004 + #endif + #ifndef POLLERR + #define POLLERR 0x0008 + #endif + #ifndef POLLHUP + #define POLLHUP 0x0010 + #endif + #ifndef POLLNVAL + #define POLLNVAL 0x0020 + #endif + #ifndef POLLPRI + #define POLLPRI 0x0002 + #endif + + struct pollfd { + int fd; + short events; + short revents; + }; + + // gettimeofday for Windows + struct timezone { + int tz_minuteswest; + int tz_dsttime; + }; + + static inline int gettimeofday(struct timeval *tv, struct timezone *tz) { + (void)tz; + if (tv) { + FILETIME ft; + ULARGE_INTEGER ull; + GetSystemTimeAsFileTime(&ft); + ull.LowPart = ft.dwLowDateTime; + ull.HighPart = ft.dwHighDateTime; + // Convert from 100-nanosecond intervals since 1601 to Unix epoch + tv->tv_sec = (long)(ull.QuadPart / 10000000ULL - 11644473600ULL); + tv->tv_usec = (long)((ull.QuadPart % 10000000ULL) / 10); + } + return 0; + } + + // Pipe creation for Windows + static inline int pipe(int pipefd[2]) { + return _pipe(pipefd, 4096, _O_BINARY); + } + + // poll() using select() for Windows + static inline int poll(struct pollfd *fds, nfds_t nfds, int timeout) { + fd_set readfds, writefds, exceptfds; + FD_ZERO(&readfds); + FD_ZERO(&writefds); + FD_ZERO(&exceptfds); + + int max_fd = -1; + for (nfds_t i = 0; i < nfds; i++) { + if (fds[i].fd < 0) continue; + if (fds[i].events & POLLIN) FD_SET(fds[i].fd, &readfds); + if (fds[i].events & POLLOUT) FD_SET(fds[i].fd, &writefds); + FD_SET(fds[i].fd, &exceptfds); + if (fds[i].fd > max_fd) max_fd = fds[i].fd; + } + + struct timeval tv, *ptv = NULL; + if (timeout >= 0) { + tv.tv_sec = timeout / 1000; + tv.tv_usec = (timeout % 1000) * 1000; + ptv = &tv; + } + + int ret = select(max_fd + 1, &readfds, &writefds, &exceptfds, ptv); + if (ret < 0) return ret; + + // Set revents + for (nfds_t i = 0; i < nfds; i++) { + fds[i].revents = 0; + if (fds[i].fd < 0) continue; + if (FD_ISSET(fds[i].fd, &readfds)) fds[i].revents |= POLLIN; + if (FD_ISSET(fds[i].fd, &writefds)) fds[i].revents |= POLLOUT; + if (FD_ISSET(fds[i].fd, &exceptfds)) fds[i].revents |= POLLERR; + } + + return ret; + } + + // fcntl replacement for Windows (simplified - only supports F_GETFL/F_SETFL with O_NONBLOCK) + #define F_GETFL 3 + #define F_SETFL 4 + #define O_NONBLOCK 0x4000 + + static inline int fcntl(int fd, int cmd, ... /* arg */ ) { + va_list ap; + va_start(ap, cmd); + + if (cmd == F_GETFL) { + va_end(ap); + // Return current flags (always 0 on Windows, can't query easily) + return 0; + } else if (cmd == F_SETFL) { + int flags = va_arg(ap, int); + va_end(ap); + if (flags & O_NONBLOCK) { + // Set non-blocking mode + u_long mode = 1; + return ioctlsocket(fd, FIONBIO, &mode); + } + return 0; + } + + va_end(ap); + errno = EINVAL; + return -1; + } + + // nanosleep replacement + static inline int nanosleep(const struct timespec *req, struct timespec *rem) { + (void)rem; + Sleep((DWORD)(req->tv_sec * 1000 + req->tv_nsec / 1000000)); + return 0; + } + +#else + // POSIX - include standard headers + #include + #include + #include + #include + #include + #include + #include +#endif + +#endif // PLATFORM_COMPAT_H diff --git a/lib/u_async.c b/lib/u_async.c index 105f62c..9eefd7c 100644 --- a/lib/u_async.c +++ b/lib/u_async.c @@ -1,18 +1,13 @@ // uasync.c #include "u_async.h" +#include "platform_compat.h" #include "debug_config.h" #include #include #include #include #include -#include - -#ifndef _WIN32 -#include -#include -#endif // Platform-specific includes #ifdef __linux__ diff --git a/lib/u_async.h b/lib/u_async.h index 619c2e7..9025558 100644 --- a/lib/u_async.h +++ b/lib/u_async.h @@ -5,7 +5,7 @@ #ifndef UASYNC_H #define UASYNC_H -#include +#include "platform_compat.h" #include #include "timeout_heap.h" #include "socket_compat.h"