1 From efebf4d4f882a57a98a0653d21d543cd4132d23d Mon Sep 17 00:00:00 2001
2 From: Palo Markovic <pavol.markovic@kompiler.info>
3 Date: Sat, 18 Mar 2017 16:37:02 +1300
4 Subject: [PATCH] macOS: Fixed crash on 10.8 caused by missing connectx()
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
10 The connectx() function call appeared in Darwin 15.0.0
11 That covers OS X 10.11, iOS 9 and tvOS 9.
13 Because connectx is not declared with weak_import attribute it’s not possible
14 to build libcurl on OS X 10.11 and later and target systems which don’t have
15 _connectx symbol declared in libsystem_kernel.dylib (i.e. OS 10.8 and earlier).
17 Solution is to use connectx only on platforms that officially support it
18 i.e. by defining CFLAGS="-mmacosx-version-min=10.11" in configure step.
20 Note: It is possible to conditionally use connectx() in libcurl targeting
21 range of systems based on availability determined during runtime using dlsym().
23 [Bug: https://github.com/curl/curl/issues/1330]
26 lib/curl_setup.h | 16 ++++++++++++++++
28 3 files changed, 18 insertions(+), 2 deletions(-)
30 diff --git a/lib/connect.c b/lib/connect.c
31 index 197eff242f..33251914b8 100644
34 @@ -1075,7 +1075,7 @@ static CURLcode singleipconnect(struct connectdata *conn,
35 /* Connect TCP sockets, bind UDP */
36 if(!isconnected && (conn->socktype == SOCK_STREAM)) {
37 if(conn->bits.tcp_fastopen) {
38 -#if defined(CONNECT_DATA_IDEMPOTENT) /* OS X */
39 +#if defined(HAVE_DARWIN_CONNECTX) /* Darwin */
40 sa_endpoints_t endpoints;
41 endpoints.sae_srcif = 0;
42 endpoints.sae_srcaddr = NULL;
43 diff --git a/lib/curl_setup.h b/lib/curl_setup.h
44 index 0fe3633ec7..8643e1fd28 100644
45 --- a/lib/curl_setup.h
46 +++ b/lib/curl_setup.h
47 @@ -762,4 +762,20 @@ endings either CRLF or LF so 't' is appropriate.
51 +/* Detect Darwin connectx() function availability.
52 + * The connectx() function call appeared in Darwin 15.0.0
53 + * but it's not declared using availability attribute.
55 +#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
56 +# if (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
57 +# define HAVE_DARWIN_CONNECTX 1
59 +#elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
60 +# if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 90000)
61 +# define HAVE_DARWIN_CONNECTX 1
63 +#elif defined(CONNECT_DATA_IDEMPOTENT) /* Fallback for other Darwin OS */
64 +# define HAVE_DARWIN_CONNECTX 1
67 #endif /* HEADER_CURL_SETUP_H */
68 diff --git a/lib/url.c b/lib/url.c
69 index 03feaa20f7..08fbe5132b 100644
72 @@ -2834,7 +2834,7 @@ CURLcode Curl_setopt(struct Curl_easy *data, CURLoption option,
73 data->set.tcp_keepintvl = va_arg(param, long);
75 case CURLOPT_TCP_FASTOPEN:
76 -#if defined(CONNECT_DATA_IDEMPOTENT) || defined(MSG_FASTOPEN)
77 +#if defined(HAVE_DARWIN_CONNECTX) || defined(MSG_FASTOPEN)
78 data->set.tcp_fastopen = (0 != va_arg(param, long))?TRUE:FALSE;
80 result = CURLE_NOT_BUILT_IN;
81 From 45756a8a23967570da1390f9b1475c1db38a52d1 Mon Sep 17 00:00:00 2001
82 From: Palo Markovic <pavol.markovic@kompiler.info>
83 Date: Sat, 25 Mar 2017 13:20:51 +1300
84 Subject: [PATCH] macOS: moved connectx check to configuration phase
87 acinclude.m4 | 40 ++++++++++++++++++++++++++++++++++++++++
90 lib/curl_setup.h | 16 ----------------
92 5 files changed, 43 insertions(+), 18 deletions(-)
94 diff --git a/acinclude.m4 b/acinclude.m4
95 index 2abae8d8ad..769e67c510 100644
98 @@ -3243,3 +3243,43 @@ AC_DEFUN([CURL_MAC_CFLAGS], [
104 +dnl CURL_CHECK_FUNC_CONNECTX
106 +dnl Check if connectx() function is present.
107 +dnl The connectx() function call appeared in Darwin 15.0.0
108 +dnl but it's not declared using availability attribute.
109 +dnl Additionally _connectx symbol is part of OS X 10.9/10.10
110 +dnl system lib but does not have specified functionality.
113 +AC_DEFUN([CURL_CHECK_FUNC_CONNECTX], [
114 + AC_REQUIRE([CURL_MAC_CFLAGS])dnl
115 + AC_CHECK_FUNCS([connectx])
116 + AC_MSG_CHECKING([if connectx is available in deployment target])
118 + [AC_LANG_PROGRAM([[
119 +#if defined(HAVE_CONNECTX)
120 +# include <Availability.h>
121 +# if defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
122 +# if (__MAC_OS_X_VERSION_MIN_REQUIRED < 101100)
123 +# error Function requires deployment target OS X 10.11 or later
125 +# elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
126 +# if (__IPHONE_OS_VERSION_MIN_REQUIRED < 90000)
127 +# error Function requires deployment target iOS 9.0 or later
131 +# error Function not present in the headers
135 + AC_DEFINE(HAVE_VALID_CONNECTX, 1,
136 + [Set to 1 if connectx() function have specified functionality.])
137 + AC_MSG_RESULT([yes])
139 + [AC_MSG_RESULT([no])]
142 diff --git a/configure.ac b/configure.ac
143 index abd0def369..a3930447c3 100644
146 @@ -3226,6 +3226,7 @@ CURL_CHECK_FUNC_BASENAME
147 CURL_CHECK_FUNC_CLOSESOCKET
148 CURL_CHECK_FUNC_CLOSESOCKET_CAMEL
149 CURL_CHECK_FUNC_CONNECT
150 +CURL_CHECK_FUNC_CONNECTX
151 CURL_CHECK_FUNC_FCNTL
152 CURL_CHECK_FUNC_FDOPEN
153 CURL_CHECK_FUNC_FREEADDRINFO
154 diff --git a/lib/connect.c b/lib/connect.c
155 index 33251914b8..8c5e45aea5 100644
158 @@ -1075,7 +1075,7 @@ static CURLcode singleipconnect(struct connectdata *conn,
159 /* Connect TCP sockets, bind UDP */
160 if(!isconnected && (conn->socktype == SOCK_STREAM)) {
161 if(conn->bits.tcp_fastopen) {
162 -#if defined(HAVE_DARWIN_CONNECTX) /* Darwin */
163 +#if defined(HAVE_VALID_CONNECTX) /* Darwin */
164 sa_endpoints_t endpoints;
165 endpoints.sae_srcif = 0;
166 endpoints.sae_srcaddr = NULL;
167 diff --git a/lib/curl_setup.h b/lib/curl_setup.h
168 index 8643e1fd28..0fe3633ec7 100644
169 --- a/lib/curl_setup.h
170 +++ b/lib/curl_setup.h
171 @@ -762,20 +762,4 @@ endings either CRLF or LF so 't' is appropriate.
175 -/* Detect Darwin connectx() function availability.
176 - * The connectx() function call appeared in Darwin 15.0.0
177 - * but it's not declared using availability attribute.
179 -#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
180 -# if (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
181 -# define HAVE_DARWIN_CONNECTX 1
183 -#elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
184 -# if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 90000)
185 -# define HAVE_DARWIN_CONNECTX 1
187 -#elif defined(CONNECT_DATA_IDEMPOTENT) /* Fallback for other Darwin OS */
188 -# define HAVE_DARWIN_CONNECTX 1
191 #endif /* HEADER_CURL_SETUP_H */
192 diff --git a/lib/url.c b/lib/url.c
193 index 08fbe5132b..7160ae041d 100644
196 @@ -2834,7 +2834,7 @@ CURLcode Curl_setopt(struct Curl_easy *data, CURLoption option,
197 data->set.tcp_keepintvl = va_arg(param, long);
199 case CURLOPT_TCP_FASTOPEN:
200 -#if defined(HAVE_DARWIN_CONNECTX) || defined(MSG_FASTOPEN)
201 +#if defined(HAVE_VALID_CONNECTX) || defined(MSG_FASTOPEN)
202 data->set.tcp_fastopen = (0 != va_arg(param, long))?TRUE:FALSE;
204 result = CURLE_NOT_BUILT_IN;
205 From 113088ac81edbb9d51582a114d006bf60e3e6a87 Mon Sep 17 00:00:00 2001
206 From: Palo Markovic <pavol.markovic@kompiler.info>
207 Date: Wed, 5 Apr 2017 06:04:42 +1200
208 Subject: [PATCH] macOS: added connectx check for cmake
211 CMake/CurlTests.c | 18 ++++++++++++++++++
212 CMakeLists.txt | 9 +++++++++
213 lib/curl_config.h.cmake | 6 ++++++
214 3 files changed, 33 insertions(+)
216 diff --git a/CMake/CurlTests.c b/CMake/CurlTests.c
217 index bc36c8ef7d..7077059f9c 100644
218 --- a/CMake/CurlTests.c
219 +++ b/CMake/CurlTests.c
220 @@ -533,3 +533,21 @@ main() {
224 +#ifdef HAVE_VALID_CONNECTX
225 +# include <Availability.h>
226 +# include <sys/socket.h>
227 +# if defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
228 +# if (__MAC_OS_X_VERSION_MIN_REQUIRED < 101100)
229 +# error Function requires deployment target OS X 10.11 or later
231 +# elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
232 +# if (__IPHONE_OS_VERSION_MIN_REQUIRED < 90000)
233 +# error Function requires deployment target iOS 9.0 or later
238 + connectx(0, 0, 0, 0, 0, 0, 0, 0);
242 diff --git a/CMakeLists.txt b/CMakeLists.txt
243 index 8390c38c99..ab8be51ebc 100644
246 @@ -849,6 +849,15 @@ check_symbol_exists(fcntl "${CURL_INCLUDES}" HAVE_FCNTL)
247 check_symbol_exists(ioctl "${CURL_INCLUDES}" HAVE_IOCTL)
248 check_symbol_exists(setsockopt "${CURL_INCLUDES}" HAVE_SETSOCKOPT)
250 +# The connectx() function call appeared in Darwin 15.0.0
251 +# but it's not declared using availability attribute.
252 +# Additionally _connectx symbol is part of OS X 10.9/10.10
253 +# system lib but does not have specified functionality.
254 +check_symbol_exists(connectx "${CURL_INCLUDES}" HAVE_CONNECTX)
256 + curl_internal_test_run(HAVE_VALID_CONNECTX)
257 +endif(HAVE_CONNECTX)
259 # symbol exists in win32, but function does not.
260 check_function_exists(inet_pton HAVE_INET_PTON)
262 diff --git a/lib/curl_config.h.cmake b/lib/curl_config.h.cmake
263 index 9fcdd97f98..6fc4415a8d 100644
264 --- a/lib/curl_config.h.cmake
265 +++ b/lib/curl_config.h.cmake
267 /* Define to 1 if bool is an available type. */
268 #cmakedefine HAVE_BOOL_T 1
270 +/* Define to 1 if you have the connectx function. */
271 +#cmakedefine HAVE_CONNECTX 1
273 /* Define to 1 if you have the clock_gettime function and monotonic timer. */
274 #cmakedefine HAVE_CLOCK_GETTIME_MONOTONIC 1
277 /* Define to 1 if you have the <utime.h> header file. */
278 #cmakedefine HAVE_UTIME_H 1
280 +/* Define to 1 if you have valid connectx function. */
281 +#cmakedefine HAVE_VALID_CONNECTX 1
283 /* Define to 1 if compiler supports C99 variadic macro style. */
284 #cmakedefine HAVE_VARIADIC_MACROS_C99 1