Skip to content

Commit 79e98e3

Browse files
authored
Make ptls allocations at least 128 byte aligned (#57310)
Fixes #54560 (comment)
1 parent dbd5280 commit 79e98e3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/threading.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,17 @@ jl_ptls_t jl_init_threadtls(int16_t tid)
336336
#endif
337337
if (jl_get_pgcstack() != NULL)
338338
abort();
339-
jl_ptls_t ptls = (jl_ptls_t)calloc(1, sizeof(jl_tls_states_t));
339+
jl_ptls_t ptls;
340+
#if defined(_OS_WINDOWS_)
341+
ptls = _aligned_malloc(sizeof(jl_tls_states_t), alignof(jl_tls_states_t));
342+
if (ptls == NULL)
343+
abort();
344+
#else
345+
if (posix_memalign((void**)&ptls, alignof(jl_tls_states_t), sizeof(jl_tls_states_t)))
346+
abort();
347+
#endif
348+
memset(ptls, 0, sizeof(jl_tls_states_t));
349+
340350
#ifndef _OS_WINDOWS_
341351
pthread_setspecific(jl_task_exit_key, (void*)ptls);
342352
#endif

0 commit comments

Comments
 (0)