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