Coverage Report

Created: 2023-12-14 14:13

/src/openssl/include/openssl/macros.h
Line
Count
Source
1
/*
2
 * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (the "License").  You may not use
5
 * this file except in compliance with the License.  You can obtain a copy
6
 * in the file LICENSE in the source distribution or at
7
 * https://www.openssl.org/source/license.html
8
 */
9
10
#include <openssl/opensslconf.h>
11
#include <openssl/opensslv.h>
12
13
#ifndef OPENSSL_MACROS_H
14
# define OPENSSL_MACROS_H
15
16
/* Helper macros for CPP string composition */
17
# define OPENSSL_MSTR_HELPER(x) #x
18
# define OPENSSL_MSTR(x) OPENSSL_MSTR_HELPER(x)
19
20
/*
21
 * Sometimes OPENSSSL_NO_xxx ends up with an empty file and some compilers
22
 * don't like that.  This will hopefully silence them.
23
 */
24
# define NON_EMPTY_TRANSLATION_UNIT static void *dummy = &dummy;
25
26
/*
27
 * Generic deprecation macro
28
  *
29
  * If OPENSSL_SUPPRESS_DEPRECATED is defined, then DECLARE_DEPRECATED
30
  * becomes a no-op
31
 */
32
# ifndef DECLARE_DEPRECATED
33
#  define DECLARE_DEPRECATED(f)   f;
34
#  ifndef OPENSSL_SUPPRESS_DEPRECATED
35
#   ifdef __GNUC__
36
#    if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)
37
#     undef DECLARE_DEPRECATED
38
#     define DECLARE_DEPRECATED(f)    f __attribute__ ((deprecated));
39
#    endif
40
#   elif defined(__SUNPRO_C)
41
#    if (__SUNPRO_C >= 0x5130)
42
#     undef DECLARE_DEPRECATED
43
#     define DECLARE_DEPRECATED(f)    f __attribute__ ((deprecated));
44
#    endif
45
#   endif
46
#  endif
47
# endif
48
49
/*
50
 * Applications should use -DOPENSSL_API_COMPAT=<version> to suppress the
51
 * declarations of functions deprecated in or before <version>.  If this is
52
 * undefined, the value of the macro OPENSSL_CONFIGURED_API (defined in
53
 * <openssl/opensslconf.h>) is the default.
54
 *
55
 * For any version number up until version 1.1.x, <version> is expected to be
56
 * the calculated version number 0xMNNFFPPSL.
57
 * For version numbers 3.0 and on, <version> is expected to be a computation
58
 * of the major and minor numbers in decimal using this formula:
59
 *
60
 *     MAJOR * 10000 + MINOR * 100
61
 *
62
 * So version 3.0 becomes 30000, version 3.2 becomes 30200, etc.
63
 */
64
65
/*
66
 * We use the OPENSSL_API_COMPAT value to define API level macros.  These
67
 * macros are used to enable or disable features at that API version boundary.
68
 */
69
70
# ifdef OPENSSL_API_LEVEL
71
#  error "OPENSSL_API_LEVEL must not be defined by application"
72
# endif
73
74
/*
75
 * We figure out what API level was intended by simple numeric comparison.
76
 * The lowest old style number we recognise is 0x00908000L, so we take some
77
 * safety margin and assume that anything below 0x00900000L is a new style
78
 * number.  This allows new versions up to and including v943.71.83.
79
 */
80
# ifdef OPENSSL_API_COMPAT
81
#  if OPENSSL_API_COMPAT < 0x900000L
82
#   define OPENSSL_API_LEVEL (OPENSSL_API_COMPAT)
83
#  else
84
#   define OPENSSL_API_LEVEL                            \
85
           (((OPENSSL_API_COMPAT >> 28) & 0xF) * 10000  \
86
            + ((OPENSSL_API_COMPAT >> 20) & 0xFF) * 100 \
87
            + ((OPENSSL_API_COMPAT >> 12) & 0xFF))
