From 3a988859504cd3f6b4a379560837a81356d4ffab Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 29 Jan 2026 16:25:15 +0100 Subject: [PATCH] Create a header to declare platform requirements On some platforms, the system headers expose different interfaces depending on what macros are defined, for example to provide different standards compliance level. Create a common place where we can declare such macros, so that our code can behave in the same way when it's in different files. Individual .c files can still override these requirements by defining macros before including the common header, if it's really necessary. Signed-off-by: Gilles Peskine --- library/mbedtls_common.h | 10 ++++++++++ library/mbedtls_platform_requirements.h | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 library/mbedtls_platform_requirements.h diff --git a/library/mbedtls_common.h b/library/mbedtls_common.h index 11d7c8249f..2aacfcbc22 100644 --- a/library/mbedtls_common.h +++ b/library/mbedtls_common.h @@ -11,6 +11,16 @@ #ifndef MBEDTLS_MBEDTLS_COMMON_H #define MBEDTLS_MBEDTLS_COMMON_H +/* Before including any system header, declare some macros to tell system + * headers what we expect of them. + * + * Do this before including any header from TF-PSA-Crypto, since the + * convention is first-come-first-served (so that users can + * override some macros on the command line, and individual users can + * override some macros before including the common header). + */ +#include "mbedtls_platform_requirements.h" + /* Mbed TLS requires TF-PSA-Crypto internals. */ #include "tf_psa_crypto_common.h" diff --git a/library/mbedtls_platform_requirements.h b/library/mbedtls_platform_requirements.h new file mode 100644 index 0000000000..f6dd4ce4aa --- /dev/null +++ b/library/mbedtls_platform_requirements.h @@ -0,0 +1,18 @@ +/** + * \file mbedtls_platform_requirements.h + * + * \brief Declare macros that tell system headers what we expect of them. + * + * This file must be included before any system header, and so in particular + * before build_info.h (which includes the user config, which may include + * system headers). + */ +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + */ + +#ifndef MBEDTLS_MBEDTLS_PLATFORM_REQUIREMENTS_H +#define MBEDTLS_MBEDTLS_PLATFORM_REQUIREMENTS_H + +#endif /* MBEDTLS_MBEDTLS_PLATFORM_REQUIREMENTS_H */