1 /* Catastrophic failure reports. Generic POSIX.1 version.
2 Copyright (C) 1993-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
33 #include <not-cancel.h>
34 #include <setvmaname.h>
36 #ifdef FATAL_PREPARE_INCLUDE
37 #include FATAL_PREPARE_INCLUDE
40 #ifndef WRITEV_FOR_FATAL
41 # define WRITEV_FOR_FATAL writev_for_fatal
43 writev_for_fatal (int fd, const struct iovec *iov, size_t niov, size_t total)
45 return TEMP_FAILURE_RETRY (__writev (fd, iov, niov)) == total;
49 /* Abort with an error message. */
51 __libc_message_impl (const char *fmt, ...)
63 struct iovec iov[LIBC_MESSAGE_MAX_ARGS * 2 - 1];
71 /* Find the next "%s" or the end of the string. */
72 const char *next = cp;
73 while (next[0] != '%' || next[1] != 's')
75 next = __strchrnul (next + 1, '%');
81 /* Determine what to print. */
84 if (cp[0] == '%' && cp[1] == 's')
86 str = va_arg (ap, const char *);
97 iov[iovcnt].iov_base = (char *) str;
98 iov[iovcnt].iov_len = len;
106 WRITEV_FOR_FATAL (fd, iov, iovcnt, total);
108 total = (total + 1 + GLRO(dl_pagesize) - 1) & ~(GLRO(dl_pagesize) - 1);
109 struct abort_msg_s *buf = __mmap (NULL, total,
110 PROT_READ | PROT_WRITE,
111 MAP_ANON | MAP_PRIVATE, -1, 0);
112 if (__glibc_likely (buf != MAP_FAILED))
116 for (int cnt = 0; cnt < iovcnt; ++cnt)
117 wp = mempcpy (wp, iov[cnt].iov_base, iov[cnt].iov_len);
120 __set_vma_name (buf, total, " glibc: fatal");
122 /* We have to free the old buffer since the application might
123 catch the SIGABRT signal. */
124 struct abort_msg_s *old = atomic_exchange_acquire (&__abort_msg,
127 __munmap (old, old->size);
131 /* Kill the application. */
137 __libc_fatal (const char *message)
139 /* The loop is added only to keep gcc happy. */
141 __libc_message ("%s", message);
143 libc_hidden_def (__libc_fatal)