diff --git a/lib/libthr/arch/aarch64/Makefile.inc b/lib/libthr/arch/aarch64/Makefile.inc --- a/lib/libthr/arch/aarch64/Makefile.inc +++ b/lib/libthr/arch/aarch64/Makefile.inc @@ -1,2 +1,3 @@ # $FreeBSD$ +SRCS+= _thread_start.S diff --git a/lib/libthr/arch/riscv/include/pthread_md.h b/lib/libthr/arch/aarch64/aarch64/_thread_start.S copy from lib/libthr/arch/riscv/include/pthread_md.h copy to lib/libthr/arch/aarch64/aarch64/_thread_start.S --- a/lib/libthr/arch/riscv/include/pthread_md.h +++ b/lib/libthr/arch/aarch64/aarch64/_thread_start.S @@ -1,15 +1,7 @@ /*- - * Copyright (c) 2005 David Xu - * Copyright (c) 2015 Ruslan Bukin - * All rights reserved. + * SPDX-License-Identifier: BSD-2-Clause * - * Portions of this software were developed by SRI International and the - * University of Cambridge Computer Laboratory under DARPA/AFRL contract - * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. - * - * Portions of this software were developed by the University of Cambridge - * Computer Laboratory as part of the CTSRD Project, with support from the - * UK Higher Education Innovation Fund (HEIF). + * Copyright (C) 2023 Dmitry Chagin * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,31 +23,17 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -/* - * Machine-dependent thread prototypes/definitions. */ -#ifndef _PTHREAD_MD_H_ -#define _PTHREAD_MD_H_ - -#include -#include - -#define CPU_SPINWAIT -/* For use in _Static_assert to check structs will fit in a page */ -#define THR_PAGE_SIZE_MIN PAGE_SIZE +#include -static __inline struct pthread * -_get_curthread(void) -{ + .text - if (_thr_initial) - return (_tcb_get()->tcb_thread); - return (NULL); -} +ENTRY(_thread_start) + .cfi_undefined x30 + mov x29, #0 + mov x30, #0 + bl thread_start +END(_thread_start) -#endif /* _PTHREAD_MD_H_ */ + .section .note.GNU-stack,"",%progbits diff --git a/lib/libthr/arch/amd64/Makefile.inc b/lib/libthr/arch/amd64/Makefile.inc --- a/lib/libthr/arch/amd64/Makefile.inc +++ b/lib/libthr/arch/amd64/Makefile.inc @@ -1,6 +1,6 @@ #$FreeBSD$ -SRCS+= _umtx_op_err.S +SRCS+= _umtx_op_err.S _thread_start.S # With the current compiler and libthr code, using SSE in libthr # does not provide enough performance improvement to outweigh diff --git a/lib/libthr/arch/riscv/include/pthread_md.h b/lib/libthr/arch/amd64/amd64/_thread_start.S copy from lib/libthr/arch/riscv/include/pthread_md.h copy to lib/libthr/arch/amd64/amd64/_thread_start.S --- a/lib/libthr/arch/riscv/include/pthread_md.h +++ b/lib/libthr/arch/amd64/amd64/_thread_start.S @@ -1,15 +1,7 @@ /*- - * Copyright (c) 2005 David Xu - * Copyright (c) 2015 Ruslan Bukin - * All rights reserved. + * SPDX-License-Identifier: BSD-2-Clause * - * Portions of this software were developed by SRI International and the - * University of Cambridge Computer Laboratory under DARPA/AFRL contract - * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. - * - * Portions of this software were developed by the University of Cambridge - * Computer Laboratory as part of the CTSRD Project, with support from the - * UK Higher Education Innovation Fund (HEIF). + * Copyright (C) 2023 Dmitry Chagin * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,31 +23,18 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -/* - * Machine-dependent thread prototypes/definitions. */ -#ifndef _PTHREAD_MD_H_ -#define _PTHREAD_MD_H_ - -#include -#include - -#define CPU_SPINWAIT -/* For use in _Static_assert to check structs will fit in a page */ -#define THR_PAGE_SIZE_MIN PAGE_SIZE +#include -static __inline struct pthread * -_get_curthread(void) -{ + .text - if (_thr_initial) - return (_tcb_get()->tcb_thread); - return (NULL); -} +ENTRY(_thread_start) + .cfi_undefined %rip /* Terminate call stack. */ + .cfi_def_cfa %rsp, 0 + addq $8,%rsp /* Skip return address. */ + .cfi_def_cfa %rsp, -8 + callq thread_start +END(_thread_start) -#endif /* _PTHREAD_MD_H_ */ + .section .note.GNU-stack,"",%progbits diff --git a/lib/libthr/arch/arm/include/pthread_md.h b/lib/libthr/arch/arm/include/pthread_md.h --- a/lib/libthr/arch/arm/include/pthread_md.h +++ b/lib/libthr/arch/arm/include/pthread_md.h @@ -50,4 +50,6 @@ return (NULL); } +__weak_reference(thread_start, _thread_start); + #endif /* _PTHREAD_MD_H_ */ diff --git a/lib/libthr/arch/i386/Makefile.inc b/lib/libthr/arch/i386/Makefile.inc --- a/lib/libthr/arch/i386/Makefile.inc +++ b/lib/libthr/arch/i386/Makefile.inc @@ -1,6 +1,6 @@ # $FreeBSD$ -SRCS+= _umtx_op_err.S +SRCS+= _umtx_op_err.S _thread_start.S # With the current compiler and libthr code, using SSE in libthr # does not provide enough performance improvement to outweigh diff --git a/lib/libthr/arch/riscv/include/pthread_md.h b/lib/libthr/arch/i386/i386/_thread_start.S copy from lib/libthr/arch/riscv/include/pthread_md.h copy to lib/libthr/arch/i386/i386/_thread_start.S --- a/lib/libthr/arch/riscv/include/pthread_md.h +++ b/lib/libthr/arch/i386/i386/_thread_start.S @@ -1,15 +1,7 @@ /*- - * Copyright (c) 2005 David Xu - * Copyright (c) 2015 Ruslan Bukin - * All rights reserved. + * SPDX-License-Identifier: BSD-2-Clause * - * Portions of this software were developed by SRI International and the - * University of Cambridge Computer Laboratory under DARPA/AFRL contract - * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. - * - * Portions of this software were developed by the University of Cambridge - * Computer Laboratory as part of the CTSRD Project, with support from the - * UK Higher Education Innovation Fund (HEIF). + * Copyright (C) 2023 Dmitry Chagin * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,31 +23,18 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -/* - * Machine-dependent thread prototypes/definitions. */ -#ifndef _PTHREAD_MD_H_ -#define _PTHREAD_MD_H_ - -#include -#include - -#define CPU_SPINWAIT -/* For use in _Static_assert to check structs will fit in a page */ -#define THR_PAGE_SIZE_MIN PAGE_SIZE +#include -static __inline struct pthread * -_get_curthread(void) -{ + .text - if (_thr_initial) - return (_tcb_get()->tcb_thread); - return (NULL); -} +ENTRY(_thread_start) + .cfi_undefined %eip /* Terminate call stack. */ + .cfi_def_cfa %esp, 0 + addl $4,%esp /* Skip return address. */ + .cfi_def_cfa %esp, -4 + call thread_start +END(_thread_start) -#endif /* _PTHREAD_MD_H_ */ + .section .note.GNU-stack,"",%progbits 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 @@ -53,4 +53,6 @@ #define HAS__UMTX_OP_ERR 1 +__weak_reference(thread_start, _thread_start); + #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 @@ -58,4 +58,6 @@ return (NULL); } +__weak_reference(thread_start, _thread_start); + #endif /* _PTHREAD_MD_H_ */ diff --git a/lib/libthr/thread/thr_create.c b/lib/libthr/thread/thr_create.c --- a/lib/libthr/thread/thr_create.c +++ b/lib/libthr/thread/thr_create.c @@ -47,7 +47,7 @@ #include "thr_private.h" static int create_stack(struct pthread_attr *pattr); -static void thread_start(struct pthread *curthread); +void thread_start(struct pthread *curthread) __hidden __dead2; __weak_reference(_pthread_create, pthread_create); @@ -155,7 +155,7 @@ locked = 1; } else locked = 0; - param.start_func = (void (*)(void *)) thread_start; + param.start_func = (void (*)(void *))_thread_start; param.arg = new_thread; param.stack_base = new_thread->attr.stackaddr_attr; param.stack_size = new_thread->attr.stacksize_attr; @@ -250,7 +250,7 @@ return (ret); } -static void +void thread_start(struct pthread *curthread) { sigset_t set; 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 @@ -802,6 +802,7 @@ void _thread_exit(const char *, int, const char *) __hidden __dead2; void _thread_exitf(const char *, int, const char *, ...) __hidden __dead2 __printflike(3, 4); +void _thread_start(struct pthread *) __hidden __dead2; int _thr_ref_add(struct pthread *, struct pthread *, int) __hidden; void _thr_ref_delete(struct pthread *, struct pthread *) __hidden; void _thr_ref_delete_unlocked(struct pthread *, struct pthread *) __hidden;