summaryrefslogtreecommitdiff
path: root/src/sysdep.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2015-02-24 16:34:13 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2015-02-24 16:35:03 -0800
commitb74db6347cf5cac1ebd4c604fd5691c588fd8e32 (patch)
treedeb27634521d10950819b8ae4fec445848df6f6c /src/sysdep.c
parent0c4f73a09d9069824911420f0205da0dd90c1504 (diff)
downloademacs-b74db6347cf5cac1ebd4c604fd5691c588fd8e32.tar.gz
Backtrace after malloc arena is corrupted
Without this change, if the malloc arena is corrupted and then 'backtrace' is called, the backtrace can crash because 'backtrace' calls 'malloc'. For more, please see: https://sourceware.org/ml/libc-alpha/2015-02/msg00678.html * emacs.c (main): Initialize tables used by 'backtrace'. * sysdep.c (emacs_backtrace): Document the newly used part of the API.
Diffstat (limited to 'src/sysdep.c')
-rw-r--r--src/sysdep.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/sysdep.c b/src/sysdep.c
index a2bda96192f..cb361ec2dc5 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -2147,7 +2147,17 @@ snprintf (char *buf, size_t bufsize, char const *format, ...)
/* If a backtrace is available, output the top lines of it to stderr.
Do not output more than BACKTRACE_LIMIT or BACKTRACE_LIMIT_MAX lines.
This function may be called from a signal handler, so it should
- not invoke async-unsafe functions like malloc. */
+ not invoke async-unsafe functions like malloc.
+
+ If BACKTRACE_LIMIT is -1, initialize tables that 'backtrace' uses
+ but do not output anything. This avoids some problems that can
+ otherwise occur if the malloc arena is corrupted before 'backtrace'
+ is called, since 'backtrace' may call malloc if the tables are not
+ initialized.
+
+ If the static variable THREAD_BACKTRACE_NPOINTERS is nonzero, a
+ fatal error has occurred in some other thread; generate a thread
+ backtrace instead, ignoring BACKTRACE_LIMIT. */
void
emacs_backtrace (int backtrace_limit)
{