|
2 | 2 | /*
|
3 | 3 | * android_kabi.h - Android kernel abi abstraction header
|
4 | 4 | *
|
5 |
| - * Copyright (C) 2020 Google, Inc. |
| 5 | + * Copyright (C) 2020-2025 Google, Inc. |
6 | 6 | *
|
7 | 7 | * Heavily influenced by rh_kabi.h which came from the RHEL/CENTOS kernel and
|
8 | 8 | * was:
|
|
29 | 29 | * If a field is added to a structure, the padding fields can be used to add
|
30 | 30 | * the new field in a "safe" way.
|
31 | 31 | */
|
| 32 | + |
32 | 33 | #ifndef _ANDROID_KABI_H
|
33 | 34 | #define _ANDROID_KABI_H
|
34 | 35 |
|
| 36 | +#include <linux/args.h> |
35 | 37 | #include <linux/compiler.h>
|
| 38 | +#include <linux/compiler_attributes.h> |
36 | 39 | #include <linux/stringify.h>
|
37 | 40 |
|
38 | 41 | /*
|
39 | 42 | * Worker macros, don't use these, use the ones without a leading '_'
|
40 | 43 | */
|
41 | 44 |
|
42 |
| -#define __ANDROID_KABI_CHECK_SIZE_ALIGN(_orig, _new) \ |
43 |
| - union { \ |
44 |
| - _Static_assert(sizeof(struct{_new;}) <= sizeof(struct{_orig;}), \ |
45 |
| - __FILE__ ":" __stringify(__LINE__) ": " \ |
46 |
| - __stringify(_new) \ |
47 |
| - " is larger than " \ |
48 |
| - __stringify(_orig) ); \ |
49 |
| - _Static_assert(__alignof__(struct{_new;}) <= __alignof__(struct{_orig;}), \ |
50 |
| - __FILE__ ":" __stringify(__LINE__) ": " \ |
51 |
| - __stringify(_orig) \ |
52 |
| - " is not aligned the same as " \ |
53 |
| - __stringify(_new) ); \ |
| 45 | +#define _ANDROID_KABI_RULE(hint, target, value) \ |
| 46 | + static const char CONCATENATE(__gendwarfksyms_rule_, \ |
| 47 | + __COUNTER__)[] __used __aligned(1) \ |
| 48 | + __section(".discard.gendwarfksyms.kabi_rules") = \ |
| 49 | + "1\0" #hint "\0" #target "\0" #value |
| 50 | + |
| 51 | +#define _ANDROID_KABI_NORMAL_SIZE_ALIGN(_orig, _new) \ |
| 52 | + union { \ |
| 53 | + _Static_assert( \ |
| 54 | + sizeof(struct { _new; }) <= \ |
| 55 | + sizeof(struct { _orig; }), \ |
| 56 | + FILE_LINE ": " __stringify(_new) \ |
| 57 | + " is larger than " __stringify(_orig)); \ |
| 58 | + _Static_assert( \ |
| 59 | + __alignof__(struct { _new; }) <= \ |
| 60 | + __alignof__(struct { _orig; }), \ |
| 61 | + FILE_LINE ": " __stringify(_orig) \ |
| 62 | + " is not aligned the same as " \ |
| 63 | + __stringify(_new)); \ |
54 | 64 | }
|
55 | 65 |
|
56 |
| -#ifdef __GENKSYMS__ |
57 |
| - |
58 |
| -#define _ANDROID_KABI_REPLACE(_orig, _new) _orig |
59 |
| - |
60 |
| -#else |
61 |
| - |
62 |
| -#define _ANDROID_KABI_REPLACE(_orig, _new) \ |
63 |
| - union { \ |
64 |
| - _new; \ |
65 |
| - struct { \ |
66 |
| - _orig; \ |
67 |
| - }; \ |
68 |
| - __ANDROID_KABI_CHECK_SIZE_ALIGN(_orig, _new); \ |
| 66 | +#define _ANDROID_KABI_REPLACE(_orig, _new) \ |
| 67 | + union { \ |
| 68 | + _new; \ |
| 69 | + struct { \ |
| 70 | + _orig; \ |
| 71 | + }; \ |
| 72 | + _ANDROID_KABI_NORMAL_SIZE_ALIGN(_orig, _new); \ |
69 | 73 | }
|
70 | 74 |
|
71 |
| -#endif /* __GENKSYMS__ */ |
72 |
| - |
73 |
| -#define _ANDROID_KABI_RESERVE(n) u64 __kabi_reserved##n |
74 |
| - |
75 | 75 |
|
76 | 76 | /*
|
77 | 77 | * Macros to use _before_ the ABI is frozen
|
|
84 | 84 | * number: the "number" of the padding variable in the structure. Start with
|
85 | 85 | * 1 and go up.
|
86 | 86 | */
|
87 |
| -#ifdef CONFIG_ANDROID_KABI_RESERVE |
88 |
| -#define ANDROID_KABI_RESERVE(number) _ANDROID_KABI_RESERVE(number) |
89 |
| -#else |
90 |
| -#define ANDROID_KABI_RESERVE(number) |
91 |
| -#endif |
| 87 | +#define ANDROID_KABI_RESERVE(number) u64 __kabi_reserved##number |
92 | 88 |
|
93 | 89 | /*
|
94 |
| - * ANDROID_KABI_BACKPORT_OK |
95 |
| - * Used to allow padding originally reserved with ANDROID_KABI_RESERVE |
96 |
| - * to be used for backports of non-LTS patches by partners. These |
97 |
| - * fields can by used by replacing with ANDROID_KABI_BACKPORT_USE() |
98 |
| - * for partner backports. |
| 90 | + * Macros to use _after_ the ABI is frozen |
99 | 91 | */
|
100 |
| -#define ANDROID_KABI_BACKPORT_OK(number) ANDROID_KABI_RESERVE(number) |
101 | 92 |
|
102 | 93 | /*
|
103 |
| - * Macros to use _after_ the ABI is frozen |
| 94 | + * ANDROID_KABI_DECLONLY(fqn) |
| 95 | + * Treat the struct/union/enum fqn as a declaration, i.e. even if |
| 96 | + * a definition is available, don't expand the contents. |
| 97 | + */ |
| 98 | +#define ANDROID_KABI_DECLONLY(fqn) _ANDROID_KABI_RULE(declonly, fqn, /**/) |
| 99 | + |
| 100 | +/* |
| 101 | + * ANDROID_KABI_ENUMERATOR_IGNORE(fqn, field) |
| 102 | + * When expanding enum fqn, skip the provided field. This makes it |
| 103 | + * possible to hide added enum fields from versioning. |
| 104 | + */ |
| 105 | +#define ANDROID_KABI_ENUMERATOR_IGNORE(fqn, field) \ |
| 106 | + _ANDROID_KABI_RULE(enumerator_ignore, fqn field, /**/) |
| 107 | + |
| 108 | +/* |
| 109 | + * ANDROID_KABI_ENUMERATOR_VALUE(fqn, field, value) |
| 110 | + * When expanding enum fqn, use the provided value for the |
| 111 | + * specified field. This makes it possible to override enumerator |
| 112 | + * values when calculating versions. |
| 113 | + */ |
| 114 | +#define ANDROID_KABI_ENUMERATOR_VALUE(fqn, field, value) \ |
| 115 | + _ANDROID_KABI_RULE(enumerator_value, fqn field, value) |
| 116 | + |
| 117 | +/* |
| 118 | + * ANDROID_KABI_IGNORE |
| 119 | + * Add a new field that's ignored in versioning. |
| 120 | + */ |
| 121 | +#define ANDROID_KABI_IGNORE(n, _new) \ |
| 122 | + union { \ |
| 123 | + _new; \ |
| 124 | + unsigned char __kabi_ignored##n; \ |
| 125 | + } |
| 126 | + |
| 127 | +/* |
| 128 | + * ANDROID_KABI_REPLACE |
| 129 | + * Replace a field with a compatible new field. |
104 | 130 | */
|
| 131 | +#define ANDROID_KABI_REPLACE(_oldtype, _oldname, _new) \ |
| 132 | + _ANDROID_KABI_REPLACE(_oldtype __kabi_renamed##_oldname, struct { _new; }) |
105 | 133 |
|
106 | 134 | /*
|
107 | 135 | * ANDROID_KABI_USE(number, _new)
|
108 | 136 | * Use a previous padding entry that was defined with ANDROID_KABI_RESERVE
|
109 | 137 | * number: the previous "number" of the padding variable
|
110 | 138 | * _new: the variable to use now instead of the padding variable
|
111 | 139 | */
|
112 |
| -#define ANDROID_KABI_USE(number, _new) \ |
113 |
| - _ANDROID_KABI_REPLACE(_ANDROID_KABI_RESERVE(number), _new) |
114 |
| - |
115 |
| -/* |
116 |
| - * ANDROID_KABI_BACKPORT_USE(number, _new) |
117 |
| - * Use a previous padding entry that was defined with |
118 |
| - * ANDROID_KABI_BACKPORT_OK(). This is functionally identical |
119 |
| - * to ANDROID_KABI_USE() except that it differentiates the |
120 |
| - * normal use of KABI fields for LTS from KABI fields that |
121 |
| - * were released for use with other backports from upstream. |
122 |
| - */ |
123 |
| -#define ANDROID_KABI_BACKPORT_USE(number, _new) \ |
124 |
| - ANDROID_KABI_USE(number, _new) |
| 140 | +#define ANDROID_KABI_USE(number, _new) \ |
| 141 | + _ANDROID_KABI_REPLACE(ANDROID_KABI_RESERVE(number), _new) |
125 | 142 |
|
126 | 143 | /*
|
127 | 144 | * ANDROID_KABI_USE2(number, _new1, _new2)
|
|
130 | 147 | * want to "burn" a 64bit padding variable for a smaller variable size if not
|
131 | 148 | * needed.
|
132 | 149 | */
|
133 |
| -#define ANDROID_KABI_USE2(number, _new1, _new2) \ |
134 |
| - _ANDROID_KABI_REPLACE(_ANDROID_KABI_RESERVE(number), struct{ _new1; _new2; }) |
| 150 | +#define ANDROID_KABI_USE2(number, _new1, _new2) \ |
| 151 | + _ANDROID_KABI_REPLACE(ANDROID_KABI_RESERVE(number), struct{ _new1; _new2; }) |
135 | 152 |
|
136 | 153 |
|
137 | 154 | #endif /* _ANDROID_KABI_H */
|
0 commit comments