tls.c (234569) | tls.c (261071) |
---|---|
1/*- 2 * Copyright (c) 2004 Doug Rabson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (c) 2004 Doug Rabson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/lib/libc/gen/tls.c 234569 2012-04-22 08:49:13Z jasone $ | 26 * $FreeBSD: head/lib/libc/gen/tls.c 261071 2014-01-23 02:47:36Z jasone $ |
27 */ 28 29/* 30 * Define stubs for TLS internals so that programs and libraries can 31 * link. These functions will be replaced by functional versions at 32 * runtime from ld-elf.so.1. 33 */ 34 35#include <sys/cdefs.h> 36#include <stdlib.h> 37#include <string.h> 38#include <elf.h> 39 40#include "libc_private.h" 41 42/* Provided by jemalloc to avoid bootstrapping issues. */ | 27 */ 28 29/* 30 * Define stubs for TLS internals so that programs and libraries can 31 * link. These functions will be replaced by functional versions at 32 * runtime from ld-elf.so.1. 33 */ 34 35#include <sys/cdefs.h> 36#include <stdlib.h> 37#include <string.h> 38#include <elf.h> 39 40#include "libc_private.h" 41 42/* Provided by jemalloc to avoid bootstrapping issues. */ |
43void *__jemalloc_a0malloc(size_t size); 44void *__jemalloc_a0calloc(size_t num, size_t size); 45void __jemalloc_a0free(void *ptr); | 43void *__je_a0malloc(size_t size); 44void *__je_a0calloc(size_t num, size_t size); 45void __je_a0free(void *ptr); |
46 47__weak_reference(__libc_allocate_tls, _rtld_allocate_tls); 48__weak_reference(__libc_free_tls, _rtld_free_tls); 49 50#ifdef __i386__ 51 52__weak_reference(___libc_tls_get_addr, ___tls_get_addr); 53__attribute__((__regparm__(1))) void * ___libc_tls_get_addr(void *); --- 66 unchanged lines hidden (view full) --- 120void 121__libc_free_tls(void *tcb, size_t tcbsize, size_t tcbalign __unused) 122{ 123 Elf_Addr *dtv; 124 Elf_Addr **tls; 125 126 tls = (Elf_Addr **)((Elf_Addr)tcb + tcbsize - TLS_TCB_SIZE); 127 dtv = tls[0]; | 46 47__weak_reference(__libc_allocate_tls, _rtld_allocate_tls); 48__weak_reference(__libc_free_tls, _rtld_free_tls); 49 50#ifdef __i386__ 51 52__weak_reference(___libc_tls_get_addr, ___tls_get_addr); 53__attribute__((__regparm__(1))) void * ___libc_tls_get_addr(void *); --- 66 unchanged lines hidden (view full) --- 120void 121__libc_free_tls(void *tcb, size_t tcbsize, size_t tcbalign __unused) 122{ 123 Elf_Addr *dtv; 124 Elf_Addr **tls; 125 126 tls = (Elf_Addr **)((Elf_Addr)tcb + tcbsize - TLS_TCB_SIZE); 127 dtv = tls[0]; |
128 __jemalloc_a0free(dtv); 129 __jemalloc_a0free(tcb); | 128 __je_a0free(dtv); 129 __je_a0free(tcb); |
130} 131 132/* 133 * Allocate Static TLS using the Variant I method. 134 */ 135void * 136__libc_allocate_tls(void *oldtcb, size_t tcbsize, size_t tcbalign __unused) 137{ 138 Elf_Addr *dtv; 139 Elf_Addr **tls; 140 char *tcb; 141 142 if (oldtcb != NULL && tcbsize == TLS_TCB_SIZE) 143 return (oldtcb); 144 | 130} 131 132/* 133 * Allocate Static TLS using the Variant I method. 134 */ 135void * 136__libc_allocate_tls(void *oldtcb, size_t tcbsize, size_t tcbalign __unused) 137{ 138 Elf_Addr *dtv; 139 Elf_Addr **tls; 140 char *tcb; 141 142 if (oldtcb != NULL && tcbsize == TLS_TCB_SIZE) 143 return (oldtcb); 144 |
145 tcb = __jemalloc_a0calloc(1, tls_static_space + tcbsize - TLS_TCB_SIZE); | 145 tcb = __je_a0calloc(1, tls_static_space + tcbsize - TLS_TCB_SIZE); |
146 tls = (Elf_Addr **)(tcb + tcbsize - TLS_TCB_SIZE); 147 148 if (oldtcb != NULL) { 149 memcpy(tls, oldtcb, tls_static_space); | 146 tls = (Elf_Addr **)(tcb + tcbsize - TLS_TCB_SIZE); 147 148 if (oldtcb != NULL) { 149 memcpy(tls, oldtcb, tls_static_space); |
150 __jemalloc_a0free(oldtcb); | 150 __je_a0free(oldtcb); |
151 152 /* Adjust the DTV. */ 153 dtv = tls[0]; 154 dtv[2] = (Elf_Addr)tls + TLS_TCB_SIZE; 155 } else { | 151 152 /* Adjust the DTV. */ 153 dtv = tls[0]; 154 dtv[2] = (Elf_Addr)tls + TLS_TCB_SIZE; 155 } else { |
156 dtv = __jemalloc_a0malloc(3 * sizeof(Elf_Addr)); | 156 dtv = __je_a0malloc(3 * sizeof(Elf_Addr)); |
157 tls[0] = dtv; 158 dtv[0] = 1; 159 dtv[1] = 1; 160 dtv[2] = (Elf_Addr)tls + TLS_TCB_SIZE; 161 162 if (tls_init_size > 0) 163 memcpy((void*)dtv[2], tls_init, tls_init_size); 164 if (tls_static_space > tls_init_size) --- 24 unchanged lines hidden (view full) --- 189 * Figure out the size of the initial TLS block so that we can 190 * find stuff which ___tls_get_addr() allocated dynamically. 191 */ 192 size = round(tls_static_space, tcbalign); 193 194 dtv = ((Elf_Addr**)tcb)[1]; 195 tlsend = (Elf_Addr) tcb; 196 tlsstart = tlsend - size; | 157 tls[0] = dtv; 158 dtv[0] = 1; 159 dtv[1] = 1; 160 dtv[2] = (Elf_Addr)tls + TLS_TCB_SIZE; 161 162 if (tls_init_size > 0) 163 memcpy((void*)dtv[2], tls_init, tls_init_size); 164 if (tls_static_space > tls_init_size) --- 24 unchanged lines hidden (view full) --- 189 * Figure out the size of the initial TLS block so that we can 190 * find stuff which ___tls_get_addr() allocated dynamically. 191 */ 192 size = round(tls_static_space, tcbalign); 193 194 dtv = ((Elf_Addr**)tcb)[1]; 195 tlsend = (Elf_Addr) tcb; 196 tlsstart = tlsend - size; |
197 __jemalloc_a0free((void*) tlsstart); 198 __jemalloc_a0free(dtv); | 197 __je_a0free((void*) tlsstart); 198 __je_a0free(dtv); |
199} 200 201/* 202 * Allocate Static TLS using the Variant II method. 203 */ 204void * 205__libc_allocate_tls(void *oldtls, size_t tcbsize, size_t tcbalign) 206{ 207 size_t size; 208 char *tls; 209 Elf_Addr *dtv; 210 Elf_Addr segbase, oldsegbase; 211 212 size = round(tls_static_space, tcbalign); 213 214 if (tcbsize < 2 * sizeof(Elf_Addr)) 215 tcbsize = 2 * sizeof(Elf_Addr); | 199} 200 201/* 202 * Allocate Static TLS using the Variant II method. 203 */ 204void * 205__libc_allocate_tls(void *oldtls, size_t tcbsize, size_t tcbalign) 206{ 207 size_t size; 208 char *tls; 209 Elf_Addr *dtv; 210 Elf_Addr segbase, oldsegbase; 211 212 size = round(tls_static_space, tcbalign); 213 214 if (tcbsize < 2 * sizeof(Elf_Addr)) 215 tcbsize = 2 * sizeof(Elf_Addr); |
216 tls = __jemalloc_a0calloc(1, size + tcbsize); 217 dtv = __jemalloc_a0malloc(3 * sizeof(Elf_Addr)); | 216 tls = __je_a0calloc(1, size + tcbsize); 217 dtv = __je_a0malloc(3 * sizeof(Elf_Addr)); |
218 219 segbase = (Elf_Addr)(tls + size); 220 ((Elf_Addr*)segbase)[0] = segbase; 221 ((Elf_Addr*)segbase)[1] = (Elf_Addr) dtv; 222 223 dtv[0] = 1; 224 dtv[1] = 1; 225 dtv[2] = segbase - tls_static_space; --- 102 unchanged lines hidden --- | 218 219 segbase = (Elf_Addr)(tls + size); 220 ((Elf_Addr*)segbase)[0] = segbase; 221 ((Elf_Addr*)segbase)[1] = (Elf_Addr) dtv; 222 223 dtv[0] = 1; 224 dtv[1] = 1; 225 dtv[2] = segbase - tls_static_space; --- 102 unchanged lines hidden --- |