00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00040 #include <tls.h>
00041 #include <malloc.h>
00042 #include <str.h>
00043 #include <align.h>
00044
00052 tcb_t *__make_tls(void)
00053 {
00054 void *data;
00055 tcb_t *tcb;
00056 size_t tls_size = &_tbss_end - &_tdata_start;
00057
00058 tcb = __alloc_tls(&data, tls_size);
00059
00060
00061
00062
00063 memcpy(data, &_tdata_start, &_tdata_end - &_tdata_start);
00064
00065
00066
00067 memset(data + (&_tbss_start - &_tdata_start), 0,
00068 &_tbss_end - &_tbss_start);
00069
00070 return tcb;
00071 }
00072
00073 void __free_tls(tcb_t *tcb)
00074 {
00075 size_t tls_size = &_tbss_end - &_tdata_start;
00076 __free_tls_arch(tcb, tls_size);
00077 }
00078
00079 #ifdef CONFIG_TLS_VARIANT_1
00080
00086 tcb_t *tls_alloc_variant_1(void **data, size_t size)
00087 {
00088 tcb_t *result;
00089
00090 result = malloc(sizeof(tcb_t) + size);
00091 *data = ((void *)result) + sizeof(tcb_t);
00092 return result;
00093 }
00094
00100 void tls_free_variant_1(tcb_t *tcb, size_t size)
00101 {
00102 free(tcb);
00103 }
00104 #endif
00105
00106 #ifdef CONFIG_TLS_VARIANT_2
00107
00114 tcb_t * tls_alloc_variant_2(void **data, size_t size)
00115 {
00116 tcb_t *tcb;
00117
00118 size = ALIGN_UP(size, &_tls_alignment);
00119 *data = memalign((uintptr_t) &_tls_alignment, sizeof(tcb_t) + size);
00120
00121 tcb = (tcb_t *) (*data + size);
00122 tcb->self = tcb;
00123
00124 return tcb;
00125 }
00126
00132 void tls_free_variant_2(tcb_t *tcb, size_t size)
00133 {
00134 size = ALIGN_UP(size, &_tls_alignment);
00135 void *start = ((void *) tcb) - size;
00136 free(start);
00137 }
00138 #endif
00139