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