1 /* Catastrophic failure reports. Generic POSIX.1 version.
2 Copyright (C) 1993-2020 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>
35 #ifdef FATAL_PREPARE_INCLUDE
36 #include FATAL_PREPARE_INCLUDE
39 #ifndef WRITEV_FOR_FATAL
40 # define WRITEV_FOR_FATAL writev_for_fatal
42 writev_for_fatal (int fd
, const struct iovec
*iov
, size_t niov
, size_t total
)
44 return TEMP_FAILURE_RETRY (__writev (fd
, iov
, niov
)) == total
;
52 struct str_list
*next
;
55 /* Abort with an error message. */
57 __libc_message (enum __libc_message_action action
, const char *fmt
, ...)
71 struct str_list
*list
= NULL
;
77 /* Find the next "%s" or the end of the string. */
78 const char *next
= cp
;
79 while (next
[0] != '%' || next
[1] != 's')
81 next
= __strchrnul (next
+ 1, '%');
87 /* Determine what to print. */
90 if (cp
[0] == '%' && cp
[1] == 's')
92 str
= va_arg (ap
, const char *);
103 struct str_list
*newp
= alloca (sizeof (struct str_list
));
113 struct iovec
*iov
= alloca (nlist
* sizeof (struct iovec
));
116 for (int cnt
= nlist
- 1; cnt
>= 0; --cnt
)
118 iov
[cnt
].iov_base
= (char *) list
->str
;
119 iov
[cnt
].iov_len
= list
->len
;
124 WRITEV_FOR_FATAL (fd
, iov
, nlist
, total
);
126 if ((action
& do_abort
))
128 total
= ((total
+ 1 + GLRO(dl_pagesize
) - 1)
129 & ~(GLRO(dl_pagesize
) - 1));
130 struct abort_msg_s
*buf
= __mmap (NULL
, total
,
131 PROT_READ
| PROT_WRITE
,
132 MAP_ANON
| MAP_PRIVATE
, -1, 0);
133 if (__glibc_likely (buf
!= MAP_FAILED
))
137 for (int cnt
= 0; cnt
< nlist
; ++cnt
)
138 wp
= mempcpy (wp
, iov
[cnt
].iov_base
, iov
[cnt
].iov_len
);
141 /* We have to free the old buffer since the application might
142 catch the SIGABRT signal. */
143 struct abort_msg_s
*old
= atomic_exchange_acq (&__abort_msg
,
146 __munmap (old
, old
->size
);
153 if ((action
& do_abort
))
154 /* Kill the application. */
160 __libc_fatal (const char *message
)
162 /* The loop is added only to keep gcc happy. */
164 __libc_message (do_abort
, "%s", message
);
166 libc_hidden_def (__libc_fatal
)