Skip to content

Commit dc41ddc

Browse files
TingDaoKgraebm
andauthored
Use s2n_cleanup_thread() and path (#682)
Co-authored-by: Michael Graeb <graebm@amazon.com>
1 parent 9e1bb08 commit dc41ddc

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

CMakeLists.txt

+15-4
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,21 @@ if (BYO_CRYPTO)
152152
endif()
153153

154154
if (USE_S2N)
155-
file(GLOB AWS_IO_TLS_SRC
156-
"source/s2n/*.c"
157-
)
158-
aws_use_package(s2n)
155+
file(GLOB AWS_IO_TLS_SRC
156+
"source/s2n/*.c"
157+
)
158+
# Prefer find_package() because it's the normal CMake way to do dependencies.
159+
# But fall back on aws_use_package() because some projects still need to do an IN_SOURCE_BUILD of S2N.
160+
# (e.g. aws-crt-java until this is resolved: https://github.com/awslabs/aws-crt-java/pull/817)
161+
find_package(s2n QUIET)
162+
163+
if (s2n_FOUND)
164+
list(APPEND DEP_AWS_LIBS AWS::s2n)
165+
else()
166+
# Set flag to use in-source path to <s2n/unstable/*.h> headers if we do an IN_SOURCE_BUILD.
167+
aws_use_package(s2n)
168+
add_definitions(-DAWS_S2N_INSOURCE_PATH)
169+
endif()
159170
endif()
160171

161172
file(GLOB IO_HEADERS

source/s2n/s2n_tls_channel_handler.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@
2020
#include <aws/common/task_scheduler.h>
2121
#include <aws/common/thread.h>
2222

23+
#include <s2n.h>
24+
#ifdef AWS_S2N_INSOURCE_PATH
25+
# include <api/unstable/cleanup.h>
26+
#else
27+
# include <s2n/unstable/cleanup.h>
28+
#endif
29+
2330
#include <errno.h>
2431
#include <inttypes.h>
2532
#include <math.h>
26-
#include <s2n.h>
2733
#include <stdio.h>
2834
#include <stdlib.h>
2935

@@ -1247,7 +1253,7 @@ static struct aws_event_loop_local_object s_tl_cleanup_object = {
12471253
static void s_aws_cleanup_s2n_thread_local_state(void *user_data) {
12481254
(void)user_data;
12491255

1250-
s2n_cleanup();
1256+
s2n_cleanup_thread();
12511257
}
12521258

12531259
/* s2n allocates thread-local data structures. We need to clean these up when the event loop's thread exits. */

0 commit comments

Comments
 (0)