93dc2d
commit 8dbeb0561eeb876f557ac9eef5721912ec074ea5
93dc2d
Author: Florian Weimer <fweimer@redhat.com>
93dc2d
Date:   Thu Dec 9 09:49:32 2021 +0100
93dc2d
93dc2d
    nptl: Add <thread_pointer.h> for defining __thread_pointer
93dc2d
    
93dc2d
    <tls.h> already contains a definition that is quite similar,
93dc2d
    but it is not consistent across architectures.
93dc2d
    
93dc2d
    Only architectures for which rseq support is added are covered.
93dc2d
    
93dc2d
    Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
93dc2d
93dc2d
diff --git a/sysdeps/nptl/thread_pointer.h b/sysdeps/nptl/thread_pointer.h
93dc2d
new file mode 100644
93dc2d
index 0000000000000000..92f2f3093eba55bb
93dc2d
--- /dev/null
93dc2d
+++ b/sysdeps/nptl/thread_pointer.h
93dc2d
@@ -0,0 +1,28 @@
93dc2d
+/* __thread_pointer definition.  Generic version.
93dc2d
+   Copyright (C) 2021 Free Software Foundation, Inc.
93dc2d
+   This file is part of the GNU C Library.
93dc2d
+
93dc2d
+   The GNU C Library is free software; you can redistribute it and/or
93dc2d
+   modify it under the terms of the GNU Lesser General Public
93dc2d
+   License as published by the Free Software Foundation; either
93dc2d
+   version 2.1 of the License, or (at your option) any later version.
93dc2d
+
93dc2d
+   The GNU C Library is distributed in the hope that it will be useful,
93dc2d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
93dc2d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
93dc2d
+   Lesser General Public License for more details.
93dc2d
+
93dc2d
+   You should have received a copy of the GNU Lesser General Public
93dc2d
+   License along with the GNU C Library.  If not, see
93dc2d
+   <https://www.gnu.org/licenses/>.  */
93dc2d
+
93dc2d
+#ifndef _SYS_THREAD_POINTER_H
93dc2d
+#define _SYS_THREAD_POINTER_H
93dc2d
+
93dc2d
+static inline void *
93dc2d
+__thread_pointer (void)
93dc2d
+{
93dc2d
+  return __builtin_thread_pointer ();
93dc2d
+}
93dc2d
+
93dc2d
+#endif /* _SYS_THREAD_POINTER_H */
93dc2d
diff --git a/sysdeps/powerpc/nptl/thread_pointer.h b/sysdeps/powerpc/nptl/thread_pointer.h
93dc2d
new file mode 100644
93dc2d
index 0000000000000000..8fd5ba671f6f5e64
93dc2d
--- /dev/null
93dc2d
+++ b/sysdeps/powerpc/nptl/thread_pointer.h
93dc2d
@@ -0,0 +1,33 @@
93dc2d
+/* __thread_pointer definition.  powerpc version.
93dc2d
+   Copyright (C) 2021 Free Software Foundation, Inc.
93dc2d
+   This file is part of the GNU C Library.
93dc2d
+
93dc2d
+   The GNU C Library is free software; you can redistribute it and/or
93dc2d
+   modify it under the terms of the GNU Lesser General Public
93dc2d
+   License as published by the Free Software Foundation; either
93dc2d
+   version 2.1 of the License, or (at your option) any later version.
93dc2d
+
93dc2d
+   The GNU C Library is distributed in the hope that it will be useful,
93dc2d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
93dc2d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
93dc2d
+   Lesser General Public License for more details.
93dc2d
+
93dc2d
+   You should have received a copy of the GNU Lesser General Public
93dc2d
+   License along with the GNU C Library.  If not, see
93dc2d
+   <https://www.gnu.org/licenses/>.  */
93dc2d
+
93dc2d
+#ifndef _SYS_THREAD_POINTER_H
93dc2d
+#define _SYS_THREAD_POINTER_H
93dc2d
+
93dc2d
+static inline void *
93dc2d
+__thread_pointer (void)
93dc2d
+{
93dc2d
+#ifdef __powerpc64__
93dc2d
+  register void *__result asm ("r13");
93dc2d
+#else
93dc2d
+  register void *__result asm ("r2");
93dc2d
+#endif
93dc2d
+  return __result;
93dc2d
+}
93dc2d
+
93dc2d
+#endif /* _SYS_THREAD_POINTER_H */
93dc2d
diff --git a/sysdeps/x86/nptl/thread_pointer.h b/sysdeps/x86/nptl/thread_pointer.h
93dc2d
new file mode 100644
93dc2d
index 0000000000000000..6b71b6f7e1401e4c
93dc2d
--- /dev/null
93dc2d
+++ b/sysdeps/x86/nptl/thread_pointer.h
93dc2d
@@ -0,0 +1,38 @@
93dc2d
+/* __thread_pointer definition.  x86 version.
93dc2d
+   Copyright (C) 2021 Free Software Foundation, Inc.
93dc2d
+   This file is part of the GNU C Library.
93dc2d
+
93dc2d
+   The GNU C Library is free software; you can redistribute it and/or
93dc2d
+   modify it under the terms of the GNU Lesser General Public
93dc2d
+   License as published by the Free Software Foundation; either
93dc2d
+   version 2.1 of the License, or (at your option) any later version.
93dc2d
+
93dc2d
+   The GNU C Library is distributed in the hope that it will be useful,
93dc2d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
93dc2d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
93dc2d
+   Lesser General Public License for more details.
93dc2d
+
93dc2d
+   You should have received a copy of the GNU Lesser General Public
93dc2d
+   License along with the GNU C Library.  If not, see
93dc2d
+   <https://www.gnu.org/licenses/>.  */
93dc2d
+
93dc2d
+#ifndef _SYS_THREAD_POINTER_H
93dc2d
+#define _SYS_THREAD_POINTER_H
93dc2d
+
93dc2d
+static inline void *
93dc2d
+__thread_pointer (void)
93dc2d
+{
93dc2d
+#if __GNUC_PREREQ (11, 1)
93dc2d
+  return __builtin_thread_pointer ();
93dc2d
+#else
93dc2d
+  void *__result;
93dc2d
+# ifdef __x86_64__
93dc2d
+  __asm__ ("mov %%fs:0, %0" : "=r" (__result));
93dc2d
+# else
93dc2d
+  __asm__ ("mov %%gs:0, %0" : "=r" (__result));
93dc2d
+# endif
93dc2d
+  return __result;
93dc2d
+#endif /* !GCC 11 */
93dc2d
+}
93dc2d
+
93dc2d
+#endif /* _SYS_THREAD_POINTER_H */