1 /* 2 * SPDX-FileCopyrightText: 2010-2014,2017 Wind River Systems, Inc. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef _BLE_MESH_COMPILER_H_ 8 #define _BLE_MESH_COMPILER_H_ 9 10 #ifdef __cplusplus 11 extern "C" { 12 #endif 13 14 #define ___in_section(a, b, c) 15 16 #define __in_section(a, b, c) ___in_section(a, b, c) 17 18 #define __in_section_unique(seg) ___in_section(seg, __FILE__, __COUNTER__) 19 20 #ifndef __packed 21 #define __packed __attribute__((__packed__)) 22 #endif 23 24 #ifndef __aligned 25 #define __aligned(x) __attribute__((__aligned__(x))) 26 #endif 27 28 #ifndef __used 29 #define __used __attribute__((__used__)) 30 #endif 31 32 #ifndef ARG_UNUSED 33 #define ARG_UNUSED(x) (void)(x) 34 #endif 35 36 #ifndef popcount 37 #define popcount(x) __builtin_popcount(x) 38 #endif 39 40 #ifndef ALWAYS_INLINE 41 #define ALWAYS_INLINE inline __attribute__((always_inline)) 42 #endif 43 44 45 /* 46 * This is meant to be used in conjunction with __in_section() and similar 47 * where scattered structure instances are concatened together by the linker 48 * and walked by the code at run time just like a contiguous array of such 49 * structures. 50 * 51 * Assemblers and linkers may insert alignment padding by default whose 52 * size is larger than the natural alignment for those structures when 53 * gathering various section segments together, messing up the array walk. 54 * To prevent this, we need to provide an explicit alignment not to rely 55 * on the default that might just work by luck. 56 * 57 * Alignment statements in linker scripts are not sufficient as 58 * the assembler may add padding by itself to each segment when switching 59 * between sections within the same file even if it merges many such segments 60 * into a single section in the end. 61 */ 62 #ifndef Z_DECL_ALIGN 63 #define Z_DECL_ALIGN(type) __aligned(__alignof(type)) type 64 #endif 65 66 /* 67 * Convenience helper combining __in_section() and Z_DECL_ALIGN(). 68 * The section name is the struct type prepended with an underscore. 69 * The subsection is "static" and the subsubsection is the variable name. 70 */ 71 #ifndef Z_STRUCT_SECTION_ITERABLE 72 #define Z_STRUCT_SECTION_ITERABLE(struct_type, name) \ 73 Z_DECL_ALIGN(struct struct_type) name 74 #endif 75 76 #ifdef __cplusplus 77 } 78 #endif 79 80 #endif /* _BLE_MESH_COMPILER_H_ */ 81