Branch data Line data Source code
1 : : /* 2 : : * Copyright (c) 2022 Intel Corporation 3 : : * 4 : : * SPDX-License-Identifier: Apache-2.0 5 : : */ 6 : : 7 : : #ifndef ZEPHYR_INCLUDE_LINKER_UTILS_H_ 8 : : #define ZEPHYR_INCLUDE_LINKER_UTILS_H_ 9 : : 10 : : #include <stdbool.h> 11 : : 12 : : /** 13 : : * @brief Check if address is in read only section. 14 : : * 15 : : * Note that this may return false if the address lies outside 16 : : * the compiler's default read only sections (e.g. .rodata 17 : : * section), depending on the linker script used. This also 18 : : * applies to constants with explicit section attributes. 19 : : * 20 : : * @param addr Address. 21 : : * 22 : : * @return True if address identified within read only section. 23 : : */ 24 : 0 : static inline bool linker_is_in_rodata(const void *addr) 25 : : { 26 : : #if defined(CONFIG_LINKER_USE_PINNED_SECTION) 27 : : extern const char lnkr_pinned_rodata_start[]; 28 : : extern const char lnkr_pinned_rodata_end[]; 29 : : 30 : : if (((const char *)addr >= (const char *)lnkr_pinned_rodata_start) && 31 : : ((const char *)addr < (const char *)lnkr_pinned_rodata_end)) { 32 : : return true; 33 : : } 34 : : #endif 35 : : 36 : : #if defined(CONFIG_ARM) || defined(CONFIG_ARC) || defined(CONFIG_X86) || \ 37 : : defined(CONFIG_ARM64) || defined(CONFIG_NIOS2) || \ 38 : : defined(CONFIG_RISCV) || defined(CONFIG_SPARC) || defined(CONFIG_MIPS) 39 : : extern char __rodata_region_start[]; 40 : : extern char __rodata_region_end[]; 41 : : #define RO_START __rodata_region_start 42 : : #define RO_END __rodata_region_end 43 : : #elif defined(CONFIG_XTENSA) 44 : : extern const char _rodata_start[]; 45 : : extern const char _rodata_end[]; 46 : : #define RO_START _rodata_start 47 : : #define RO_END _rodata_end 48 : : #else 49 : : #define RO_START 0 50 : : #define RO_END 0 51 : : #endif 52 : : 53 [ # # # # ]: 0 : return (((const char *)addr >= (const char *)RO_START) && 54 : : ((const char *)addr < (const char *)RO_END)); 55 : : 56 : : #undef RO_START 57 : : #undef RO_END 58 : : } 59 : : 60 : : #endif /* ZEPHYR_INCLUDE_LINKER_UTILS_H_ */