summaryrefslogtreecommitdiffstats
path: root/crypto/mem_sec.c
diff options
context:
space:
mode:
authorJames Knight <james.d.knight@live.com>2023-05-05 20:20:02 -0400
committerTomas Mraz <tomas@openssl.org>2023-06-12 07:56:03 +0200
commit78634e8ac253a8edf338d329965724dfa8e033ab (patch)
tree590cf853d2f4c6992967184ef15f61ca3a52b6e2 /crypto/mem_sec.c
parent6181a333670199d20fb60028807edba44899e8d5 (diff)
Introduce [HAVE_/NO_]MADVISE defines
Toolchains that target a non-MMU architecture may not have the `madvise` function available, even if the `sys/mman.h` header provides a define for `MADV_DONTDUMP` (e.g. when targeting ARMv7-M with uClibc). The following tweaks the implementation to use `HAVE_MADVISE`/`NO_MADVISE` defines to help indicate when to attempt to use `madvise`. This change operates in the same manner as the original implementation (i.e. relies on `MADV_DONTDUMP` to indicate if `madvise` can be used); however, this change now allows a builder to override the internal detection by explicitly providing the `HAVE_MADVISE` define at compile time. This should give flexibility for environments which do not have `madvise` when there is no easy logic to set `NO_MADVISE`. Signed-off-by: James Knight <james.d.knight@live.com> Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Todd Short <todd.short@me.com> (Merged from https://github.com/openssl/openssl/pull/20851)
Diffstat (limited to 'crypto/mem_sec.c')
-rw-r--r--crypto/mem_sec.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/crypto/mem_sec.c b/crypto/mem_sec.c
index d29f261ec4..409aee5e0c 100644
--- a/crypto/mem_sec.c
+++ b/crypto/mem_sec.c
@@ -66,6 +66,18 @@ VirtualLock(
# include <sys/stat.h>
# include <fcntl.h>
#endif
+#ifndef HAVE_MADVISE
+# if defined(MADV_DONTDUMP)
+# define HAVE_MADVISE 1
+# else
+# define HAVE_MADVISE 0
+# endif
+#endif
+#if HAVE_MADVISE
+# undef NO_MADVISE
+#else
+# define NO_MADVISE
+#endif
#define CLEAR(p, s) OPENSSL_cleanse(p, s)
#ifndef PAGE_SIZE
@@ -567,7 +579,7 @@ static int sh_init(size_t size, size_t minsize)
if (mlock(sh.arena, sh.arena_size) < 0)
ret = 2;
#endif
-#ifdef MADV_DONTDUMP
+#ifndef NO_MADVISE
if (madvise(sh.arena, sh.arena_size, MADV_DONTDUMP) < 0)
ret = 2;
#endif