From 7a4c4459f85ae8d245595fcd2e52b09abb202195 Mon Sep 17 00:00:00 2001 From: Lev Serebryakov Date: Wed, 18 May 2016 23:04:09 +0300 Subject: [PATCH] Support madvise() on FreeBSD FreeBSD have madvise() behaviors equivalent to MADV_DONTDUMP and MADV_DODUMP but with its own names. Add definitions for these behaviors used in sodium_mlock() and sodium_munlock() if FreeBSD names are found and Linux ones don't. --- src/libsodium/sodium/utils.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libsodium/sodium/utils.c b/src/libsodium/sodium/utils.c index b2c99325..625b291a 100644 --- a/src/libsodium/sodium/utils.c +++ b/src/libsodium/sodium/utils.c @@ -50,6 +50,13 @@ #if defined(HAVE_ALIGNED_MALLOC) && (defined(WINAPI_DESKTOP) || defined(HAVE_MPROTECT)) # define HAVE_PAGE_PROTECTION #endif +/* FreeBSD defines these with its own names */ +if !defined(MADV_DONTDUMP) && defined(HAVE_MADVISE) +# define MADV_DONTDUMP MADV_NOCORE +#endif +if !defined(MADV_DODUMP) && defined(HAVE_MADVISE) +# define MADV_DODUMP MADV_CORE +#endif static size_t page_size; static unsigned char canary[CANARY_SIZE];