Page MenuHomeFreeBSD

D33351.diff
No OneTemporary

D33351.diff

diff --git a/sys/amd64/include/tls.h b/sys/amd64/include/tls.h
new file mode 100644
--- /dev/null
+++ b/sys/amd64/include/tls.h
@@ -0,0 +1,5 @@
+/*-
+ * This file is in the public domain.
+ */
+
+#include <x86/tls.h>
diff --git a/sys/arm/include/tls.h b/sys/arm/include/tls.h
new file mode 100644
--- /dev/null
+++ b/sys/arm/include/tls.h
@@ -0,0 +1,55 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2005 David Xu <davidxu@freebsd.org>.
+ * 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.
+ */
+
+#ifndef _MACHINE_TLS_H_
+#define _MACHINE_TLS_H_
+
+#include <sys/_tls_variant_i.h>
+#include <machine/sysarch.h>
+
+#define TLS_DTV_OFFSET 0
+#define TLS_TCB_ALIGN 8
+#define TLS_TP_OFFSET 0
+
+static __inline void
+_tcb_set(struct tcb *tcb)
+{
+ sysarch(ARM_SET_TP, tcb);
+}
+
+static __inline struct tcb *
+_tcb_get(void)
+{
+ struct tcb *tcb;
+
+ __asm __volatile("mrc p15, 0, %0, c13, c0, 3" \
+ : "=r" (tcb));
+ return (tcb);
+}
+
+#endif /* !_MACHINE_TLS_H_ */
diff --git a/sys/arm64/include/tls.h b/sys/arm64/include/tls.h
new file mode 100644
--- /dev/null
+++ b/sys/arm64/include/tls.h
@@ -0,0 +1,55 @@
+/*-
+ * Copyright (c) 2005 David Xu <davidxu@freebsd.org>.
+ * 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.
+ */
+
+#ifndef _MACHINE_TLS_H_
+#define _MACHINE_TLS_H_
+
+#include <sys/_tls_variant_i.h>
+
+#define TLS_DTV_OFFSET 0
+#define TLS_TCB_ALIGN 16
+#define TLS_TP_OFFSET 0
+
+static __inline void
+_tcb_set(struct tcb *tcb)
+{
+ __asm __volatile("msr tpidr_el0, %x0" :: "r" (tcb));
+}
+
+static __inline struct tcb *
+_tcb_get(void)
+{
+ struct tcb *tcb;
+
+ __asm __volatile("mrs %x0, tpidr_el0" : "=r" (tcb));
+ return (tcb);
+}
+
+#endif /* !_MACHINE_TLS_H_ */
diff --git a/sys/i386/include/tls.h b/sys/i386/include/tls.h
new file mode 100644
--- /dev/null
+++ b/sys/i386/include/tls.h
@@ -0,0 +1,5 @@
+/*-
+ * This file is in the public domain.
+ */
+
+#include <x86/tls.h>
diff --git a/sys/mips/include/tls.h b/sys/mips/include/tls.h
--- a/sys/mips/include/tls.h
+++ b/sys/mips/include/tls.h
@@ -34,20 +34,52 @@
#ifndef __MIPS_TLS_H__
#define __MIPS_TLS_H__
+#include <sys/_tls_variant_i.h>
+#include <machine/sysarch.h>
+
/*
* TLS parameters
*/
-#define TLS_TP_OFFSET 0x7000
-#define TLS_DTV_OFFSET 0x8000
+#define TLS_DTV_OFFSET 0x8000
+#define TLS_TCB_ALIGN 8
+#define TLS_TP_OFFSET 0x7000
-#ifdef __mips_n64
-#define TLS_TCB_SIZE 16
#ifdef COMPAT_FREEBSD32
-#define TLS_TCB_SIZE32 8
+#define TLS_TCB_SIZE32 8
#endif
+
+#ifndef _KERNEL
+
+static __inline void
+_tcb_set(struct tcb *tcb)
+{
+ sysarch(MIPS_SET_TLS, tcb);
+}
+
+static __inline struct tcb *
+_tcb_get(void)
+{
+ struct tcb *tcb;
+
+#ifdef TLS_USE_SYSARCH
+ sysarch(MIPS_GET_TLS, &tcb);
#else
-#define TLS_TCB_SIZE 8
+ __asm__ __volatile__ (
+ ".set\tpush\n\t"
+#ifdef __mips_n64
+ ".set\tmips64r2\n\t"
+#else
+ ".set\tmips32r2\n\t"
+#endif
+ "rdhwr\t%0, $29\n\t"
+ ".set\tpop"
+ : "=r" (tcb));
+ tcb = (struct tcb *)((uintptr_t)tcb - TLS_TP_OFFSET - TLS_TCB_SIZE);
+#endif
+ return (tcb);
+}
+
#endif
#endif /* __MIPS_TLS_H__ */
diff --git a/sys/powerpc/include/tls.h b/sys/powerpc/include/tls.h
new file mode 100644
--- /dev/null
+++ b/sys/powerpc/include/tls.h
@@ -0,0 +1,66 @@
+/*-
+ * 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.
+ */
+
+#ifndef _MACHINE_TLS_H_
+#define _MACHINE_TLS_H_
+
+#include <sys/_tls_variant_i.h>
+
+#define TLS_DTV_OFFSET 0x8000
+#define TLS_TCB_ALIGN TLS_TCB_SIZE
+#define TLS_TP_OFFSET 0x7000
+
+static __inline void
+_tcb_set(struct tcb *tcb)
+{
+#ifdef __powerpc64__
+ __asm __volatile("mr 13,%0" ::
+ "r" ((uint8_t *)tcb + TLS_TP_OFFSET + TLS_TCB_SIZE));
+#else
+ __asm __volatile("mr 2,%0" ::
+ "r" ((uint8_t *)tcb + TLS_TP_OFFSET + TLS_TCB_SIZE));
+#endif
+}
+
+static __inline struct tcb *
+_tcb_get(void)
+{
+ struct tcb *tcb;
+
+#ifdef __powerpc64__
+ __asm __volatile("addi %0,13,%1" : "=r" (tcb) :
+ "i" (-(TLS_TP_OFFSET + TLS_TCB_SIZE)));
+#else
+ __asm __volatile("addi %0,2,%1" : "=r" (tcb) :
+ "i" (-(TLS_TP_OFFSET + TLS_TCB_SIZE)));
+#endif
+ return (tcb);
+}
+
+#endif /* !_MACHINE_TLS_H_ */
diff --git a/sys/riscv/include/tls.h b/sys/riscv/include/tls.h
new file mode 100644
--- /dev/null
+++ b/sys/riscv/include/tls.h
@@ -0,0 +1,60 @@
+/*-
+ * Copyright (c) 2005 David Xu <davidxu@freebsd.org>
+ * Copyright (c) 2015 Ruslan Bukin <br@bsdpad.com>
+ * 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.
+ */
+
+#ifndef _MACHINE_TLS_H_
+#define _MACHINE_TLS_H_
+
+#include <sys/_tls_variant_i.h>
+
+#define TLS_DTV_OFFSET 0x800
+#define TLS_TCB_ALIGN 16
+#define TLS_TP_OFFSET 0
+
+static __inline void
+_tcb_set(struct tcb *tcb)
+{
+ __asm __volatile("addi tp, %0, %1" :: "r" (tcb), "I" (TLS_TCB_SIZE));
+}
+
+static __inline struct tcb *
+_tcb_get(void)
+{
+ struct tcb *tcb;
+
+ __asm __volatile("addi %0, tp, %1" : "=r" (tcb) : "I" (-TLS_TCB_SIZE));
+ return (tcb);
+}
+
+#endif /* !_MACHINE_TLS_H_ */
diff --git a/sys/sys/_tls_variant_i.h b/sys/sys/_tls_variant_i.h
new file mode 100644
--- /dev/null
+++ b/sys/sys/_tls_variant_i.h
@@ -0,0 +1,47 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2005 David Xu <davidxu@freebsd.org>.
+ * 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.
+ */
+
+#ifndef _SYS_TLS_VARIANT_I_H_
+#define _SYS_TLS_VARIANT_I_H_
+
+/*
+ * Variant I TLS uses the same TCB layout across architectures.
+ */
+
+#define TLS_VARIANT_I
+
+struct pthread;
+
+struct tcb {
+ uintptr_t *tcb_dtv; /* required by rtld */
+ struct pthread *tcb_thread;
+};
+
+#define TLS_TCB_SIZE sizeof(struct tcb)
+
+#endif /* !_SYS_TLS_VARIANT_I_H_ */
diff --git a/sys/x86/include/tls.h b/sys/x86/include/tls.h
new file mode 100644
--- /dev/null
+++ b/sys/x86/include/tls.h
@@ -0,0 +1,81 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (C) 2003 David Xu <davidxu@freebsd.org>
+ * Copyright (c) 2001 Daniel Eischen <deischen@freebsd.org>
+ * 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.
+ */
+
+#ifndef _MACHINE_TLS_H_
+#define _MACHINE_TLS_H_
+
+#include <x86/sysarch.h>
+
+#define TLS_VARIANT_II
+
+struct pthread;
+
+/*
+ * Variant II tcb, first two members are required by rtld,
+ * %fs (amd64) / %gs (i386) points to the structure.
+ */
+struct tcb {
+ struct tcb *tcb_self; /* required by rtld */
+ uintptr_t *tcb_dtv; /* required by rtld */
+ struct pthread *tcb_thread;
+};
+
+#define TLS_DTV_OFFSET 0
+#ifdef __amd64__
+#define TLS_TCB_ALIGN 16
+#else
+#define TLS_TCB_ALIGN 4
+#endif
+#define TLS_TCB_SIZE sizeof(struct tcb)
+#define TLS_TP_OFFSET 0
+
+static __inline void
+_tcb_set(struct tcb *tcb)
+{
+#ifdef __amd64__
+ amd64_set_fsbase(tcb);
+#else
+ i386_set_gsbase(tcb);
+#endif
+}
+
+static __inline struct tcb *
+_tcb_get(void)
+{
+ struct tcb *tcb;
+
+#ifdef __amd64__
+ __asm __volatile("movq %%fs:0, %0" : "=r" (tcb));
+#else
+ __asm __volatile("movl %%gs:0, %0" : "=r" (tcb));
+#endif
+ return (tcb);
+}
+
+#endif /* !_MACHINE_TLS_H_ */

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 19, 11:46 AM (22 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
14699461
Default Alt Text
D33351.diff (14 KB)

Event Timeline