File indexing completed on 2025-05-11 08:24:27
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 #ifdef HAVE_CONFIG_H
0038 #include "config.h"
0039 #endif
0040
0041 #include <rtems/score/tls.h>
0042 #include <rtems/score/interr.h>
0043 #include <rtems/score/thread.h>
0044
0045 extern char _TLS_Data_begin[];
0046
0047 extern char _TLS_Data_size[];
0048
0049 extern char _TLS_BSS_begin[];
0050
0051 extern char _TLS_BSS_size[];
0052
0053 extern char _TLS_Size[];
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065 extern char _TLS_Alignment[];
0066
0067 const volatile TLS_Configuration _TLS_Configuration = {
0068 .data_begin = _TLS_Data_begin,
0069 .data_size = _TLS_Data_size,
0070 .bss_begin = _TLS_BSS_begin,
0071 .bss_size = _TLS_BSS_size,
0072 .size = _TLS_Size,
0073 .alignment = _TLS_Alignment
0074 };
0075
0076 static uintptr_t _TLS_Allocation_size;
0077
0078 uintptr_t _TLS_Get_allocation_size( void )
0079 {
0080 const volatile TLS_Configuration *config;
0081 uintptr_t size;
0082 uintptr_t allocation_size;
0083
0084 config = &_TLS_Configuration;
0085 size = (uintptr_t) config->size;
0086
0087 if ( size == 0 ) {
0088 return 0;
0089 }
0090
0091 allocation_size = _TLS_Allocation_size;
0092
0093 if ( allocation_size == 0 ) {
0094 uintptr_t tls_align;
0095 uintptr_t stack_align;
0096
0097
0098
0099
0100
0101 stack_align = CPU_STACK_ALIGNMENT;
0102 tls_align = RTEMS_ALIGN_UP( (uintptr_t) config->alignment, stack_align );
0103
0104 #if !defined(__i386__) && !defined(__x86_64__)
0105
0106 allocation_size +=
0107 RTEMS_ALIGN_UP( sizeof( TLS_Dynamic_thread_vector ), stack_align );
0108 #endif
0109
0110
0111 allocation_size +=
0112 #if CPU_THREAD_LOCAL_STORAGE_VARIANT == 11
0113 RTEMS_ALIGN_UP( sizeof( TLS_Thread_control_block ), tls_align );
0114 #else
0115 RTEMS_ALIGN_UP( sizeof( TLS_Thread_control_block ), stack_align );
0116 #endif
0117
0118
0119 allocation_size +=
0120 #if CPU_THREAD_LOCAL_STORAGE_VARIANT == 20
0121 RTEMS_ALIGN_UP( size, tls_align );
0122 #else
0123 RTEMS_ALIGN_UP( size, stack_align );
0124 #endif
0125
0126
0127
0128
0129
0130 if ( tls_align > stack_align ) {
0131 _Assert( tls_align % stack_align == 0 );
0132 allocation_size += tls_align - stack_align;
0133 }
0134
0135 if ( _Thread_Maximum_TLS_size != 0 ) {
0136 if ( allocation_size <= _Thread_Maximum_TLS_size ) {
0137 _Assert( _Thread_Maximum_TLS_size % CPU_STACK_ALIGNMENT == 0 );
0138 allocation_size = _Thread_Maximum_TLS_size;
0139 } else {
0140 _Internal_error( INTERNAL_ERROR_TOO_LARGE_TLS_SIZE );
0141 }
0142 }
0143
0144 _TLS_Allocation_size = allocation_size;
0145 }
0146
0147 return allocation_size;
0148 }