From 78bb46e678e801a2c18819739960f36062d4ec6e Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Tue, 26 May 2020 18:34:18 +0200 Subject: [PATCH 01/14] port,sock: minor tweaks to 'alloc()' and 'free()' functions --- src/port.c | 6 +++--- src/sock.c | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/port.c b/src/port.c index 7dd6eee..2980b80 100644 --- a/src/port.c +++ b/src/port.c @@ -28,7 +28,7 @@ typedef struct port_state { size_t active_poll_count; } port_state_t; -static port_state_t* port__alloc(void) { +static inline port_state_t* port__alloc(void) { port_state_t* port_state = malloc(sizeof *port_state); if (port_state == NULL) return_set_error(NULL, ERROR_NOT_ENOUGH_MEMORY); @@ -36,12 +36,12 @@ static port_state_t* port__alloc(void) { return port_state; } -static void port__free(port_state_t* port) { +static inline void port__free(port_state_t* port) { assert(port != NULL); free(port); } -static HANDLE port__create_iocp(void) { +static inline HANDLE port__create_iocp(void) { HANDLE iocp_handle = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0); if (iocp_handle == NULL) diff --git a/src/sock.c b/src/sock.c index 342a1a8..b26d7d3 100644 --- a/src/sock.c +++ b/src/sock.c @@ -47,6 +47,7 @@ static inline sock_state_t* sock__alloc(void) { } static inline void sock__free(sock_state_t* sock_state) { + assert(sock_state != NULL); free(sock_state); } From 07af653b1759f93d5992861c2f4491df263ca9cf Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Tue, 26 May 2020 18:42:36 +0200 Subject: [PATCH 02/14] src: rename 'afd_helper' to the more descriptive 'afd_device' --- src/afd.c | 32 ++++++++++++++++---------------- src/afd.h | 8 ++++---- src/poll-group.c | 10 +++++----- src/poll-group.h | 2 +- src/sock.c | 4 ++-- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/afd.c b/src/afd.c index 7373938..0a353a5 100644 --- a/src/afd.c +++ b/src/afd.c @@ -9,24 +9,24 @@ #define IOCTL_AFD_POLL 0x00012024 -static UNICODE_STRING afd__helper_name = +static UNICODE_STRING afd__device_name = RTL_CONSTANT_STRING(L"\\Device\\Afd\\Wepoll"); -static OBJECT_ATTRIBUTES afd__helper_attributes = - RTL_CONSTANT_OBJECT_ATTRIBUTES(&afd__helper_name, 0); +static OBJECT_ATTRIBUTES afd__device_attributes = + RTL_CONSTANT_OBJECT_ATTRIBUTES(&afd__device_name, 0); -int afd_create_helper_handle(HANDLE iocp_handle, - HANDLE* afd_helper_handle_out) { - HANDLE afd_helper_handle; +int afd_create_device_handle(HANDLE iocp_handle, + HANDLE* afd_device_handle_out) { + HANDLE afd_device_handle; IO_STATUS_BLOCK iosb; NTSTATUS status; /* By opening \Device\Afd without specifying any extended attributes, we'll * get a handle that lets us talk to the AFD driver, but that doesn't have an * associated endpoint (so it's not a socket). */ - status = NtCreateFile(&afd_helper_handle, + status = NtCreateFile(&afd_device_handle, SYNCHRONIZE, - &afd__helper_attributes, + &afd__device_attributes, &iosb, NULL, 0, @@ -38,22 +38,22 @@ int afd_create_helper_handle(HANDLE iocp_handle, if (status != STATUS_SUCCESS) return_set_error(-1, RtlNtStatusToDosError(status)); - if (CreateIoCompletionPort(afd_helper_handle, iocp_handle, 0, 0) == NULL) + if (CreateIoCompletionPort(afd_device_handle, iocp_handle, 0, 0) == NULL) goto error; - if (!SetFileCompletionNotificationModes(afd_helper_handle, + if (!SetFileCompletionNotificationModes(afd_device_handle, FILE_SKIP_SET_EVENT_ON_HANDLE)) goto error; - *afd_helper_handle_out = afd_helper_handle; + *afd_device_handle_out = afd_device_handle; return 0; error: - CloseHandle(afd_helper_handle); + CloseHandle(afd_device_handle); return_map_error(-1); } -int afd_poll(HANDLE afd_helper_handle, +int afd_poll(HANDLE afd_device_handle, AFD_POLL_INFO* poll_info, IO_STATUS_BLOCK* io_status_block) { NTSTATUS status; @@ -62,7 +62,7 @@ int afd_poll(HANDLE afd_helper_handle, assert(io_status_block != NULL); io_status_block->Status = STATUS_PENDING; - status = NtDeviceIoControlFile(afd_helper_handle, + status = NtDeviceIoControlFile(afd_device_handle, NULL, NULL, io_status_block, @@ -81,7 +81,7 @@ int afd_poll(HANDLE afd_helper_handle, return_set_error(-1, RtlNtStatusToDosError(status)); } -int afd_cancel_poll(HANDLE afd_helper_handle, +int afd_cancel_poll(HANDLE afd_device_handle, IO_STATUS_BLOCK* io_status_block) { NTSTATUS cancel_status; IO_STATUS_BLOCK cancel_iosb; @@ -92,7 +92,7 @@ int afd_cancel_poll(HANDLE afd_helper_handle, return 0; cancel_status = - NtCancelIoFileEx(afd_helper_handle, io_status_block, &cancel_iosb); + NtCancelIoFileEx(afd_device_handle, io_status_block, &cancel_iosb); /* NtCancelIoFileEx() may return STATUS_NOT_FOUND if the operation completed * just before calling NtCancelIoFileEx(). This is not an error. */ diff --git a/src/afd.h b/src/afd.h index 93dde65..af90219 100644 --- a/src/afd.h +++ b/src/afd.h @@ -29,13 +29,13 @@ typedef struct _AFD_POLL_INFO { AFD_POLL_HANDLE_INFO Handles[1]; } AFD_POLL_INFO, *PAFD_POLL_INFO; -WEPOLL_INTERNAL int afd_create_helper_handle(HANDLE iocp_handle, - HANDLE* afd_helper_handle_out); +WEPOLL_INTERNAL int afd_create_device_handle(HANDLE iocp_handle, + HANDLE* afd_device_handle_out); -WEPOLL_INTERNAL int afd_poll(HANDLE afd_helper_handle, +WEPOLL_INTERNAL int afd_poll(HANDLE afd_device_handle, AFD_POLL_INFO* poll_info, IO_STATUS_BLOCK* io_status_block); -WEPOLL_INTERNAL int afd_cancel_poll(HANDLE afd_helper_handle, +WEPOLL_INTERNAL int afd_cancel_poll(HANDLE afd_device_handle, IO_STATUS_BLOCK* io_status_block); #endif /* WEPOLL_AFD_H_ */ diff --git a/src/poll-group.c b/src/poll-group.c index 083400a..2fe8299 100644 --- a/src/poll-group.c +++ b/src/poll-group.c @@ -15,7 +15,7 @@ static const size_t POLL_GROUP__MAX_GROUP_SIZE = 32; typedef struct poll_group { port_state_t* port_state; queue_node_t queue_node; - HANDLE afd_helper_handle; + HANDLE afd_device_handle; size_t group_size; } poll_group_t; @@ -32,7 +32,7 @@ static poll_group_t* poll_group__new(port_state_t* port_state) { queue_node_init(&poll_group->queue_node); poll_group->port_state = port_state; - if (afd_create_helper_handle(iocp_handle, &poll_group->afd_helper_handle) < + if (afd_create_device_handle(iocp_handle, &poll_group->afd_device_handle) < 0) { free(poll_group); return NULL; @@ -45,7 +45,7 @@ static poll_group_t* poll_group__new(port_state_t* port_state) { void poll_group_delete(poll_group_t* poll_group) { assert(poll_group->group_size == 0); - CloseHandle(poll_group->afd_helper_handle); + CloseHandle(poll_group->afd_device_handle); queue_remove(&poll_group->queue_node); free(poll_group); } @@ -54,8 +54,8 @@ poll_group_t* poll_group_from_queue_node(queue_node_t* queue_node) { return container_of(queue_node, poll_group_t, queue_node); } -HANDLE poll_group_get_afd_helper_handle(poll_group_t* poll_group) { - return poll_group->afd_helper_handle; +HANDLE poll_group_get_afd_device_handle(poll_group_t* poll_group) { + return poll_group->afd_device_handle; } poll_group_t* poll_group_acquire(port_state_t* port_state) { diff --git a/src/poll-group.h b/src/poll-group.h index 9aa97f8..dfc5428 100644 --- a/src/poll-group.h +++ b/src/poll-group.h @@ -16,6 +16,6 @@ WEPOLL_INTERNAL void poll_group_delete(poll_group_t* poll_group); WEPOLL_INTERNAL poll_group_t* poll_group_from_queue_node( queue_node_t* queue_node); WEPOLL_INTERNAL HANDLE - poll_group_get_afd_helper_handle(poll_group_t* poll_group); + poll_group_get_afd_device_handle(poll_group_t* poll_group); #endif /* WEPOLL_POLL_GROUP_H_ */ diff --git a/src/sock.c b/src/sock.c index b26d7d3..687b080 100644 --- a/src/sock.c +++ b/src/sock.c @@ -54,7 +54,7 @@ static inline void sock__free(sock_state_t* sock_state) { static int sock__cancel_poll(sock_state_t* sock_state) { assert(sock_state->poll_status == SOCK__POLL_PENDING); - if (afd_cancel_poll(poll_group_get_afd_helper_handle(sock_state->poll_group), + if (afd_cancel_poll(poll_group_get_afd_device_handle(sock_state->poll_group), &sock_state->io_status_block) < 0) return -1; @@ -233,7 +233,7 @@ int sock_update(port_state_t* port_state, sock_state_t* sock_state) { sock_state->poll_info.Handles[0].Events = sock__epoll_events_to_afd_events(sock_state->user_events); - if (afd_poll(poll_group_get_afd_helper_handle(sock_state->poll_group), + if (afd_poll(poll_group_get_afd_device_handle(sock_state->poll_group), &sock_state->poll_info, &sock_state->io_status_block) < 0) { switch (GetLastError()) { From f8a135487de7eb79bc6d8eee270cbd81bd69fbbc Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Tue, 26 May 2020 18:27:08 +0200 Subject: [PATCH 03/14] src: improve code comments --- src/sock.c | 2 +- src/ws.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/sock.c b/src/sock.c index 687b080..d40d28c 100644 --- a/src/sock.c +++ b/src/sock.c @@ -146,7 +146,7 @@ int sock_set_event(port_state_t* port_state, const struct epoll_event* ev) { /* EPOLLERR and EPOLLHUP are always reported, even when not requested by the * caller. However they are disabled after a event has been reported for a - * socket for which the EPOLLONESHOT flag as set. */ + * socket for which the EPOLLONESHOT flag was set. */ uint32_t events = ev->events | EPOLLERR | EPOLLHUP; sock_state->user_events = events; diff --git a/src/ws.c b/src/ws.c index 2a97c96..8a3428e 100644 --- a/src/ws.c +++ b/src/ws.c @@ -60,10 +60,10 @@ SOCKET ws_get_base_socket(SOCKET socket) { * never intercept the `SIO_BASE_HANDLE` ioctl [1], Komodia based LSPs do * so anyway, breaking it, with the apparent intention of preventing LSP * bypass [2]. Fortunately they don't handle `SIO_BSP_HANDLE_POLL`, which - * we can use to obtain the socket associated with the next protocol chain - * entry. If this succeeds, loop around and call `SIO_BASE_HANDLE` again - * with the retrieved BSP socket to be sure that we actually got all the - * way to the base. + * will at least let us obtain the socket associated with the next winsock + * protocol chain entry. If this succeeds, loop around and call + * `SIO_BASE_HANDLE` again with the returned BSP socket, to make sure that + * we unwrap all layers and retrieve the actual base socket. * [1] https://docs.microsoft.com/en-us/windows/win32/winsock/winsock-ioctls * [2] https://www.komodia.com/newwiki/index.php?title=Komodia%27s_Redirector_bug_fixes#Version_2.2.2.6 */ From 2ce1a56c40564c7e99f94b23d027e29c56695172 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Tue, 26 May 2020 18:39:55 +0200 Subject: [PATCH 04/14] config: rename macro 'WEPOLL_INTERNAL_VAR' to 'WEPOLL_INTERNAL_EXTERN' The old name was not really appropriate; this attribute should only be used on variable declarations, while the definition of the same variable needs to be tagged with 'WEPOLL_INTERNAL'. --- config/internal/bundle/config-internal.h | 2 +- config/internal/default/config-internal.h | 2 +- src/nt.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/internal/bundle/config-internal.h b/config/internal/bundle/config-internal.h index d14707d..88abc63 100644 --- a/config/internal/bundle/config-internal.h +++ b/config/internal/bundle/config-internal.h @@ -1,2 +1,2 @@ #define WEPOLL_INTERNAL static -#define WEPOLL_INTERNAL_VAR static +#define WEPOLL_INTERNAL_EXTERN static diff --git a/config/internal/default/config-internal.h b/config/internal/default/config-internal.h index 8d58100..e8adda2 100644 --- a/config/internal/default/config-internal.h +++ b/config/internal/default/config-internal.h @@ -1,2 +1,2 @@ #define WEPOLL_INTERNAL -#define WEPOLL_INTERNAL_VAR extern +#define WEPOLL_INTERNAL_EXTERN extern diff --git a/src/nt.h b/src/nt.h index 8c31882..4e66548 100644 --- a/src/nt.h +++ b/src/nt.h @@ -132,7 +132,7 @@ typedef struct _OBJECT_ATTRIBUTES { X(ULONG, WINAPI, RtlNtStatusToDosError, (NTSTATUS Status)) #define X(return_type, attributes, name, parameters) \ - WEPOLL_INTERNAL_VAR return_type(attributes* name) parameters; + WEPOLL_INTERNAL_EXTERN return_type(attributes* name) parameters; NT_NTDLL_IMPORT_LIST(X) #undef X From e9fa25980bac0ca39f38127c9c398064ad5297cd Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Tue, 26 May 2020 18:51:52 +0200 Subject: [PATCH 05/14] config: re-enable overriding 'WEPOLL_EXPORT' when compiling bundle This possibility got inadvertently removed in the big config refactor (3ad20d7), which made building a shared library from the bundled source distribution (as is done by e.g. vcpkg) impossible. --- CMakeLists.txt | 7 ++++--- config/external/bundle/config-external.h | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 config/external/bundle/config-external.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b5e6be8..dfc13b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ add_definitions(-D_CRT_HAS_CXX17=0) file(GLOB SOURCES_DOC LICENSE *.md) file(GLOB_RECURSE SOURCES_CONFIG config/*.h) file(GLOB SOURCES_CONFIG_EXTERNAL_DLLEXPORT config/external/dllexport/*.h) +file(GLOB SOURCES_CONFIG_EXTERNAL_BUNDLE config/external/bundle/*.h) file(GLOB SOURCES_CONFIG_EXTERNAL_STATIC config/external/static/*.h) file(GLOB SOURCES_CONFIG_INTERNAL_BUNDLE config/internal/bundle/*.h) file(GLOB SOURCES_CONFIG_INTERNAL_DEFAULT config/internal/default/*.h) @@ -84,8 +85,8 @@ endfunction() set(BUNDLE_DIST_TARGET "dist") set(BUNDLE_DIST_HEADER "${DIST_DIR}/${LIB_NAME}.h") set(BUNDLE_DIST_SOURCE "${DIST_DIR}/${LIB_NAME}.c") -bundle_header(OUTPUT ${BUNDLE_DIST_HEADER} EXTERNAL_CONFIG static) -bundle_source(OUTPUT ${BUNDLE_DIST_SOURCE} EXTERNAL_CONFIG static) +bundle_header(OUTPUT ${BUNDLE_DIST_HEADER} EXTERNAL_CONFIG bundle) +bundle_source(OUTPUT ${BUNDLE_DIST_SOURCE} EXTERNAL_CONFIG bundle) set_source_files_properties( ${BUNDLE_DIST_HEADER} ${BUNDLE_DIST_SOURCE} PROPERTIES GENERATED TRUE @@ -93,7 +94,7 @@ set_source_files_properties( add_custom_target( ${BUNDLE_DIST_TARGET} DEPENDS ${BUNDLE_DIST_SOURCE} ${BUNDLE_DIST_HEADER} - SOURCES ${SOURCES_CONFIG_EXTERNAL_STATIC} ${SOURCES_CONFIG_INTERNAL_BUNDLE} + SOURCES ${SOURCES_CONFIG_EXTERNAL_BUNDLE} ${SOURCES_CONFIG_INTERNAL_BUNDLE} ${SOURCES_INCLUDE} ${SOURCES_SRC} ${SOURCES_DOC} ) add_custom_command( diff --git a/config/external/bundle/config-external.h b/config/external/bundle/config-external.h new file mode 100644 index 0000000..2b5d1a8 --- /dev/null +++ b/config/external/bundle/config-external.h @@ -0,0 +1,3 @@ +#ifndef WEPOLL_EXPORT +#define WEPOLL_EXPORT +#endif From 71e9ea666498b84c9cdea4041d7ad4102cc4821c Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Tue, 26 May 2020 19:05:02 +0200 Subject: [PATCH 06/14] tools/bundle: don't emit empty line when stripping 'clang-format on|off' comment --- tools/bundle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/bundle.js b/tools/bundle.js index 25e577b..8d4afec 100644 --- a/tools/bundle.js +++ b/tools/bundle.js @@ -156,7 +156,7 @@ restart: for (let lno = 0; lno < source.length; ) { } source = source - .map(line => line.replace(/\/\* clang-format (on|off) \*\//g, '')) + .filter(line => !/^\s*\/\* clang-format (on|off) \*\/\s*$/.test(line)) .map(line => line.replace(/\s+$/, '')) .join('\n') .replace(/\n{3,}/g, '\n\n') From f8325fba920f6f5c8830c19b438b26b0c930fcf6 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Tue, 26 May 2020 19:24:53 +0200 Subject: [PATCH 07/14] ci: don't dump the entire environment into the build log --- .appveyor.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 1d4550d..1fc57e5 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -103,9 +103,6 @@ clone_depth: 1 cache: - c:\lspinst -init: - - cmd: set - install: - ps: Install-Product node 10 - ps: >- From 4a7e05917f3d49e235c2426d9640fc4ba15ec512 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Wed, 3 Jun 2020 12:04:25 +0200 Subject: [PATCH 08/14] src: inline some small and single-caller functions --- src/port.c | 44 ++++++++++++++++++++++---------------------- src/sock.c | 2 +- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/port.c b/src/port.c index 2980b80..58dccc1 100644 --- a/src/port.c +++ b/src/port.c @@ -81,7 +81,7 @@ err1: return NULL; } -static int port__close_iocp(port_state_t* port_state) { +static inline int port__close_iocp(port_state_t* port_state) { HANDLE iocp_handle = port_state->iocp_handle; port_state->iocp_handle = NULL; @@ -150,15 +150,15 @@ static int port__update_events(port_state_t* port_state) { return 0; } -static void port__update_events_if_polling(port_state_t* port_state) { +static inline void port__update_events_if_polling(port_state_t* port_state) { if (port_state->active_poll_count > 0) port__update_events(port_state); } -static int port__feed_events(port_state_t* port_state, - struct epoll_event* epoll_events, - OVERLAPPED_ENTRY* iocp_events, - DWORD iocp_event_count) { +static inline int port__feed_events(port_state_t* port_state, + struct epoll_event* epoll_events, + OVERLAPPED_ENTRY* iocp_events, + DWORD iocp_event_count) { int epoll_event_count = 0; DWORD i; @@ -173,11 +173,11 @@ static int port__feed_events(port_state_t* port_state, return epoll_event_count; } -static int port__poll(port_state_t* port_state, - struct epoll_event* epoll_events, - OVERLAPPED_ENTRY* iocp_events, - DWORD maxevents, - DWORD timeout) { +static inline int port__poll(port_state_t* port_state, + struct epoll_event* epoll_events, + OVERLAPPED_ENTRY* iocp_events, + DWORD maxevents, + DWORD timeout) { DWORD completion_count; if (port__update_events(port_state) < 0) @@ -283,9 +283,9 @@ int port_wait(port_state_t* port_state, return -1; } -static int port__ctl_add(port_state_t* port_state, - SOCKET sock, - struct epoll_event* ev) { +static inline int port__ctl_add(port_state_t* port_state, + SOCKET sock, + struct epoll_event* ev) { sock_state_t* sock_state = sock_new(port_state, sock); if (sock_state == NULL) return -1; @@ -300,9 +300,9 @@ static int port__ctl_add(port_state_t* port_state, return 0; } -static int port__ctl_mod(port_state_t* port_state, - SOCKET sock, - struct epoll_event* ev) { +static inline int port__ctl_mod(port_state_t* port_state, + SOCKET sock, + struct epoll_event* ev) { sock_state_t* sock_state = port_find_socket(port_state, sock); if (sock_state == NULL) return -1; @@ -315,7 +315,7 @@ static int port__ctl_mod(port_state_t* port_state, return 0; } -static int port__ctl_del(port_state_t* port_state, SOCKET sock) { +static inline int port__ctl_del(port_state_t* port_state, SOCKET sock) { sock_state_t* sock_state = port_find_socket(port_state, sock); if (sock_state == NULL) return -1; @@ -325,10 +325,10 @@ static int port__ctl_del(port_state_t* port_state, SOCKET sock) { return 0; } -static int port__ctl_op(port_state_t* port_state, - int op, - SOCKET sock, - struct epoll_event* ev) { +static inline int port__ctl_op(port_state_t* port_state, + int op, + SOCKET sock, + struct epoll_event* ev) { switch (op) { case EPOLL_CTL_ADD: return port__ctl_add(port_state, sock, ev); diff --git a/src/sock.c b/src/sock.c index d40d28c..a12d287 100644 --- a/src/sock.c +++ b/src/sock.c @@ -51,7 +51,7 @@ static inline void sock__free(sock_state_t* sock_state) { free(sock_state); } -static int sock__cancel_poll(sock_state_t* sock_state) { +static inline int sock__cancel_poll(sock_state_t* sock_state) { assert(sock_state->poll_status == SOCK__POLL_PENDING); if (afd_cancel_poll(poll_group_get_afd_device_handle(sock_state->poll_group), From dcaa6606e035b1e939964db4610fc262cdb67755 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Thu, 4 Jun 2020 03:02:50 +0200 Subject: [PATCH 09/14] reflock: squelch clang warning about unused const var 'REFLOCK_DESTROY_MASK' It is used, except when assertions are disabled due to the 'NDEBUG' preprocessor variable being defined. --- src/reflock.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/reflock.c b/src/reflock.c index 98c73ca..ad579c9 100644 --- a/src/reflock.c +++ b/src/reflock.c @@ -49,6 +49,7 @@ void reflock_ref(reflock_t* reflock) { /* Verify that the counter didn't overflow and the lock isn't destroyed. */ assert((state & REFLOCK__DESTROY_MASK) == 0); unused_var(state); + unused_var(REFLOCK__DESTROY_MASK); } void reflock_unref(reflock_t* reflock) { @@ -56,6 +57,7 @@ void reflock_unref(reflock_t* reflock) { /* Verify that the lock was referenced and not already destroyed. */ assert((state & REFLOCK__DESTROY_MASK & ~REFLOCK__DESTROY) == 0); + unused_var(REFLOCK__DESTROY_MASK); if (state == REFLOCK__DESTROY) reflock__signal_event(reflock); From 1c549c3ab7f055ba25480fc9e36270828f20e1b5 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Sat, 20 Jun 2020 08:51:18 +0200 Subject: [PATCH 10/14] ci: upgrade node.js to v12.x LTS --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 1fc57e5..b6c499e 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -104,7 +104,7 @@ cache: - c:\lspinst install: - - ps: Install-Product node 10 + - ps: Install-Product node 12 - ps: >- if ($env:lsp_name) { if (-Not (Test-Path -Path "c:\lspinst\${env:lsp_name}.exe")) { From 98decd24e24cce08ab6cd199cb21ae32a1bbd157 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Tue, 9 Jun 2020 21:08:00 +0200 Subject: [PATCH 11/14] src: use '#define's instead of global variables for integer constants By doing this, it is no longer necessary to invoke `unused_var()` to squelch compiler warnings about unused variables that are used only in `assert()` calls. These `assert()` calls are removed by the preprocessor in release builds, which causes these warnings. --- src/poll-group.c | 2 +- src/reflock.c | 12 +++++------- src/sock.c | 6 +++--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/poll-group.c b/src/poll-group.c index 2fe8299..c0c260d 100644 --- a/src/poll-group.c +++ b/src/poll-group.c @@ -10,7 +10,7 @@ #include "util.h" #include "win.h" -static const size_t POLL_GROUP__MAX_GROUP_SIZE = 32; +#define POLL_GROUP__MAX_GROUP_SIZE 32 typedef struct poll_group { port_state_t* port_state; diff --git a/src/reflock.c b/src/reflock.c index ad579c9..60a96b5 100644 --- a/src/reflock.c +++ b/src/reflock.c @@ -8,11 +8,11 @@ #include "win.h" /* clang-format off */ -static const long REFLOCK__REF = (long) 0x00000001; -static const long REFLOCK__REF_MASK = (long) 0x0fffffff; -static const long REFLOCK__DESTROY = (long) 0x10000000; -static const long REFLOCK__DESTROY_MASK = (long) 0xf0000000; -static const long REFLOCK__POISON = (long) 0x300dead0; +#define REFLOCK__REF ((long) 0x00000001UL) +#define REFLOCK__REF_MASK ((long) 0x0fffffffUL) +#define REFLOCK__DESTROY ((long) 0x10000000UL) +#define REFLOCK__DESTROY_MASK ((long) 0xf0000000UL) +#define REFLOCK__POISON ((long) 0x300dead0UL) /* clang-format on */ static HANDLE reflock__keyed_event = NULL; @@ -49,7 +49,6 @@ void reflock_ref(reflock_t* reflock) { /* Verify that the counter didn't overflow and the lock isn't destroyed. */ assert((state & REFLOCK__DESTROY_MASK) == 0); unused_var(state); - unused_var(REFLOCK__DESTROY_MASK); } void reflock_unref(reflock_t* reflock) { @@ -57,7 +56,6 @@ void reflock_unref(reflock_t* reflock) { /* Verify that the lock was referenced and not already destroyed. */ assert((state & REFLOCK__DESTROY_MASK & ~REFLOCK__DESTROY) == 0); - unused_var(REFLOCK__DESTROY_MASK); if (state == REFLOCK__DESTROY) reflock__signal_event(reflock); diff --git a/src/sock.c b/src/sock.c index a12d287..c578d79 100644 --- a/src/sock.c +++ b/src/sock.c @@ -15,9 +15,9 @@ #include "wepoll.h" #include "ws.h" -static const uint32_t SOCK__KNOWN_EPOLL_EVENTS = - EPOLLIN | EPOLLPRI | EPOLLOUT | EPOLLERR | EPOLLHUP | EPOLLRDNORM | - EPOLLRDBAND | EPOLLWRNORM | EPOLLWRBAND | EPOLLMSG | EPOLLRDHUP; +#define SOCK__KNOWN_EPOLL_EVENTS \ + (EPOLLIN | EPOLLPRI | EPOLLOUT | EPOLLERR | EPOLLHUP | EPOLLRDNORM | \ + EPOLLRDBAND | EPOLLWRNORM | EPOLLWRBAND | EPOLLMSG | EPOLLRDHUP) typedef enum sock__poll_status { SOCK__POLL_IDLE = 0, From 990ab03d70031587190f230f98a2021807bf6b96 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Mon, 29 Jun 2020 02:31:22 +0200 Subject: [PATCH 12/14] ci: use msvc x64 toolset to build x64 targets --- .appveyor.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index b6c499e..b98802e 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -4,27 +4,27 @@ environment: matrix: - job: msvc-vs2013-x86 appveyor_build_worker_image: Visual Studio 2013 - cmake_options: -G "Visual Studio 12 2013" + cmake_options: -G "Visual Studio 12 2013" -A Win32 - job: msvc-vs2013-x64 appveyor_build_worker_image: Visual Studio 2013 - cmake_options: -G "Visual Studio 12 2013 Win64" + cmake_options: -G "Visual Studio 12 2013" -A x64 -T host=x64 - job: msvc-vs2015-x86 appveyor_build_worker_image: Visual Studio 2015 - cmake_options: -G "Visual Studio 14 2015" + cmake_options: -G "Visual Studio 14 2015" -A Win32 - job: msvc-vs2015-x64 appveyor_build_worker_image: Visual Studio 2015 - cmake_options: -G "Visual Studio 14 2015 Win64" + cmake_options: -G "Visual Studio 14 2015" -A x64 -T host=x64 - job: msvc-vs2017-x86 appveyor_build_worker_image: Visual Studio 2017 - cmake_options: -G "Visual Studio 15 2017" + cmake_options: -G "Visual Studio 15 2017" -A Win32 - job: msvc-vs2017-x64 appveyor_build_worker_image: Visual Studio 2017 - cmake_options: -G "Visual Studio 15 2017 Win64" + cmake_options: -G "Visual Studio 15 2017" -A x64 -T host=x64 - job: gcc-mingw-x86 appveyor_build_worker_image: Visual Studio 2015 @@ -72,25 +72,25 @@ environment: - job: msvc-vs2013-x86-lsp-ifs appveyor_build_worker_image: Visual Studio 2013 - cmake_options: -G "Visual Studio 12 2013" + cmake_options: -G "Visual Studio 12 2013" -A Win32 lsp_name: Proxifier lsp_installer: http://www.proxifier.com/download/ProxifierSetup.exe - job: msvc-vs2017-x64-lsp-ifs appveyor_build_worker_image: Visual Studio 2017 - cmake_options: -G "Visual Studio 15 2017 Win64" + cmake_options: -G "Visual Studio 15 2017" -A x64 -T host=x64 lsp_name: Proxifier lsp_installer: http://www.proxifier.com/download/ProxifierSetup.exe - job: msvc-vs2013-x86-lsp-nonifs appveyor_build_worker_image: Visual Studio 2013 - cmake_options: -G "Visual Studio 12 2013" + cmake_options: -G "Visual Studio 12 2013" -A Win32 lsp_name: PCTools lsp_installer: http://download.pctools.com/mirror/updates/9.0.0.2308-SDavfree-lite_en.exe - job: msvc-vs2017-x64-lsp-nonifs appveyor_build_worker_image: Visual Studio 2017 - cmake_options: -G "Visual Studio 15 2017 Win64" + cmake_options: -G "Visual Studio 15 2017" -A x64 -T host=x64 lsp_name: PCTools lsp_installer: http://download.pctools.com/mirror/updates/9.0.0.2308-SDavfree-lite_en.exe From 8ddde747041c8c4a3ed7dabbd2cfadaf733a2277 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Mon, 29 Jun 2020 02:33:56 +0200 Subject: [PATCH 13/14] ci: add Visual Studio 2019 x86 and x64 test jobs --- .appveyor.yml | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index b98802e..52d1d77 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -26,6 +26,14 @@ environment: appveyor_build_worker_image: Visual Studio 2017 cmake_options: -G "Visual Studio 15 2017" -A x64 -T host=x64 + - job: msvc-vs2019-x86 + appveyor_build_worker_image: Visual Studio 2019 + cmake_options: -G "Visual Studio 16 2019" -A Win32 + + - job: msvc-vs2019-x64 + appveyor_build_worker_image: Visual Studio 2019 + cmake_options: -G "Visual Studio 16 2019" -A x64 -T host=x64 + - job: gcc-mingw-x86 appveyor_build_worker_image: Visual Studio 2015 mingw_path: c:\msys64\mingw32\bin @@ -76,9 +84,9 @@ environment: lsp_name: Proxifier lsp_installer: http://www.proxifier.com/download/ProxifierSetup.exe - - job: msvc-vs2017-x64-lsp-ifs - appveyor_build_worker_image: Visual Studio 2017 - cmake_options: -G "Visual Studio 15 2017" -A x64 -T host=x64 + - job: msvc-vs2019-x64-lsp-ifs + appveyor_build_worker_image: Visual Studio 2019 + cmake_options: -G "Visual Studio 16 2019" -A x64 -T host=x64 lsp_name: Proxifier lsp_installer: http://www.proxifier.com/download/ProxifierSetup.exe @@ -88,9 +96,9 @@ environment: lsp_name: PCTools lsp_installer: http://download.pctools.com/mirror/updates/9.0.0.2308-SDavfree-lite_en.exe - - job: msvc-vs2017-x64-lsp-nonifs - appveyor_build_worker_image: Visual Studio 2017 - cmake_options: -G "Visual Studio 15 2017" -A x64 -T host=x64 + - job: msvc-vs2019-x64-lsp-nonifs + appveyor_build_worker_image: Visual Studio 2019 + cmake_options: -G "Visual Studio 16 2019" -A x64 -T host=x64 lsp_name: PCTools lsp_installer: http://download.pctools.com/mirror/updates/9.0.0.2308-SDavfree-lite_en.exe From e215682be2fb05fb579edf3a1c2f99fa85ee88a8 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Mon, 29 Jun 2020 01:03:11 +0200 Subject: [PATCH 14/14] win: use lower case file names when importing Windows SDK headers Although the header files included in the official Windows SDK have mixed case file names, MinGW opted to ship headers with entirely lower case names. Since the MinGW headers are often used when cross compiling Windows binaries on Linux hosts, and Linux treats paths as case sensitive by default, following the 'official' spelling breaks many cross build setups. Non-cross builds do not seem to be affected by using lower case file names, and Microsoft also does not seem particularly consistent in the way it spells header file names in e.g. documentation and sample code. Therefore, this patch makes wepoll use lower case file names when including Windows headers, regardless of whether MinGW or the official SDK is used. See also https://github.com/libevent/libevent/pull/1039 and https://github.com/stjepang/smol/issues/138. Closes: https://github.com/piscisaureus/wepoll/pull/19 --- src/win.h | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/src/win.h b/src/win.h index 0c3a223..ee01304 100644 --- a/src/win.h +++ b/src/win.h @@ -1,34 +1,29 @@ #ifndef WEPOLL_WIN_H_ #define WEPOLL_WIN_H_ -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif - -#ifdef __clang__ +#if defined(__clang__) #pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wnonportable-system-include-path" #pragma clang diagnostic ignored "-Wreserved-id-macro" -#endif - -#ifdef _WIN32_WINNT -#undef _WIN32_WINNT -#endif - -#define _WIN32_WINNT 0x0600 - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - -#ifndef __GNUC__ +#elif defined(_MSC_VER) #pragma warning(push, 1) #endif -#include -#include -#include +#undef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN -#ifndef __GNUC__ +#undef _WIN32_WINNT +#define _WIN32_WINNT 0x0600 + +/* clang-format off */ +#include +#include +#include +/* clang-format on */ + +#if defined(__clang__) +#pragma clang diagnostic pop +#elif defined(_MSC_VER) #pragma warning(pop) #endif