Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup aws-lc thread locals and thread local key on library shutdown #152

Merged
merged 6 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/aws/cal/cal.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ AWS_EXTERN_C_BEGIN
AWS_CAL_API void aws_cal_library_init(struct aws_allocator *allocator);
AWS_CAL_API void aws_cal_library_clean_up(void);

/*
* Every CRT thread that might invoke aws-lc functionality should call this as part of the thread at_exit process
*/
AWS_CAL_API void aws_cal_thread_clean_up(void);

AWS_EXTERN_C_END
AWS_POP_SANE_WARNING_LEVEL

Expand Down
7 changes: 7 additions & 0 deletions source/cal.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ static struct aws_log_subject_info_list s_cal_log_subject_list = {
#ifndef BYO_CRYPTO
extern void aws_cal_platform_init(struct aws_allocator *allocator);
extern void aws_cal_platform_clean_up(void);
extern void aws_cal_platform_thread_clean_up(void);
#endif /* BYO_CRYPTO */

static bool s_cal_library_initialized = false;
Expand All @@ -96,3 +97,9 @@ void aws_cal_library_clean_up(void) {
aws_common_library_clean_up();
}
}

void aws_cal_thread_clean_up(void) {
#ifndef BYO_CRYPTO
aws_cal_platform_thread_clean_up();
#endif /* BYO_CRYPTO */
}
2 changes: 2 additions & 0 deletions source/darwin/commoncrypto_platform_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ void aws_cal_platform_init(struct aws_allocator *allocator) {
}

void aws_cal_platform_clean_up(void) {}

void aws_cal_platform_thread_clean_up(void) {}
14 changes: 14 additions & 0 deletions source/unix/openssl_platform_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

#include <aws/cal/private/opensslcrypto_common.h>

#include <openssl/crypto.h>

static struct openssl_hmac_ctx_table hmac_ctx_table;
static struct openssl_evp_md_ctx_table evp_md_ctx_table;

Expand Down Expand Up @@ -651,12 +653,24 @@ void aws_cal_platform_clean_up(void) {
}
#endif

#if defined(OPENSSL_IS_AWSLC)
AWSLC_thread_local_clear();
AWSLC_thread_local_shutdown();
#endif

if (s_libcrypto_module) {
dlclose(s_libcrypto_module);
}

s_libcrypto_allocator = NULL;
}

void aws_cal_platform_thread_clean_up(void) {
#if defined(OPENSSL_IS_AWSLC)
AWSLC_thread_local_clear();
#endif
}

#if !defined(__GNUC__) || (__GNUC__ >= 4 && __GNUC_MINOR__ > 1)
# pragma GCC diagnostic pop
#endif
2 changes: 2 additions & 0 deletions source/windows/bcrypt_platform_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ void aws_cal_platform_init(struct aws_allocator *allocator) {
}

void aws_cal_platform_clean_up(void) {}

void aws_cal_platform_thread_clean_up(void) {}