1 /* 2 * Copyright (c) 2020 Intel Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /** 8 * @file 9 * @brief Kernel Thread Local Storage APIs. 10 * 11 * Kernel APIs related to thread local storage. 12 */ 13 14 #ifndef ZEPHYR_KERNEL_INCLUDE_KERNEL_TLS_H_ 15 #define ZEPHYR_KERNEL_INCLUDE_KERNEL_TLS_H_ 16 17 #include <zephyr/linker/linker-defs.h> 18 19 /** 20 * @brief Return the total size of TLS data/bss areas 21 * 22 * This returns the total size of thread local storage (TLS) 23 * data and bss areas as defined in the linker script. 24 * Note that this does not include any architecture specific 25 * bits required for proper functionality of TLS. 26 * 27 * @return Total size of TLS data/bss areas 28 */ z_tls_data_size(void)29static inline size_t z_tls_data_size(void) 30 { 31 return (size_t)(uintptr_t)__tdata_size + 32 (size_t)(uintptr_t)__tbss_size; 33 } 34 35 /** 36 * @brief Copy the TLS data/bss areas into destination 37 * 38 * This copies the TLS data into destination and clear the area 39 * of TLS bss size after the data section. 40 * 41 * @param dest Pointer to destination 42 */ z_tls_copy(char * dest)43static inline void z_tls_copy(char *dest) 44 { 45 /* Copy initialized data (tdata) */ 46 memcpy(dest, __tdata_start, (size_t)(uintptr_t)__tdata_size); 47 48 /* Clear BSS data (tbss) */ 49 dest += (size_t)(uintptr_t)__tdata_size; 50 memset(dest, 0, (size_t)(uintptr_t)__tbss_size); 51 } 52 53 #endif /* ZEPHYR_KERNEL_INCLUDE_KERNEL_TLS_H_ */ 54