summaryrefslogtreecommitdiffstats
path: root/libpthread/nptl/sysdeps
diff options
context:
space:
mode:
Diffstat (limited to 'libpthread/nptl/sysdeps')
-rw-r--r--libpthread/nptl/sysdeps/alpha/dl-tls.c1
-rw-r--r--libpthread/nptl/sysdeps/generic/dl-minimal.c129
-rw-r--r--libpthread/nptl/sysdeps/generic/dl-tls.c69
-rw-r--r--libpthread/nptl/sysdeps/generic/powerpc/libc-tls.c1
-rw-r--r--libpthread/nptl/sysdeps/generic/sh/libc-tls.c1
-rw-r--r--libpthread/nptl/sysdeps/generic/sparc/libc-tls.c1
-rw-r--r--libpthread/nptl/sysdeps/i386/dl-tls.c1
-rw-r--r--libpthread/nptl/sysdeps/i386/libc-tls.c1
-rw-r--r--libpthread/nptl/sysdeps/mips/dl-tls.c1
-rw-r--r--libpthread/nptl/sysdeps/powerpc/dl-tls.c1
-rw-r--r--libpthread/nptl/sysdeps/sh/dl-tls.c1
-rw-r--r--libpthread/nptl/sysdeps/sparc/dl-tls.c1
-rw-r--r--libpthread/nptl/sysdeps/x86_64/dl-tls.c1
13 files changed, 184 insertions, 25 deletions
diff --git a/libpthread/nptl/sysdeps/alpha/dl-tls.c b/libpthread/nptl/sysdeps/alpha/dl-tls.c
new file mode 100644
index 000000000..db50de8ab
--- /dev/null
+++ b/libpthread/nptl/sysdeps/alpha/dl-tls.c
@@ -0,0 +1 @@
+#include <../generic/dl-tls.c>
diff --git a/libpthread/nptl/sysdeps/generic/dl-minimal.c b/libpthread/nptl/sysdeps/generic/dl-minimal.c
new file mode 100644
index 000000000..02968a91c
--- /dev/null
+++ b/libpthread/nptl/sysdeps/generic/dl-minimal.c
@@ -0,0 +1,129 @@
+/* Minimal replacements for basic facilities used in the dynamic linker.
+ Copyright (C) 1995-1998,2000-2002,2004 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+//#include <errno.h>
+#include <limits.h>
+#include <string.h>
+#include <tls.h>
+//#include <unistd.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <ldsodefs.h>
+
+/* Minimal `malloc' allocator for use while loading shared libraries.
+ No block is ever freed. */
+
+static void *alloc_ptr, *alloc_end, *alloc_last_block;
+
+/* Declarations of global functions. */
+extern void weak_function free (void *ptr);
+extern void * weak_function realloc (void *ptr, size_t n);
+
+/* Allocate an aligned memory block. */
+void * weak_function
+memalign (size_t align, size_t n)
+{
+#ifdef MAP_ANON
+#define _dl_zerofd (-1)
+#else
+ extern int _dl_zerofd;
+
+ if (_dl_zerofd == -1)
+ _dl_zerofd = _dl_sysdep_open_zero_fill ();
+#define MAP_ANON 0
+#endif
+
+ if (alloc_end == 0)
+ {
+ /* Consume any unused space in the last page of our data segment. */
+ extern int _end attribute_hidden;
+ alloc_ptr = &_end;
+ alloc_end = (void *) 0 + (((alloc_ptr - (void *) 0)
+ + GLRO(dl_pagesize) - 1)
+ & ~(GLRO(dl_pagesize) - 1));
+ }
+
+ /* Make sure the allocation pointer is ideally aligned. */
+ alloc_ptr = (void *) 0 + (((alloc_ptr - (void *) 0) + align - 1)
+ & ~(align - 1));
+
+ if (alloc_ptr + n >= alloc_end)
+ {
+ /* Insufficient space left; allocate another page. */
+ caddr_t page;
+ size_t nup = (n + GLRO(dl_pagesize) - 1) & ~(GLRO(dl_pagesize) - 1);
+ page = _dl_mmap (0, nup, PROT_READ|PROT_WRITE,
+ MAP_ANON|MAP_PRIVATE, _dl_zerofd, 0);
+ if (_dl_mmap_check_error(page))
+ return -1;
+ if (page != alloc_end)
+ alloc_ptr = page;
+ alloc_end = page + nup;
+ }
+
+ alloc_last_block = (void *) alloc_ptr;
+ alloc_ptr += n;
+ return alloc_last_block;
+}
+
+void * weak_function
+malloc (size_t n)
+{
+ return memalign (sizeof (double), n);
+}
+
+/* We use this function occasionally since the real implementation may
+ be optimized when it can assume the memory it returns already is
+ set to NUL. */
+void * weak_function
+calloc (size_t nmemb, size_t size)
+{
+ /* New memory from the trivial malloc above is always already cleared.
+ (We make sure that's true in the rare occasion it might not be,
+ by clearing memory in free, below.) */
+ return malloc (nmemb * size);
+}
+
+/* This will rarely be called. */
+void weak_function
+free (void *ptr)
+{
+ /* We can free only the last block allocated. */
+ if (ptr == alloc_last_block)
+ {
+ /* Since this is rare, we clear the freed block here
+ so that calloc can presume malloc returns cleared memory. */
+ _dl_memset (alloc_last_block, '\0', alloc_ptr - alloc_last_block);
+ alloc_ptr = alloc_last_block;
+ }
+}
+
+/* This is only called with the most recent block returned by malloc. */
+void * weak_function
+realloc (void *ptr, size_t n)
+{
+ void *new;
+ if (ptr == NULL)
+ return malloc (n);
+ assert (ptr == alloc_last_block);
+ alloc_ptr = alloc_last_block;
+ new = malloc (n);
+ assert (new == ptr);
+ return new;
+}
diff --git a/libpthread/nptl/sysdeps/generic/dl-tls.c b/libpthread/nptl/sysdeps/generic/dl-tls.c
index 4fed570d5..4c3a9db4b 100644
--- a/libpthread/nptl/sysdeps/generic/dl-tls.c
+++ b/libpthread/nptl/sysdeps/generic/dl-tls.c
@@ -1,4 +1,4 @@
-/* Thread-local storage handling in the ELF dynamic linker. Generic version.
+/* tHREAD-local storage handling in the ELF dynamic linker. Generic version.
Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
@@ -17,21 +17,27 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#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>
-/* We don't need any of this if TLS is not supported. */
-#ifdef USE_TLS
+#ifndef IS_IN_rtld
+#include <assert.h>
+#include <link.h>
+#include <string.h>
+#include <unistd.h>
-# include <dl-tls.h>
-# include <ldsodefs.h>
+#define _dl_malloc malloc
+#define _dl_memset memset
+#define _dl_mempcpy mempcpy
+#define _dl_dprintf fprintf
+#define _dl_debug_file stderr
+#define _dl_exit exit
+#endif
/* Amount of excess space to allocate in the static TLS area
to allow dynamic loading of modules defining IE-model TLS data. */
@@ -47,11 +53,20 @@ static void
__attribute__ ((__noreturn__))
oom (void)
{
- _dl_fatal_printf ("cannot allocate memory for thread-local data: ABORT\n");
+ do {
+ _dl_dprintf (_dl_debug_file,
+ "cannot allocate thread-local memory: ABORT\n");
+ _dl_exit (127);
+ } while (1);
}
# endif
+void *_dl_memalign(size_t alignment, size_t bytes)
+{
+ return _dl_malloc(bytes);
+}
+
size_t
internal_function
_dl_next_tls_modid (void)
@@ -208,8 +223,9 @@ _dl_determine_tlsoffset (void)
# elif TLS_DTV_AT_TP
/* The TLS blocks start right after the TCB. */
size_t offset = TLS_TCB_SIZE;
+ size_t cnt;
- for (size_t cnt = 0; slotinfo[cnt].map != NULL; ++cnt)
+ for (cnt = 0; slotinfo[cnt].map != NULL; ++cnt)
{
assert (cnt < GL(dl_tls_dtv_slotinfo_list)->len);
@@ -346,7 +362,7 @@ _dl_allocate_tls_storage (void)
# endif
/* Allocate a correctly aligned chunk of memory. */
- result = __libc_memalign (GL(dl_tls_static_align), size);
+ result = _dl_memalign (GL(dl_tls_static_align), size);
if (__builtin_expect (result != NULL, 1))
{
/* Allocate the DTV. */
@@ -358,14 +374,14 @@ _dl_allocate_tls_storage (void)
/* Clear the TCB data structure. We can't ask the caller (i.e.
libpthread) to do it, because we will initialize the DTV et al. */
- memset (result, '\0', TLS_TCB_SIZE);
+ _dl_memset (result, '\0', TLS_TCB_SIZE);
# elif TLS_DTV_AT_TP
result = (char *) result + size - GL(dl_tls_static_size);
/* Clear the TCB data structure and TLS_PRE_TCB_SIZE bytes before it.
We can't ask the caller (i.e. libpthread) to do it, because we will
initialize the DTV et al. */
- memset ((char *) result - TLS_PRE_TCB_SIZE, '\0',
+ _dl_memset ((char *) result - TLS_PRE_TCB_SIZE, '\0',
TLS_PRE_TCB_SIZE + TLS_TCB_SIZE);
# endif
@@ -440,7 +456,7 @@ _dl_allocate_tls_init (void *result)
/* Copy the initialization image and clear the BSS part. */
dtv[map->l_tls_modid].pointer.val = dest;
dtv[map->l_tls_modid].pointer.is_static = true;
- memset (__mempcpy (dest, map->l_tls_initimage,
+ _dl_memset (_dl_mempcpy (dest, map->l_tls_initimage,
map->l_tls_initimage_size), '\0',
map->l_tls_blocksize - map->l_tls_initimage_size);
}
@@ -476,9 +492,10 @@ internal_function
_dl_deallocate_tls (void *tcb, bool dealloc_tcb)
{
dtv_t *dtv = GET_DTV (tcb);
+ size_t cnt;
/* We need to free the memory allocated for non-static TLS. */
- for (size_t cnt = 0; cnt < dtv[-1].counter; ++cnt)
+ for (cnt = 0; cnt < dtv[-1].counter; ++cnt)
if (! dtv[1 + cnt].pointer.is_static
&& dtv[1 + cnt].pointer.val != TLS_DTV_UNALLOCATED)
free (dtv[1 + cnt].pointer.val);
@@ -529,12 +546,12 @@ allocate_and_init (struct link_map *map)
{
void *newp;
- newp = __libc_memalign (map->l_tls_align, map->l_tls_blocksize);
+ newp = _dl_memalign (map->l_tls_align, map->l_tls_blocksize);
if (newp == NULL)
oom ();
/* Initialize the memory. */
- memset (__mempcpy (newp, map->l_tls_initimage, map->l_tls_initimage_size),
+ _dl_memset (_dl_mempcpy (newp, map->l_tls_initimage, map->l_tls_initimage_size),
'\0', map->l_tls_blocksize - map->l_tls_initimage_size);
return newp;
@@ -584,7 +601,9 @@ _dl_update_slotinfo (unsigned long int req_modid)
listp = GL(dl_tls_dtv_slotinfo_list);
do
{
- for (size_t cnt = total == 0 ? 1 : 0; cnt < listp->len; ++cnt)
+ size_t cnt;
+
+ for (cnt = total == 0 ? 1 : 0; cnt < listp->len; ++cnt)
{
size_t gen = listp->slotinfo[cnt].gen;
@@ -637,7 +656,7 @@ _dl_update_slotinfo (unsigned long int req_modid)
newp = malloc ((2 + newsize) * sizeof (dtv_t));
if (newp == NULL)
oom ();
- memcpy (newp, &dtv[-1], oldsize * sizeof (dtv_t));
+ _dl_memcpy (newp, &dtv[-1], oldsize * sizeof (dtv_t));
}
else
{
@@ -650,7 +669,7 @@ _dl_update_slotinfo (unsigned long int req_modid)
newp[0].counter = newsize;
/* Clear the newly allocated part. */
- memset (newp + 2 + oldsize, '\0',
+ _dl_memset (newp + 2 + oldsize, '\0',
(newsize - oldsize) * sizeof (dtv_t));
/* Point dtv to the generation counter. */
@@ -782,13 +801,14 @@ _dl_add_to_slotinfo (struct link_map *l)
generation. */
++GL(dl_tls_generation);
- _dl_signal_error (ENOMEM, "dlopen", NULL, N_("\
-cannot create TLS data structures"));
+ _dl_dprintf (_dl_debug_file,
+ "cannot create TLS data structures: ABORT\n");
+ _dl_exit (127);
}
listp->len = TLS_SLOTINFO_SURPLUS;
listp->next = NULL;
- memset (listp->slotinfo, '\0',
+ _dl_memset (listp->slotinfo, '\0',
TLS_SLOTINFO_SURPLUS * sizeof (struct dtv_slotinfo));
}
@@ -796,4 +816,3 @@ cannot create TLS data structures"));
listp->slotinfo[idx].map = l;
listp->slotinfo[idx].gen = GL(dl_tls_generation) + 1;
}
-#endif /* use TLS */
diff --git a/libpthread/nptl/sysdeps/generic/powerpc/libc-tls.c b/libpthread/nptl/sysdeps/generic/powerpc/libc-tls.c
new file mode 100644
index 000000000..4e726c14d
--- /dev/null
+++ b/libpthread/nptl/sysdeps/generic/powerpc/libc-tls.c
@@ -0,0 +1 @@
+#include <../generic/libc-tls.c>
diff --git a/libpthread/nptl/sysdeps/generic/sh/libc-tls.c b/libpthread/nptl/sysdeps/generic/sh/libc-tls.c
new file mode 100644
index 000000000..4e726c14d
--- /dev/null
+++ b/libpthread/nptl/sysdeps/generic/sh/libc-tls.c
@@ -0,0 +1 @@
+#include <../generic/libc-tls.c>
diff --git a/libpthread/nptl/sysdeps/generic/sparc/libc-tls.c b/libpthread/nptl/sysdeps/generic/sparc/libc-tls.c
new file mode 100644
index 000000000..4e726c14d
--- /dev/null
+++ b/libpthread/nptl/sysdeps/generic/sparc/libc-tls.c
@@ -0,0 +1 @@
+#include <../generic/libc-tls.c>
diff --git a/libpthread/nptl/sysdeps/i386/dl-tls.c b/libpthread/nptl/sysdeps/i386/dl-tls.c
new file mode 100644
index 000000000..db50de8ab
--- /dev/null
+++ b/libpthread/nptl/sysdeps/i386/dl-tls.c
@@ -0,0 +1 @@
+#include <../generic/dl-tls.c>
diff --git a/libpthread/nptl/sysdeps/i386/libc-tls.c b/libpthread/nptl/sysdeps/i386/libc-tls.c
new file mode 100644
index 000000000..4e726c14d
--- /dev/null
+++ b/libpthread/nptl/sysdeps/i386/libc-tls.c
@@ -0,0 +1 @@
+#include <../generic/libc-tls.c>
diff --git a/libpthread/nptl/sysdeps/mips/dl-tls.c b/libpthread/nptl/sysdeps/mips/dl-tls.c
new file mode 100644
index 000000000..db50de8ab
--- /dev/null
+++ b/libpthread/nptl/sysdeps/mips/dl-tls.c
@@ -0,0 +1 @@
+#include <../generic/dl-tls.c>
diff --git a/libpthread/nptl/sysdeps/powerpc/dl-tls.c b/libpthread/nptl/sysdeps/powerpc/dl-tls.c
new file mode 100644
index 000000000..db50de8ab
--- /dev/null
+++ b/libpthread/nptl/sysdeps/powerpc/dl-tls.c
@@ -0,0 +1 @@
+#include <../generic/dl-tls.c>
diff --git a/libpthread/nptl/sysdeps/sh/dl-tls.c b/libpthread/nptl/sysdeps/sh/dl-tls.c
new file mode 100644
index 000000000..db50de8ab
--- /dev/null
+++ b/libpthread/nptl/sysdeps/sh/dl-tls.c
@@ -0,0 +1 @@
+#include <../generic/dl-tls.c>
diff --git a/libpthread/nptl/sysdeps/sparc/dl-tls.c b/libpthread/nptl/sysdeps/sparc/dl-tls.c
new file mode 100644
index 000000000..db50de8ab
--- /dev/null
+++ b/libpthread/nptl/sysdeps/sparc/dl-tls.c
@@ -0,0 +1 @@
+#include <../generic/dl-tls.c>
diff --git a/libpthread/nptl/sysdeps/x86_64/dl-tls.c b/libpthread/nptl/sysdeps/x86_64/dl-tls.c
new file mode 100644
index 000000000..db50de8ab
--- /dev/null
+++ b/libpthread/nptl/sysdeps/x86_64/dl-tls.c
@@ -0,0 +1 @@
+#include <../generic/dl-tls.c>