dllmain: exclude from Cygwin builds

On Cygwin, it is unsafe to call POSIX functions from DllMain, which
OPENSSL_thread_stop does.  Additionally, it should be unnecessary as
OpenSSL uses pthread_key_create to register a thread destructor to do
thread cleanup in a POSIX way.

Reported-by: Yuyi Wang

Ref: https://cygwin.com/pipermail/cygwin/2025-June/258235.html

Fixes #17262
Closes https://github.com/curl/curl/pull/17528
This commit is contained in:
Jeremy Drake 2025-06-03 10:35:46 -07:00 committed by Jay Satiro
parent f1e1c8b98a
commit 7a30481760
4 changed files with 3 additions and 29 deletions

View File

@ -637,7 +637,6 @@ curl_cv_cygwin='no'
case $host_os in
cygwin*|msys*) curl_cv_cygwin='yes';;
esac
AM_CONDITIONAL(DOING_CYGWIN, test "x$curl_cv_cygwin" = xyes)
AM_CONDITIONAL([HAVE_WINDRES],
[test "$curl_cv_native_windows" = "yes" && test -n "${RC}"])

View File

@ -179,15 +179,8 @@ if(BUILD_SHARED_LIBS)
list(APPEND libcurl_export ${LIB_SHARED})
add_library(${LIB_SHARED} SHARED ${LIB_SOURCE})
add_library(${PROJECT_NAME}::${LIB_SHARED} ALIAS ${LIB_SHARED})
if(WIN32 OR CYGWIN)
if(CYGWIN)
# For Cygwin always compile dllmain.c as a separate unit since it
# includes windows.h, which should not be included in other units.
set_source_files_properties("dllmain.c" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
endif()
set_property(TARGET ${LIB_SHARED} APPEND PROPERTY SOURCES "dllmain.c")
endif()
if(WIN32)
set_property(TARGET ${LIB_SHARED} APPEND PROPERTY SOURCES "dllmain.c")
set_property(TARGET ${LIB_SHARED} APPEND PROPERTY SOURCES "libcurl.rc")
if(CURL_HIDES_PRIVATE_SYMBOLS)
set_property(TARGET ${LIB_SHARED} APPEND PROPERTY SOURCES "${PROJECT_SOURCE_DIR}/lib/libcurl.def")

View File

@ -74,10 +74,6 @@ include Makefile.inc
if DOING_NATIVE_WINDOWS
CSOURCES += dllmain.c
else
if DOING_CYGWIN
CSOURCES += dllmain.c
endif
endif
if USE_UNITY
@ -89,11 +85,6 @@ if CURLDEBUG
# applying to it.
curl_EXCLUDE += memdebug.c
endif
# For Cygwin always compile dllmain.c as a separate unit since it
# includes windows.h, which should not be included in other units.
if DOING_CYGWIN
curl_EXCLUDE += dllmain.c
endif
libcurl_unity.c: $(top_srcdir)/scripts/mk-unity.pl $(CSOURCES)
@PERL@ $(top_srcdir)/scripts/mk-unity.pl $(srcdir) $(CSOURCES) --exclude $(curl_EXCLUDE) > libcurl_unity.c

View File

@ -28,22 +28,13 @@
#include <openssl/crypto.h>
#endif
/* The fourth-to-last include */
#ifdef __CYGWIN__
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#ifdef _WIN32
#undef _WIN32
#endif
#endif
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
#include "curl_memory.h"
#include "memdebug.h"
/* DllMain() must only be defined for Windows and Cygwin DLL builds. */
#if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(CURL_STATICLIB)
/* DllMain() must only be defined for Windows DLL builds. */
#if defined(_WIN32) && !defined(CURL_STATICLIB)
#if defined(USE_OPENSSL) && \
!defined(OPENSSL_IS_AWSLC) && \