1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright (C) 2024 Google LLC 4 * 5 * Example macros for maintaining kABI stability. 6 * 7 * This file is based on android_kabi.h, which has the following notice: 8 * 9 * Heavily influenced by rh_kabi.h which came from the RHEL/CENTOS kernel 10 * and was: 11 * Copyright (c) 2014 Don Zickus 12 * Copyright (c) 2015-2018 Jiri Benc 13 * Copyright (c) 2015 Sabrina Dubroca, Hannes Frederic Sowa 14 * Copyright (c) 2016-2018 Prarit Bhargava 15 * Copyright (c) 2017 Paolo Abeni, Larry Woodman 16 */ 17 18 #ifndef __KABI_H__ 19 #define __KABI_H__ 20 21 /* Kernel macros for userspace testing. */ 22 #ifndef __aligned 23 #define __aligned(x) __attribute__((__aligned__(x))) 24 #endif 25 #ifndef __used 26 #define __used __attribute__((__used__)) 27 #endif 28 #ifndef __section 29 #define __section(section) __attribute__((__section__(section))) 30 #endif 31 #ifndef __PASTE 32 #define ___PASTE(a, b) a##b 33 #define __PASTE(a, b) ___PASTE(a, b) 34 #endif 35 #ifndef __stringify 36 #define __stringify_1(x...) #x 37 #define __stringify(x...) __stringify_1(x) 38 #endif 39 40 #define __KABI_RULE(hint, target, value) \ 41 static const char __PASTE(__gendwarfksyms_rule_, \ 42 __COUNTER__)[] __used __aligned(1) \ 43 __section(".discard.gendwarfksyms.kabi_rules") = \ 44 "1\0" #hint "\0" #target "\0" #value 45 46 /* 47 * KABI_DECLONLY(fqn) 48 * Treat the struct/union/enum fqn as a declaration, i.e. even if 49 * a definition is available, don't expand the contents. 50 */ 51 #define KABI_DECLONLY(fqn) __KABI_RULE(declonly, fqn, ) 52 53 /* 54 * KABI_ENUMERATOR_IGNORE(fqn, field) 55 * When expanding enum fqn, skip the provided field. This makes it 56 * possible to hide added enum fields from versioning. 57 */ 58 #define KABI_ENUMERATOR_IGNORE(fqn, field) \ 59 __KABI_RULE(enumerator_ignore, fqn field, ) 60 61 /* 62 * KABI_ENUMERATOR_VALUE(fqn, field, value) 63 * When expanding enum fqn, use the provided value for the 64 * specified field. This makes it possible to override enumerator 65 * values when calculating versions. 66 */ 67 #define KABI_ENUMERATOR_VALUE(fqn, field, value) \ 68 __KABI_RULE(enumerator_value, fqn field, value) 69 70 #endif /* __KABI_H__ */ 71