codekingpro/portable-devtools
114k
1/*2 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.3 *4 * Licensed under the Apache License 2.0 (the "License"). You may not use5 * this file except in compliance with the License. You can obtain a copy6 * in the file LICENSE in the source distribution or at7 * https://www.openssl.org/source/license.html8 */9 10#ifndef OPENSSL_MACROS_H11# define OPENSSL_MACROS_H12# pragma once13 14#include <openssl/opensslconf.h>15#include <openssl/opensslv.h>16 17 18/* Helper macros for CPP string composition */19# define OPENSSL_MSTR_HELPER(x) #x20# define OPENSSL_MSTR(x) OPENSSL_MSTR_HELPER(x)21 22/*23 * Sometimes OPENSSL_NO_xxx ends up with an empty file and some compilers24 * don't like that. This will hopefully silence them.25 */26# define NON_EMPTY_TRANSLATION_UNIT static void *dummy = &dummy;27 28/*29 * Generic deprecation macro30 *31 * If OPENSSL_SUPPRESS_DEPRECATED is defined, then OSSL_DEPRECATED and32 * OSSL_DEPRECATED_FOR become no-ops33 */34# ifndef OSSL_DEPRECATED35# undef OSSL_DEPRECATED_FOR36# ifndef OPENSSL_SUPPRESS_DEPRECATED37# if defined(_MSC_VER)38 /*39 * MSVC supports __declspec(deprecated) since MSVC 2003 (13.10),40 * and __declspec(deprecated(message)) since MSVC 2005 (14.00)41 */42# if _MSC_VER >= 140043# define OSSL_DEPRECATED(since) \44 __declspec(deprecated("Since OpenSSL " # since))45# define OSSL_DEPRECATED_FOR(since, message) \46 __declspec(deprecated("Since OpenSSL " # since ";" message))47# elif _MSC_VER >= 131048# define OSSL_DEPRECATED(since) __declspec(deprecated)49# define OSSL_DEPRECATED_FOR(since, message) __declspec(deprecated)50# endif51# elif defined(__GNUC__)52 /*53 * According to GCC documentation, deprecations with message appeared in54 * GCC 4.5.055 */56# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)57# define OSSL_DEPRECATED(since) \58 __attribute__((deprecated("Since OpenSSL " # since)))59# define OSSL_DEPRECATED_FOR(since, message) \60 __attribute__((deprecated("Since OpenSSL " # since ";" message)))61# elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)62# define OSSL_DEPRECATED(since) __attribute__((deprecated))63# define OSSL_DEPRECATED_FOR(since, message) __attribute__((deprecated))64# endif65# elif defined(__SUNPRO_C)66# if (__SUNPRO_C >= 0x5130)67# define OSSL_DEPRECATED(since) __attribute__ ((deprecated))68# define OSSL_DEPRECATED_FOR(since, message) __attribute__ ((deprecated))69# endif70# endif71# endif72# endif73 74/*75 * Still not defined? Then define no-op macros. This means these macros76 * are unsuitable for use in a typedef.77 */78# ifndef OSSL_DEPRECATED79# define OSSL_DEPRECATED(since) extern80# define OSSL_DEPRECATED_FOR(since, message) extern81# endif82 83/*84 * Applications should use -DOPENSSL_API_COMPAT=<version> to suppress the85 * declarations of functions deprecated in or before <version>. If this is86 * undefined, the value of the macro OPENSSL_CONFIGURED_API (defined in87 * <openssl/opensslconf.h>) is the default.88 *89 * For any version number up until version 1.1.x, <version> is expected to be90 * the calculated version number 0xMNNFFPPSL.91 * For version numbers 3.0 and on, <version> is expected to be a computation92 * of the major and minor numbers in decimal using this formula:93 *94 * MAJOR * 10000 + MINOR * 10095 *96 * So version 3.0 becomes 30000, version 3.2 becomes 30200, etc.97 */98 99/*100 * We use the OPENSSL_API_COMPAT value to define API level macros. These101 * macros are used to enable or disable features at that API version boundary.102 */103 104# ifdef OPENSSL_API_LEVEL105# error "OPENSSL_API_LEVEL must not be defined by application"106# endif107 108/*109 * We figure out what API level was intended by simple numeric comparison.110 * The lowest old style number we recognise is 0x00908000L, so we take some111 * safety margin and assume that anything below 0x00900000L is a new style112 * number. This allows new versions up to and including v943.71.83.113 */114# ifdef OPENSSL_API_COMPAT115# if OPENSSL_API_COMPAT < 0x900000L116# define OPENSSL_API_LEVEL (OPENSSL_API_COMPAT)117# else118# define OPENSSL_API_LEVEL \119 (((OPENSSL_API_COMPAT >> 28) & 0xF) * 10000 \120 + ((OPENSSL_API_COMPAT >> 20) & 0xFF) * 100 \121 + ((OPENSSL_API_COMPAT >> 12) & 0xFF))122# endif123# endif124 125/*126 * If OPENSSL_API_COMPAT wasn't given, we use default numbers to set127 * the API compatibility level.128 */129# ifndef OPENSSL_API_LEVEL130# if OPENSSL_CONFIGURED_API > 0131# define OPENSSL_API_LEVEL (OPENSSL_CONFIGURED_API)132# else133# define OPENSSL_API_LEVEL \134 (OPENSSL_VERSION_MAJOR * 10000 + OPENSSL_VERSION_MINOR * 100)135# endif136# endif137 138# if OPENSSL_API_LEVEL > OPENSSL_CONFIGURED_API139# error "The requested API level higher than the configured API compatibility level"140# endif141 142/*143 * Check of sane values.144 */145/* Can't go higher than the current version. */146# if OPENSSL_API_LEVEL > (OPENSSL_VERSION_MAJOR * 10000 + OPENSSL_VERSION_MINOR * 100)147# error "OPENSSL_API_COMPAT expresses an impossible API compatibility level"148# endif149/* OpenSSL will have no version 2.y.z */150# if OPENSSL_API_LEVEL < 30000 && OPENSSL_API_LEVEL >= 20000151# error "OPENSSL_API_COMPAT expresses an impossible API compatibility level"152# endif153/* Below 0.9.8 is unacceptably low */154# if OPENSSL_API_LEVEL < 908155# error "OPENSSL_API_COMPAT expresses an impossible API compatibility level"156# endif157 158/*159 * Define macros for deprecation and simulated removal purposes.160 *161 * The macros OSSL_DEPRECATED_{major}_{minor} are always defined for162 * all OpenSSL versions we care for. They can be used as attributes163 * in function declarations where appropriate.164 *165 * The macros OPENSSL_NO_DEPRECATED_{major}_{minor} are defined for166 * all OpenSSL versions up to or equal to the version given with167 * OPENSSL_API_COMPAT. They are used as guards around anything that's168 * deprecated up to that version, as an effect of the developer option169 * 'no-deprecated'.170 */171 172# undef OPENSSL_NO_DEPRECATED_3_0173# undef OPENSSL_NO_DEPRECATED_1_1_1174# undef OPENSSL_NO_DEPRECATED_1_1_0175# undef OPENSSL_NO_DEPRECATED_1_0_2176# undef OPENSSL_NO_DEPRECATED_1_0_1177# undef OPENSSL_NO_DEPRECATED_1_0_0178# undef OPENSSL_NO_DEPRECATED_0_9_8179 180# if OPENSSL_API_LEVEL >= 30000181# ifndef OPENSSL_NO_DEPRECATED182# define OSSL_DEPRECATEDIN_3_0 OSSL_DEPRECATED(3.0)183# define OSSL_DEPRECATEDIN_3_0_FOR(msg) OSSL_DEPRECATED_FOR(3.0, msg)184# else185# define OPENSSL_NO_DEPRECATED_3_0186# endif187# else188# define OSSL_DEPRECATEDIN_3_0189# define OSSL_DEPRECATEDIN_3_0_FOR(msg)190# endif191# if OPENSSL_API_LEVEL >= 10101192# ifndef OPENSSL_NO_DEPRECATED193# define OSSL_DEPRECATEDIN_1_1_1 OSSL_DEPRECATED(1.1.1)194# define OSSL_DEPRECATEDIN_1_1_1_FOR(msg) OSSL_DEPRECATED_FOR(1.1.1, msg)195# else196# define OPENSSL_NO_DEPRECATED_1_1_1197# endif198# else199# define OSSL_DEPRECATEDIN_1_1_1200# define OSSL_DEPRECATEDIN_1_1_1_FOR(msg)201# endif202# if OPENSSL_API_LEVEL >= 10100203# ifndef OPENSSL_NO_DEPRECATED204# define OSSL_DEPRECATEDIN_1_1_0 OSSL_DEPRECATED(1.1.0)205# define OSSL_DEPRECATEDIN_1_1_0_FOR(msg) OSSL_DEPRECATED_FOR(1.1.0, msg)206# else207# define OPENSSL_NO_DEPRECATED_1_1_0208# endif209# else210# define OSSL_DEPRECATEDIN_1_1_0211# define OSSL_DEPRECATEDIN_1_1_0_FOR(msg)212# endif213# if OPENSSL_API_LEVEL >= 10002214# ifndef OPENSSL_NO_DEPRECATED215# define OSSL_DEPRECATEDIN_1_0_2 OSSL_DEPRECATED(1.0.2)216# define OSSL_DEPRECATEDIN_1_0_2_FOR(msg) OSSL_DEPRECATED_FOR(1.0.2, msg)217# else218# define OPENSSL_NO_DEPRECATED_1_0_2219# endif220# else221# define OSSL_DEPRECATEDIN_1_0_2222# define OSSL_DEPRECATEDIN_1_0_2_FOR(msg)223# endif224# if OPENSSL_API_LEVEL >= 10001225# ifndef OPENSSL_NO_DEPRECATED226# define OSSL_DEPRECATEDIN_1_0_1 OSSL_DEPRECATED(1.0.1)227# define OSSL_DEPRECATEDIN_1_0_1_FOR(msg) OSSL_DEPRECATED_FOR(1.0.1, msg)228# else229# define OPENSSL_NO_DEPRECATED_1_0_1230# endif231# else232# define OSSL_DEPRECATEDIN_1_0_1233# define OSSL_DEPRECATEDIN_1_0_1_FOR(msg)234# endif235# if OPENSSL_API_LEVEL >= 10000236# ifndef OPENSSL_NO_DEPRECATED237# define OSSL_DEPRECATEDIN_1_0_0 OSSL_DEPRECATED(1.0.0)238# define OSSL_DEPRECATEDIN_1_0_0_FOR(msg) OSSL_DEPRECATED_FOR(1.0.0, msg)239# else240# define OPENSSL_NO_DEPRECATED_1_0_0241# endif242# else243# define OSSL_DEPRECATEDIN_1_0_0244# define OSSL_DEPRECATEDIN_1_0_0_FOR(msg)245# endif246# if OPENSSL_API_LEVEL >= 908247# ifndef OPENSSL_NO_DEPRECATED248# define OSSL_DEPRECATEDIN_0_9_8 OSSL_DEPRECATED(0.9.8)249# define OSSL_DEPRECATEDIN_0_9_8_FOR(msg) OSSL_DEPRECATED_FOR(0.9.8, msg)250# else251# define OPENSSL_NO_DEPRECATED_0_9_8252# endif253# else254# define OSSL_DEPRECATEDIN_0_9_8255# define OSSL_DEPRECATEDIN_0_9_8_FOR(msg)256# endif257 258/*259 * Make our own variants of __FILE__ and __LINE__, depending on configuration260 */261 262# ifndef OPENSSL_FILE263# ifdef OPENSSL_NO_FILENAMES264# define OPENSSL_FILE ""265# define OPENSSL_LINE 0266# else267# define OPENSSL_FILE __FILE__268# define OPENSSL_LINE __LINE__269# endif270# endif271 272/*273 * __func__ was standardized in C99, so for any compiler that claims274 * to implement that language level or newer, we assume we can safely275 * use that symbol.276 *277 * GNU C also provides __FUNCTION__ since version 2, which predates278 * C99. We can, however, only use this if __STDC_VERSION__ exists,279 * as it's otherwise not allowed according to ISO C standards (C90).280 * (compiling with GNU C's -pedantic tells us so)281 *282 * If none of the above applies, we check if the compiler is MSVC,283 * and use __FUNCTION__ if that's the case.284 */285# ifndef OPENSSL_FUNC286# if defined(__STDC_VERSION__)287# if __STDC_VERSION__ >= 199901L288# define OPENSSL_FUNC __func__289# elif defined(__GNUC__) && __GNUC__ >= 2290# define OPENSSL_FUNC __FUNCTION__291# endif292# elif defined(_MSC_VER)293# define OPENSSL_FUNC __FUNCTION__294# endif295/*296 * If all these possibilities are exhausted, we give up and use a297 * static string.298 */299# ifndef OPENSSL_FUNC300# define OPENSSL_FUNC "(unknown function)"301# endif302# endif303 304#endif /* OPENSSL_MACROS_H */305 