git: 22e564c74eb2 - main - libthr: properly align struct pthreads

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Fri, 25 Apr 2025 11:48:34 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=22e564c74eb20e14bd93fd9fdde20e38a29cfcf1

commit 22e564c74eb20e14bd93fd9fdde20e38a29cfcf1
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-04-24 21:24:19 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-04-25 11:48:12 +0000

    libthr: properly align struct pthreads
    
    For instance, the structure contains the struct _Unwind_Exception, and
    it seems that libgcc requires specific alignment for it.
    
    PR:     285711
    Tested by:      Oleg Sidorkin <osidorkin@gmail.com>
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
---
 lib/libthr/thread/thr_list.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/libthr/thread/thr_list.c b/lib/libthr/thread/thr_list.c
index bbc1d2899cb9..5578abdc8727 100644
--- a/lib/libthr/thread/thr_list.c
+++ b/lib/libthr/thread/thr_list.c
@@ -150,11 +150,13 @@ _thr_alloc(struct pthread *curthread)
 		if (total_threads > MAX_THREADS)
 			return (NULL);
 		atomic_add_int(&total_threads, 1);
-		thread = __thr_calloc(1, sizeof(struct pthread));
+		thread = __thr_aligned_alloc_offset(_Alignof(struct pthread),
+		    sizeof(struct pthread), 0);
 		if (thread == NULL) {
 			atomic_add_int(&total_threads, -1);
 			return (NULL);
 		}
+		memset(thread, 0, sizeof(*thread));
 		if ((thread->sleepqueue = _sleepq_alloc()) == NULL ||
 		    (thread->wake_addr = _thr_alloc_wake_addr()) == NULL) {
 			thr_destroy(curthread, thread);