Changeset 2c4e1cc in mainline for uspace/lib/c/generic/tls.c
- Timestamp:
- 2018-04-04T17:01:18Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5754c31e
- Parents:
- 1433ecda
- git-author:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-04-03 16:54:34)
- git-committer:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-04-04 17:01:18)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/tls.c
r1433ecda r2c4e1cc 41 41 #include <stdlib.h> 42 42 #include <str.h> 43 #include <elf/elf.h> 43 44 44 45 #ifdef CONFIG_RTLD … … 52 53 return runtime_env->tls_size; 53 54 #endif 54 return &_tbss_end - &_tdata_start; 55 56 const elf_segment_header_t *tls = 57 elf_get_phdr(__executable_start, PT_TLS); 58 return tls->p_memsz; 55 59 } 56 60 … … 73 77 void *data; 74 78 tcb_t *tcb; 75 size_t tls_size = &_tbss_end - &_tdata_start;76 79 77 80 #ifdef CONFIG_RTLD … … 80 83 #endif 81 84 82 tcb = tls_alloc_arch(&data, tls_size); 83 if (!tcb) 85 const elf_segment_header_t *tls = 86 elf_get_phdr(__executable_start, PT_TLS); 87 if (tls == NULL) 84 88 return NULL; 89 90 uintptr_t bias = elf_get_bias(__executable_start); 91 92 tcb = tls_alloc_arch(&data, tls->p_memsz); 85 93 86 94 /* 87 95 * Copy thread local data from the initialization image. 88 96 */ 89 memcpy(data, &_tdata_start, &_tdata_end - &_tdata_start);97 memcpy(data, (void *)(tls->p_vaddr + bias), tls->p_filesz); 90 98 /* 91 99 * Zero out the thread local uninitialized data. 92 100 */ 93 memset(data + (&_tbss_start - &_tdata_start), 0, 94 &_tbss_end - &_tbss_start); 101 memset(data + tls->p_filesz, 0, tls->p_memsz - tls->p_filesz); 95 102 96 103 return tcb; … … 151 158 tcb_t *tcb; 152 159 153 size = ALIGN_UP(size, &_tls_alignment); 154 *data = memalign((uintptr_t) &_tls_alignment, sizeof(tcb_t) + size); 160 uintptr_t align = elf_get_phdr(__executable_start, PT_TLS)->p_align; 161 162 size = ALIGN_UP(size, align); 163 *data = memalign(align, sizeof(tcb_t) + size); 155 164 if (*data == NULL) 156 165 return NULL; … … 171 180 void tls_free_variant_2(tcb_t *tcb, size_t size) 172 181 { 173 size = ALIGN_UP(size, &_tls_alignment); 182 uintptr_t align = elf_get_phdr(__executable_start, PT_TLS)->p_align; 183 size = ALIGN_UP(size, align); 174 184 void *start = ((void *) tcb) - size; 175 185 free(start);
Note:
See TracChangeset
for help on using the changeset viewer.