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/aarch64/aarch64/_thread_start.S b/lib/libthr/arch/aarch64/aarch64/_thread_start.S new file mode 100644 --- /dev/null +++ b/lib/libthr/arch/aarch64/aarch64/_thread_start.S @@ -0,0 +1,40 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (C) 2023 Dmitry Chagin + * + * 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. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * 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. + */ + +#include + + .text + +ENTRY(_thread_start) + .cfi_undefined x30 + mov x29,#0 + mov x30,#0 + + b thread_start +END(_thread_start) + + .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/amd64/amd64/_thread_start.S b/lib/libthr/arch/amd64/amd64/_thread_start.S new file mode 100644 --- /dev/null +++ b/lib/libthr/arch/amd64/amd64/_thread_start.S @@ -0,0 +1,40 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (C) 2023 Dmitry Chagin + * + * 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. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * 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. + */ + +#include + + .text + +ENTRY(_thread_start) + .cfi_undefined %rip + xorq %rbp,%rbp + pushq %rbp + + callq thread_start +END(_thread_start) + + .section .note.GNU-stack,"",%progbits 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/i386/i386/_thread_start.S b/lib/libthr/arch/i386/i386/_thread_start.S new file mode 100644 --- /dev/null +++ b/lib/libthr/arch/i386/i386/_thread_start.S @@ -0,0 +1,40 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (C) 2023 Dmitry Chagin + * + * 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. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * 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. + */ + +#include + + .text + +ENTRY(_thread_start) + .cfi_undefined %eip + popl %ebp + xorl %ebp,%ebp + + call thread_start +END(_thread_start) + + .section .note.GNU-stack,"",%progbits 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,8 @@ #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); +void _thread_start(struct pthread *curthread); __weak_reference(_pthread_create, pthread_create); @@ -155,7 +156,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 +251,9 @@ return (ret); } -static void +__weak_reference(thread_start, _thread_start); + +void thread_start(struct pthread *curthread) { sigset_t set;