88
#  endif
89
# endif
90
91
/*
92
 * If OPENSSL_API_COMPAT wasn't given, we use default numbers to set
93
 * the API compatibility level.
94
 */
95
# ifndef OPENSSL_API_LEVEL
96
#  if OPENSSL_CONFIGURED_API > 0
97
#   define OPENSSL_API_LEVEL (OPENSSL_CONFIGURED_API)
98
#  else
99
#   define OPENSSL_API_LEVEL \
100
           (OPENSSL_VERSION_MAJOR * 10000 + OPENSSL_VERSION_MINOR * 100)
101
#  endif
102
# endif
103
104
# if OPENSSL_API_LEVEL > OPENSSL_CONFIGURED_API
105
#  error "The requested API level higher than the configured API compatibility level"
106
# endif
107
108
/*
109
 * Check of sane values.
110
 */
111
/* Can't go higher than the current version. */
112
# if OPENSSL_API_LEVEL > (OPENSSL_VERSION_MAJOR * 10000 + OPENSSL_VERSION_MINOR * 100)
113
#  error "OPENSSL_API_COMPAT expresses an impossible API compatibility level"
114
# endif
115
/* OpenSSL will have no version 2.y.z */
116
# if OPENSSL_API_LEVEL < 30000 && OPENSSL_API_LEVEL >= 20000
117
#  error "OPENSSL_API_COMPAT expresses an impossible API compatibility level"
118
# endif
119
/* Below 0.9.8 is unacceptably low */
120
# if OPENSSL_API_LEVEL < 908
121
#  error "OPENSSL_API_COMPAT expresses an impossible API compatibility level"
122
# endif
123
124
/*
125
 * Define macros for deprecation purposes.  We always define the macros
126
 * DEPERECATEDIN_{major}_{minor}() for all OpenSSL versions we care for,
127
 * and OPENSSL_NO_DEPRECATED_{major}_{minor} to be used to check if
128
 * removal of deprecated functions applies on that particular version.
129
 */
