diff options
author | Ian Lance Taylor <iant@golang.org> | 2018-04-17 13:59:38 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-04-17 13:59:38 +0000 |
commit | 83a658ca0b5164509f86a2b674192e50a934c6db (patch) | |
tree | dbceef94aeb346b1a317fc802cf86815e747eaa6 /libbacktrace | |
parent | 50ffe7adc0d686e9f193c4e53ea2f0d617309f35 (diff) | |
download | gcc-83a658ca0b5164509f86a2b674192e50a934c6db.zip gcc-83a658ca0b5164509f86a2b674192e50a934c6db.tar.gz gcc-83a658ca0b5164509f86a2b674192e50a934c6db.tar.bz2 |
backtrace.c (backtrace_full): When testing whether we can allocate memory...
* backtrace.c (backtrace_full): When testing whether we can
allocate memory, call mmap directly, and munmap the memory.
Fixes https://github.com/ianlancetaylor/libbacktrace/issues/13 .
From-SVN: r259434
Diffstat (limited to 'libbacktrace')
-rw-r--r-- | libbacktrace/ChangeLog | 5 | ||||
-rw-r--r-- | libbacktrace/backtrace.c | 44 |
2 files changed, 38 insertions, 11 deletions
diff --git a/libbacktrace/ChangeLog b/libbacktrace/ChangeLog index 85c8742..b26da88 100644 --- a/libbacktrace/ChangeLog +++ b/libbacktrace/ChangeLog @@ -1,3 +1,8 @@ +2018-04-17 Ian Lance Taylor <iant@golang.org> + + * backtrace.c (backtrace_full): When testing whether we can + allocate memory, call mmap directly, and munmap the memory. + 2018-04-04 Jakub Jelinek <jakub@redhat.com> PR other/85161 diff --git a/libbacktrace/backtrace.c b/libbacktrace/backtrace.c index f8e3dc5..319edcf 100644 --- a/libbacktrace/backtrace.c +++ b/libbacktrace/backtrace.c @@ -32,12 +32,26 @@ POSSIBILITY OF SUCH DAMAGE. */ #include "config.h" +#include <unistd.h> #include <sys/types.h> +#if !BACKTRACE_USES_MALLOC +#include <sys/mman.h> +#endif + #include "unwind.h" #include "backtrace.h" +#include "backtrace-supported.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. */ @@ -104,7 +118,6 @@ 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; @@ -113,16 +126,25 @@ backtrace_full (struct backtrace_state *state, int skip, bdata.data = data; bdata.ret = 0; - /* 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; - } +#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 _Unwind_Backtrace (unwind, &bdata); return bdata.ret; |