|
Packit Service |
82fcde |
/* Catastrophic failure reports. Linux version.
|
|
Packit Service |
82fcde |
Copyright (C) 1993-2018 Free Software Foundation, Inc.
|
|
Packit Service |
82fcde |
This file is part of the GNU C Library.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
82fcde |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License as published by the Free Software Foundation; either
|
|
Packit Service |
82fcde |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
82fcde |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
82fcde |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
82fcde |
Lesser General Public License for more details.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License along with the GNU C Library; if not, see
|
|
Packit Service |
82fcde |
<http://www.gnu.org/licenses/>. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include <errno.h>
|
|
Packit Service |
82fcde |
#include <execinfo.h>
|
|
Packit Service |
82fcde |
#include <fcntl.h>
|
|
Packit Service |
82fcde |
#include <not-cancel.h>
|
|
Packit Service |
82fcde |
#include <string.h>
|
|
Packit Service |
82fcde |
#include <sys/mman.h>
|
|
Packit Service |
82fcde |
#include <sys/uio.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static bool
|
|
Packit Service |
82fcde |
writev_for_fatal (int fd, const struct iovec *iov, size_t niov, size_t total)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
INTERNAL_SYSCALL_DECL (err);
|
|
Packit Service |
82fcde |
ssize_t cnt;
|
|
Packit Service |
82fcde |
do
|
|
Packit Service |
82fcde |
cnt = INTERNAL_SYSCALL (writev, err, 3, fd, iov, niov);
|
|
Packit Service |
82fcde |
while (INTERNAL_SYSCALL_ERROR_P (cnt, err)
|
|
Packit Service |
82fcde |
&& INTERNAL_SYSCALL_ERRNO (cnt, err) == EINTR);
|
|
Packit Service |
82fcde |
return cnt == total;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
#define WRITEV_FOR_FATAL writev_for_fatal
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static void
|
|
Packit Service |
82fcde |
backtrace_and_maps (int do_abort, bool written, int fd)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
if (do_abort > 1 && written)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
void *addrs[64];
|
|
Packit Service |
82fcde |
#define naddrs (sizeof (addrs) / sizeof (addrs[0]))
|
|
Packit Service |
82fcde |
int n = __backtrace (addrs, naddrs);
|
|
Packit Service |
82fcde |
if (n > 2)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
#define strnsize(str) str, strlen (str)
|
|
Packit Service |
82fcde |
#define writestr(str) __write_nocancel (fd, str)
|
|
Packit Service |
82fcde |
writestr (strnsize ("======= Backtrace: =========\n"));
|
|
Packit Service |
82fcde |
__backtrace_symbols_fd (addrs + 1, n - 1, fd);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
writestr (strnsize ("======= Memory map: ========\n"));
|
|
Packit Service |
82fcde |
int fd2 = __open_nocancel ("/proc/self/maps", O_RDONLY);
|
|
Packit Service |
82fcde |
char buf[1024];
|
|
Packit Service |
82fcde |
ssize_t n2;
|
|
Packit Service |
82fcde |
while ((n2 = __read_nocancel (fd2, buf, sizeof (buf))) > 0)
|
|
Packit Service |
82fcde |
if (__write_nocancel (fd, buf, n2) != n2)
|
|
Packit Service |
82fcde |
break;
|
|
Packit Service |
82fcde |
__close_nocancel_nostatus (fd2);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
#define BEFORE_ABORT backtrace_and_maps
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include <sysdeps/posix/libc_fatal.c>
|