From cd54bbbd9ab195a829f965294b8f06d4e5092d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Thu, 29 Apr 2021 14:43:45 +0200 Subject: [PATCH] Add trampoline around iocompletionport_createthreads() On Windows, the iocompletionport_createthreads() didn't use isc_thread_create() to create new threads for processing IO, but just a simple CreateThread() function that completely circumvent the isc_trampoline mechanism to initialize global isc_tid_v. This lead to segmentation fault in isc_hp API because '-1' isn't valid index to the hazard pointer array. This commit changes the iocompletionport_createthreads() to use isc_thread_create() instead of CreateThread() to properly initialize isc_tid_v. --- lib/isc/win32/socket.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/isc/win32/socket.c b/lib/isc/win32/socket.c index 8964964102..cf101189f8 100644 --- a/lib/isc/win32/socket.c +++ b/lib/isc/win32/socket.c @@ -337,7 +337,6 @@ struct isc_socketmgr { HANDLE hIoCompletionPort; int maxIOCPThreads; HANDLE hIOCPThreads[MAX_IOCPTHREADS]; - DWORD dwIOCPThreadIds[MAX_IOCPTHREADS]; size_t maxudp; /* @@ -500,15 +499,8 @@ iocompletionport_createthreads(int total_threads, isc_socketmgr_t *manager) { * We need at least one */ for (i = 0; i < total_threads; i++) { - manager->hIOCPThreads[i] = - CreateThread(NULL, 0, SocketIoThread, manager, 0, - &manager->dwIOCPThreadIds[i]); - if (manager->hIOCPThreads[i] == NULL) { - errval = GetLastError(); - strerror_r(errval, strbuf, sizeof(strbuf)); - FATAL_ERROR(__FILE__, __LINE__, - "Can't create IOCP thread: %s", strbuf); - } + isc_thread_create(SocketIoThread, manager, + &manager->hIOCPThreads[i]); } }