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 */ linker_is_in_rodata(const void * addr)24static 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) || \ 39 defined(CONFIG_MIPS) || defined(CONFIG_XTENSA) 40 extern char __rodata_region_start[]; 41 extern char __rodata_region_end[]; 42 #define RO_START __rodata_region_start 43 #define RO_END __rodata_region_end 44 #else 45 #define RO_START 0 46 #define RO_END 0 47 #endif 48 49 return (((const char *)addr >= (const char *)RO_START) && 50 ((const char *)addr < (const char *)RO_END)); 51 52 #undef RO_START 53 #undef RO_END 54 } 55 56 #endif /* ZEPHYR_INCLUDE_LINKER_UTILS_H_ */ 57