Don't include locked memory in coredumps

Linux 3.4+ supports a DONTDUMP advisory, which prevents memory
from being included in coredumps.
This commit is contained in:
Colm MacCarthaigh 2014-06-27 22:12:25 -07:00 committed by Frank Denis
parent 768b78b711
commit 08e578c421

View File

@ -169,6 +169,9 @@ sodium_hex2bin(unsigned char * const bin, const size_t bin_maxlen,
int
sodium_mlock(void * const addr, const size_t len)
{
#ifdef MADV_DONTDUMP
(void) madvise(addr, len, MADV_DONTDUMP);
#endif
#ifdef HAVE_MLOCK
return mlock(addr, len);
#elif defined(HAVE_VIRTUALLOCK)
@ -183,6 +186,9 @@ int
sodium_munlock(void * const addr, const size_t len)
{
sodium_memzero(addr, len);
#ifdef MADV_DODUMP
(void) madvise(addr, len, MADV_DODUMP);
#endif
#ifdef HAVE_MLOCK
return munlock(addr, len);
#elif defined(HAVE_VIRTUALLOCK)