From 21070494d80ebf9586ecf2fe9a3c24d34329e4db Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 17 Apr 2018 17:58:05 +0000 Subject: [PATCH] backtrace.c: Revert last two changes. * backtrace.c: Revert last two changes. Don't call mmap directly. From-SVN: r259440 --- libbacktrace/ChangeLog | 5 +++++ libbacktrace/backtrace.c | 45 ++++++++++------------------------------ 2 files changed, 16 insertions(+), 34 deletions(-) diff --git a/libbacktrace/ChangeLog b/libbacktrace/ChangeLog index 039e56f7aa0..08c06e5ebe1 100644 --- a/libbacktrace/ChangeLog +++ b/libbacktrace/ChangeLog @@ -1,3 +1,8 @@ +2018-04-17 Ian Lance Taylor + + * backtrace.c: Revert last two changes. Don't call mmap + directly. + 2018-04-17 Ian Lance Taylor * backtrace.c: Include backtrace-supported.h before checking diff --git a/libbacktrace/backtrace.c b/libbacktrace/backtrace.c index 5bcd370e378..f8e3dc59d45 100644 --- a/libbacktrace/backtrace.c +++ b/libbacktrace/backtrace.c @@ -32,27 +32,12 @@ POSSIBILITY OF SUCH DAMAGE. */ #include "config.h" -#include #include -#include "backtrace-supported.h" - -#if !BACKTRACE_USES_MALLOC -#include -#endif - #include "unwind.h" #include "backtrace.h" #include "internal.h" -#ifndef MAP_ANONYMOUS -#define MAP_ANONYMOUS MAP_ANON -#endif - -#ifndef MAP_FAILED -#define MAP_FAILED ((void *)-1) -#endif - /* The main backtrace_full routine. */ /* Data passed through _Unwind_Backtrace. */ @@ -119,6 +104,7 @@ backtrace_full (struct backtrace_state *state, int skip, backtrace_error_callback error_callback, void *data) { struct backtrace_data bdata; + void *p; bdata.skip = skip + 1; bdata.state = state; @@ -127,25 +113,16 @@ backtrace_full (struct backtrace_state *state, int skip, bdata.data = data; bdata.ret = 0; -#if !BACKTRACE_USES_MALLOC - { - size_t pagesize; - void *page; - - /* If we can't allocate any memory at all, don't try to produce - file/line information. */ - pagesize = getpagesize (); - page = mmap (NULL, pagesize, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - if (page == MAP_FAILED) - bdata.can_alloc = 0; - else - { - munmap (page, pagesize); - bdata.can_alloc = 1; - } - } -#endif + /* If we can't allocate any memory at all, don't try to produce + file/line information. */ + p = backtrace_alloc (state, 4096, NULL, NULL); + if (p == NULL) + bdata.can_alloc = 0; + else + { + backtrace_free (state, p, 4096, NULL, NULL); + bdata.can_alloc = 1; + } _Unwind_Backtrace (unwind, &bdata); return bdata.ret; -- 2.30.2