diff --git a/lib/libthr/arch/aarch64/include/pthread_md.h b/lib/libthr/arch/aarch64/include/pthread_md.h index d14bce244f8f..3209a2cbe7e2 100644 --- a/lib/libthr/arch/aarch64/include/pthread_md.h +++ b/lib/libthr/arch/aarch64/include/pthread_md.h @@ -1,82 +1,80 @@ /*- * Copyright (c) 2005 David Xu . * Copyright (c) 2014 the FreeBSD Foundation * All rights reserved. * * Portions of this software were developed by Andrew Turner * under sponsorship from the FreeBSD Foundation * * 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 ``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 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. * * $FreeBSD$ */ /* * Machine-dependent thread prototypes/definitions. */ #ifndef _PTHREAD_MD_H_ #define _PTHREAD_MD_H_ #include #include -#include #define CPU_SPINWAIT -#define DTV_OFFSET offsetof(struct tcb, tcb_dtv) /* * Variant I tcb. The structure layout is fixed, don't blindly * change it. */ struct tcb { void *tcb_dtv; struct pthread *tcb_thread; }; /* Called from the thread to set its private data. */ static __inline void _tcb_set(struct tcb *tcb) { __asm __volatile("msr tpidr_el0, %x0" :: "r" (tcb)); } /* * Get the current tcb. */ static __inline struct tcb * _tcb_get(void) { struct tcb *tcb; __asm __volatile("mrs %x0, tpidr_el0" : "=r" (tcb)); return (tcb); } static __inline struct pthread * _get_curthread(void) { return (_tcb_get()->tcb_thread); } #endif /* _PTHREAD_MD_H_ */ diff --git a/lib/libthr/arch/amd64/include/pthread_md.h b/lib/libthr/arch/amd64/include/pthread_md.h index 1d393d9cbbed..b3367e85ee65 100644 --- a/lib/libthr/arch/amd64/include/pthread_md.h +++ b/lib/libthr/arch/amd64/include/pthread_md.h @@ -1,102 +1,100 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (C) 2003 David Xu * Copyright (c) 2001 Daniel Eischen * All rights reserved. * * 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. Neither the name of the author nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * 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. * * $FreeBSD$ */ /* * Machine-dependent thread prototypes/definitions. */ #ifndef _PTHREAD_MD_H_ #define _PTHREAD_MD_H_ #include #include #include #define CPU_SPINWAIT __asm __volatile("pause") -#define DTV_OFFSET offsetof(struct tcb, tcb_dtv) - /* * Variant II tcb, first two members are required by rtld, * %fs points to the structure. */ struct tcb { struct tcb *tcb_self; /* required by rtld */ void *tcb_dtv; /* required by rtld */ struct pthread *tcb_thread; void *tcb_spare[1]; }; /* * Evaluates to the byte offset of the per-tcb variable name. */ #define __tcb_offset(name) __offsetof(struct tcb, name) /* * Evaluates to the type of the per-tcb variable name. */ #define __tcb_type(name) __typeof(((struct tcb *)0)->name) /* * Evaluates to the value of the per-tcb variable name. */ #define TCB_GET64(name) ({ \ __tcb_type(name) __result; \ \ u_long __i; \ __asm __volatile("movq %%fs:%1, %0" \ : "=r" (__i) \ : "m" (*(volatile u_long *)(__tcb_offset(name)))); \ __result = (__tcb_type(name))__i; \ \ __result; \ }) static __inline void _tcb_set(struct tcb *tcb) { amd64_set_fsbase(tcb); } static __inline struct tcb * _tcb_get(void) { return (TCB_GET64(tcb_self)); } static __inline struct pthread * _get_curthread(void) { return (TCB_GET64(tcb_thread)); } #define HAS__UMTX_OP_ERR 1 #endif diff --git a/lib/libthr/arch/arm/include/pthread_md.h b/lib/libthr/arch/arm/include/pthread_md.h index 55d93d0853bc..d1fce8551b2e 100644 --- a/lib/libthr/arch/arm/include/pthread_md.h +++ b/lib/libthr/arch/arm/include/pthread_md.h @@ -1,89 +1,87 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2005 David Xu . * All rights reserved. * * 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 ``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 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. * * $FreeBSD$ */ /* * Machine-dependent thread prototypes/definitions. */ #ifndef _PTHREAD_MD_H_ #define _PTHREAD_MD_H_ #include #include -#include #define CPU_SPINWAIT -#define DTV_OFFSET offsetof(struct tcb, tcb_dtv) /* * Variant I tcb. The structure layout is fixed, don't blindly * change it. */ struct tcb { void *tcb_dtv; /* required by rtld */ struct pthread *tcb_thread; /* our hook */ }; /* Called from the thread to set its private data. */ static __inline void _tcb_set(struct tcb *tcb) { #ifdef ARM_TP_ADDRESS *((struct tcb **)ARM_TP_ADDRESS) = tcb; /* avoids a system call */ #else sysarch(ARM_SET_TP, tcb); #endif } /* * Get the current tcb. */ static __inline struct tcb * _tcb_get(void) { #ifdef ARM_TP_ADDRESS return (*((struct tcb **)ARM_TP_ADDRESS)); #else struct tcb *tcb; __asm __volatile("mrc p15, 0, %0, c13, c0, 3" \ : "=r" (tcb)); return (tcb); #endif } static __inline struct pthread * _get_curthread(void) { if (_thr_initial) return (_tcb_get()->tcb_thread); return (NULL); } #endif /* _PTHREAD_MD_H_ */ diff --git a/lib/libthr/arch/i386/include/pthread_md.h b/lib/libthr/arch/i386/include/pthread_md.h index 7de8aa56203e..48374480d207 100644 --- a/lib/libthr/arch/i386/include/pthread_md.h +++ b/lib/libthr/arch/i386/include/pthread_md.h @@ -1,104 +1,102 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2002 Daniel Eischen . * Copyright (c) 2005 David Xu . * All rights reserved. * * 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. * * $FreeBSD$ */ /* * Machine-dependent thread prototypes/definitions. */ #ifndef _PTHREAD_MD_H_ #define _PTHREAD_MD_H_ #include #include #include #define CPU_SPINWAIT __asm __volatile("pause") -#define DTV_OFFSET offsetof(struct tcb, tcb_dtv) - /* * Variant II tcb, first two members are required by rtld, * %gs points to the structure. */ struct tcb { struct tcb *tcb_self; /* required by rtld */ void *tcb_dtv; /* required by rtld */ struct pthread *tcb_thread; }; /* * Evaluates to the byte offset of the per-tcb variable name. */ #define __tcb_offset(name) __offsetof(struct tcb, name) /* * Evaluates to the type of the per-tcb variable name. */ #define __tcb_type(name) __typeof(((struct tcb *)0)->name) /* * Evaluates to the value of the per-tcb variable name. */ #define TCB_GET32(name) ({ \ __tcb_type(name) __result; \ \ u_int __i; \ __asm __volatile("movl %%gs:%1, %0" \ : "=r" (__i) \ : "m" (*(volatile u_int *)(__tcb_offset(name)))); \ __result = (__tcb_type(name))__i; \ \ __result; \ }) /* Called from the thread to set its private data. */ static __inline void _tcb_set(struct tcb *tcb) { i386_set_gsbase(tcb); } /* Get the current kcb. */ static __inline struct tcb * _tcb_get(void) { return (TCB_GET32(tcb_self)); } /* Get the current thread. */ static __inline struct pthread * _get_curthread(void) { return (TCB_GET32(tcb_thread)); } #define HAS__UMTX_OP_ERR 1 #endif diff --git a/lib/libthr/arch/mips/include/pthread_md.h b/lib/libthr/arch/mips/include/pthread_md.h index 20b0e7065595..2a29e6717abe 100644 --- a/lib/libthr/arch/mips/include/pthread_md.h +++ b/lib/libthr/arch/mips/include/pthread_md.h @@ -1,133 +1,131 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2005 David Xu . * All rights reserved. * * 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 ``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 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. * * from: src/lib/libthr/arch/arm/include/pthread_md.h,v 1.3 2005/10/29 13:40:31 davidxu * $FreeBSD$ */ /* * Machine-dependent thread prototypes/definitions. */ #ifndef _PTHREAD_MD_H_ #define _PTHREAD_MD_H_ #include #include #include -#include #define CPU_SPINWAIT -#define DTV_OFFSET offsetof(struct tcb, tcb_dtv) /* * Variant I tcb. The structure layout is fixed, don't blindly * change it! */ struct tcb { void *tcb_dtv; struct pthread *tcb_thread; }; /* Called from the thread to set its private data. */ static __inline void _tcb_set(struct tcb *tcb) { sysarch(MIPS_SET_TLS, tcb); } /* * Get the current tcb. */ #ifdef TLS_USE_SYSARCH static __inline struct tcb * _tcb_get(void) { struct tcb *tcb; sysarch(MIPS_GET_TLS, &tcb); return tcb; } #else /* ! TLS_USE_SYSARCH */ # if defined(__mips_n64) static __inline struct tcb * _tcb_get(void) { uint64_t _rv; __asm__ __volatile__ ( ".set\tpush\n\t" ".set\tmips64r2\n\t" "rdhwr\t%0, $29\n\t" ".set\tpop" : "=r" (_rv)); /* * XXXSS See 'git show c6be4f4d2d1b71c04de5d3bbb6933ce2dbcdb317' * * Remove the offset since this really a request to get the TLS * pointer via sysarch() (in theory). Of course, this may go away * once the TLS code is rewritten. */ return (struct tcb *)(_rv - TLS_TP_OFFSET - TLS_TCB_SIZE); } # else /* mips 32 */ static __inline struct tcb * _tcb_get(void) { uint32_t _rv; __asm__ __volatile__ ( ".set\tpush\n\t" ".set\tmips32r2\n\t" "rdhwr\t%0, $29\n\t" ".set\tpop" : "=r" (_rv)); /* * XXXSS See 'git show c6be4f4d2d1b71c04de5d3bbb6933ce2dbcdb317' * * Remove the offset since this really a request to get the TLS * pointer via sysarch() (in theory). Of course, this may go away * once the TLS code is rewritten. */ return (struct tcb *)(_rv - TLS_TP_OFFSET - TLS_TCB_SIZE); } # endif /* ! __mips_n64 */ #endif /* ! TLS_USE_SYSARCH */ static __inline struct pthread * _get_curthread(void) { if (_thr_initial) return (_tcb_get()->tcb_thread); return (NULL); } #endif /* _PTHREAD_MD_H_ */ diff --git a/lib/libthr/arch/powerpc/include/pthread_md.h b/lib/libthr/arch/powerpc/include/pthread_md.h index 0ed44058a7a7..3fcf8c3245da 100644 --- a/lib/libthr/arch/powerpc/include/pthread_md.h +++ b/lib/libthr/arch/powerpc/include/pthread_md.h @@ -1,96 +1,94 @@ /*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright 2004 by Peter Grehan. All rights reserved. * * 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. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. * * $FreeBSD$ */ /* * Machine-dependent thread prototypes/definitions. */ #ifndef _PTHREAD_MD_H_ #define _PTHREAD_MD_H_ -#include #include #define CPU_SPINWAIT -#define DTV_OFFSET offsetof(struct tcb, tcb_dtv) #ifdef __powerpc64__ #define TP_OFFSET 0x7010 #else #define TP_OFFSET 0x7008 #endif /* * Variant I tcb. The structure layout is fixed, don't blindly * change it. * %r2 (32-bit) or %r13 (64-bit) points to end of the structure. */ struct tcb { void *tcb_dtv; struct pthread *tcb_thread; }; static __inline void _tcb_set(struct tcb *tcb) { #ifdef __powerpc64__ __asm __volatile("mr 13,%0" :: "r"((uint8_t *)tcb + TP_OFFSET)); #else __asm __volatile("mr 2,%0" :: "r"((uint8_t *)tcb + TP_OFFSET)); #endif } static __inline struct tcb * _tcb_get(void) { register struct tcb *tcb; #ifdef __powerpc64__ __asm __volatile("addi %0,13,%1" : "=r"(tcb) : "i"(-TP_OFFSET)); #else __asm __volatile("addi %0,2,%1" : "=r"(tcb) : "i"(-TP_OFFSET)); #endif return (tcb); } static __inline struct pthread * _get_curthread(void) { if (_thr_initial) return (_tcb_get()->tcb_thread); return (NULL); } #define HAS__UMTX_OP_ERR 1 #endif /* _PTHREAD_MD_H_ */ diff --git a/lib/libthr/arch/riscv/include/pthread_md.h b/lib/libthr/arch/riscv/include/pthread_md.h index 55d9b7260fd2..1cdc8a12be95 100644 --- a/lib/libthr/arch/riscv/include/pthread_md.h +++ b/lib/libthr/arch/riscv/include/pthread_md.h @@ -1,90 +1,88 @@ /*- * Copyright (c) 2005 David Xu * Copyright (c) 2015 Ruslan Bukin * All rights reserved. * * 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). * * 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. * * $FreeBSD$ */ /* * Machine-dependent thread prototypes/definitions. */ #ifndef _PTHREAD_MD_H_ #define _PTHREAD_MD_H_ #include -#include #define CPU_SPINWAIT -#define DTV_OFFSET offsetof(struct tcb, tcb_dtv) #define TP_OFFSET sizeof(struct tcb) /* * Variant I tcb. The structure layout is fixed, don't blindly * change it! */ struct tcb { void *tcb_dtv; struct pthread *tcb_thread; }; /* Called from the thread to set its private data. */ static __inline void _tcb_set(struct tcb *tcb) { __asm __volatile("addi tp, %0, %1" :: "r"(tcb), "I"(TP_OFFSET)); } /* * Get the current tcb. */ static __inline struct tcb * _tcb_get(void) { struct tcb *_tcb; __asm __volatile("addi %0, tp, %1" : "=r"(_tcb) : "I"(-TP_OFFSET)); return (_tcb); } static __inline struct pthread * _get_curthread(void) { if (_thr_initial) return (_tcb_get()->tcb_thread); return (NULL); } #endif /* _PTHREAD_MD_H_ */ diff --git a/lib/libthr/thread/thr_symbols.c b/lib/libthr/thread/thr_symbols.c index cee263c56826..71737392c62f 100644 --- a/lib/libthr/thread/thr_symbols.c +++ b/lib/libthr/thread/thr_symbols.c @@ -1,61 +1,61 @@ /*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 2004 David Xu * All rights reserved. * * 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. * 3. Neither the name of the author nor the names of any co-contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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 __FBSDID("$FreeBSD$"); #include #include #include #include #include "thr_private.h" /* A collection of symbols needed by debugger */ /* int _libthr_debug */ int _thread_off_tcb = offsetof(struct pthread, tcb); int _thread_off_tid = offsetof(struct pthread, tid); int _thread_off_next = offsetof(struct pthread, tle.tqe_next); int _thread_off_attr_flags = offsetof(struct pthread, attr.flags); int _thread_off_linkmap = offsetof(Obj_Entry, linkmap); int _thread_off_tlsindex = offsetof(Obj_Entry, tlsindex); int _thread_off_report_events = offsetof(struct pthread, report_events); int _thread_off_event_mask = offsetof(struct pthread, event_mask); int _thread_off_event_buf = offsetof(struct pthread, event_buf); int _thread_size_key = sizeof(struct pthread_key); int _thread_off_key_allocated = offsetof(struct pthread_key, allocated); int _thread_off_key_destructor = offsetof(struct pthread_key, destructor); int _thread_max_keys = PTHREAD_KEYS_MAX; -int _thread_off_dtv = DTV_OFFSET; +int _thread_off_dtv = offsetof(struct tcb, tcb_dtv); int _thread_off_state = offsetof(struct pthread, state); int _thread_state_running = PS_RUNNING; int _thread_state_zoombie = PS_DEAD;