|
|
b40826 |
2011-05-15 Ulrich Drepper <drepper@gmail.com>
|
|
|
b40826 |
|
|
|
b40826 |
[BZ #11901]
|
|
|
b40826 |
* include/stdlib.h: Move include protection to the right place.
|
|
|
b40826 |
Define abort_msg_s. Declare __abort_msg with it.
|
|
|
b40826 |
* stdlib/abort.c (__abort_msg): Adjust type.
|
|
|
b40826 |
* assert/assert.c (__assert_fail_base): New function. Majority
|
|
|
b40826 |
of code from __assert_fail. Allocate memory for __abort_msg with
|
|
|
b40826 |
mmap.
|
|
|
b40826 |
(__assert_fail): Now call __assert_fail_base.
|
|
|
b40826 |
* assert/assert-perr.c: Remove bulk of implementation. Use
|
|
|
b40826 |
__assert_fail_base.
|
|
|
b40826 |
* include/assert.hL Declare __assert_fail_base.
|
|
|
b40826 |
* sysdeps/posix/libc_fatal.c: Allocate memory for __abort_msg with
|
|
|
b40826 |
mmap.
|
|
|
b40826 |
* sysdeps/unix/sysv/linux/libc_fatal.c: Likewise.
|
|
|
b40826 |
|
|
|
b40826 |
Index: glibc-2.12-2-gc4ccff1/assert/assert-perr.c
|
|
|
b40826 |
===================================================================
|
|
|
b40826 |
--- glibc-2.12-2-gc4ccff1.orig/assert/assert-perr.c
|
|
|
b40826 |
+++ glibc-2.12-2-gc4ccff1/assert/assert-perr.c
|
|
|
b40826 |
@@ -17,66 +17,23 @@
|
|
|
b40826 |
02111-1307 USA. */
|
|
|
b40826 |
|
|
|
b40826 |
#include <assert.h>
|
|
|
b40826 |
-#include <atomic.h>
|
|
|
b40826 |
#include <libintl.h>
|
|
|
b40826 |
-#include <stdio.h>
|
|
|
b40826 |
-#include <stdlib.h>
|
|
|
b40826 |
#include <string.h>
|
|
|
b40826 |
-#include <sysdep.h>
|
|
|
b40826 |
-#include <unistd.h>
|
|
|
b40826 |
|
|
|
b40826 |
|
|
|
b40826 |
-extern const char *__progname;
|
|
|
b40826 |
-
|
|
|
b40826 |
-#ifdef USE_IN_LIBIO
|
|
|
b40826 |
-# include <wchar.h>
|
|
|
b40826 |
-# include <libio/iolibio.h>
|
|
|
b40826 |
-# define fflush(s) INTUSE(_IO_fflush) (s)
|
|
|
b40826 |
-#endif
|
|
|
b40826 |
-
|
|
|
b40826 |
/* This function, when passed an error number, a filename, and a line
|
|
|
b40826 |
number, prints a message on the standard error stream of the form:
|
|
|
b40826 |
- a.c:10: foobar: Unexpected error: Computer bought the farm
|
|
|
b40826 |
+ a.c:10: foobar: Unexpected error: Computer bought the farm
|
|
|
b40826 |
It then aborts program execution via a call to `abort'. */
|
|
|
b40826 |
-
|
|
|
b40826 |
-#ifdef FATAL_PREPARE_INCLUDE
|
|
|
b40826 |
-# include FATAL_PREPARE_INCLUDE
|
|
|
b40826 |
-#endif
|
|
|
b40826 |
-
|
|
|
b40826 |
void
|
|
|
b40826 |
__assert_perror_fail (int errnum,
|
|
|
b40826 |
const char *file, unsigned int line,
|
|
|
b40826 |
const char *function)
|
|
|
b40826 |
{
|
|
|
b40826 |
char errbuf[1024];
|
|
|
b40826 |
- char *buf;
|
|
|
b40826 |
-
|
|
|
b40826 |
-#ifdef FATAL_PREPARE
|
|
|
b40826 |
- FATAL_PREPARE;
|
|
|
b40826 |
-#endif
|
|
|
b40826 |
-
|
|
|
b40826 |
- if (__asprintf (&buf, _("%s%s%s:%u: %s%sUnexpected error: %s.\n"),
|
|
|
b40826 |
- __progname, __progname[0] ? ": " : "",
|
|
|
b40826 |
- file, line,
|
|
|
b40826 |
- function ? function : "", function ? ": " : "",
|
|
|
b40826 |
- __strerror_r (errnum, errbuf, sizeof errbuf)) >= 0)
|
|
|
b40826 |
- {
|
|
|
b40826 |
- /* Print the message. */
|
|
|
b40826 |
- (void) __fxprintf (NULL, "%s", buf);
|
|
|
b40826 |
- (void) fflush (stderr);
|
|
|
b40826 |
-
|
|
|
b40826 |
- /* We have to free the old buffer since the application might
|
|
|
b40826 |
- catch the SIGABRT signal. */
|
|
|
b40826 |
- char *old = atomic_exchange_acq (&__abort_msg, buf);
|
|
|
b40826 |
- free (old);
|
|
|
b40826 |
- }
|
|
|
b40826 |
- else
|
|
|
b40826 |
- {
|
|
|
b40826 |
- /* At least print a minimal message. */
|
|
|
b40826 |
- static const char errstr[] = "Unexpected error.\n";
|
|
|
b40826 |
- __libc_write (STDERR_FILENO, errstr, sizeof (errstr) - 1);
|
|
|
b40826 |
- }
|
|
|
b40826 |
|
|
|
b40826 |
- abort ();
|
|
|
b40826 |
+ char *e = __strerror_r (errnum, errbuf, sizeof errbuf);
|
|
|
b40826 |
+ __assert_fail_base (_("%s%s%s:%u: %s%sUnexpected error: %s.\n"),
|
|
|
b40826 |
+ e, file, line, function);
|
|
|
b40826 |
}
|
|
|
b40826 |
libc_hidden_def (__assert_perror_fail)
|
|
|
b40826 |
Index: glibc-2.12-2-gc4ccff1/assert/assert.c
|
|
|
b40826 |
===================================================================
|
|
|
b40826 |
--- glibc-2.12-2-gc4ccff1.orig/assert/assert.c
|
|
|
b40826 |
+++ glibc-2.12-2-gc4ccff1/assert/assert.c
|
|
|
b40826 |
@@ -19,11 +19,13 @@
|
|
|
b40826 |
|
|
|
b40826 |
#include <assert.h>
|
|
|
b40826 |
#include <atomic.h>
|
|
|
b40826 |
+#include <ldsodefs.h>
|
|
|
b40826 |
#include <libintl.h>
|
|
|
b40826 |
#include <stdio.h>
|
|
|
b40826 |
#include <stdlib.h>
|
|
|
b40826 |
#include <sysdep.h>
|
|
|
b40826 |
#include <unistd.h>
|
|
|
b40826 |
+#include <sys/mman.h>
|
|
|
b40826 |
|
|
|
b40826 |
|
|
|
b40826 |
extern const char *__progname;
|
|
|
b40826 |
@@ -45,31 +47,44 @@ extern const char *__progname;
|
|
|
b40826 |
#endif
|
|
|
b40826 |
|
|
|
b40826 |
|
|
|
b40826 |
-#undef __assert_fail
|
|
|
b40826 |
void
|
|
|
b40826 |
-__assert_fail (const char *assertion, const char *file, unsigned int line,
|
|
|
b40826 |
- const char *function)
|
|
|
b40826 |
+__assert_fail_base (const char *fmt, const char *assertion, const char *file,
|
|
|
b40826 |
+ unsigned int line, const char *function)
|
|
|
b40826 |
{
|
|
|
b40826 |
- char *buf;
|
|
|
b40826 |
+ char *str;
|
|
|
b40826 |
|
|
|
b40826 |
#ifdef FATAL_PREPARE
|
|
|
b40826 |
FATAL_PREPARE;
|
|
|
b40826 |
#endif
|
|
|
b40826 |
|
|
|
b40826 |
- if (__asprintf (&buf, _("%s%s%s:%u: %s%sAssertion `%s' failed.\n"),
|
|
|
b40826 |
+ int total;
|
|
|
b40826 |
+ if (__asprintf (&str, fmt,
|
|
|
b40826 |
__progname, __progname[0] ? ": " : "",
|
|
|
b40826 |
file, line,
|
|
|
b40826 |
function ? function : "", function ? ": " : "",
|
|
|
b40826 |
- assertion) >= 0)
|
|
|
b40826 |
+ assertion, &total) >= 0)
|
|
|
b40826 |
{
|
|
|
b40826 |
/* Print the message. */
|
|
|
b40826 |
- (void) __fxprintf (NULL, "%s", buf);
|
|
|
b40826 |
+ (void) __fxprintf (NULL, "%s", str);
|
|
|
b40826 |
(void) fflush (stderr);
|
|
|
b40826 |
|
|
|
b40826 |
- /* We have to free the old buffer since the application might
|
|
|
b40826 |
- catch the SIGABRT signal. */
|
|
|
b40826 |
- char *old = atomic_exchange_acq (&__abort_msg, buf);
|
|
|
b40826 |
- free (old);
|
|
|
b40826 |
+ total = (total + 1 + GLRO(dl_pagesize) - 1) & ~(GLRO(dl_pagesize) - 1);
|
|
|
b40826 |
+ struct abort_msg_s *buf = __mmap (NULL, total, PROT_READ | PROT_WRITE,
|
|
|
b40826 |
+ MAP_ANON | MAP_PRIVATE, -1, 0);
|
|
|
b40826 |
+ if (__builtin_expect (buf != MAP_FAILED, 1))
|
|
|
b40826 |
+ {
|
|
|
b40826 |
+ buf->size = total;
|
|
|
b40826 |
+ strcpy (buf->msg, str);
|
|
|
b40826 |
+
|
|
|
b40826 |
+ /* We have to free the old buffer since the application might
|
|
|
b40826 |
+ catch the SIGABRT signal. */
|
|
|
b40826 |
+ struct abort_msg_s *old = atomic_exchange_acq (&__abort_msg, buf);
|
|
|
b40826 |
+
|
|
|
b40826 |
+ if (old != NULL)
|
|
|
b40826 |
+ __munmap (old, old->size);
|
|
|
b40826 |
+ }
|
|
|
b40826 |
+
|
|
|
b40826 |
+ free (str);
|
|
|
b40826 |
}
|
|
|
b40826 |
else
|
|
|
b40826 |
{
|
|
|
b40826 |
@@ -80,4 +95,14 @@ __assert_fail (const char *assertion, co
|
|
|
b40826 |
|
|
|
b40826 |
abort ();
|
|
|
b40826 |
}
|
|
|
b40826 |
+
|
|
|
b40826 |
+
|
|
|
b40826 |
+#undef __assert_fail
|
|
|
b40826 |
+void
|
|
|
b40826 |
+__assert_fail (const char *assertion, const char *file, unsigned int line,
|
|
|
b40826 |
+ const char *function)
|
|
|
b40826 |
+{
|
|
|
b40826 |
+ __assert_fail_base (_("%s%s%s:%u: %s%sAssertion `%s' failed.\n%n"),
|
|
|
b40826 |
+ assertion, file, line, function);
|
|
|
b40826 |
+}
|
|
|
b40826 |
hidden_def(__assert_fail)
|
|
|
b40826 |
Index: glibc-2.12-2-gc4ccff1/include/assert.h
|
|
|
b40826 |
===================================================================
|
|
|
b40826 |
--- glibc-2.12-2-gc4ccff1.orig/include/assert.h
|
|
|
b40826 |
+++ glibc-2.12-2-gc4ccff1/include/assert.h
|
|
|
b40826 |
@@ -13,6 +13,12 @@ extern void __assert_perror_fail (int __
|
|
|
b40826 |
__const char *__function)
|
|
|
b40826 |
__THROW __attribute__ ((__noreturn__));
|
|
|
b40826 |
|
|
|
b40826 |
+/* The real implementation of the two functions above. */
|
|
|
b40826 |
+extern void __assert_fail_base (const char *fmt, const char *assertion,
|
|
|
b40826 |
+ const char *file, unsigned int line,
|
|
|
b40826 |
+ const char *function)
|
|
|
b40826 |
+ __THROW __attribute__ ((__noreturn__));
|
|
|
b40826 |
+
|
|
|
b40826 |
#if !defined NOT_IN_libc || defined IS_IN_rtld
|
|
|
b40826 |
hidden_proto (__assert_fail)
|
|
|
b40826 |
hidden_proto (__assert_perror_fail)
|
|
|
b40826 |
Index: glibc-2.12-2-gc4ccff1/include/stdlib.h
|
|
|
b40826 |
===================================================================
|
|
|
b40826 |
--- glibc-2.12-2-gc4ccff1.orig/include/stdlib.h
|
|
|
b40826 |
+++ glibc-2.12-2-gc4ccff1/include/stdlib.h
|
|
|
b40826 |
@@ -223,16 +223,21 @@ extern int __qfcvt_r (long double __valu
|
|
|
b40826 |
# define __cxa_atexit(func, arg, d) INTUSE(__cxa_atexit) (func, arg, d)
|
|
|
b40826 |
# endif
|
|
|
b40826 |
|
|
|
b40826 |
-#endif
|
|
|
b40826 |
-
|
|
|
b40826 |
extern void *__default_morecore (ptrdiff_t) __THROW;
|
|
|
b40826 |
libc_hidden_proto (__default_morecore)
|
|
|
b40826 |
|
|
|
b40826 |
-extern char *__abort_msg;
|
|
|
b40826 |
+struct abort_msg_s
|
|
|
b40826 |
+{
|
|
|
b40826 |
+ unsigned int size;
|
|
|
b40826 |
+ char msg[0];
|
|
|
b40826 |
+};
|
|
|
b40826 |
+extern struct abort_msg_s *__abort_msg;
|
|
|
b40826 |
libc_hidden_proto (__abort_msg)
|
|
|
b40826 |
|
|
|
b40826 |
__END_DECLS
|
|
|
b40826 |
|
|
|
b40826 |
+#endif
|
|
|
b40826 |
+
|
|
|
b40826 |
#undef __Need_M_And_C
|
|
|
b40826 |
|
|
|
b40826 |
#endif /* include/stdlib.h */
|
|
|
b40826 |
Index: glibc-2.12-2-gc4ccff1/stdlib/abort.c
|
|
|
b40826 |
===================================================================
|
|
|
b40826 |
--- glibc-2.12-2-gc4ccff1.orig/stdlib/abort.c
|
|
|
b40826 |
+++ glibc-2.12-2-gc4ccff1/stdlib/abort.c
|
|
|
b40826 |
@@ -37,7 +37,7 @@
|
|
|
b40826 |
#endif
|
|
|
b40826 |
|
|
|
b40826 |
/* Exported variable to locate abort message in core files etc. */
|
|
|
b40826 |
-char *__abort_msg __attribute__ ((nocommon));
|
|
|
b40826 |
+struct abort_msg_s *__abort_msg __attribute__ ((nocommon));
|
|
|
b40826 |
libc_hidden_def (__abort_msg)
|
|
|
b40826 |
|
|
|
b40826 |
/* We must avoid to run in circles. Therefore we remember how far we
|
|
|
b40826 |
Index: glibc-2.12-2-gc4ccff1/sysdeps/posix/libc_fatal.c
|
|
|
b40826 |
===================================================================
|
|
|
b40826 |
--- glibc-2.12-2-gc4ccff1.orig/sysdeps/posix/libc_fatal.c
|
|
|
b40826 |
+++ glibc-2.12-2-gc4ccff1/sysdeps/posix/libc_fatal.c
|
|
|
b40826 |
@@ -20,6 +20,7 @@
|
|
|
b40826 |
#include <atomic.h>
|
|
|
b40826 |
#include <errno.h>
|
|
|
b40826 |
#include <fcntl.h>
|
|
|
b40826 |
+#include <ldsodefs.h>
|
|
|
b40826 |
#include <paths.h>
|
|
|
b40826 |
#include <stdarg.h>
|
|
|
b40826 |
#include <stdbool.h>
|
|
|
b40826 |
@@ -125,18 +126,28 @@ __libc_message (int do_abort, const char
|
|
|
b40826 |
if (TEMP_FAILURE_RETRY (__writev (fd, iov, nlist)) == total)
|
|
|
b40826 |
written = true;
|
|
|
b40826 |
|
|
|
b40826 |
- char *buf = do_abort ? malloc (total + 1) : NULL;
|
|
|
b40826 |
- if (buf != NULL)
|
|
|
b40826 |
+ if (do_abort)
|
|
|
b40826 |
{
|
|
|
b40826 |
- char *wp = buf;
|
|
|
b40826 |
- for (int cnt = 0; cnt < nlist; ++cnt)
|
|
|
b40826 |
- wp = mempcpy (wp, iov[cnt].iov_base, iov[cnt].iov_len);
|
|
|
b40826 |
- *wp = '\0';
|
|
|
b40826 |
-
|
|
|
b40826 |
- /* We have to free the old buffer since the application might
|
|
|
b40826 |
- catch the SIGABRT signal. */
|
|
|
b40826 |
- char *old = atomic_exchange_acq (&__abort_msg, buf);
|
|
|
b40826 |
- free (old);
|
|
|
b40826 |
+ total = ((total + 1 + GLRO(dl_pagesize) - 1)
|
|
|
b40826 |
+ & ~(GLRO(dl_pagesize) - 1));
|
|
|
b40826 |
+ struct abort_msg_s *buf = __mmap (NULL, total,
|
|
|
b40826 |
+ PROT_READ | PROT_WRITE,
|
|
|
b40826 |
+ MAP_ANON | MAP_PRIVATE, -1, 0);
|
|
|
b40826 |
+ if (buf != MAP_FAILED)
|
|
|
b40826 |
+ {
|
|
|
b40826 |
+ buf->size = total;
|
|
|
b40826 |
+ char *wp = buf->msg;
|
|
|
b40826 |
+ for (int cnt = 0; cnt < nlist; ++cnt)
|
|
|
b40826 |
+ wp = mempcpy (wp, iov[cnt].iov_base, iov[cnt].iov_len);
|
|
|
b40826 |
+ *wp = '\0';
|
|
|
b40826 |
+
|
|
|
b40826 |
+ /* We have to free the old buffer since the application might
|
|
|
b40826 |
+ catch the SIGABRT signal. */
|
|
|
b40826 |
+ struct abort_msg_s *old = atomic_exchange_acq (&__abort_msg,
|
|
|
b40826 |
+ buf);
|
|
|
b40826 |
+ if (old != NULL)
|
|
|
b40826 |
+ __munmap (old, old->size);
|
|
|
b40826 |
+ }
|
|
|
b40826 |
}
|
|
|
b40826 |
}
|
|
|
b40826 |
|
|
|
b40826 |
Index: glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/libc_fatal.c
|
|
|
b40826 |
===================================================================
|
|
|
b40826 |
--- glibc-2.12-2-gc4ccff1.orig/sysdeps/unix/sysv/linux/libc_fatal.c
|
|
|
b40826 |
+++ glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/libc_fatal.c
|
|
|
b40826 |
@@ -20,6 +20,7 @@
|
|
|
b40826 |
#include <atomic.h>
|
|
|
b40826 |
#include <errno.h>
|
|
|
b40826 |
#include <fcntl.h>
|
|
|
b40826 |
+#include <ldsodefs.h>
|
|
|
b40826 |
#include <paths.h>
|
|
|
b40826 |
#include <stdarg.h>
|
|
|
b40826 |
#include <stdbool.h>
|
|
|
b40826 |
@@ -28,6 +29,7 @@
|
|
|
b40826 |
#include <string.h>
|
|
|
b40826 |
#include <sysdep.h>
|
|
|
b40826 |
#include <unistd.h>
|
|
|
b40826 |
+#include <sys/mman.h>
|
|
|
b40826 |
#include <sys/syslog.h>
|
|
|
b40826 |
#include <execinfo.h>
|
|
|
b40826 |
|
|
|
b40826 |
@@ -134,18 +136,28 @@ __libc_message (int do_abort, const char
|
|
|
b40826 |
if (cnt == total)
|
|
|
b40826 |
written = true;
|
|
|
b40826 |
|
|
|
b40826 |
- char *buf = do_abort ? malloc (total + 1) : NULL;
|
|
|
b40826 |
- if (buf != NULL)
|
|
|
b40826 |
+ if (do_abort)
|
|
|
b40826 |
{
|
|
|
b40826 |
- char *wp = buf;
|
|
|
b40826 |
- for (int cnt = 0; cnt < nlist; ++cnt)
|
|
|
b40826 |
- wp = mempcpy (wp, iov[cnt].iov_base, iov[cnt].iov_len);
|
|
|
b40826 |
- *wp = '\0';
|
|
|
b40826 |
-
|
|
|
b40826 |
- /* We have to free the old buffer since the application might
|
|
|
b40826 |
- catch the SIGABRT signal. */
|
|
|
b40826 |
- char *old = atomic_exchange_acq (&__abort_msg, buf);
|
|
|
b40826 |
- free (old);
|
|
|
b40826 |
+ total = ((total + 1 + GLRO(dl_pagesize) - 1)
|
|
|
b40826 |
+ & ~(GLRO(dl_pagesize) - 1));
|
|
|
b40826 |
+ struct abort_msg_s *buf = __mmap (NULL, total,
|
|
|
b40826 |
+ PROT_READ | PROT_WRITE,
|
|
|
b40826 |
+ MAP_ANON | MAP_PRIVATE, -1, 0);
|
|
|
b40826 |
+ if (__builtin_expect (buf != MAP_FAILED, 1))
|
|
|
b40826 |
+ {
|
|
|
b40826 |
+ buf->size = total;
|
|
|
b40826 |
+ char *wp = buf->msg;
|
|
|
b40826 |
+ for (int cnt = 0; cnt < nlist; ++cnt)
|
|
|
b40826 |
+ wp = mempcpy (wp, iov[cnt].iov_base, iov[cnt].iov_len);
|
|
|
b40826 |
+ *wp = '\0';
|
|
|
b40826 |
+
|
|
|
b40826 |
+ /* We have to free the old buffer since the application might
|
|
|
b40826 |
+ catch the SIGABRT signal. */
|
|
|
b40826 |
+ struct abort_msg_s *old = atomic_exchange_acq (&__abort_msg,
|
|
|
b40826 |
+ buf);
|
|
|
b40826 |
+ if (old != NULL)
|
|
|
b40826 |
+ __munmap (old, old->size);
|
|
|
b40826 |
+ }
|
|
|
b40826 |
}
|
|
|
b40826 |
}
|
|
|
b40826 |
|