diff --git a/lib/libthr/arch/aarch64/include/pthread_md.h b/lib/libthr/arch/aarch64/include/pthread_md.h --- a/lib/libthr/arch/aarch64/include/pthread_md.h +++ b/lib/libthr/arch/aarch64/include/pthread_md.h @@ -49,4 +49,9 @@ return (_tcb_get()->tcb_thread); } +static __inline void +_thr_resolve_machdep(void) +{ +} + #endif /* _PTHREAD_MD_H_ */ diff --git a/lib/libthr/arch/amd64/include/pthread_md.h b/lib/libthr/arch/amd64/include/pthread_md.h --- a/lib/libthr/arch/amd64/include/pthread_md.h +++ b/lib/libthr/arch/amd64/include/pthread_md.h @@ -52,4 +52,9 @@ return (thr); } +static __inline void +_thr_resolve_machdep(void) +{ +} + #endif diff --git a/lib/libthr/arch/arm/Makefile.inc b/lib/libthr/arch/arm/Makefile.inc new file mode 100644 --- /dev/null +++ b/lib/libthr/arch/arm/Makefile.inc @@ -0,0 +1,3 @@ +.PATH: ${.CURDIR}/arch/arm +SRCS+= \ + thr_rtld_arm.c diff --git a/lib/libthr/arch/aarch64/include/pthread_md.h b/lib/libthr/arch/arm/thr_rtld_arm.c copy from lib/libthr/arch/aarch64/include/pthread_md.h copy to lib/libthr/arch/arm/thr_rtld_arm.c --- a/lib/libthr/arch/aarch64/include/pthread_md.h +++ b/lib/libthr/arch/arm/thr_rtld_arm.c @@ -1,17 +1,14 @@ /*- - * Copyright (c) 2005 David Xu . - * Copyright (c) 2014 the FreeBSD Foundation - * All rights reserved. + * SPDX-License-Identifier: BSD-2-Clause * - * Portions of this software were developed by Andrew Turner - * under sponsorship from the FreeBSD Foundation + * Copyright (c) 2024, Michal Meloun * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice unmodified, this list of conditions, and the following + * disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. @@ -28,25 +25,43 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* - * Machine-dependent thread prototypes/definitions. - */ -#ifndef _PTHREAD_MD_H_ -#define _PTHREAD_MD_H_ +#include +#include + +#include "thr_private.h" + +int __aeabi_idiv(int , int ); +unsigned __aeabi_uidiv(unsigned, unsigned ); -#include -#include +struct {int q; int r;} __aeabi_idivmod(int, int ); +struct {unsigned q; unsigned r;} __aeabi_uidivmod(unsigned, unsigned); -#define CPU_SPINWAIT +struct {int64_t q; int64_t r;} __aeabi_ldivmod(int64_t, int64_t); +struct {uint64_t q; uint64_t r;} __aeabi_uldivmod(uint64_t, uint64_t); -/* For use in _Static_assert to check structs will fit in a page */ -#define THR_PAGE_SIZE_MIN PAGE_SIZE_4K +void __aeabi_memset(void *dest, size_t n, int c); +void __aeabi_memclr(void *dest, size_t n); +void __aeabi_memmove(void *dest, void *src, size_t n); +void __aeabi_memcpy(void *dest, void *src, size_t n); +void __aeabi_memcmp(void *dest, void *src, size_t n); -static __inline struct pthread * -_get_curthread(void) +void +_thr_resolve_machdep(void) { + char tmp[2]; - return (_tcb_get()->tcb_thread); -} + __aeabi_idiv(1, 1); + __aeabi_uidiv(1, 1); + + __aeabi_idivmod(1, 1); + __aeabi_uidivmod(1, 1); -#endif /* _PTHREAD_MD_H_ */ + __aeabi_ldivmod(1, 1); + __aeabi_uldivmod(1, 1); + + __aeabi_memset(tmp, 1, 0); + __aeabi_memclr(tmp, 1); + __aeabi_memmove(tmp, tmp + 1, 1); + __aeabi_memcpy(tmp, tmp + 1, 1); + __aeabi_memcmp(tmp, tmp + 1, 1); +} diff --git a/lib/libthr/arch/i386/include/pthread_md.h b/lib/libthr/arch/i386/include/pthread_md.h --- a/lib/libthr/arch/i386/include/pthread_md.h +++ b/lib/libthr/arch/i386/include/pthread_md.h @@ -52,4 +52,9 @@ return (thr); } +static __inline void +_thr_resolve_machdep(void) +{ +} + #endif diff --git a/lib/libthr/arch/powerpc/include/pthread_md.h b/lib/libthr/arch/powerpc/include/pthread_md.h --- a/lib/libthr/arch/powerpc/include/pthread_md.h +++ b/lib/libthr/arch/powerpc/include/pthread_md.h @@ -49,4 +49,9 @@ return (NULL); } +static __inline void +_thr_resolve_machdep(void) +{ +} + #endif /* _PTHREAD_MD_H_ */ diff --git a/lib/libthr/arch/riscv/include/pthread_md.h b/lib/libthr/arch/riscv/include/pthread_md.h --- a/lib/libthr/arch/riscv/include/pthread_md.h +++ b/lib/libthr/arch/riscv/include/pthread_md.h @@ -56,4 +56,9 @@ return (NULL); } +static __inline void +_thr_resolve_machdep(void) +{ +} + #endif /* _PTHREAD_MD_H_ */ diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h --- a/lib/libthr/thread/thr_private.h +++ b/lib/libthr/thread/thr_private.h @@ -1103,6 +1103,7 @@ bool __thr_get_main_stack_base(char **base); bool __thr_get_main_stack_lim(size_t *lim); int _Tthr_sigqueue(pthread_t pthread, int sig, const union sigval value); +void _thr_resolve_machdep(void); __END_DECLS __NULLABILITY_PRAGMA_POP diff --git a/lib/libthr/thread/thr_rtld.c b/lib/libthr/thread/thr_rtld.c --- a/lib/libthr/thread/thr_rtld.c +++ b/lib/libthr/thread/thr_rtld.c @@ -276,6 +276,9 @@ _thr_signal_block_check_fast(); _thr_signal_block_setup(curthread); + /* resolve machine depended functions, if any */ + _thr_resolve_machdep(); + uc_len = __getcontextx_size(); uc = alloca(uc_len); getcontext(uc);