/* Thread-local storage handling in the ELF dynamic linker. Generic version.
Copyright (C) 2002-2006,2008,2011,2012 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
<http://www.gnu.org/licenses/>. */
#include <assert.h>
#include <errno.h>
#include <libintl.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/param.h>
#include <tls.h>
#include <dl-tls.h>
#include <ldsodefs.h>
/* Amount of excess space to allocate in the static TLS area
to allow dynamic loading of modules defining IE-model TLS data. */
#define TLS_STATIC_SURPLUS 64 + DL_NNS * 100
/* Out-of-memory handler. */
#ifdef SHARED
static void
__attribute__ ((__noreturn__))
oom (void)
{
_dl_fatal_printf ("cannot allocate memory for thread-local data: ABORT\n");
}
#endif
size_t
internal_function
_dl_next_tls_modid (void)
{
size_t result;
if (__builtin_expect (GL(dl_tls_dtv_gaps), false))
{
size_t disp = 0;
struct dtv_slotinfo_list *runp = GL(dl_tls_dtv_slotinfo_list);
/* Note that this branch will never be executed during program
start since there are no gaps at that time. Therefore it
does not matter that the dl_tls_dtv_slotinfo is not allocated
yet when the function is called for the first times.
NB: the offset +1 is due to the fact that DTV[0] is used
for something else. */
result = GL(dl_tls_static_nelem) + 1;
if (result <= GL(dl_tls_max_dtv_idx))
do
{
while (result - disp < runp->len)
{
if (runp->slotinfo[result - disp].map == NULL)
break;
++result;
assert (result <=