Gilles Peskine | c0a562c | 2025-07-25 17:07:13 +0200 | [diff] [blame] | 1 | /* -*-c-*- |
Bence Szépkúti | bb0cfeb | 2021-05-28 09:42:25 +0200 | [diff] [blame] | 2 | * Query Mbed TLS compile time configurations from mbedtls_config.h |
Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 3 | * |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 4 | * Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 5 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
Bence Szépkúti | c662b36 | 2021-05-27 11:25:03 +0200 | [diff] [blame] | 8 | #include "mbedtls/build_info.h" |
Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 9 | |
Gilles Peskine | c772b18 | 2021-01-12 15:55:10 +0100 | [diff] [blame] | 10 | #include "query_config.h" |
| 11 | |
Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 12 | #include "mbedtls/platform.h" |
Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 13 | #include <string.h> |
| 14 | |
Gilles Peskine | c0a562c | 2025-07-25 17:07:13 +0200 | [diff] [blame] | 15 | INCLUDE_HEADERS |
| 16 | |
Andres Amaya Garcia | 27b3372 | 2018-12-05 10:47:31 +0000 | [diff] [blame] | 17 | /* |
| 18 | * Helper macros to convert a macro or its expansion into a string |
| 19 | * WARNING: This does not work for expanding function-like macros. However, |
| 20 | * Mbed TLS does not currently have configuration options used in this fashion. |
| 21 | */ |
Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 22 | #define MACRO_EXPANSION_TO_STR(macro) MACRO_NAME_TO_STR(macro) |
Andres Amaya Garcia | 27b3372 | 2018-12-05 10:47:31 +0000 | [diff] [blame] | 23 | #define MACRO_NAME_TO_STR(macro) \ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 24 | mbedtls_printf("%s", strlen( #macro "") > 0 ? #macro "\n" : "") |
Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 25 | |
Jerry Yu | 2e8b001 | 2021-12-10 20:29:02 +0800 | [diff] [blame] | 26 | #define STRINGIFY(macro) #macro |
Jerry Yu | 84e63a7 | 2021-12-06 13:40:37 +0800 | [diff] [blame] | 27 | #define OUTPUT_MACRO_NAME_VALUE(macro) mbedtls_printf( #macro "%s\n", \ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 28 | (STRINGIFY(macro) "")[0] != 0 ? "=" STRINGIFY( \ |
| 29 | macro) : "") |
Jerry Yu | 84e63a7 | 2021-12-06 13:40:37 +0800 | [diff] [blame] | 30 | |
Andres Amaya Garcia | 17c53c5 | 2019-01-24 09:55:14 +0000 | [diff] [blame] | 31 | #if defined(_MSC_VER) |
| 32 | /* |
| 33 | * Visual Studio throws the warning 4003 because many Mbed TLS feature macros |
| 34 | * are defined empty. This means that from the preprocessor's point of view |
| 35 | * the macro MBEDTLS_EXPANSION_TO_STR is being invoked without arguments as |
| 36 | * some macros expand to nothing. We suppress that specific warning to get a |
| 37 | * clean build and to ensure that tests treating warnings as errors do not |
| 38 | * fail. |
| 39 | */ |
| 40 | #pragma warning(push) |
| 41 | #pragma warning(disable:4003) |
| 42 | #endif /* _MSC_VER */ |
| 43 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 44 | int query_config(const char *config) |
Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 45 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 46 | CHECK_CONFIG /* If the symbol is not found, return an error */ |
| 47 | return 1; |
Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 48 | } |
Andres Amaya Garcia | 17c53c5 | 2019-01-24 09:55:14 +0000 | [diff] [blame] | 49 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 50 | void list_config(void) |
Jerry Yu | 84e63a7 | 2021-12-06 13:40:37 +0800 | [diff] [blame] | 51 | { |
| 52 | LIST_CONFIG |
| 53 | } |
Andres Amaya Garcia | 17c53c5 | 2019-01-24 09:55:14 +0000 | [diff] [blame] | 54 | #if defined(_MSC_VER) |
| 55 | #pragma warning(pop) |
| 56 | #endif /* _MSC_VER */ |