diff options
50 files changed, 578 insertions, 503 deletions
@@ -42,7 +42,8 @@ Nick Logan <ugexe@cpan.org> <nlogan@gmail.com> Olivier Valentin <ovalenti@redhat.com> <valentio@free.fr> Rasmus Christian Pedersen <zerhacken@yahoo.com> Rasmus Christian Pedersen <zerhacken@yahoo.com> <ruysch@outlook.com> -Richard Lau <rlau@redhat.com> <riclau@uk.ibm.com> +Richard Lau <richard.lau@ibm.com> <riclau@uk.ibm.com> +Richard Lau <richard.lau@ibm.com> <rlau@redhat.com> Robert Mustacchi <rm@joyent.com> <rm@fingolfin.org> Ryan Dahl <ryan@joyent.com> <ry@tinyclouds.org> Ryan Emery <seebees@gmail.com> @@ -210,7 +210,7 @@ guworks <ground.up.works@gmail.com> RossBencina <rossb@audiomulch.com> Roger A. Light <roger@atchoo.org> chenttuuvv <chenttuuvv@yahoo.com> -Richard Lau <rlau@redhat.com> +Richard Lau <richard.lau@ibm.com> ronkorving <rkorving@wizcorp.jp> Corbin Simpson <MostAwesomeDude@gmail.com> Zachary Hamm <zsh@imipolexg.org> diff --git a/CMakeLists.txt b/CMakeLists.txt index 73d5aff8..e725bff7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -747,6 +747,14 @@ if(LIBUV_BUILD_TESTS) "$<TARGET_FILE:uv_run_tests_a>" "$<TARGET_FILE_DIR:uv_run_tests_a>/uv_run_tests_a_no_ext") endif() + + if(QNX) + install(TARGETS uv_run_tests uv_run_tests_a uv_run_benchmarks_a + DESTINATION ${CMAKE_INSTALL_BINDIR}/libuv_tests) + + install(DIRECTORY test/fixtures + DESTINATION ${CMAKE_INSTALL_BINDIR}/libuv_tests) + endif() endif() # Now for some gibbering horrors from beyond the stars... diff --git a/Makefile.am b/Makefile.am index f3808b69..8a41f18a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -61,7 +61,6 @@ AM_CPPFLAGS += -I$(top_srcdir)/src/win \ -DWIN32_LEAN_AND_MEAN \ -D_WIN32_WINNT=0x0A00 libuv_la_SOURCES += src/win/async.c \ - src/win/atomicops-inl.h \ src/win/core.c \ src/win/detect-wakeup.c \ src/win/dl.c \ @@ -438,7 +437,7 @@ libuv_la_SOURCES += src/unix/bsd-ifaddrs.c \ src/unix/kqueue.c \ src/unix/proctitle.c \ src/unix/random-getentropy.c -test_run_tests_LDFLAGS += -lutil +test_run_tests_LDFLAGS += -lutil -lm endif if DRAGONFLY @@ -448,7 +447,7 @@ libuv_la_SOURCES += src/unix/bsd-ifaddrs.c \ src/unix/freebsd.c \ src/unix/kqueue.c \ src/unix/posix-hrtime.c -test_run_tests_LDFLAGS += -lutil +test_run_tests_LDFLAGS += -lutil -lm endif if FREEBSD @@ -459,7 +458,7 @@ libuv_la_SOURCES += src/unix/bsd-ifaddrs.c \ src/unix/kqueue.c \ src/unix/posix-hrtime.c \ src/unix/random-getrandom.c -test_run_tests_LDFLAGS += -lutil +test_run_tests_LDFLAGS += -lutil -lm endif if HAIKU @@ -491,7 +490,7 @@ libuv_la_SOURCES += src/unix/linux.c \ src/unix/proctitle.c \ src/unix/random-getrandom.c \ src/unix/random-sysctl-linux.c -test_run_tests_LDFLAGS += -lutil +test_run_tests_LDFLAGS += -lutil -lm endif if MSYS @@ -514,7 +513,7 @@ libuv_la_SOURCES += src/unix/bsd-ifaddrs.c \ src/unix/kqueue.c \ src/unix/netbsd.c \ src/unix/posix-hrtime.c -test_run_tests_LDFLAGS += -lutil +test_run_tests_LDFLAGS += -lutil -lm endif if OPENBSD @@ -525,7 +524,7 @@ libuv_la_SOURCES += src/unix/bsd-ifaddrs.c \ src/unix/openbsd.c \ src/unix/posix-hrtime.c \ src/unix/random-getentropy.c -test_run_tests_LDFLAGS += -lutil +test_run_tests_LDFLAGS += -lutil -lm endif if SUNOS diff --git a/docs/requirements.txt b/docs/requirements.txt index 2e310ebe..0319b308 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,36 +1,29 @@ # primary -furo==2023.5.20 -Sphinx==6.1.3 +furo==2024.8.6 +Sphinx==7.0.1 # dependencies -alabaster==0.7.13 -Babel==2.11.0 -beautifulsoup4==4.12.2 -certifi==2022.12.7 -charset-normalizer==3.0.1 -colorama==0.4.6 -docutils==0.19 -idna==3.4 +alabaster==0.7.16 +babel==2.17.0 +beautifulsoup4==4.13.3 +certifi==2025.1.31 +charset-normalizer==3.4.1 +docutils==0.20.1 +idna==3.10 imagesize==1.4.1 -importlib-metadata==6.0.0 -Jinja2==3.1.2 -livereload==2.6.3 -MarkupSafe==2.1.2 -packaging==23.0 -Pygments==2.14.0 -pytz==2022.7.1 -requests==2.28.2 -six==1.16.0 +Jinja2==3.1.6 +MarkupSafe==3.0.2 +packaging==24.2 +Pygments==2.19.1 +requests==2.32.3 snowballstemmer==2.2.0 -soupsieve==2.4.1 -sphinx-autobuild==2021.3.14 +soupsieve==2.6 sphinx-basic-ng==1.0.0b2 -sphinxcontrib-devhelp==1.0.2 -sphinxcontrib-htmlhelp==2.0.0 +sphinxcontrib-applehelp==2.0.0 +sphinxcontrib-devhelp==2.0.0 +sphinxcontrib-htmlhelp==2.1.0 sphinxcontrib-jsmath==1.0.1 -sphinxcontrib-qthelp==1.0.3 -sphinxcontrib-serializinghtml==1.1.5 -sphinxcontrib.applehelp==1.0.3 -tornado==6.3.2 -urllib3==1.26.14 -zipp==3.11.0 +sphinxcontrib-qthelp==2.0.0 +sphinxcontrib-serializinghtml==2.0.0 +typing_extensions==4.13.0 +urllib3==2.3.0 diff --git a/include/uv.h b/include/uv.h index b301aac0..f788c040 100644 --- a/include/uv.h +++ b/include/uv.h @@ -1969,7 +1969,6 @@ UV_EXTERN void uv_wtf8_to_utf16(const char* wtf8, size_t utf16_len); /* Don't export the private CPP symbols. */ -#undef UV_HANDLE_TYPE_PRIVATE #undef UV_REQ_TYPE_PRIVATE #undef UV_REQ_PRIVATE_FIELDS #undef UV_STREAM_PRIVATE_FIELDS @@ -1981,12 +1980,10 @@ UV_EXTERN void uv_wtf8_to_utf16(const char* wtf8, #undef UV_TIMER_PRIVATE_FIELDS #undef UV_GETADDRINFO_PRIVATE_FIELDS #undef UV_GETNAMEINFO_PRIVATE_FIELDS -#undef UV_FS_REQ_PRIVATE_FIELDS #undef UV_WORK_PRIVATE_FIELDS #undef UV_FS_EVENT_PRIVATE_FIELDS #undef UV_SIGNAL_PRIVATE_FIELDS #undef UV_LOOP_PRIVATE_FIELDS -#undef UV_LOOP_PRIVATE_PLATFORM_FIELDS #undef UV__ERR #ifdef __cplusplus diff --git a/src/random.c b/src/random.c index 57fc0d91..402678cb 100644 --- a/src/random.c +++ b/src/random.c @@ -61,7 +61,7 @@ static int uv__random(void* buf, size_t buflen) { # endif #elif defined(_WIN32) uv__once_init(); - rc = uv__random_rtlgenrandom(buf, buflen); + rc = uv__random_winrandom(buf, buflen); #else rc = uv__random_devurandom(buf, buflen); #endif diff --git a/src/unix/aix.c b/src/unix/aix.c index 48da0c9c..8343bc5c 100644 --- a/src/unix/aix.c +++ b/src/unix/aix.c @@ -1288,12 +1288,6 @@ cleanup: } -void uv_free_interface_addresses(uv_interface_address_t* addresses, - int count) { - uv__free(addresses); -} - - void uv__platform_invalidate_fd(uv_loop_t* loop, int fd) { struct pollfd* events; uintptr_t i; diff --git a/src/unix/bsd-ifaddrs.c b/src/unix/bsd-ifaddrs.c index 8d9ebd25..6829e2a8 100644 --- a/src/unix/bsd-ifaddrs.c +++ b/src/unix/bsd-ifaddrs.c @@ -155,10 +155,3 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { return 0; } - - -/* TODO(bnoordhuis) share with linux.c */ -void uv_free_interface_addresses(uv_interface_address_t* addresses, - int count) { - uv__free(addresses); -} diff --git a/src/unix/core.c b/src/unix/core.c index 1dde27bd..6e741628 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -275,7 +275,7 @@ void uv__make_close_pending(uv_handle_t* handle) { int uv__getiovmax(void) { #if defined(IOV_MAX) return IOV_MAX; -#elif defined(_SC_IOV_MAX) +#elif defined(_SC_IOV_MAX) && !defined(__QNX__) static _Atomic int iovmax_cached = -1; int iovmax; @@ -1611,6 +1611,10 @@ int uv_cpumask_size(void) { } int uv_os_getpriority(uv_pid_t pid, int* priority) { +#if defined(__QNX__) + /* QNX priority is not process-based */ + return UV_ENOSYS; +#else int r; if (priority == NULL) @@ -1624,10 +1628,15 @@ int uv_os_getpriority(uv_pid_t pid, int* priority) { *priority = r; return 0; +#endif } int uv_os_setpriority(uv_pid_t pid, int priority) { +#if defined(__QNX__) + /* QNX priority is not process-based */ + return UV_ENOSYS; +#else if (priority < UV_PRIORITY_HIGHEST || priority > UV_PRIORITY_LOW) return UV_EINVAL; @@ -1635,6 +1644,7 @@ int uv_os_setpriority(uv_pid_t pid, int priority) { return UV__ERR(errno); return 0; +#endif } /** diff --git a/src/unix/fs.c b/src/unix/fs.c index 717f3fab..bd3f5962 100644 --- a/src/unix/fs.c +++ b/src/unix/fs.c @@ -211,7 +211,8 @@ static ssize_t uv__fs_fdatasync(uv_fs_t* req) { || defined(__NetBSD__) \ || defined(__OpenBSD__) \ || defined(__linux__) \ - || defined(__sun) + || defined(__sun) \ + || defined(__QNX__) static struct timespec uv__fs_to_timespec(double time) { struct timespec ts; @@ -248,7 +249,8 @@ static ssize_t uv__fs_futime(uv_fs_t* req) { || defined(__NetBSD__) \ || defined(__OpenBSD__) \ || defined(__linux__) \ - || defined(__sun) + || defined(__sun) \ + || defined(__QNX__) struct timespec ts[2]; ts[0] = uv__fs_to_timespec(req->atime); ts[1] = uv__fs_to_timespec(req->mtime); @@ -1147,7 +1149,8 @@ static ssize_t uv__fs_utime(uv_fs_t* req) { || defined(__NetBSD__) \ || defined(__OpenBSD__) \ || defined(__linux__) \ - || defined(__sun) + || defined(__sun) \ + || defined(__QNX__) struct timespec ts[2]; ts[0] = uv__fs_to_timespec(req->atime); ts[1] = uv__fs_to_timespec(req->mtime); @@ -1181,7 +1184,8 @@ static ssize_t uv__fs_lutime(uv_fs_t* req) { || defined(__NetBSD__) \ || defined(__OpenBSD__) \ || defined(__linux__) \ - || defined(__sun) + || defined(__sun) \ + || defined(__QNX__) struct timespec ts[2]; ts[0] = uv__fs_to_timespec(req->atime); ts[1] = uv__fs_to_timespec(req->mtime); diff --git a/src/unix/ibmi.c b/src/unix/ibmi.c index 9d94d2af..fe270f8c 100644 --- a/src/unix/ibmi.c +++ b/src/unix/ibmi.c @@ -505,11 +505,6 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { } -void uv_free_interface_addresses(uv_interface_address_t* addresses, - int count) { - uv__free(addresses); -} - char** uv_setup_args(int argc, char** argv) { char exepath[UV__PATH_MAX]; char* s; diff --git a/src/unix/internal.h b/src/unix/internal.h index 89b73e2b..d8c792f6 100644 --- a/src/unix/internal.h +++ b/src/unix/internal.h @@ -141,6 +141,11 @@ union uv__sockaddr { /* Leans on the fact that, on Linux, POLLRDHUP == EPOLLRDHUP. */ #ifdef POLLRDHUP # define UV__POLLRDHUP POLLRDHUP +#elif defined(__QNX__) +/* On QNX, POLLRDHUP is not available and the 0x2000 workaround + * leads to undefined bahavior. + */ +# define UV__POLLRDHUP 0 #else # define UV__POLLRDHUP 0x2000 #endif diff --git a/src/unix/linux.c b/src/unix/linux.c index ea3e2de0..1a62d78d 100644 --- a/src/unix/linux.c +++ b/src/unix/linux.c @@ -2045,13 +2045,6 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { } -/* TODO(bnoordhuis) share with bsd-ifaddrs.c */ -void uv_free_interface_addresses(uv_interface_address_t* addresses, - int count) { - uv__free(addresses); -} - - void uv__set_process_title(const char* title) { #if defined(PR_SET_NAME) prctl(PR_SET_NAME, title); /* Only copies first 16 characters. */ @@ -2309,8 +2302,8 @@ static int uv__get_cgroupv2_constrained_cpu(const char* cgroup, static const char cgroup_mount[] = "/sys/fs/cgroup"; const char* cgroup_trimmed; char buf[1024]; - char full_path[256]; char path[256]; + char full_path[sizeof(path) + sizeof("/cpu.max")]; char quota_buf[16]; char* last_slash; int cgroup_size; diff --git a/src/unix/pipe.c b/src/unix/pipe.c index 68e225e2..f086a22f 100644 --- a/src/unix/pipe.c +++ b/src/unix/pipe.c @@ -171,8 +171,7 @@ int uv__pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) { handle->connection_cb = cb; handle->io_watcher.cb = uv__server_io; - uv__io_start(handle->loop, &handle->io_watcher, POLLIN); - return 0; + return uv__io_start(handle->loop, &handle->io_watcher, POLLIN); } diff --git a/src/unix/qnx.c b/src/unix/qnx.c index 57ea9dfd..d873165f 100644 --- a/src/unix/qnx.c +++ b/src/unix/qnx.c @@ -28,6 +28,14 @@ #include <sys/memmsg.h> #include <sys/syspage.h> #include <sys/procfs.h> +#include <time.h> +#include <stdlib.h> +#include <inttypes.h> +#if __QNX__ >= 800 +#define cpuinfo_val cpuinfo +#else +#define cpuinfo_val new_cpuinfo +#endif static void get_mem_info(uint64_t* totalmem, uint64_t* freemem) { @@ -67,18 +75,44 @@ int uv_exepath(char* buffer, size_t* size) { } +static uint64_t uv__read_pidin_info(const char* what) { + uint64_t rc; + char* p; + char buf[2048]; + + FILE* fp = popen("pidin info", "r"); + if (fp == NULL) + return 0; + + size_t sz = fread(buf, 1, sizeof(buf) - 1, fp); + buf[sz] = '\0'; + + pclose(fp); + + p = strstr(buf, what); + if (p == NULL) + return 0; + + p += strlen(what); + + rc = 0; + sscanf(p, "%" PRIu64 " MB", &rc); + + return rc * 1024 * 1024; +} + uint64_t uv_get_free_memory(void) { - uint64_t totalmem; uint64_t freemem; - get_mem_info(&totalmem, &freemem); + + freemem = uv__read_pidin_info("FreeMem:"); return freemem; } uint64_t uv_get_total_memory(void) { uint64_t totalmem; - uint64_t freemem; - get_mem_info(&totalmem, &freemem); + + totalmem = uv__read_pidin_info("MB/"); return totalmem; } @@ -113,15 +147,17 @@ int uv_resident_set_memory(size_t* rss) { int uv_uptime(double* uptime) { - struct qtime_entry* qtime = _SYSPAGE_ENTRY(_syspage_ptr, qtime); - *uptime = (qtime->nsec / 1000000000.0); + struct timespec ts; + if(clock_gettime(CLOCK_MONOTONIC, &ts)) + return UV__ERR(errno); + *uptime = (double)ts.tv_sec; return 0; } int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { struct cpuinfo_entry* cpuinfo = - (struct cpuinfo_entry*)_SYSPAGE_ENTRY(_syspage_ptr, new_cpuinfo); + (struct cpuinfo_entry*)_SYSPAGE_ENTRY(_syspage_ptr, cpuinfo_val); size_t cpuinfo_size = _SYSPAGE_ELEMENT_SIZE(_syspage_ptr, cpuinfo); struct strings_entry* strings = _SYSPAGE_ENTRY(_syspage_ptr, strings); int num_cpus = _syspage_ptr->num_cpu; diff --git a/src/unix/sunos.c b/src/unix/sunos.c index 6c38c31a..62584d72 100644 --- a/src/unix/sunos.c +++ b/src/unix/sunos.c @@ -898,11 +898,6 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { } #endif /* SUNOS_NO_IFADDRS */ -void uv_free_interface_addresses(uv_interface_address_t* addresses, - int count) { - uv__free(addresses); -} - #if !defined(_POSIX_VERSION) || _POSIX_VERSION < 200809L size_t strnlen(const char* s, size_t maxlen) { diff --git a/src/unix/tcp.c b/src/unix/tcp.c index b8800bdc..1f59083e 100644 --- a/src/unix/tcp.c +++ b/src/unix/tcp.c @@ -445,9 +445,8 @@ int uv__tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) { /* Start listening for connections. */ tcp->io_watcher.cb = uv__server_io; - uv__io_start(tcp->loop, &tcp->io_watcher, POLLIN); - return 0; + return uv__io_start(tcp->loop, &tcp->io_watcher, POLLIN); } diff --git a/src/unix/udp.c b/src/unix/udp.c index c4a3559d..9f58edfe 100644 --- a/src/unix/udp.c +++ b/src/unix/udp.c @@ -560,7 +560,7 @@ int uv__udp_disconnect(uv_udp_t* handle) { } while (r == -1 && errno == EINTR); if (r == -1) { -#if defined(BSD) /* The macro BSD is from sys/param.h */ +#if defined(BSD) || defined(__QNX__) /* The macro BSD is from sys/param.h */ if (errno != EAFNOSUPPORT && errno != EINVAL) return UV__ERR(errno); #else @@ -766,8 +766,8 @@ static int uv__udp_set_membership6(uv_udp_t* handle, !defined(__NetBSD__) && \ !defined(__ANDROID__) && \ !defined(__DragonFly__) && \ - !defined(__QNX__) && \ - !defined(__GNU__) + !defined(__GNU__) && \ + !defined(QNX_IOPKT) static int uv__udp_set_source_membership4(uv_udp_t* handle, const struct sockaddr_in* multicast_addr, const char* interface_addr, @@ -957,8 +957,8 @@ int uv_udp_set_source_membership(uv_udp_t* handle, !defined(__NetBSD__) && \ !defined(__ANDROID__) && \ !defined(__DragonFly__) && \ - !defined(__QNX__) && \ - !defined(__GNU__) + !defined(__GNU__) && \ + !defined(QNX_IOPKT) int err; union uv__sockaddr mcast_addr; union uv__sockaddr src_addr; @@ -1312,7 +1312,7 @@ static int uv__udp_sendmsgv(int fd, nsent = 0; #if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) || \ - (defined(__sun__) && defined(MSG_WAITFORONE)) + (defined(__sun__) && defined(MSG_WAITFORONE)) || defined(__QNX__) if (count > 1) { for (i = 0; i < count; /*empty*/) { struct mmsghdr m[20]; @@ -1340,7 +1340,7 @@ static int uv__udp_sendmsgv(int fd, goto exit; } #endif /* defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) || - * (defined(__sun__) && defined(MSG_WAITFORONE)) + * (defined(__sun__) && defined(MSG_WAITFORONE)) || defined(__QNX__) */ for (i = 0; i < count; i++, nsent++) diff --git a/src/uv-common.c b/src/uv-common.c index 60ff56b9..e5a76329 100644 --- a/src/uv-common.c +++ b/src/uv-common.c @@ -575,12 +575,17 @@ static void uv__print_handles(uv_loop_t* loop, int only_active, FILE* stream) { struct uv__queue* q; uv_handle_t* h; - if (loop == NULL) - loop = uv_default_loop(); - if (stream == NULL) stream = stderr; + if (loop == NULL) { + loop = uv_default_loop(); + if (loop == NULL) { + fprintf(stream, "uv_default_loop() failed\n"); + return; + } + } + uv__queue_foreach(q, &loop->handle_queue) { h = uv__queue_data(q, uv_handle_t, handle_queue); @@ -1049,3 +1054,11 @@ uint64_t uv_metrics_idle_time(uv_loop_t* loop) { idle_time += uv_hrtime() - entry_time; return idle_time; } + +/* OS390 needs a different implementation, already provided in os390.c. */ +#ifndef __MVS__ +void uv_free_interface_addresses(uv_interface_address_t* addresses, + int count) { + uv__free(addresses); +} +#endif /* !__MVS__ */ diff --git a/src/win/async.c b/src/win/async.c index b904676e..4c2cd265 100644 --- a/src/win/async.c +++ b/src/win/async.c @@ -23,10 +23,28 @@ #include "uv.h" #include "internal.h" -#include "atomicops-inl.h" #include "handle-inl.h" #include "req-inl.h" +#ifdef _MSC_VER /* MSVC */ + +/* _InterlockedOr8 is supported by MSVC on x32 and x64. It is slightly less + * efficient than InterlockedExchange, but InterlockedExchange8 does not exist, + * and interlocked operations on larger targets might require the target to be + * aligned. */ +#pragma intrinsic(_InterlockedOr8) + +static char uv__atomic_exchange_set(char volatile* target) { + return _InterlockedOr8(target, 1); +} + +#else /* GCC, Clang in mingw mode */ + +static char uv__atomic_exchange_set(char volatile* target) { + return __sync_fetch_and_or(target, 1); +} + +#endif /* _MSC_VER */ void uv__async_endgame(uv_loop_t* loop, uv_async_t* handle) { if (handle->flags & UV_HANDLE_CLOSING && diff --git a/src/win/atomicops-inl.h b/src/win/atomicops-inl.h deleted file mode 100644 index 2f984c6d..00000000 --- a/src/win/atomicops-inl.h +++ /dev/null @@ -1,61 +0,0 @@ -/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -#ifndef UV_WIN_ATOMICOPS_INL_H_ -#define UV_WIN_ATOMICOPS_INL_H_ - -#include "uv.h" -#include "internal.h" - - -/* Atomic set operation on char */ -#ifdef _MSC_VER /* MSVC */ - -/* _InterlockedOr8 is supported by MSVC on x32 and x64. It is slightly less - * efficient than InterlockedExchange, but InterlockedExchange8 does not exist, - * and interlocked operations on larger targets might require the target to be - * aligned. */ -#pragma intrinsic(_InterlockedOr8) - -static char INLINE uv__atomic_exchange_set(char volatile* target) { - return _InterlockedOr8(target, 1); -} - -#else /* GCC, Clang in mingw mode */ - -static inline char uv__atomic_exchange_set(char volatile* target) { -#if defined(__i386__) || defined(__x86_64__) - /* Mingw-32 version, hopefully this works for 64-bit gcc as well. */ - const char one = 1; - char old_value; - __asm__ __volatile__ ("lock xchgb %0, %1\n\t" - : "=r"(old_value), "=m"(*target) - : "0"(one), "m"(*target) - : "memory"); - return old_value; -#else - return __sync_fetch_and_or(target, 1); -#endif -} - -#endif - -#endif /* UV_WIN_ATOMICOPS_INL_H_ */ diff --git a/src/win/core.c b/src/win/core.c index 5f41c87a..317238fd 100644 --- a/src/win/core.c +++ b/src/win/core.c @@ -428,6 +428,7 @@ static void uv__poll(uv_loop_t* loop, DWORD timeout) { BOOL success; uv_req_t* req; OVERLAPPED_ENTRY overlappeds[128]; + OVERLAPPED* overlapped; ULONG count; ULONG i; int repeat; @@ -491,7 +492,8 @@ static void uv__poll(uv_loop_t* loop, DWORD timeout) { if (actual_timeout == 0) uv__metrics_inc_events_waiting(loop, 1); - req = uv__overlapped_to_req(overlappeds[i].lpOverlapped); + overlapped = overlappeds[i].lpOverlapped; + req = container_of(overlapped, uv_req_t, u.io.overlapped); uv__insert_pending_req(loop, req); } } @@ -525,6 +527,177 @@ static void uv__poll(uv_loop_t* loop, DWORD timeout) { } +#define DELEGATE_STREAM_REQ(loop, req, method, handle_at) \ + do { \ + switch (((uv_handle_t*) (req)->handle_at)->type) { \ + case UV_TCP: \ + uv__process_tcp_##method##_req(loop, \ + (uv_tcp_t*) ((req)->handle_at), \ + req); \ + break; \ + \ + case UV_NAMED_PIPE: \ + uv__process_pipe_##method##_req(loop, \ + (uv_pipe_t*) ((req)->handle_at), \ + req); \ + break; \ + \ + case UV_TTY: \ + uv__process_tty_##method##_req(loop, \ + (uv_tty_t*) ((req)->handle_at), \ + req); \ + break; \ + \ + default: \ + assert(0); \ + } \ + } while (0) + + +static void uv__process_reqs(uv_loop_t* loop) { + uv_req_t* req; + uv_req_t* first; + uv_req_t* next; + + if (loop->pending_reqs_tail == NULL) + return; + + first = loop->pending_reqs_tail->next_req; + next = first; + loop->pending_reqs_tail = NULL; + + while (next != NULL) { + req = next; + next = req->next_req != first ? req->next_req : NULL; + + switch (req->type) { + case UV_READ: + DELEGATE_STREAM_REQ(loop, req, read, data); + break; + + case UV_WRITE: + DELEGATE_STREAM_REQ(loop, (uv_write_t*) req, write, handle); + break; + + case UV_ACCEPT: + DELEGATE_STREAM_REQ(loop, req, accept, data); + break; + + case UV_CONNECT: + DELEGATE_STREAM_REQ(loop, (uv_connect_t*) req, connect, handle); + break; + + case UV_SHUTDOWN: + DELEGATE_STREAM_REQ(loop, (uv_shutdown_t*) req, shutdown, handle); + break; + + case UV_UDP_RECV: + uv__process_udp_recv_req(loop, (uv_udp_t*) req->data, req); + break; + + case UV_UDP_SEND: + uv__process_udp_send_req(loop, + ((uv_udp_send_t*) req)->handle, + (uv_udp_send_t*) req); + break; + + case UV_WAKEUP: + uv__process_async_wakeup_req(loop, (uv_async_t*) req->data, req); + break; + + case UV_SIGNAL_REQ: + uv__process_signal_req(loop, (uv_signal_t*) req->data, req); + break; + + case UV_POLL_REQ: + uv__process_poll_req(loop, (uv_poll_t*) req->data, req); + break; + + case UV_PROCESS_EXIT: + uv__process_proc_exit(loop, (uv_process_t*) req->data); + break; + + case UV_FS_EVENT_REQ: + uv__process_fs_event_req(loop, req, (uv_fs_event_t*) req->data); + break; + + default: + assert(0); + } + } +} + +#undef DELEGATE_STREAM_REQ + +static void uv__process_endgames(uv_loop_t* loop) { + uv_handle_t* handle; + + while (loop->endgame_handles) { + handle = loop->endgame_handles; + loop->endgame_handles = handle->endgame_next; + + handle->flags &= ~UV_HANDLE_ENDGAME_QUEUED; + + switch (handle->type) { + case UV_TCP: + uv__tcp_endgame(loop, (uv_tcp_t*) handle); + break; + + case UV_NAMED_PIPE: + uv__pipe_endgame(loop, (uv_pipe_t*) handle); + break; + + case UV_TTY: + uv__tty_endgame(loop, (uv_tty_t*) handle); + break; + + case UV_UDP: + uv__udp_endgame(loop, (uv_udp_t*) handle); + break; + + case UV_POLL: + uv__poll_endgame(loop, (uv_poll_t*) handle); + break; + + case UV_TIMER: + uv__timer_close((uv_timer_t*) handle); + uv__handle_close(handle); + break; + + case UV_PREPARE: + case UV_CHECK: + case UV_IDLE: + uv__loop_watcher_endgame(loop, handle); + break; + + case UV_ASYNC: + uv__async_endgame(loop, (uv_async_t*) handle); + break; + + case UV_SIGNAL: + uv__signal_endgame(loop, (uv_signal_t*) handle); + break; + + case UV_PROCESS: + uv__process_endgame(loop, (uv_process_t*) handle); + break; + + case UV_FS_EVENT: + uv__fs_event_endgame(loop, (uv_fs_event_t*) handle); + break; + + case UV_FS_POLL: + uv__fs_poll_endgame(loop, (uv_fs_poll_t*) handle); + break; + + default: + assert(0); + break; + } + } +} + + int uv_run(uv_loop_t *loop, uv_run_mode mode) { DWORD timeout; int r; @@ -681,3 +854,26 @@ int uv__getsockpeername(const uv_handle_t* handle, return 0; } + +void uv__insert_pending_req(uv_loop_t* loop, uv_req_t* req) { + req->next_req = NULL; + if (loop->pending_reqs_tail) { +#ifdef _DEBUG + /* Ensure the request is not already in the queue, or the queue + * will get corrupted. + */ + uv_req_t* current = loop->pending_reqs_tail; + do { + assert(req != current); + current = current->next_req; + } while (current != loop->pending_reqs_tail); +#endif + + req->next_req = loop->pending_reqs_tail->next_req; + loop->pending_reqs_tail->next_req = req; + loop->pending_reqs_tail = req; + } else { + req->next_req = req; + loop->pending_reqs_tail = req; + } +} diff --git a/src/win/fs-fd-hash-inl.h b/src/win/fs-fd-hash-inl.h index 0b532af1..fd875d28 100644 --- a/src/win/fs-fd-hash-inl.h +++ b/src/win/fs-fd-hash-inl.h @@ -73,7 +73,7 @@ static struct uv__fd_hash_entry_group_s static struct uv__fd_hash_bucket_s uv__fd_hash[UV__FD_HASH_SIZE]; -INLINE static void uv__fd_hash_init(void) { +static void uv__fd_hash_init(void) { size_t i; int err; @@ -119,7 +119,7 @@ INLINE static void uv__fd_hash_init(void) { FIND_IN_GROUP_PTR(UV__FD_HASH_GROUP_SIZE); \ } while (0) -INLINE static int uv__fd_hash_get(int fd, struct uv__fd_info_s* info) { +static int uv__fd_hash_get(int fd, struct uv__fd_info_s* info) { FIND_COMMON_VARIABLES uv_mutex_lock(&uv__fd_hash_mutex); @@ -134,7 +134,7 @@ INLINE static int uv__fd_hash_get(int fd, struct uv__fd_info_s* info) { return entry_ptr != NULL; } -INLINE static void uv__fd_hash_add(int fd, struct uv__fd_info_s* info) { +static void uv__fd_hash_add(int fd, struct uv__fd_info_s* info) { FIND_COMMON_VARIABLES uv_mutex_lock(&uv__fd_hash_mutex); @@ -164,7 +164,7 @@ INLINE static void uv__fd_hash_add(int fd, struct uv__fd_info_s* info) { uv_mutex_unlock(&uv__fd_hash_mutex); } -INLINE static int uv__fd_hash_remove(int fd, struct uv__fd_info_s* info) { +static int uv__fd_hash_remove(int fd, struct uv__fd_info_s* info) { FIND_COMMON_VARIABLES uv_mutex_lock(&uv__fd_hash_mutex); diff --git a/src/win/fs.c b/src/win/fs.c index 27248f64..acaa5689 100644 --- a/src/win/fs.c +++ b/src/win/fs.c @@ -167,9 +167,10 @@ typedef enum { FS__STAT_PATH_TRY_SLOW } fs__stat_path_return_t; -INLINE static void fs__stat_assign_statbuf_null(uv_stat_t* statbuf); -INLINE static void fs__stat_assign_statbuf(uv_stat_t* statbuf, - FILE_STAT_BASIC_INFORMATION stat_info, int do_lstat); +static void fs__stat_assign_statbuf_null(uv_stat_t* statbuf); +static void fs__stat_assign_statbuf(uv_stat_t* statbuf, + FILE_STAT_BASIC_INFORMATION stat_info, + int do_lstat); void uv__fs_init(void) { @@ -182,9 +183,9 @@ void uv__fs_init(void) { } -INLINE static int fs__readlink_handle(HANDLE handle, - char** target_ptr, - size_t* target_len_ptr) { +static int fs__readlink_handle(HANDLE handle, + char** target_ptr, + size_t* target_len_ptr) { char buffer[MAXIMUM_REPARSE_DATA_BUFFER_SIZE]; REPARSE_DATA_BUFFER* reparse_data = (REPARSE_DATA_BUFFER*) buffer; WCHAR* w_target; @@ -319,8 +320,10 @@ INLINE static int fs__readlink_handle(HANDLE handle, } -INLINE static int fs__capture_path(uv_fs_t* req, const char* path, - const char* new_path, const int copy_path) { +static int fs__capture_path(uv_fs_t* req, + const char* path, + const char* new_path, + const int copy_path) { WCHAR* buf; WCHAR* pos; size_t buf_sz = 0; @@ -394,8 +397,10 @@ INLINE static int fs__capture_path(uv_fs_t* req, const char* path, } -INLINE static void uv__fs_req_init(uv_loop_t* loop, uv_fs_t* req, - uv_fs_type fs_type, const uv_fs_cb cb) { +static void uv__fs_req_init(uv_loop_t* loop, + uv_fs_t* req, + uv_fs_type fs_type, + const uv_fs_cb cb) { uv__once_init(); UV_REQ_INIT(req, UV_FS); req->loop = loop; @@ -1264,7 +1269,7 @@ void fs__mktemp(uv_fs_t* req, uv__fs_mktemp_func func) { tries = TMP_MAX; do { - if (uv__random_rtlgenrandom((void *)&v, sizeof(v)) < 0) { + if (uv__random_winrandom(&v, sizeof(v)) < 0) { SET_REQ_UV_ERROR(req, UV_EIO, ERROR_IO_DEVICE); goto clobber; } @@ -1698,8 +1703,9 @@ void fs__closedir(uv_fs_t* req) { SET_REQ_RESULT(req, 0); } -INLINE static fs__stat_path_return_t fs__stat_path(WCHAR* path, - uv_stat_t* statbuf, int do_lstat) { +static fs__stat_path_return_t fs__stat_path(WCHAR* path, + uv_stat_t* statbuf, + int do_lstat) { FILE_STAT_BASIC_INFORMATION stat_info; /* Check if the new fast API is available. */ @@ -1735,8 +1741,7 @@ INLINE static fs__stat_path_return_t fs__stat_path(WCHAR* path, return FS__STAT_PATH_SUCCESS; } -INLINE static int fs__stat_handle(HANDLE handle, uv_stat_t* statbuf, - int do_lstat) { +static int fs__stat_handle(HANDLE handle, uv_stat_t* statbuf, int do_lstat) { size_t target_length = 0; FILE_FS_DEVICE_INFORMATION device_info; FILE_ALL_INFORMATION file_info; @@ -1827,7 +1832,7 @@ INLINE static int fs__stat_handle(HANDLE handle, uv_stat_t* statbuf, return 0; } -INLINE static void fs__stat_assign_statbuf_null(uv_stat_t* statbuf) { +static void fs__stat_assign_statbuf_null(uv_stat_t* statbuf) { memset(statbuf, 0, sizeof(uv_stat_t)); statbuf->st_mode = _S_IFCHR; statbuf->st_mode |= (_S_IREAD | _S_IWRITE) | ((_S_IREAD | _S_IWRITE) >> 3) | @@ -1837,8 +1842,9 @@ INLINE static void fs__stat_assign_statbuf_null(uv_stat_t* statbuf) { statbuf->st_rdev = FILE_DEVICE_NULL << 16; } -INLINE static void fs__stat_assign_statbuf(uv_stat_t* statbuf, - FILE_STAT_BASIC_INFORMATION stat_info, int do_lstat) { +static void fs__stat_assign_statbuf(uv_stat_t* statbuf, + FILE_STAT_BASIC_INFORMATION stat_info, + int do_lstat) { statbuf->st_dev = stat_info.VolumeSerialNumber.LowPart; /* Todo: st_mode should probably always be 0666 for everyone. We might also @@ -1943,18 +1949,19 @@ INLINE static void fs__stat_assign_statbuf(uv_stat_t* statbuf, } -INLINE static void fs__stat_prepare_path(WCHAR* pathw) { +static void fs__stat_prepare_path(WCHAR* pathw) { size_t len = wcslen(pathw); - /* TODO: ignore namespaced paths. */ if (len > 1 && pathw[len - 2] != L':' && (pathw[len - 1] == L'\\' || pathw[len - 1] == L'/')) { pathw[len - 1] = '\0'; } } -INLINE static DWORD fs__stat_directory(WCHAR* path, uv_stat_t* statbuf, - int do_lstat, DWORD ret_error) { +static DWORD fs__stat_directory(WCHAR* path, + uv_stat_t* statbuf, + int do_lstat, + DWORD ret_error) { HANDLE handle = INVALID_HANDLE_VALUE; FILE_STAT_BASIC_INFORMATION stat_info; FILE_ID_FULL_DIR_INFORMATION dir_info; @@ -2127,9 +2134,9 @@ cleanup: return ret_error; } -INLINE static DWORD fs__stat_impl_from_path(WCHAR* path, - int do_lstat, - uv_stat_t* statbuf) { +static DWORD fs__stat_impl_from_path(WCHAR* path, + int do_lstat, + uv_stat_t* statbuf) { HANDLE handle; DWORD flags; DWORD ret; @@ -2174,7 +2181,7 @@ INLINE static DWORD fs__stat_impl_from_path(WCHAR* path, } -INLINE static void fs__stat_impl(uv_fs_t* req, int do_lstat) { +static void fs__stat_impl(uv_fs_t* req, int do_lstat) { DWORD error; error = fs__stat_impl_from_path(req->file.pathw, do_lstat, &req->statbuf); @@ -2197,7 +2204,7 @@ INLINE static void fs__stat_impl(uv_fs_t* req, int do_lstat) { } -INLINE static int fs__fstat_handle(int fd, HANDLE handle, uv_stat_t* statbuf) { +static int fs__fstat_handle(int fd, HANDLE handle, uv_stat_t* statbuf) { DWORD file_type; /* Each file type is processed differently. */ @@ -2273,7 +2280,7 @@ static void fs__rename(uv_fs_t* req) { } -INLINE static void fs__sync_impl(uv_fs_t* req) { +static void fs__sync_impl(uv_fs_t* req) { int fd = req->file.fd; int result; @@ -2579,7 +2586,7 @@ fchmod_cleanup: } -INLINE static int fs__utime_handle(HANDLE handle, double atime, double mtime) { +static int fs__utime_handle(HANDLE handle, double atime, double mtime) { FILETIME filetime_as, *filetime_a = &filetime_as; FILETIME filetime_ms, *filetime_m = &filetime_ms; FILETIME now; @@ -2607,10 +2614,10 @@ INLINE static int fs__utime_handle(HANDLE handle, double atime, double mtime) { return 0; } -INLINE static DWORD fs__utime_impl_from_path(WCHAR* path, - double atime, - double mtime, - int do_lutime) { +static DWORD fs__utime_impl_from_path(WCHAR* path, + double atime, + double mtime, + int do_lutime) { HANDLE handle; DWORD flags; DWORD ret; @@ -2640,7 +2647,7 @@ INLINE static DWORD fs__utime_impl_from_path(WCHAR* path, return ret; } -INLINE static void fs__utime_impl(uv_fs_t* req, int do_lutime) { +static void fs__utime_impl(uv_fs_t* req, int do_lutime) { DWORD error; error = fs__utime_impl_from_path(req->file.pathw, diff --git a/src/win/handle-inl.h b/src/win/handle-inl.h index 4722e857..e30d148c 100644 --- a/src/win/handle-inl.h +++ b/src/win/handle-inl.h @@ -95,74 +95,6 @@ INLINE static void uv__want_endgame(uv_loop_t* loop, uv_handle_t* handle) { } -INLINE static void uv__process_endgames(uv_loop_t* loop) { - uv_handle_t* handle; - - while (loop->endgame_handles) { - handle = loop->endgame_handles; - loop->endgame_handles = handle->endgame_next; - - handle->flags &= ~UV_HANDLE_ENDGAME_QUEUED; - - switch (handle->type) { - case UV_TCP: - uv__tcp_endgame(loop, (uv_tcp_t*) handle); - break; - - case UV_NAMED_PIPE: - uv__pipe_endgame(loop, (uv_pipe_t*) handle); - break; - - case UV_TTY: - uv__tty_endgame(loop, (uv_tty_t*) handle); - break; - - case UV_UDP: - uv__udp_endgame(loop, (uv_udp_t*) handle); - break; - - case UV_POLL: - uv__poll_endgame(loop, (uv_poll_t*) handle); - break; - - case UV_TIMER: - uv__timer_close((uv_timer_t*) handle); - uv__handle_close(handle); - break; - - case UV_PREPARE: - case UV_CHECK: - case UV_IDLE: - uv__loop_watcher_endgame(loop, handle); - break; - - case UV_ASYNC: - uv__async_endgame(loop, (uv_async_t*) handle); - break; - - case UV_SIGNAL: - uv__signal_endgame(loop, (uv_signal_t*) handle); - break; - - case UV_PROCESS: - uv__process_endgame(loop, (uv_process_t*) handle); - break; - - case UV_FS_EVENT: - uv__fs_event_endgame(loop, (uv_fs_event_t*) handle); - break; - - case UV_FS_POLL: - uv__fs_poll_endgame(loop, (uv_fs_poll_t*) handle); - break; - - default: - assert(0); - break; - } - } -} - INLINE static HANDLE uv__get_osfhandle(int fd) { /* _get_osfhandle() raises an assert in debug builds if the FD is invalid. diff --git a/src/win/internal.h b/src/win/internal.h index be408af6..db488be7 100644 --- a/src/win/internal.h +++ b/src/win/internal.h @@ -269,7 +269,7 @@ int uv__getsockpeername(const uv_handle_t* handle, int* namelen, int delayed_error); -int uv__random_rtlgenrandom(void* buf, size_t buflen); +int uv__random_winrandom(void* buf, size_t buflen); /* diff --git a/src/win/pipe.c b/src/win/pipe.c index d05bfd28..8f86a1fe 100644 --- a/src/win/pipe.c +++ b/src/win/pipe.c @@ -2149,7 +2149,8 @@ void uv__process_pipe_read_req(uv_loop_t* loop, } else { /* The zero-read completed without error, indicating there is data * available in the kernel buffer. */ - while (handle->flags & UV_HANDLE_READING) { + while (handle->flags & UV_HANDLE_READING && + !(handle->flags & UV_HANDLE_READ_PENDING)) { bytes_requested = 65536; /* Depending on the type of pipe, read either IPC frames or raw data. */ if (handle->ipc) diff --git a/src/win/poll.c b/src/win/poll.c index 7fec2b99..a20867a9 100644 --- a/src/win/poll.c +++ b/src/win/poll.c @@ -211,15 +211,11 @@ static SOCKET uv__fast_poll_create_peer_socket(HANDLE iocp, protocol_info->iProtocol, protocol_info, 0, - WSA_FLAG_OVERLAPPED); + WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); if (sock == INVALID_SOCKET) { return INVALID_SOCKET; } - if (!SetHandleInformation((HANDLE) sock, HANDLE_FLAG_INHERIT, 0)) { - goto error; - }; - if (CreateIoCompletionPort((HANDLE) sock, iocp, (ULONG_PTR) sock, diff --git a/src/win/req-inl.h b/src/win/req-inl.h index cf16e8ba..af6fb752 100644 --- a/src/win/req-inl.h +++ b/src/win/req-inl.h @@ -81,134 +81,6 @@ uv_fatal_error(GetLastError(), "PostQueuedCompletionStatus"); \ } - -INLINE static uv_req_t* uv__overlapped_to_req(OVERLAPPED* overlapped) { - return container_of(overlapped, uv_req_t, u.io.overlapped); -} - - -INLINE static void uv__insert_pending_req(uv_loop_t* loop, uv_req_t* req) { - req->next_req = NULL; - if (loop->pending_reqs_tail) { -#ifdef _DEBUG - /* Ensure the request is not already in the queue, or the queue - * will get corrupted. - */ - uv_req_t* current = loop->pending_reqs_tail; - do { - assert(req != current); - current = current->next_req; - } while(current != loop->pending_reqs_tail); -#endif - - req->next_req = loop->pending_reqs_tail->next_req; - loop->pending_reqs_tail->next_req = req; - loop->pending_reqs_tail = req; - } else { - req->next_req = req; - loop->pending_reqs_tail = req; - } -} - - -#define DELEGATE_STREAM_REQ(loop, req, method, handle_at) \ - do { \ - switch (((uv_handle_t*) (req)->handle_at)->type) { \ - case UV_TCP: \ - uv__process_tcp_##method##_req(loop, \ - (uv_tcp_t*) ((req)->handle_at), \ - req); \ - break; \ - \ - case UV_NAMED_PIPE: \ - uv__process_pipe_##method##_req(loop, \ - (uv_pipe_t*) ((req)->handle_at), \ - req); \ - break; \ - \ - case UV_TTY: \ - uv__process_tty_##method##_req(loop, \ - (uv_tty_t*) ((req)->handle_at), \ - req); \ - break; \ - \ - default: \ - assert(0); \ - } \ - } while (0) - - -INLINE static void uv__process_reqs(uv_loop_t* loop) { - uv_req_t* req; - uv_req_t* first; - uv_req_t* next; - - if (loop->pending_reqs_tail == NULL) - return; - - first = loop->pending_reqs_tail->next_req; - next = first; - loop->pending_reqs_tail = NULL; - - while (next != NULL) { - req = next; - next = req->next_req != first ? req->next_req : NULL; - - switch (req->type) { - case UV_READ: - DELEGATE_STREAM_REQ(loop, req, read, data); - break; - - case UV_WRITE: - DELEGATE_STREAM_REQ(loop, (uv_write_t*) req, write, handle); - break; - - case UV_ACCEPT: - DELEGATE_STREAM_REQ(loop, req, accept, data); - break; - - case UV_CONNECT: - DELEGATE_STREAM_REQ(loop, (uv_connect_t*) req, connect, handle); - break; - - case UV_SHUTDOWN: - DELEGATE_STREAM_REQ(loop, (uv_shutdown_t*) req, shutdown, handle); - break; - - case UV_UDP_RECV: - uv__process_udp_recv_req(loop, (uv_udp_t*) req->data, req); - break; - - case UV_UDP_SEND: - uv__process_udp_send_req(loop, - ((uv_udp_send_t*) req)->handle, - (uv_udp_send_t*) req); - break; - - case UV_WAKEUP: - uv__process_async_wakeup_req(loop, (uv_async_t*) req->data, req); - break; - - case UV_SIGNAL_REQ: - uv__process_signal_req(loop, (uv_signal_t*) req->data, req); - break; - - case UV_POLL_REQ: - uv__process_poll_req(loop, (uv_poll_t*) req->data, req); - break; - - case UV_PROCESS_EXIT: - uv__process_proc_exit(loop, (uv_process_t*) req->data); - break; - - case UV_FS_EVENT_REQ: - uv__process_fs_event_req(loop, req, (uv_fs_event_t*) req->data); - break; - - default: - assert(0); - } - } -} +void uv__insert_pending_req(uv_loop_t* loop, uv_req_t* req); #endif /* UV_WIN_REQ_INL_H_ */ diff --git a/src/win/thread.c b/src/win/thread.c index 753cb6a3..9c38e3d8 100644 --- a/src/win/thread.c +++ b/src/win/thread.c @@ -284,7 +284,7 @@ int uv_thread_equal(const uv_thread_t* t1, const uv_thread_t* t2) { static void uv__thread_name_init_once(void) { HMODULE m; - m = GetModuleHandleA("api-ms-win-core-processthreads-l1-1-3.dll"); + m = GetModuleHandleW(L"api-ms-win-core-processthreads-l1-1-3.dll"); if (m != NULL) { pGetThreadDescription = (void*) GetProcAddress(m, "GetThreadDescription"); pSetThreadDescription = (void*) GetProcAddress(m, "SetThreadDescription"); diff --git a/src/win/udp.c b/src/win/udp.c index e0873c2a..f8aa2435 100644 --- a/src/win/udp.c +++ b/src/win/udp.c @@ -1149,10 +1149,13 @@ int uv__udp_try_send2(uv_udp_t* handle, uv_buf_t* bufs[/*count*/], unsigned int nbufs[/*count*/], struct sockaddr* addrs[/*count*/]) { - unsigned int i; + int i; int r; - for (i = 0; i < count; i++) { + if (count > INT_MAX) + return UV_EINVAL; + + for (i = 0; i < (int) count; i++) { r = uv_udp_try_send(handle, bufs[i], nbufs[i], addrs[i]); if (r < 0) return i > 0 ? i : r; /* Error if first packet, else send count. */ diff --git a/src/win/util.c b/src/win/util.c index da1238d3..9e3daac8 100644 --- a/src/win/util.c +++ b/src/win/util.c @@ -378,10 +378,15 @@ done: static int uv__get_process_title(void) { WCHAR title_w[MAX_TITLE_LENGTH]; DWORD wlen; + DWORD err; + SetLastError(ERROR_SUCCESS); wlen = GetConsoleTitleW(title_w, sizeof(title_w) / sizeof(WCHAR)); - if (wlen == 0) - return uv_translate_sys_error(GetLastError()); + if (wlen == 0) { + err = GetLastError(); + if (err != 0) + return uv_translate_sys_error(err); + } return uv__convert_utf16_to_utf8(title_w, wlen, &process_title); } @@ -508,8 +513,8 @@ int uv_uptime(double* uptime) { unsigned int uv_available_parallelism(void) { DWORD_PTR procmask; DWORD_PTR sysmask; - int count; - int i; + unsigned count; + unsigned i; /* TODO(bnoordhuis) Use GetLogicalProcessorInformationEx() to support systems * with > 64 CPUs? See https://github.com/libuv/libuv/pull/3458 @@ -867,12 +872,6 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr, } -void uv_free_interface_addresses(uv_interface_address_t* addresses, - int count) { - uv__free(addresses); -} - - int uv_getrusage(uv_rusage_t *uv_rusage) { FILETIME create_time, exit_time, kernel_time, user_time; SYSTEMTIME kernel_system_time, user_system_time; @@ -1713,6 +1712,9 @@ int uv_os_uname(uv_utsname_t* buffer) { case PROCESSOR_ARCHITECTURE_ARM: uv__strscpy(buffer->machine, "arm", sizeof(buffer->machine)); break; + case PROCESSOR_ARCHITECTURE_ARM64: + uv__strscpy(buffer->machine, "arm64", sizeof(buffer->machine)); + break; default: uv__strscpy(buffer->machine, "unknown", sizeof(buffer->machine)); break; @@ -1745,10 +1747,13 @@ int uv_gettimeofday(uv_timeval64_t* tv) { return 0; } -int uv__random_rtlgenrandom(void* buf, size_t buflen) { +int uv__random_winrandom(void* buf, size_t buflen) { if (buflen == 0) return 0; + if (pProcessPrng != NULL && pProcessPrng(buf, buflen)) + return 0; + if (SystemFunction036(buf, buflen) == FALSE) return UV_EIO; diff --git a/src/win/winapi.c b/src/win/winapi.c index 315a0d49..7ed08dd2 100644 --- a/src/win/winapi.c +++ b/src/win/winapi.c @@ -39,6 +39,9 @@ sNtQueryInformationProcess pNtQueryInformationProcess; /* Powrprof.dll function pointer */ sPowerRegisterSuspendResumeNotification pPowerRegisterSuspendResumeNotification; +/* bcryptprimitives.dll function pointer */ +sProcessPrng pProcessPrng; + /* User32.dll function pointer */ sSetWinEventHook pSetWinEventHook; @@ -53,92 +56,118 @@ void uv__winapi_init(void) { HMODULE powrprof_module; HMODULE user32_module; HMODULE ws2_32_module; + HMODULE bcryptprimitives_module; HMODULE api_win_core_file_module; - ntdll_module = GetModuleHandleA("ntdll.dll"); + union { + FARPROC proc; + sRtlGetVersion pRtlGetVersion; + sRtlNtStatusToDosError pRtlNtStatusToDosError; + sNtDeviceIoControlFile pNtDeviceIoControlFile; + sNtQueryInformationFile pNtQueryInformationFile; + sNtSetInformationFile pNtSetInformationFile; + sNtQueryVolumeInformationFile pNtQueryVolumeInformationFile; + sNtQueryDirectoryFile pNtQueryDirectoryFile; + sNtQuerySystemInformation pNtQuerySystemInformation; + sNtQueryInformationProcess pNtQueryInformationProcess; + sPowerRegisterSuspendResumeNotification pPowerRegisterSuspendResumeNotification; + sProcessPrng pProcessPrng; + sSetWinEventHook pSetWinEventHook; + uv_sGetHostNameW pGetHostNameW; + sGetFileInformationByName pGetFileInformationByName; + } u; + + ntdll_module = GetModuleHandleW(L"ntdll.dll"); if (ntdll_module == NULL) { - uv_fatal_error(GetLastError(), "GetModuleHandleA"); + uv_fatal_error(GetLastError(), "GetModuleHandleW"); } - pRtlGetVersion = (sRtlGetVersion) GetProcAddress(ntdll_module, - "RtlGetVersion"); + u.proc = GetProcAddress(ntdll_module, "RtlGetVersion"); + pRtlGetVersion = u.pRtlGetVersion; - pRtlNtStatusToDosError = (sRtlNtStatusToDosError) GetProcAddress( - ntdll_module, - "RtlNtStatusToDosError"); + u.proc = GetProcAddress(ntdll_module, "RtlNtStatusToDosError"); + pRtlNtStatusToDosError = u.pRtlNtStatusToDosError; if (pRtlNtStatusToDosError == NULL) { uv_fatal_error(GetLastError(), "GetProcAddress"); } - pNtDeviceIoControlFile = (sNtDeviceIoControlFile) GetProcAddress( - ntdll_module, - "NtDeviceIoControlFile"); + u.proc = GetProcAddress(ntdll_module, "NtDeviceIoControlFile"); + pNtDeviceIoControlFile = u.pNtDeviceIoControlFile; if (pNtDeviceIoControlFile == NULL) { uv_fatal_error(GetLastError(), "GetProcAddress"); } - pNtQueryInformationFile = (sNtQueryInformationFile) GetProcAddress( - ntdll_module, - "NtQueryInformationFile"); + u.proc = GetProcAddress(ntdll_module, "NtQueryInformationFile"); + pNtQueryInformationFile = u.pNtQueryInformationFile; if (pNtQueryInformationFile == NULL) { uv_fatal_error(GetLastError(), "GetProcAddress"); } - pNtSetInformationFile = (sNtSetInformationFile) GetProcAddress( - ntdll_module, - "NtSetInformationFile"); + u.proc = GetProcAddress(ntdll_module, "NtSetInformationFile"); + pNtSetInformationFile = u.pNtSetInformationFile; if (pNtSetInformationFile == NULL) { uv_fatal_error(GetLastError(), "GetProcAddress"); } - pNtQueryVolumeInformationFile = (sNtQueryVolumeInformationFile) - GetProcAddress(ntdll_module, "NtQueryVolumeInformationFile"); + u.proc = GetProcAddress(ntdll_module, "NtQueryVolumeInformationFile"); + pNtQueryVolumeInformationFile = u.pNtQueryVolumeInformationFile; if (pNtQueryVolumeInformationFile == NULL) { uv_fatal_error(GetLastError(), "GetProcAddress"); } - pNtQueryDirectoryFile = (sNtQueryDirectoryFile) - GetProcAddress(ntdll_module, "NtQueryDirectoryFile"); + u.proc = GetProcAddress(ntdll_module, "NtQueryDirectoryFile"); + pNtQueryDirectoryFile = u.pNtQueryDirectoryFile; if (pNtQueryDirectoryFile == NULL) { uv_fatal_error(GetLastError(), "GetProcAddress"); } - pNtQuerySystemInformation = (sNtQuerySystemInformation) GetProcAddress( - ntdll_module, - "NtQuerySystemInformation"); + u.proc = GetProcAddress(ntdll_module, "NtQuerySystemInformation"); + pNtQuerySystemInformation = u.pNtQuerySystemInformation; if (pNtQuerySystemInformation == NULL) { uv_fatal_error(GetLastError(), "GetProcAddress"); } - pNtQueryInformationProcess = (sNtQueryInformationProcess) GetProcAddress( - ntdll_module, - "NtQueryInformationProcess"); + u.proc = GetProcAddress(ntdll_module, "NtQueryInformationProcess"); + pNtQueryInformationProcess = u.pNtQueryInformationProcess; if (pNtQueryInformationProcess == NULL) { uv_fatal_error(GetLastError(), "GetProcAddress"); } - powrprof_module = LoadLibraryExA("powrprof.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); + powrprof_module = LoadLibraryExA("powrprof.dll", + NULL, + LOAD_LIBRARY_SEARCH_SYSTEM32); if (powrprof_module != NULL) { - pPowerRegisterSuspendResumeNotification = (sPowerRegisterSuspendResumeNotification) - GetProcAddress(powrprof_module, "PowerRegisterSuspendResumeNotification"); + u.proc = GetProcAddress(powrprof_module, + "PowerRegisterSuspendResumeNotification"); + pPowerRegisterSuspendResumeNotification = + u.pPowerRegisterSuspendResumeNotification; + } + + bcryptprimitives_module = LoadLibraryExA("bcryptprimitives.dll", + NULL, + LOAD_LIBRARY_SEARCH_SYSTEM32); + if (bcryptprimitives_module != NULL) { + u.proc = GetProcAddress(bcryptprimitives_module, "ProcessPrng"); + pProcessPrng = u.pProcessPrng; } - user32_module = GetModuleHandleA("user32.dll"); + user32_module = GetModuleHandleW(L"user32.dll"); if (user32_module != NULL) { - pSetWinEventHook = (sSetWinEventHook) - GetProcAddress(user32_module, "SetWinEventHook"); + u.proc = GetProcAddress(user32_module, "SetWinEventHook"); + pSetWinEventHook = u.pSetWinEventHook; } - ws2_32_module = GetModuleHandleA("ws2_32.dll"); + ws2_32_module = GetModuleHandleW(L"ws2_32.dll"); if (ws2_32_module != NULL) { - pGetHostNameW = (uv_sGetHostNameW) GetProcAddress( - ws2_32_module, - "GetHostNameW"); + u.proc = GetProcAddress(ws2_32_module, "GetHostNameW"); + pGetHostNameW = u.pGetHostNameW; } - api_win_core_file_module = GetModuleHandleA("api-ms-win-core-file-l2-1-4.dll"); + api_win_core_file_module = + GetModuleHandleW(L"api-ms-win-core-file-l2-1-4.dll"); if (api_win_core_file_module != NULL) { - pGetFileInformationByName = (sGetFileInformationByName)GetProcAddress( - api_win_core_file_module, "GetFileInformationByName"); + u.proc = GetProcAddress(api_win_core_file_module, + "GetFileInformationByName"); + pGetFileInformationByName = u.pGetFileInformationByName; } } diff --git a/src/win/winapi.h b/src/win/winapi.h index b9c9f1ab..a7e1b179 100644 --- a/src/win/winapi.h +++ b/src/win/winapi.h @@ -4751,6 +4751,8 @@ typedef DWORD (WINAPI *sPowerRegisterSuspendResumeNotification) HANDLE Recipient, _PHPOWERNOTIFY RegistrationHandle); +typedef BOOL (WINAPI *sProcessPrng)(/*_Out_*/PBYTE pbData, SIZE_T cbData); + /* from Winuser.h */ typedef VOID (CALLBACK* WINEVENTPROC) (HWINEVENTHOOK hWinEventHook, @@ -4815,6 +4817,9 @@ extern sNtQueryInformationProcess pNtQueryInformationProcess; /* Powrprof.dll function pointer */ extern sPowerRegisterSuspendResumeNotification pPowerRegisterSuspendResumeNotification; +/* bcryptprimitives.dll function pointer */ +extern sProcessPrng pProcessPrng; + /* User32.dll function pointer */ extern sSetWinEventHook pSetWinEventHook; diff --git a/test/run-benchmarks.c b/test/run-benchmarks.c index 2b343da4..d7290f96 100644 --- a/test/run-benchmarks.c +++ b/test/run-benchmarks.c @@ -31,7 +31,7 @@ #ifdef __MVS__ #include "zos-base.h" /* Initialize environment and zoslib */ -__attribute__((constructor)) void init() { +__attribute__((constructor)) void init(void) { zoslib_config_t config; init_zoslib_config(&config); init_zoslib(config); diff --git a/test/run-tests.c b/test/run-tests.c index 17fb0e0c..51170749 100644 --- a/test/run-tests.c +++ b/test/run-tests.c @@ -40,7 +40,7 @@ #ifdef __MVS__ #include "zos-base.h" /* Initialize environment and zoslib */ -__attribute__((constructor)) void init() { +__attribute__((constructor)) void init(void) { zoslib_config_t config; init_zoslib_config(&config); init_zoslib(config); @@ -223,7 +223,7 @@ static int maybe_run_test(int argc, char **argv) { ASSERT_GT((intptr_t) closed_fd, 0); ASSERT_GT((intptr_t) open_fd, 0); ASSERT_NE(0, GetHandleInformation(open_fd, &flags)); - kernelbase_module = GetModuleHandleA("kernelbase.dll"); + kernelbase_module = GetModuleHandleW(L"kernelbase.dll"); pCompareObjectHandles = (sCompareObjectHandles) GetProcAddress(kernelbase_module, "CompareObjectHandles"); ASSERT_NE(pCompareObjectHandles == NULL || \ diff --git a/test/runner-win.c b/test/runner-win.c index 8035ca62..52e0f64d 100644 --- a/test/runner-win.c +++ b/test/runner-win.c @@ -340,7 +340,7 @@ static int clear_line(void) { } -void rewind_cursor() { +void rewind_cursor(void) { if (clear_line() == -1) { /* If clear_line fails (stdout is not a console), print a newline. */ fprintf(stderr, "\n"); diff --git a/test/task.h b/test/task.h index e25a9c9a..2600da5e 100644 --- a/test/task.h +++ b/test/task.h @@ -113,8 +113,8 @@ typedef enum { #define ASSERT_BASE(a, operator, b, type, conv) \ do { \ - volatile type eval_a = (type) (a); \ - volatile type eval_b = (type) (b); \ + type const eval_a = (a); \ + type const eval_b = (b); \ if (!(eval_a operator eval_b)) { \ fprintf(stderr, \ "Assertion failed in %s on line %d: `%s %s %s` " \ @@ -131,6 +131,21 @@ typedef enum { } \ } while (0) +#define ASSERT_OK(a) \ + do { \ + int64_t const eval_a = (a); \ + if (eval_a) { \ + fprintf(stderr, \ + "Assertion failed in %s on line %d: `%s` okay " \ + "(error: %"PRId64")\n", \ + __FILE__, \ + __LINE__, \ + #a, \ + eval_a); \ + abort(); \ + } \ + } while (0) + #define ASSERT_BASE_STR(expr, a, operator, b, type, conv) \ do { \ if (!(expr)) { \ @@ -173,8 +188,8 @@ typedef enum { do { \ if (!(expr)) { \ int i; \ - unsigned char* a_ = (unsigned char*)a; \ - unsigned char* b_ = (unsigned char*)b; \ + const unsigned char* a_ = (a); \ + const unsigned char* b_ = (b); \ fprintf(stderr, \ "Assertion failed in %s on line %d: `%s %s %s` (", \ __FILE__, \ @@ -202,7 +217,6 @@ typedef enum { #define ASSERT_LE(a, b) ASSERT_BASE(a, <=, b, int64_t, PRId64) #define ASSERT_LT(a, b) ASSERT_BASE(a, <, b, int64_t, PRId64) #define ASSERT_NE(a, b) ASSERT_BASE(a, !=, b, int64_t, PRId64) -#define ASSERT_OK(a) ASSERT_BASE(a, ==, 0, int64_t, PRId64) #define ASSERT_UINT64_EQ(a, b) ASSERT_BASE(a, ==, b, uint64_t, PRIu64) #define ASSERT_UINT64_GE(a, b) ASSERT_BASE(a, >=, b, uint64_t, PRIu64) @@ -211,12 +225,12 @@ typedef enum { #define ASSERT_UINT64_LT(a, b) ASSERT_BASE(a, <, b, uint64_t, PRIu64) #define ASSERT_UINT64_NE(a, b) ASSERT_BASE(a, !=, b, uint64_t, PRIu64) -#define ASSERT_DOUBLE_EQ(a, b) ASSERT_BASE(a, ==, b, double, "f") -#define ASSERT_DOUBLE_GE(a, b) ASSERT_BASE(a, >=, b, double, "f") -#define ASSERT_DOUBLE_GT(a, b) ASSERT_BASE(a, >, b, double, "f") -#define ASSERT_DOUBLE_LE(a, b) ASSERT_BASE(a, <=, b, double, "f") -#define ASSERT_DOUBLE_LT(a, b) ASSERT_BASE(a, <, b, double, "f") -#define ASSERT_DOUBLE_NE(a, b) ASSERT_BASE(a, !=, b, double, "f") +#define ASSERT_DOUBLE_EQ(a, b) ASSERT_BASE(a, ==, b, volatile double, "f") +#define ASSERT_DOUBLE_GE(a, b) ASSERT_BASE(a, >=, b, volatile double, "f") +#define ASSERT_DOUBLE_GT(a, b) ASSERT_BASE(a, >, b, volatile double, "f") +#define ASSERT_DOUBLE_LE(a, b) ASSERT_BASE(a, <=, b, volatile double, "f") +#define ASSERT_DOUBLE_LT(a, b) ASSERT_BASE(a, <, b, volatile double, "f") +#define ASSERT_DOUBLE_NE(a, b) ASSERT_BASE(a, !=, b, volatile double, "f") #define ASSERT_STR_EQ(a, b) \ ASSERT_BASE_STR(strcmp(a, b) == 0, a, == , b, char*, "s") @@ -237,19 +251,23 @@ typedef enum { ASSERT_BASE_HEX(memcmp(a, b, size) != 0, a, !=, b, size) #define ASSERT_NULL(a) \ - ASSERT_BASE(a, ==, NULL, void*, "p") + ASSERT_BASE(a, ==, NULL, const void*, "p") #define ASSERT_NOT_NULL(a) \ - ASSERT_BASE(a, !=, NULL, void*, "p") + ASSERT_BASE(a, !=, NULL, const void*, "p") #define ASSERT_PTR_EQ(a, b) \ - ASSERT_BASE(a, ==, b, void*, "p") + ASSERT_BASE(a, ==, b, const void*, "p") #define ASSERT_PTR_NE(a, b) \ - ASSERT_BASE(a, !=, b, void*, "p") + ASSERT_BASE(a, !=, b, const void*, "p") #define ASSERT_PTR_LT(a, b) \ - ASSERT_BASE(a, <, b, void*, "p") + ASSERT_BASE(a, <, b, const void*, "p") +#define ASSERT_PTR_LE(a, b) \ + ASSERT_BASE(a, <=, b, const void*, "p") +#define ASSERT_PTR_GE(a, b) \ + ASSERT_BASE(a, >=, b, const void*, "p") /* This macro cleans up the event loop. This is used to avoid valgrind * warnings about memory being "leaked" by the event loop. @@ -358,7 +376,7 @@ UNUSED static int can_ipv6(void) { return supported; } -#if defined(__CYGWIN__) || defined(__MSYS__) || defined(__PASE__) +#if defined(__CYGWIN__) || defined(__MSYS__) || defined(__PASE__) || defined(__QNX__) # define NO_FS_EVENTS "Filesystem watching not supported on this platform." #endif diff --git a/test/test-embed.c b/test/test-embed.c index 6e991723..84fc7cad 100644 --- a/test/test-embed.c +++ b/test/test-embed.c @@ -25,7 +25,7 @@ #include <stdlib.h> #include <errno.h> -#if !defined(_WIN32) && !defined(_AIX) +#if !defined(_WIN32) && !defined(_AIX) && !defined(__QNX__) #include <poll.h> #endif @@ -56,7 +56,7 @@ TEST_IMPL(embed) { ASSERT_LE(0, uv_barrier_wait(&barrier)); while (uv_loop_alive(loop)) { -#if defined(_WIN32) || defined(_AIX) +#if defined(_WIN32) || defined(_AIX) || defined(__QNX__) ASSERT_LE(0, uv_run(loop, UV_RUN_ONCE)); #else int rc; diff --git a/test/test-fs.c b/test/test-fs.c index 4761b15b..4ce059c3 100644 --- a/test/test-fs.c +++ b/test/test-fs.c @@ -152,7 +152,7 @@ int uv_test_getiovmax(void) { int uv_test_getiovmax(void) { #if defined(IOV_MAX) return IOV_MAX; -#elif defined(_SC_IOV_MAX) +#elif defined(_SC_IOV_MAX) && !defined(__QNX__) static int iovmax = -1; if (iovmax == -1) { iovmax = sysconf(_SC_IOV_MAX); @@ -356,7 +356,7 @@ static void statfs_cb(uv_fs_t* req) { stats = req->ptr; #if defined(_WIN32) || defined(__sun) || defined(_AIX) || defined(__MVS__) || \ - defined(__OpenBSD__) || defined(__NetBSD__) + defined(__OpenBSD__) || defined(__NetBSD__) || defined(__QNX__) ASSERT_OK(stats->f_type); #else ASSERT_UINT64_GT(stats->f_type, 0); @@ -2833,7 +2833,9 @@ TEST_IMPL(fs_utime_round) { double mtime; uv_fs_t req; int r; - +#if defined(__QNX__) + RETURN_SKIP("Setting time to a negative value is unsupported on QNX"); +#endif loop = uv_default_loop(); unlink(path); r = uv_fs_open(NULL, &req, path, UV_FS_O_RDWR | UV_FS_O_CREAT, @@ -3889,6 +3891,12 @@ TEST_IMPL(fs_read_dir) { * created on. That is why this assertion is a bit lenient. */ ASSERT((r >= 0) || (r == UV_EISDIR)); +#elif defined(__QNX__) + /* + * If UV_FS_O_DIRECTORY is supplied, QNX returns ENOSYS. Otherwise + * UV_EISDIR is returned. Here we are lenient and accept both. + */ + ASSERT((r == UV_ENOSYS) || (r == UV_EISDIR)); #else ASSERT_EQ(r, UV_EISDIR); #endif diff --git a/test/test-poll.c b/test/test-poll.c index 5161de25..11974424 100644 --- a/test/test-poll.c +++ b/test/test-poll.c @@ -83,9 +83,9 @@ static int closed_connections = 0; static int valid_writable_wakeups = 0; static int spurious_writable_wakeups = 0; -#if !defined(__sun) && !defined(_AIX) && !defined(__MVS__) +#if !defined(__sun) && !defined(_AIX) && !defined(__MVS__) && !defined(__QNX__) static int disconnects = 0; -#endif /* !__sun && !_AIX && !__MVS__ */ +#endif /* !__sun && !_AIX && !__MVS__ && !__QNX__*/ static int got_eagain(void) { #ifdef _WIN32 @@ -409,7 +409,7 @@ static void connection_poll_cb(uv_poll_t* handle, int status, int events) { new_events &= ~UV_WRITABLE; } } -#if !defined(__sun) && !defined(_AIX) && !defined(__MVS__) +#if !defined(__sun) && !defined(_AIX) && !defined(__MVS__) && !defined(__QNX__) if (events & UV_DISCONNECT) { context->got_disconnect = 1; ++disconnects; @@ -417,9 +417,9 @@ static void connection_poll_cb(uv_poll_t* handle, int status, int events) { } if (context->got_fin && context->sent_fin && context->got_disconnect) { -#else /* __sun && _AIX && __MVS__ */ +#else /* __sun && _AIX && __MVS__ && __QNX__*/ if (context->got_fin && context->sent_fin) { -#endif /* !__sun && !_AIX && !__MVS__ */ +#endif /* !__sun && !_AIX && !__MVS__ && !__QNX__ */ /* Sent and received FIN. Close and destroy context. */ close_socket(context->sock); destroy_connection_context(context); @@ -587,7 +587,7 @@ static void start_poll_test(void) { spurious_writable_wakeups > 20, 0); ASSERT_EQ(closed_connections, NUM_CLIENTS * 2); -#if !defined(__sun) && !defined(_AIX) && !defined(__MVS__) +#if !defined(__sun) && !defined(_AIX) && !defined(__MVS__) && !defined(__QNX__) ASSERT_EQ(disconnects, NUM_CLIENTS * 2); #endif MAKE_VALGRIND_HAPPY(uv_default_loop()); @@ -638,7 +638,7 @@ TEST_IMPL(poll_unidirectional) { TEST_IMPL(poll_bad_fdtype) { #if !defined(__sun) && \ !defined(_AIX) && !defined(__MVS__) && \ - !defined(__CYGWIN__) && !defined(__MSYS__) + !defined(__CYGWIN__) && !defined(__MSYS__) && !defined(__QNX__) uv_poll_t poll_handle; int fd[2]; diff --git a/test/test-process-priority.c b/test/test-process-priority.c index 941e4b36..5e61ef4c 100644 --- a/test/test-process-priority.c +++ b/test/test-process-priority.c @@ -28,9 +28,9 @@ TEST_IMPL(process_priority) { int r; int i; -#if defined(__MVS__) +#if defined(__MVS__) || defined(__QNX__) if (uv_os_setpriority(0, 0) == UV_ENOSYS) - RETURN_SKIP("functionality not supported on zOS"); + RETURN_SKIP("functionality not supported on zOS and QNX"); #endif /* Verify that passing a NULL pointer returns UV_EINVAL. */ diff --git a/test/test-process-title-threadsafe.c b/test/test-process-title-threadsafe.c index 05baaf44..212c715a 100644 --- a/test/test-process-title-threadsafe.c +++ b/test/test-process-title-threadsafe.c @@ -85,10 +85,18 @@ TEST_IMPL(process_title_threadsafe) { int i; #if defined(__sun) || defined(__CYGWIN__) || defined(__MSYS__) || \ - defined(__MVS__) || defined(__PASE__) + defined(__MVS__) || defined(__PASE__) || defined(__QNX__) RETURN_SKIP("uv_(get|set)_process_title is not implemented."); #endif +#if defined(__ASAN__) && defined(__APPLE__) + /* uv_set_process_title loads and unloads a bunch of dynamic libraries, + * and that's quite slow and prone to time out when running concurrently + * under AddressSanitizer. + */ + RETURN_SKIP("too slow under ASAN"); +#endif + ASSERT_OK(uv_set_process_title(titles[0])); ASSERT_OK(uv_sem_init(&getter_sem, 0)); diff --git a/test/test-process-title.c b/test/test-process-title.c index 7178cf87..3478033a 100644 --- a/test/test-process-title.c +++ b/test/test-process-title.c @@ -61,7 +61,7 @@ static void uv_get_process_title_edge_cases(void) { TEST_IMPL(process_title) { #if defined(__sun) || defined(__CYGWIN__) || defined(__MSYS__) || \ - defined(__PASE__) + defined(__PASE__) || defined(__QNX__) RETURN_SKIP("uv_(get|set)_process_title is not implemented."); #endif diff --git a/test/test-spawn.c b/test/test-spawn.c index 964c8a86..0dad9bcd 100644 --- a/test/test-spawn.c +++ b/test/test-spawn.c @@ -1701,7 +1701,7 @@ TEST_IMPL(spawn_fs_open) { #ifdef _WIN32 ASSERT_NE(0, DuplicateHandle(GetCurrentProcess(), fd, GetCurrentProcess(), &dup_fd, 0, /* inherit */ TRUE, DUPLICATE_SAME_ACCESS)); - kernelbase_module = GetModuleHandleA("kernelbase.dll"); + kernelbase_module = GetModuleHandleW(L"kernelbase.dll"); pCompareObjectHandles = (sCompareObjectHandles) GetProcAddress(kernelbase_module, "CompareObjectHandles"); ASSERT_NE(pCompareObjectHandles == NULL || diff --git a/test/test-tcp-close-accept.c b/test/test-tcp-close-accept.c index 4988dd13..30e1f1fa 100644 --- a/test/test-tcp-close-accept.c +++ b/test/test-tcp-close-accept.c @@ -69,8 +69,8 @@ static void connect_cb(uv_connect_t* req, int status) { } ASSERT_OK(status); - ASSERT_LE(connect_reqs, req); - ASSERT_LE(req, connect_reqs + ARRAY_SIZE(connect_reqs)); + ASSERT_PTR_LE(connect_reqs, req); + ASSERT_PTR_LE(req, connect_reqs + ARRAY_SIZE(connect_reqs)); i = req - connect_reqs; buf = uv_buf_init("x", 1); diff --git a/test/test-udp-ipv6.c b/test/test-udp-ipv6.c index 8ad80b9b..e21ad0aa 100644 --- a/test/test-udp-ipv6.c +++ b/test/test-udp-ipv6.c @@ -26,7 +26,7 @@ #include <stdlib.h> #include <string.h> -#if defined(__FreeBSD__) || defined(__NetBSD__) +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__QNX__) #include <sys/sysctl.h> #endif @@ -49,7 +49,7 @@ static int recv_cb_called; static int close_cb_called; static uint16_t client_port; -#if defined(__FreeBSD__) || defined(__NetBSD__) +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__QNX__) static int can_ipv6_ipv4_dual(void) { int v6only; size_t size = sizeof(int); @@ -228,7 +228,7 @@ TEST_IMPL(udp_dual_stack) { if (!can_ipv6()) RETURN_SKIP("IPv6 not supported"); -#if defined(__FreeBSD__) || defined(__NetBSD__) +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__QNX__) if (!can_ipv6_ipv4_dual()) RETURN_SKIP("IPv6-IPv4 dual stack not supported"); #elif defined(__OpenBSD__) diff --git a/test/test-udp-multicast-join.c b/test/test-udp-multicast-join.c index f024e2e0..548bf741 100644 --- a/test/test-udp-multicast-join.c +++ b/test/test-udp-multicast-join.c @@ -144,8 +144,8 @@ static void cl_recv_cb(uv_udp_t* handle, TEST_IMPL(udp_multicast_join) { -#if defined(__OpenBSD__) - RETURN_SKIP("Test does not currently work in OpenBSD"); +#if defined(__OpenBSD__) || defined(QNX_IOPKT) + RETURN_SKIP("Test does not currently work in OpenBSD or QNX"); #endif int r; struct sockaddr_in addr; diff --git a/test/test-udp-multicast-join6.c b/test/test-udp-multicast-join6.c index 430e4e33..c7d62431 100644 --- a/test/test-udp-multicast-join6.c +++ b/test/test-udp-multicast-join6.c @@ -35,7 +35,8 @@ defined(__MVS__) || \ defined(__FreeBSD__) || \ defined(__NetBSD__) || \ - defined(__OpenBSD__) + defined(__OpenBSD__) || \ + defined(__QNX__) #define MULTICAST_ADDR "ff02::1%lo0" #define INTERFACE_ADDR "::1%lo0" #else @@ -167,6 +168,9 @@ static int can_ipv6_external(void) { TEST_IMPL(udp_multicast_join6) { +#if defined(QNX_IOPKT) + RETURN_SKIP("Test does not currently work in QNX"); +#endif int r; struct sockaddr_in6 addr; |