130
131
# undef OPENSSL_NO_DEPRECATED_3_0
132
# undef OPENSSL_NO_DEPRECATED_1_1_1
133
# undef OPENSSL_NO_DEPRECATED_1_1_0
134
# undef OPENSSL_NO_DEPRECATED_1_0_2
135
# undef OPENSSL_NO_DEPRECATED_1_0_1
136
# undef OPENSSL_NO_DEPRECATED_1_0_0
137
# undef OPENSSL_NO_DEPRECATED_0_9_8
138
139
# if OPENSSL_API_LEVEL >= 30000
140
#  ifndef OPENSSL_NO_DEPRECATED
141
#   define DEPRECATEDIN_3_0(f)       DECLARE_DEPRECATED(f)
142
#  else
143
#   define DEPRECATEDIN_3_0(f)
144
#   define OPENSSL_NO_DEPRECATED_3_0
145
#  endif
146
# else
147
#  define DEPRECATEDIN_3_0(f)        f;
148
# endif
149
# if OPENSSL_API_LEVEL >= 10101
150
#  ifndef OPENSSL_NO_DEPRECATED
151
#   define DEPRECATEDIN_1_1_1(f)     DECLARE_DEPRECATED(f)
152
#  else
153
#   define DEPRECATEDIN_1_1_1(f)
154
#   define OPENSSL_NO_DEPRECATED_1_1_1
155
#  endif
156
# else
157
#  define DEPRECATEDIN_1_1_1(f)      f;
158
# endif
159
# if OPENSSL_API_LEVEL >= 10100
160
#  ifndef OPENSSL_NO_DEPRECATED
161
#   define DEPRECATEDIN_1_1_0(f)     DECLARE_DEPRECATED(f)
162
#  else
163
#   define DEPRECATEDIN_1_1_0(f)
164
#   define OPENSSL_NO_DEPRECATED_1_1_0
165
#  endif
166
# else
167
#  define DEPRECATEDIN_1_1_0(f)      f;
168
# endif
169
# if OPENSSL_API_LEVEL >= 10002
170
#  ifndef OPENSSL_NO_DEPRECATED
171
#   define DEPRECATEDIN_1_0_2(f)     DECLARE_DEPRECATED(f)
172
#  else
173
#   define DEPRECATEDIN_1_0_2(f)
174
#   define OPENSSL_NO_DEPRECATED_1_0_2
175
#  endif
176
# else
177
#  define DEPRECATEDIN_1_0_2(f)      f;
178
# endif
179
# if OPENSSL_API_LEVEL >= 10001
180
#  ifndef OPENSSL_NO_DEPRECATED
181
#   define DEPRECATEDIN_1_0_1(f)     DECLARE_DEPRECATED(f)
182
#  else
183
#   define DEPRECATEDIN_1_0_1(f)
184
#   define OPENSSL_NO_DEPRECATED_1_0_1
185
#  endif
186
# else
187
#  define DEPRECATEDIN_1_0_1(f)      f;
188
# endif
189
# if OPENSSL_API_LEVEL >= 10000
190
#  ifndef OPENSSL_NO_DEPRECATED
191
#   define DEPRECATEDIN_1_0_0(f)     DECLARE_DEPRECATED(f)
192
#  else
193
#   define DEPRECATEDIN_1_0_0(f)
194
#   define OPENSSL_NO_DEPRECATED_1_0_0
195
#  endif
196
# else
197
#  define DEPRECATEDIN_1_0_0(f)      f;
198
# endif
199
# if OPENSSL_API_LEVEL >= 908
200
#  ifndef OPENSSL_NO_DEPRECATED
201
#   define DEPRECATEDIN_0_9_8(f)     DECLARE_DEPRECATED(f)
202
#  else
203
#   define DEPRECATEDIN_0_9_8(f)
204
#   define OPENSSL_NO_DEPRECATED_0_9_8
205
#  endif
206
# else
207
#  define DEPRECATEDIN_0_9_8(f)      f;
208
# endif
209
210
/*
211
 * Make our own variants of __FILE__ and __LINE__, depending on configuration
212
 */
213
214
# ifndef OPENSSL_FILE
215
#  ifdef OPENSSL_NO_FILENAMES
216
#   define OPENSSL_FILE ""
217
#   define OPENSSL_LINE 0
218
#  else
219
49.1M
#   define OPENSSL_FILE __FILE__
220
49.1M
#   define OPENSSL_LINE __LINE__
221
#  endif
222
# endif
223
224
/*
225
 * __func__ was standardized in C99, so for any compiler that claims
226
 * to implement that language level or newer, we assume we can safely
227
 * use that symbol.
228
 *
229
 * GNU C also provides __FUNCTION__ since version 2, which predates
230
 * C99.  We can, however, only use this if __STDC_VERSION__ exists,
231
 * as it's otherwise not allowed according to ISO C standards (C90).
232
 * (compiling with GNU C's -pedantic tells us so)
233
 *
234
 * If none of the above applies, we check if the compiler is MSVC,
235
 * and use __FUNCTION__ if that's the case.
236
 */
237
# ifndef OPENSSL_FUNC
238
#  if defined(__STDC_VERSION__)
239
#   if __STDC_VERSION__ >= 199901L
240
2.09M
#    define OPENSSL_FUNC __func__
241
#   elif defined(__GNUC__) && __GNUC__ >= 2
242
#    define OPENSSL_FUNC __FUNCTION__
243
#   endif
244
#  elif defined(_MSC_VER)
245
#    define OPENSSL_FUNC __FUNCTION__
246
#  endif
247
/*
248
 * If all these possibilities are exhausted, we give up and use a
249
 * static string.
250
 */
251
#  ifndef OPENSSL_FUNC
252
#   define OPENSSL_FUNC "(unknown function)"
253
#  endif
254
# endif
255
256
#endif  /* OPENSSL_MACROS_H */