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