#include <sys/param.h>
#include <array_length.h>
#include <pthreadP.h>
+#include <dl-call_tls_init_tp.h>
#ifdef SHARED
#error makefile bug, this file is for static only
tcb_offset = roundup (memsz + GLRO(dl_tls_static_surplus), max_align);
tlsblock = _dl_early_allocate (tcb_offset + TLS_INIT_TCB_SIZE + max_align);
if (tlsblock == NULL)
- _startup_fatal ("Fatal glibc error: Cannot allocate TLS block\n");
+ _startup_fatal_tls_error ();
#elif TLS_DTV_AT_TP
tcb_offset = roundup (TLS_INIT_TCB_SIZE, align ?: 1);
tlsblock = _dl_early_allocate (tcb_offset + memsz + max_align
+ TLS_PRE_TCB_SIZE
+ GLRO(dl_tls_static_surplus));
if (tlsblock == NULL)
- _startup_fatal ("Fatal glibc error: Cannot allocate TLS block\n");
+ _startup_fatal_tls_error ();
tlsblock += TLS_PRE_TCB_SIZE;
#else
/* In case a model with a different layout for the TCB and DTV
#if TLS_TCB_AT_TP
INSTALL_DTV ((char *) tlsblock + tcb_offset, _dl_static_dtv);
- const char *lossage = TLS_INIT_TP ((char *) tlsblock + tcb_offset);
+ call_tls_init_tp ((char *) tlsblock + tcb_offset);
#elif TLS_DTV_AT_TP
INSTALL_DTV (tlsblock, _dl_static_dtv);
- const char *lossage = TLS_INIT_TP (tlsblock);
-#else
-# error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
+ call_tls_init_tp (tlsblock);
#endif
- if (__builtin_expect (lossage != NULL, 0))
- _startup_fatal (lossage);
- __tls_init_tp ();
/* Update the executable's link map with enough information to make
the TLS routines happy. */
#include <dl-execve.h>
#include <dl-find_object.h>
#include <dl-audit-check.h>
+#include <dl-call_tls_init_tp.h>
#include <assert.h>
GL(dl_initial_dtv) = GET_DTV (tcbp);
/* And finally install it for the main thread. */
- const char *lossage = TLS_INIT_TP (tcbp);
- if (__glibc_unlikely (lossage != NULL))
- _dl_fatal_printf ("cannot set up thread-local storage: %s\n", lossage);
- __tls_init_tp ();
+ call_tls_init_tp (tcbp);
__rtld_tls_init_tp_called = true;
return tcbp;
/* And finally install it for the main thread. */
if (! __rtld_tls_init_tp_called)
- {
- const char *lossage = TLS_INIT_TP (tcbp);
- if (__glibc_unlikely (lossage != NULL))
- _dl_fatal_printf ("cannot set up thread-local storage: %s\n",
- lossage);
- __tls_init_tp ();
- }
+ call_tls_init_tp (tcbp);
/* Make sure no new search directories have been added. */
assert (GLRO(dl_init_all_dirs) == GL(dl_all_dirs));
special attention since 'errno' is not yet available and if the
operation can cause a failure 'errno' must not be touched. */
# define TLS_INIT_TP(tcbp) \
- ({ __asm __volatile ("msr tpidr_el0, %0" : : "r" (tcbp)); NULL; })
+ ({ __asm __volatile ("msr tpidr_el0, %0" : : "r" (tcbp)); true; })
/* Value passed to 'clone' for initialization of the thread register. */
# define TLS_DEFINE_INIT_TP(tp, pd) void *tp = (pd) + 1
special attention since 'errno' is not yet available and if the
operation can cause a failure 'errno' must not be touched. */
# define TLS_INIT_TP(tcbp) \
- (__builtin_set_thread_pointer ((void *)(tcbp)), NULL)
+ (__builtin_set_thread_pointer ((void *)(tcbp)), true)
/* Value passed to 'clone' for initialization of the thread register. */
# define TLS_DEFINE_INIT_TP(tp, pd) void *tp = (pd) + 1
long result_var; \
__builtin_set_thread_pointer (tcbp); \
result_var = INTERNAL_SYSCALL_CALL (arc_settls, (tcbp));\
- INTERNAL_SYSCALL_ERROR_P (result_var) \
- ? "settls syscall error" : NULL; \
+ !INTERNAL_SYSCALL_ERROR_P (result_var); \
})
/* Value passed to 'clone' for initialization of the thread register. */
({ long int result_var; \
result_var = INTERNAL_SYSCALL_CALL (set_thread_area, \
(char *) (tcbp) + TLS_TCB_OFFSET); \
- INTERNAL_SYSCALL_ERROR_P (result_var) \
- ? "unknown error" : NULL; })
+ !INTERNAL_SYSCALL_ERROR_P (result_var); })
/* Return the address of the dtv for the current thread. */
# define THREAD_DTV() \
--- /dev/null
+/* Invoke TLS_INIT_TP and __tls_init_tp with error handling.
+ Copyright (C) 2022 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <startup.h>
+#include <tls.h>
+
+static inline void
+_startup_fatal_tls_error (void)
+{
+ _startup_fatal ("Fatal glibc error: Cannot allocate TLS block\n");
+}
+
+static inline void
+call_tls_init_tp (void *addr)
+{
+ if (!TLS_INIT_TP (addr))
+ _startup_fatal_tls_error ();
+ __tls_init_tp ();
+}
/* Targets should override this file if the default definitions below
will not work correctly very early before TLS is initialized. */
-#include <unistd.h>
+#include <stdio.h>
/* Use macro instead of inline function to avoid including <stdio.h>. */
#define _startup_fatal(message) __libc_fatal ((message))
special attention since 'errno' is not yet available and if the
operation can cause a failure 'errno' must not be touched. */
# define TLS_INIT_TP(tcbp) \
- ({ __set_cr27(tcbp); NULL; })
+ ({ __set_cr27(tcbp); true; })
/* Value passed to 'clone' for initialization of the thread register. */
# define TLS_DEFINE_INIT_TP(tp, pd) void *tp = (pd) + 1
which is necessary since we have changed it. */ \
TLS_SET_GS (_segdescr.desc.entry_number * 8 + 3); \
\
- _result == 0 ? NULL \
- : "set_thread_area failed when setting up thread-local storage\n"; })
+ _result == 0; })
# define TLS_DEFINE_INIT_TP(tp, pd) \
union user_desc_init _segdescr; \
special attention since 'errno' is not yet available and if the
operation can cause a failure 'errno' must not be touched. */
# define TLS_INIT_TP(thrdescr) \
- (__thread_self = (thrdescr), INIT_SYSINFO, NULL)
+ (__thread_self = (thrdescr), INIT_SYSINFO, true)
/* Value passed to 'clone2' for initialization of the thread register. */
# define TLS_DEFINE_INIT_TP(tp, pd) \
#define TLS_INIT_TP(tcbp) \
({ \
__thread_self = (char *) tcbp + TLS_TCB_OFFSET; \
- NULL; \
+ true; \
})
/* Return the address of the dtv for the current thread. */
\
_sys_result = INTERNAL_SYSCALL_CALL (set_thread_area, \
((void *) (tcbp)) + TLS_TCB_OFFSET); \
- INTERNAL_SYSCALL_ERROR_P (_sys_result) ? "unknown error" : NULL; })
+ !INTERNAL_SYSCALL_ERROR_P (_sys_result); })
# define TLS_DEFINE_INIT_TP(tp, pd) \
void *tp = (void *) (pd) + TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE
# define HURD_SEL_LDT(sel) (__builtin_expect ((sel) & 4, 0))
-static inline const char * __attribute__ ((unused))
+static inline bool __attribute__ ((unused))
_hurd_tls_init (tcbhead_t *tcb)
{
HURD_TLS_DESC_DECL (desc, tcb);
thread_t self = __mach_thread_self ();
- const char *msg = NULL;
+ bool success = true;
/* This field is used by TLS accesses to get our "thread pointer"
from the TLS point of view. */
assert_perror (err);
if (err)
{
- msg = "i386_set_ldt failed";
+ success = false;
goto out;
}
}
else if (err)
{
assert_perror (err); /* Separate from above with different line #. */
- msg = "i386_set_gdt failed";
+ success = false;
goto out;
}
out:
__mach_port_deallocate (__mach_task_self (), self);
- return msg;
+ return success;
}
/* Code to initially initialize the thread pointer. This might need
/* Code to initially initialize the thread pointer.
r21 is reserved for thread pointer. */
# define TLS_INIT_TP(tcbp) \
- ({ __asm __volatile ("or r21,r0,%0" : : "r" ((void *)tcbp)); NULL; })
+ ({ __asm __volatile ("or r21,r0,%0" : : "r" ((void *)tcbp)); true; })
# define TLS_DEFINE_INIT_TP(tp, pd) void *tp = (pd) + 1
({ long int result_var; \
result_var = INTERNAL_SYSCALL_CALL (set_thread_area, \
(char *) (tcbp) + TLS_TCB_OFFSET); \
- INTERNAL_SYSCALL_ERROR_P (result_var) \
- ? "unknown error" : NULL; })
+ !INTERNAL_SYSCALL_ERROR_P (result_var); })
/* Value passed to 'clone' for initialization of the thread register. */
# define TLS_DEFINE_INIT_TP(tp, pd) \
/* Code to initially initialize the thread pointer. */
# define TLS_INIT_TP(tcbp) \
- (__thread_self = (struct pthread *) ((char *) tcbp + TLS_TCB_OFFSET), NULL)
+ (__thread_self = (struct pthread *) ((char *) tcbp + TLS_TCB_OFFSET), true)
/* Value passed to 'clone' for initialization of the thread register. */
# define TLS_DEFINE_INIT_TP(tp, pd) \
It's hard to fail this, so return NULL always. */
# define TLS_INIT_TP(tcbp) \
- ({__thread_self = ((tcbhead_t *)tcbp + 1); NULL;})
+ ({__thread_self = ((tcbhead_t *)tcbp + 1); true;})
/* Value passed to 'clone' for initialization of the thread register. */
# define TLS_DEFINE_INIT_TP(tp, pd) \
__thread_register = (void *) (tcbp) + TLS_TCB_OFFSET; \
THREAD_SET_HWCAP (__tcb.hwcap); \
THREAD_SET_AT_PLATFORM (__tcb.at_platform); \
- NULL; \
+ true; \
})
/* Value passed to 'clone' for initialization of the thread register. */
/* Code to initially initialize the thread pointer. */
# define TLS_INIT_TP(tcbp) \
- ({ __thread_self = (char*)tcbp + TLS_TCB_OFFSET; NULL; })
+ ({ __thread_self = (char*)tcbp + TLS_TCB_OFFSET; true; })
/* Return the address of the dtv for the current thread. */
# define THREAD_DTV() \
INIT_SYSINFO; \
\
__builtin_set_thread_pointer (_thrdescr); \
- NULL; \
+ true; \
})
/* Value passed to 'clone' for initialization of the thread register. */
special attention since 'errno' is not yet available and if the
operation can cause a failure 'errno' must not be touched. */
# define TLS_INIT_TP(tcbp) \
- ({ __asm __volatile ("ldc %0,gbr" : : "r" (tcbp)); NULL; })
+ ({ __asm __volatile ("ldc %0,gbr" : : "r" (tcbp)); true; })
# define TLS_DEFINE_INIT_TP(tp, pd) void *tp = (pd) + 1
/* Code to initially initialize the thread pointer. */
# define TLS_INIT_TP(descr) \
- (__thread_self = (__typeof (__thread_self)) (descr), NULL)
+ (__thread_self = (__typeof (__thread_self)) (descr), true)
/* Value passed to 'clone' for initialization of the thread register. */
# define TLS_DEFINE_INIT_TP(tp, pd) void *tp = (pd)
# define TLS_INIT_TP(tcbp) \
({ long int result_var; \
result_var = INTERNAL_SYSCALL_CALL (set_tls, (tcbp)); \
- INTERNAL_SYSCALL_ERROR_P (result_var) \
- ? "unknown error" : NULL; })
+ !INTERNAL_SYSCALL_ERROR_P (result_var); })
#endif /* __ASSEMBLER__ */
"S" (_thrdescr) \
: "memory", "cc", "r11", "cx"); \
\
- _result ? "cannot set %fs base address for thread-local storage" : 0; \
+ _result == 0; \
})
# define TLS_DEFINE_INIT_TP(tp, pd) void *tp = (pd)