diff options
author | Nick Mathewson <nickm@torproject.org> | 2019-09-02 14:49:53 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2019-09-02 14:49:53 -0400 |
commit | 52342327c7e566a25bf69dc6df651de45959e6d6 (patch) | |
tree | 766d6048dc51e73966102b2f00baa273531f5e12 /src/lib/malloc | |
parent | e3a458e441fe9f823d564ca66753e3b76c7c0943 (diff) | |
download | tor-52342327c7e566a25bf69dc6df651de45959e6d6.tar.gz tor-52342327c7e566a25bf69dc6df651de45959e6d6.zip |
madvise: tolerate EINVAL and ENOSYS
These errors can occur if we are built on a system with support for
madvise(MADV_NOFORK) but then we are run on a system whose kernel
does not support that flag.
If the error is something that we don't tolerate at all, we now log
it before crashing.
Fixes bug 31570. I am calling this a bugfix on 0.4.1.1-alpha, where
we actually started using the map_anon code.
Diffstat (limited to 'src/lib/malloc')
-rw-r--r-- | src/lib/malloc/map_anon.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/lib/malloc/map_anon.c b/src/lib/malloc/map_anon.c index 0f6a4150c7..79bbb99f72 100644 --- a/src/lib/malloc/map_anon.c +++ b/src/lib/malloc/map_anon.c @@ -27,6 +27,9 @@ #include <windows.h> #endif +#include <string.h> +#include <errno.h> + /** * Macro to get the high bytes of a size_t, if there are high bytes. * Windows needs this; other operating systems define a size_t that does @@ -108,7 +111,17 @@ static int nodump_mem(void *mem, size_t sz) { #if defined(MADV_DONTDUMP) - return madvise(mem, sz, MADV_DONTDUMP); + int rv = madvise(mem, sz, MADV_DONTDUMP); + if (rv == 0) { + return 0; + } else if (errno == ENOSYS || errno == EINVAL) { + return 0; // syscall not supported, or flag not supported. + } else { + tor_log_err_sigsafe("Unexpected error from madvise: ", + strerror(errno), + NULL); + return -1; + } #else (void) mem; (void) sz; |