Deleted Added
full compact
26c26
< * $FreeBSD: head/lib/libc/gen/tls.c 160711 2006-07-26 16:56:56Z imp $
---
> * $FreeBSD: head/lib/libc/gen/tls.c 161800 2006-09-01 06:13:16Z marcel $
61c61
< #if defined(__ia64__) || defined(__alpha__) || defined(__powerpc__)
---
> #if defined(__ia64__) || defined(__powerpc__)
76,78d75
< #ifdef TLS_VARIANT_I
< static size_t tls_init_offset;
< #endif
104a102,103
> #define TLS_TCB_SIZE (2 * sizeof(void *))
>
109c108
< __libc_free_tls(void *tls, size_t tcbsize __unused, size_t tcbalign __unused)
---
> __libc_free_tls(void *tcb, size_t tcbsize, size_t tcbalign __unused)
111c110,111
< Elf_Addr* dtv;
---
> Elf_Addr *dtv;
> Elf_Addr **tls;
113,114c113,114
< dtv = ((Elf_Addr**)tls)[0];
< free(tls);
---
> tls = (Elf_Addr **)((Elf_Addr)tcb + tcbsize - TLS_TCB_SIZE);
> dtv = tls[0];
115a116
> free(tcb);
122c123
< __libc_allocate_tls(void *oldtls, size_t tcbsize, size_t tcbalign __unused)
---
> __libc_allocate_tls(void *oldtcb, size_t tcbsize, size_t tcbalign __unused)
124,125d124
< size_t size;
< char *tls;
126a126,127
> Elf_Addr **tls;
> char *tcb;
128,130c129,130
< size = tls_static_space;
< if (size < tcbsize)
< size = tcbsize;
---
> if (oldtcb != NULL && tcbsize == TLS_TCB_SIZE)
> return (oldtcb);
132,133c132,133
< tls = calloc(1, size);
< dtv = malloc(3 * sizeof(Elf_Addr));
---
> tcb = calloc(1, tls_static_space + tcbsize);
> tls = (Elf_Addr **)(tcb + tcbsize - TLS_TCB_SIZE);
135c135,137
< *(Elf_Addr **) tls = dtv;
---
> if (oldtcb != NULL) {
> memcpy(tls, oldtcb, tls_static_space + TLS_TCB_SIZE);
> free(oldtcb);
137,152c139,141
< dtv[0] = 1;
< dtv[1] = 1;
< dtv[2] = (Elf_Addr)(tls + tls_init_offset);
< if (oldtls) {
< /*
< * Copy the static TLS block over whole.
< */
< memcpy(tls + tls_init_offset,
< (char *)oldtls + tls_init_offset,
< tls_static_space - tls_init_offset);
<
< /*
< * We assume that this block was the one we created with
< * allocate_initial_tls().
< */
< _rtld_free_tls(oldtls, 2 * sizeof(Elf_Addr), sizeof(Elf_Addr));
---
> /* Adjust the DTV. */
> dtv = tls[0];
> dtv[2] = (Elf_Addr)tls + TLS_TCB_SIZE;
154,156c143,153
< memcpy(tls + tls_init_offset, tls_init, tls_init_size);
< memset(tls + tls_init_offset + tls_init_size,
< 0, tls_static_space - tls_init_size);
---
> dtv = malloc(3 * sizeof(Elf_Addr));
> tls[0] = dtv;
> dtv[0] = 1;
> dtv[1] = 1;
> dtv[2] = (Elf_Addr)tls + TLS_TCB_SIZE;
>
> if (tls_init_size > 0)
> memcpy((void*)dtv[2], tls_init, tls_init_size);
> if (tls_static_space > tls_init_size)
> memset((void*)(dtv[2] + tls_init_size), 0,
> tls_static_space - tls_init_size);
159c156
< return tls;
---
> return(tcb);
165a163,164
> #define TLS_TCB_SIZE (3 * sizeof(Elf_Addr))
>
296,301d294
< #ifdef TLS_VARIANT_I
< tls_static_space = round(2*sizeof(Elf_Addr),
< phdr[i].p_align) + phdr[i].p_memsz;
< tls_init_offset = round(2*sizeof(Elf_Addr),
< phdr[i].p_align);
< #else
304d296
< #endif
310,311c302
< tls = _rtld_allocate_tls(NULL, 3*sizeof(Elf_Addr),
< sizeof(Elf_Addr));
---
> tls = _rtld_allocate_tls(NULL, TLS_TCB_SIZE, 1);