Skip to content

Commit

Permalink
Use s2n_cleanup_thread() and path (#682)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Graeb <[email protected]>
  • Loading branch information
TingDaoK and graebm authored Oct 10, 2024
1 parent 9e1bb08 commit dc41ddc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
19 changes: 15 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,21 @@ if (BYO_CRYPTO)
endif()

if (USE_S2N)
file(GLOB AWS_IO_TLS_SRC
"source/s2n/*.c"
)
aws_use_package(s2n)
file(GLOB AWS_IO_TLS_SRC
"source/s2n/*.c"
)
# Prefer find_package() because it's the normal CMake way to do dependencies.
# But fall back on aws_use_package() because some projects still need to do an IN_SOURCE_BUILD of S2N.
# (e.g. aws-crt-java until this is resolved: https://github.com/awslabs/aws-crt-java/pull/817)
find_package(s2n QUIET)

if (s2n_FOUND)
list(APPEND DEP_AWS_LIBS AWS::s2n)
else()
# Set flag to use in-source path to <s2n/unstable/*.h> headers if we do an IN_SOURCE_BUILD.
aws_use_package(s2n)
add_definitions(-DAWS_S2N_INSOURCE_PATH)
endif()
endif()

file(GLOB IO_HEADERS
Expand Down
10 changes: 8 additions & 2 deletions source/s2n/s2n_tls_channel_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@
#include <aws/common/task_scheduler.h>
#include <aws/common/thread.h>

#include <s2n.h>
#ifdef AWS_S2N_INSOURCE_PATH
# include <api/unstable/cleanup.h>
#else
# include <s2n/unstable/cleanup.h>
#endif

#include <errno.h>
#include <inttypes.h>
#include <math.h>
#include <s2n.h>
#include <stdio.h>
#include <stdlib.h>

Expand Down Expand Up @@ -1247,7 +1253,7 @@ static struct aws_event_loop_local_object s_tl_cleanup_object = {
static void s_aws_cleanup_s2n_thread_local_state(void *user_data) {
(void)user_data;

s2n_cleanup();
s2n_cleanup_thread();
}

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

0 comments on commit dc41ddc

Please sign in to comment.