]> git.saurik.com Git - apple/libc.git/blob - stdlib/FreeBSD/abort.c.patch
Libc-594.1.4.tar.gz
[apple/libc.git] / stdlib / FreeBSD / abort.c.patch
1 --- abort.c.orig 2008-09-07 11:37:51.000000000 -0700
2 +++ abort.c 2008-09-07 11:56:01.000000000 -0700
3 @@ -39,19 +39,26 @@ __FBSDID("$FreeBSD: src/lib/libc/stdlib/
4
5 #include "namespace.h"
6 #include <signal.h>
7 +#include <stdarg.h>
8 #include <stdlib.h>
9 #include <stddef.h>
10 #include <unistd.h>
11 #include <pthread.h>
12 #include "un-namespace.h"
13
14 -void (*__cleanup)();
15 +extern void (*__cleanup)();
16 +extern void __abort(void) __dead2;
17 +extern const char *__crashreporter_info__;
18 +
19 +#define TIMEOUT 10000 /* 10 milliseconds */
20
21 void
22 abort()
23 {
24 struct sigaction act;
25
26 + if (!__crashreporter_info__)
27 + __crashreporter_info__ = "abort() called";
28 /*
29 * POSIX requires we flush stdio buffers on abort.
30 * XXX ISO C requires that abort() be async-signal-safe.
31 @@ -67,11 +74,22 @@ abort()
32 sigdelset(&act.sa_mask, SIGABRT);
33 (void)_sigprocmask(SIG_SETMASK, &act.sa_mask, NULL);
34 (void)raise(SIGABRT);
35 + usleep(TIMEOUT); /* give time for signal to happen */
36
37 /*
38 * If SIGABRT was ignored, or caught and the handler returns, do
39 * it again, only harder.
40 */
41 + __abort();
42 +}
43 +
44 +__private_extern__ void
45 +__abort()
46 +{
47 + struct sigaction act;
48 +
49 + if (!__crashreporter_info__)
50 + __crashreporter_info__ = "__abort() called";
51 act.sa_handler = SIG_DFL;
52 act.sa_flags = 0;
53 sigfillset(&act.sa_mask);
54 @@ -79,5 +97,19 @@ abort()
55 sigdelset(&act.sa_mask, SIGABRT);
56 (void)_sigprocmask(SIG_SETMASK, &act.sa_mask, NULL);
57 (void)raise(SIGABRT);
58 - exit(1);
59 + usleep(TIMEOUT); /* give time for signal to happen */
60 + __builtin_trap(); /* never exit normally */
61 +}
62 +
63 +__private_extern__ void
64 +abort_report_np(const char *fmt, ...)
65 +{
66 + char *str;
67 + va_list ap;
68 +
69 + va_start(ap, fmt);
70 + vasprintf(&str, fmt, ap);
71 + va_end(ap);
72 + __crashreporter_info__ = str ? str : fmt;
73 + abort();
74 }