From 8b22b448e84269f6f18c0e08d9ff1f0edeae0d31 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 19 Jul 2022 13:36:57 +0200 Subject: [PATCH] lib:replace: Add macros to burn data from memory This will explicitly zero data from memory. This is guaranteed to be not optimized away. Signed-off-by: Andreas Schneider Reviewed-by: Stefan Metzmacher --- lib/replace/replace.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/replace/replace.h b/lib/replace/replace.h index a8910e2b5e4..da5526c4a2f 100644 --- a/lib/replace/replace.h +++ b/lib/replace/replace.h @@ -846,6 +846,24 @@ typedef unsigned long long ptrdiff_t ; */ #define ZERO_ARRAY_LEN(x, l) memset_s((char *)(x), (l), 0, (l)) +/** + * Explicitly zero data from memory. This is guaranteed to be not optimized + * away. + */ +#define BURN_DATA(x) memset_s((char *)&(x), sizeof(x), 0, sizeof(x)) + +/** + * Explicitly zero data from memory. This is guaranteed to be not optimized + * away. + */ +#define BURN_DATA_SIZE(x, s) memset_s((char *)&(x), (s), 0, (s)) + +/** + * Explicitly zero data from memory. This is guaranteed to be not optimized + * away. + */ +#define BURN_PTR_SIZE(x, s) memset_s((x), (s), 0, (s)) + /** * Work out how many elements there are in a static array. */ -- 2.47.3