From 1761f63cacb0d5d7c167d78c30689b464068eadc Mon Sep 17 00:00:00 2001 From: gbaraldi Date: Fri, 7 Feb 2025 18:17:51 -0300 Subject: [PATCH] Make ptls allocations at least 128 byte aligned --- src/threading.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/threading.c b/src/threading.c index a51916cdcd8d8..690c5fafb5792 100644 --- a/src/threading.c +++ b/src/threading.c @@ -336,7 +336,17 @@ jl_ptls_t jl_init_threadtls(int16_t tid) #endif if (jl_get_pgcstack() != NULL) abort(); - jl_ptls_t ptls = (jl_ptls_t)calloc(1, sizeof(jl_tls_states_t)); + jl_ptls_t ptls; +#if defined(_OS_WINDOWS_) + ptls = _aligned_malloc(sizeof(jl_tls_states_t), alignof(jl_tls_states_t)); + if (ptls == NULL) + abort(); +#else + if (posix_memalign((void**)&ptls, alignof(jl_tls_states_t), sizeof(jl_tls_states_t))) + abort(); +#endif + memset(ptls, 0, sizeof(jl_tls_states_t)); + #ifndef _OS_WINDOWS_ pthread_setspecific(jl_task_exit_key, (void*)ptls); #endif