The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in |
| 12 | * the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 18 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 19 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 25 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 26 | * SUCH DAMAGE. |
| 27 | */ |
| 28 | |
Elliott Hughes | 18a206c | 2012-10-29 17:37:13 -0700 | [diff] [blame] | 29 | #include "linker.h" |
Elliott Hughes | 18a206c | 2012-10-29 17:37:13 -0700 | [diff] [blame] | 30 | |
Elliott Hughes | 84114c8 | 2013-07-17 13:33:19 -0700 | [diff] [blame] | 31 | #include <errno.h> |
| 32 | #include <signal.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 33 | #include <stdio.h> |
| 34 | #include <stdlib.h> |
Elliott Hughes | 84114c8 | 2013-07-17 13:33:19 -0700 | [diff] [blame] | 35 | #include <sys/mman.h> |
Marco Nelissen | 3df3e67 | 2012-03-07 09:04:18 -0800 | [diff] [blame] | 36 | #include <sys/prctl.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 37 | #include <sys/socket.h> |
David 'Digit' Turner | 8bff9a3 | 2010-06-10 18:29:33 -0700 | [diff] [blame] | 38 | #include <sys/un.h> |
Elliott Hughes | 84114c8 | 2013-07-17 13:33:19 -0700 | [diff] [blame] | 39 | #include <unistd.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 40 | |
Elliott Hughes | 18a206c | 2012-10-29 17:37:13 -0700 | [diff] [blame] | 41 | extern "C" int tgkill(int tgid, int tid, int sig); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 42 | |
Elliott Hughes | f858bd1 | 2014-01-31 16:56:39 -0800 | [diff] [blame] | 43 | #if __LP64__ |
| 44 | #define DEBUGGER_SOCKET_NAME "android:debuggerd64" |
| 45 | #else |
Jeff Brown | b7630f0 | 2012-06-06 18:37:48 -0700 | [diff] [blame] | 46 | #define DEBUGGER_SOCKET_NAME "android:debuggerd" |
Elliott Hughes | f858bd1 | 2014-01-31 16:56:39 -0800 | [diff] [blame] | 47 | #endif |
Jeff Brown | b7630f0 | 2012-06-06 18:37:48 -0700 | [diff] [blame] | 48 | |
Elliott Hughes | 18a206c | 2012-10-29 17:37:13 -0700 | [diff] [blame] | 49 | enum debugger_action_t { |
Jeff Brown | b7630f0 | 2012-06-06 18:37:48 -0700 | [diff] [blame] | 50 | // dump a crash |
| 51 | DEBUGGER_ACTION_CRASH, |
| 52 | // dump a tombstone file |
| 53 | DEBUGGER_ACTION_DUMP_TOMBSTONE, |
| 54 | // dump a backtrace only back to the socket |
| 55 | DEBUGGER_ACTION_DUMP_BACKTRACE, |
Elliott Hughes | 18a206c | 2012-10-29 17:37:13 -0700 | [diff] [blame] | 56 | }; |
Jeff Brown | b7630f0 | 2012-06-06 18:37:48 -0700 | [diff] [blame] | 57 | |
| 58 | /* message sent over the socket */ |
Elliott Hughes | 18a206c | 2012-10-29 17:37:13 -0700 | [diff] [blame] | 59 | struct debugger_msg_t { |
Elliott Hughes | 0d787c1 | 2013-04-04 13:46:46 -0700 | [diff] [blame] | 60 | // version 1 included: |
| 61 | debugger_action_t action; |
| 62 | pid_t tid; |
| 63 | |
| 64 | // version 2 added: |
| 65 | uintptr_t abort_msg_address; |
Elliott Hughes | 18a206c | 2012-10-29 17:37:13 -0700 | [diff] [blame] | 66 | }; |
David 'Digit' Turner | 7934a79 | 2009-10-16 12:13:34 -0700 | [diff] [blame] | 67 | |
Marco Nelissen | 3df3e67 | 2012-03-07 09:04:18 -0800 | [diff] [blame] | 68 | // see man(2) prctl, specifically the section about PR_GET_NAME |
| 69 | #define MAX_TASK_NAME_LEN (16) |
David 'Digit' Turner | 8bff9a3 | 2010-06-10 18:29:33 -0700 | [diff] [blame] | 70 | |
Elliott Hughes | 18a206c | 2012-10-29 17:37:13 -0700 | [diff] [blame] | 71 | static int socket_abstract_client(const char* name, int type) { |
| 72 | sockaddr_un addr; |
David 'Digit' Turner | 8bff9a3 | 2010-06-10 18:29:33 -0700 | [diff] [blame] | 73 | |
| 74 | // Test with length +1 for the *initial* '\0'. |
Elliott Hughes | 18a206c | 2012-10-29 17:37:13 -0700 | [diff] [blame] | 75 | size_t namelen = strlen(name); |
David 'Digit' Turner | 8bff9a3 | 2010-06-10 18:29:33 -0700 | [diff] [blame] | 76 | if ((namelen + 1) > sizeof(addr.sun_path)) { |
| 77 | errno = EINVAL; |
| 78 | return -1; |
| 79 | } |
| 80 | |
| 81 | /* This is used for abstract socket namespace, we need |
| 82 | * an initial '\0' at the start of the Unix socket path. |
| 83 | * |
| 84 | * Note: The path in this case is *not* supposed to be |
| 85 | * '\0'-terminated. ("man 7 unix" for the gory details.) |
| 86 | */ |
Elliott Hughes | 18a206c | 2012-10-29 17:37:13 -0700 | [diff] [blame] | 87 | memset(&addr, 0, sizeof(addr)); |
David 'Digit' Turner | 8bff9a3 | 2010-06-10 18:29:33 -0700 | [diff] [blame] | 88 | addr.sun_family = AF_LOCAL; |
| 89 | addr.sun_path[0] = 0; |
| 90 | memcpy(addr.sun_path + 1, name, namelen); |
| 91 | |
Elliott Hughes | 18a206c | 2012-10-29 17:37:13 -0700 | [diff] [blame] | 92 | socklen_t alen = namelen + offsetof(sockaddr_un, sun_path) + 1; |
David 'Digit' Turner | 8bff9a3 | 2010-06-10 18:29:33 -0700 | [diff] [blame] | 93 | |
Elliott Hughes | 18a206c | 2012-10-29 17:37:13 -0700 | [diff] [blame] | 94 | int s = socket(AF_LOCAL, type, 0); |
| 95 | if (s == -1) { |
| 96 | return -1; |
| 97 | } |
David 'Digit' Turner | 8bff9a3 | 2010-06-10 18:29:33 -0700 | [diff] [blame] | 98 | |
Elliott Hughes | 62e9c76 | 2014-01-31 17:27:00 -0800 | [diff] [blame^] | 99 | int rc = TEMP_FAILURE_RETRY(connect(s, reinterpret_cast<sockaddr*>(&addr), alen)); |
| 100 | if (rc == -1) { |
David 'Digit' Turner | 8bff9a3 | 2010-06-10 18:29:33 -0700 | [diff] [blame] | 101 | close(s); |
Elliott Hughes | 62e9c76 | 2014-01-31 17:27:00 -0800 | [diff] [blame^] | 102 | return -1; |
David 'Digit' Turner | 8bff9a3 | 2010-06-10 18:29:33 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | return s; |
| 106 | } |
| 107 | |
Andy McFadden | ec92af8 | 2011-07-29 12:46:34 -0700 | [diff] [blame] | 108 | /* |
Andy McFadden | 1db6f2d | 2012-10-02 13:53:13 -0700 | [diff] [blame] | 109 | * Writes a summary of the signal to the log file. We do this so that, if |
| 110 | * for some reason we're not able to contact debuggerd, there is still some |
| 111 | * indication of the failure in the log. |
Andy McFadden | ec92af8 | 2011-07-29 12:46:34 -0700 | [diff] [blame] | 112 | * |
| 113 | * We could be here as a result of native heap corruption, or while a |
| 114 | * mutex is being held, so we don't want to use any libc functions that |
| 115 | * could allocate memory or hold a lock. |
| 116 | */ |
Elliott Hughes | 84114c8 | 2013-07-17 13:33:19 -0700 | [diff] [blame] | 117 | static void log_signal_summary(int signum, const siginfo_t* info) { |
Elliott Hughes | 6b8e321 | 2013-01-22 14:17:14 -0800 | [diff] [blame] | 118 | const char* signal_name; |
Andy McFadden | ec92af8 | 2011-07-29 12:46:34 -0700 | [diff] [blame] | 119 | switch (signum) { |
Elliott Hughes | 6b8e321 | 2013-01-22 14:17:14 -0800 | [diff] [blame] | 120 | case SIGILL: signal_name = "SIGILL"; break; |
| 121 | case SIGABRT: signal_name = "SIGABRT"; break; |
| 122 | case SIGBUS: signal_name = "SIGBUS"; break; |
| 123 | case SIGFPE: signal_name = "SIGFPE"; break; |
| 124 | case SIGSEGV: signal_name = "SIGSEGV"; break; |
Raghu Gandham | d7daacb | 2012-07-31 12:07:22 -0700 | [diff] [blame] | 125 | #if defined(SIGSTKFLT) |
Elliott Hughes | 6b8e321 | 2013-01-22 14:17:14 -0800 | [diff] [blame] | 126 | case SIGSTKFLT: signal_name = "SIGSTKFLT"; break; |
Raghu Gandham | d7daacb | 2012-07-31 12:07:22 -0700 | [diff] [blame] | 127 | #endif |
Elliott Hughes | 6b8e321 | 2013-01-22 14:17:14 -0800 | [diff] [blame] | 128 | case SIGPIPE: signal_name = "SIGPIPE"; break; |
| 129 | default: signal_name = "???"; break; |
Andy McFadden | ec92af8 | 2011-07-29 12:46:34 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Elliott Hughes | 6b8e321 | 2013-01-22 14:17:14 -0800 | [diff] [blame] | 132 | char thread_name[MAX_TASK_NAME_LEN + 1]; // one more for termination |
| 133 | if (prctl(PR_GET_NAME, (unsigned long)thread_name, 0, 0, 0) != 0) { |
| 134 | strcpy(thread_name, "<name unknown>"); |
Marco Nelissen | 3df3e67 | 2012-03-07 09:04:18 -0800 | [diff] [blame] | 135 | } else { |
Elliott Hughes | 6b8e321 | 2013-01-22 14:17:14 -0800 | [diff] [blame] | 136 | // short names are null terminated by prctl, but the man page |
Marco Nelissen | 3df3e67 | 2012-03-07 09:04:18 -0800 | [diff] [blame] | 137 | // implies that 16 byte names are not. |
Elliott Hughes | 6b8e321 | 2013-01-22 14:17:14 -0800 | [diff] [blame] | 138 | thread_name[MAX_TASK_NAME_LEN] = 0; |
Marco Nelissen | 3df3e67 | 2012-03-07 09:04:18 -0800 | [diff] [blame] | 139 | } |
Elliott Hughes | 18a206c | 2012-10-29 17:37:13 -0700 | [diff] [blame] | 140 | |
Elliott Hughes | 18a206c | 2012-10-29 17:37:13 -0700 | [diff] [blame] | 141 | // "info" will be NULL if the siginfo_t information was not available. |
Andy McFadden | 1db6f2d | 2012-10-02 13:53:13 -0700 | [diff] [blame] | 142 | if (info != NULL) { |
Elliott Hughes | 6b8e321 | 2013-01-22 14:17:14 -0800 | [diff] [blame] | 143 | __libc_format_log(ANDROID_LOG_FATAL, "libc", |
Elliott Hughes | c620059 | 2013-09-30 18:43:46 -0700 | [diff] [blame] | 144 | "Fatal signal %d (%s) at %p (code=%d), thread %d (%s)", |
| 145 | signum, signal_name, info->si_addr, info->si_code, |
| 146 | gettid(), thread_name); |
Andy McFadden | 1db6f2d | 2012-10-02 13:53:13 -0700 | [diff] [blame] | 147 | } else { |
Elliott Hughes | 6b8e321 | 2013-01-22 14:17:14 -0800 | [diff] [blame] | 148 | __libc_format_log(ANDROID_LOG_FATAL, "libc", |
| 149 | "Fatal signal %d (%s), thread %d (%s)", |
| 150 | signum, signal_name, gettid(), thread_name); |
Andy McFadden | 1db6f2d | 2012-10-02 13:53:13 -0700 | [diff] [blame] | 151 | } |
Andy McFadden | ec92af8 | 2011-07-29 12:46:34 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /* |
Andy McFadden | 1db6f2d | 2012-10-02 13:53:13 -0700 | [diff] [blame] | 155 | * Returns true if the handler for signal "signum" has SA_SIGINFO set. |
| 156 | */ |
Elliott Hughes | 84114c8 | 2013-07-17 13:33:19 -0700 | [diff] [blame] | 157 | static bool have_siginfo(int signum) { |
| 158 | struct sigaction old_action, new_action; |
Andy McFadden | 1db6f2d | 2012-10-02 13:53:13 -0700 | [diff] [blame] | 159 | |
Elliott Hughes | 84114c8 | 2013-07-17 13:33:19 -0700 | [diff] [blame] | 160 | memset(&new_action, 0, sizeof(new_action)); |
| 161 | new_action.sa_handler = SIG_DFL; |
| 162 | new_action.sa_flags = SA_RESTART; |
| 163 | sigemptyset(&new_action.sa_mask); |
Andy McFadden | 1db6f2d | 2012-10-02 13:53:13 -0700 | [diff] [blame] | 164 | |
Elliott Hughes | 84114c8 | 2013-07-17 13:33:19 -0700 | [diff] [blame] | 165 | if (sigaction(signum, &new_action, &old_action) < 0) { |
Elliott Hughes | 0d787c1 | 2013-04-04 13:46:46 -0700 | [diff] [blame] | 166 | __libc_format_log(ANDROID_LOG_WARN, "libc", "Failed testing for SA_SIGINFO: %s", |
Elliott Hughes | 8f2a5a0 | 2013-03-15 15:30:25 -0700 | [diff] [blame] | 167 | strerror(errno)); |
Elliott Hughes | 0d787c1 | 2013-04-04 13:46:46 -0700 | [diff] [blame] | 168 | return false; |
Andy McFadden | 1db6f2d | 2012-10-02 13:53:13 -0700 | [diff] [blame] | 169 | } |
Elliott Hughes | 84114c8 | 2013-07-17 13:33:19 -0700 | [diff] [blame] | 170 | bool result = (old_action.sa_flags & SA_SIGINFO) != 0; |
Andy McFadden | 1db6f2d | 2012-10-02 13:53:13 -0700 | [diff] [blame] | 171 | |
Elliott Hughes | 84114c8 | 2013-07-17 13:33:19 -0700 | [diff] [blame] | 172 | if (sigaction(signum, &old_action, NULL) == -1) { |
Elliott Hughes | 0d787c1 | 2013-04-04 13:46:46 -0700 | [diff] [blame] | 173 | __libc_format_log(ANDROID_LOG_WARN, "libc", "Restore failed in test for SA_SIGINFO: %s", |
Elliott Hughes | 8f2a5a0 | 2013-03-15 15:30:25 -0700 | [diff] [blame] | 174 | strerror(errno)); |
Andy McFadden | 1db6f2d | 2012-10-02 13:53:13 -0700 | [diff] [blame] | 175 | } |
Elliott Hughes | 84114c8 | 2013-07-17 13:33:19 -0700 | [diff] [blame] | 176 | return result; |
Andy McFadden | 1db6f2d | 2012-10-02 13:53:13 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | /* |
Andy McFadden | ec92af8 | 2011-07-29 12:46:34 -0700 | [diff] [blame] | 180 | * Catches fatal signals so we can ask debuggerd to ptrace us before |
| 181 | * we crash. |
| 182 | */ |
Elliott Hughes | 62e9c76 | 2014-01-31 17:27:00 -0800 | [diff] [blame^] | 183 | void debuggerd_signal_handler(int signal_number, siginfo_t* info, void*) { |
| 184 | // It's possible somebody cleared the SA_SIGINFO flag, which would mean |
| 185 | // our "info" arg holds an undefined value. |
| 186 | if (!have_siginfo(signal_number)) { |
Andy McFadden | 1db6f2d | 2012-10-02 13:53:13 -0700 | [diff] [blame] | 187 | info = NULL; |
| 188 | } |
| 189 | |
Elliott Hughes | 62e9c76 | 2014-01-31 17:27:00 -0800 | [diff] [blame^] | 190 | log_signal_summary(signal_number, info); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 191 | |
Elliott Hughes | 18a206c | 2012-10-29 17:37:13 -0700 | [diff] [blame] | 192 | int s = socket_abstract_client(DEBUGGER_SOCKET_NAME, SOCK_STREAM); |
Elliott Hughes | 62e9c76 | 2014-01-31 17:27:00 -0800 | [diff] [blame^] | 193 | if (s != -1) { |
Elliott Hughes | 0d787c1 | 2013-04-04 13:46:46 -0700 | [diff] [blame] | 194 | // debuggerd knows our pid from the credentials on the |
| 195 | // local socket but we need to tell it the tid of the crashing thread. |
| 196 | // debuggerd will be paranoid and verify that we sent a tid |
| 197 | // that's actually in our process. |
Jeff Brown | b7630f0 | 2012-06-06 18:37:48 -0700 | [diff] [blame] | 198 | debugger_msg_t msg; |
| 199 | msg.action = DEBUGGER_ACTION_CRASH; |
Elliott Hughes | 62e9c76 | 2014-01-31 17:27:00 -0800 | [diff] [blame^] | 200 | msg.tid = gettid(); |
Elliott Hughes | 0d787c1 | 2013-04-04 13:46:46 -0700 | [diff] [blame] | 201 | msg.abort_msg_address = reinterpret_cast<uintptr_t>(gAbortMessage); |
| 202 | int ret = TEMP_FAILURE_RETRY(write(s, &msg, sizeof(msg))); |
Jeff Brown | b7630f0 | 2012-06-06 18:37:48 -0700 | [diff] [blame] | 203 | if (ret == sizeof(msg)) { |
Elliott Hughes | 62e9c76 | 2014-01-31 17:27:00 -0800 | [diff] [blame^] | 204 | // If the write failed, there is no point trying to read a response. |
| 205 | char debuggerd_ack; |
| 206 | ret = TEMP_FAILURE_RETRY(read(s, &debuggerd_ack, 1)); |
Elliott Hughes | 18a206c | 2012-10-29 17:37:13 -0700 | [diff] [blame] | 207 | int saved_errno = errno; |
David 'Digit' Turner | 7934a79 | 2009-10-16 12:13:34 -0700 | [diff] [blame] | 208 | notify_gdb_of_libraries(); |
Elliott Hughes | 18a206c | 2012-10-29 17:37:13 -0700 | [diff] [blame] | 209 | errno = saved_errno; |
David 'Digit' Turner | 7934a79 | 2009-10-16 12:13:34 -0700 | [diff] [blame] | 210 | } |
Andy McFadden | 1fc5176 | 2012-01-26 13:21:19 -0800 | [diff] [blame] | 211 | |
| 212 | if (ret < 0) { |
Elliott Hughes | 62e9c76 | 2014-01-31 17:27:00 -0800 | [diff] [blame^] | 213 | // read or write failed -- broken connection? |
Elliott Hughes | 6b8e321 | 2013-01-22 14:17:14 -0800 | [diff] [blame] | 214 | __libc_format_log(ANDROID_LOG_FATAL, "libc", "Failed while talking to debuggerd: %s", |
| 215 | strerror(errno)); |
Andy McFadden | 1fc5176 | 2012-01-26 13:21:19 -0800 | [diff] [blame] | 216 | } |
| 217 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 218 | close(s); |
Andy McFadden | 1fc5176 | 2012-01-26 13:21:19 -0800 | [diff] [blame] | 219 | } else { |
Elliott Hughes | 62e9c76 | 2014-01-31 17:27:00 -0800 | [diff] [blame^] | 220 | // socket failed; maybe process ran out of fds? |
Elliott Hughes | 6b8e321 | 2013-01-22 14:17:14 -0800 | [diff] [blame] | 221 | __libc_format_log(ANDROID_LOG_FATAL, "libc", "Unable to open connection to debuggerd: %s", |
| 222 | strerror(errno)); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 223 | } |
| 224 | |
Elliott Hughes | 62e9c76 | 2014-01-31 17:27:00 -0800 | [diff] [blame^] | 225 | // Remove our net so we fault for real when we return. |
| 226 | signal(signal_number, SIG_DFL); |
Andy McFadden | ca9a071 | 2012-03-08 11:14:37 -0800 | [diff] [blame] | 227 | |
Elliott Hughes | 62e9c76 | 2014-01-31 17:27:00 -0800 | [diff] [blame^] | 228 | // These signals are not re-thrown when we resume. This means that |
| 229 | // crashing due to (say) SIGPIPE doesn't work the way you'd expect it |
| 230 | // to. We work around this by throwing them manually. We don't want |
| 231 | // to do this for *all* signals because it'll screw up the address for |
| 232 | // faults like SIGSEGV. |
| 233 | switch (signal_number) { |
Andy McFadden | ca9a071 | 2012-03-08 11:14:37 -0800 | [diff] [blame] | 234 | case SIGABRT: |
| 235 | case SIGFPE: |
| 236 | case SIGPIPE: |
Elliott Hughes | 4eeb1f1 | 2013-10-25 17:38:02 -0700 | [diff] [blame] | 237 | #if defined(SIGSTKFLT) |
Andy McFadden | ca9a071 | 2012-03-08 11:14:37 -0800 | [diff] [blame] | 238 | case SIGSTKFLT: |
Raghu Gandham | d7daacb | 2012-07-31 12:07:22 -0700 | [diff] [blame] | 239 | #endif |
Elliott Hughes | 62e9c76 | 2014-01-31 17:27:00 -0800 | [diff] [blame^] | 240 | tgkill(getpid(), gettid(), signal_number); |
Andy McFadden | ca9a071 | 2012-03-08 11:14:37 -0800 | [diff] [blame] | 241 | break; |
| 242 | default: // SIGILL, SIGBUS, SIGSEGV |
| 243 | break; |
| 244 | } |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 245 | } |
| 246 | |
Brian Carlstrom | d4ee82d | 2013-02-28 15:58:45 -0800 | [diff] [blame] | 247 | void debuggerd_init() { |
Elliott Hughes | 84114c8 | 2013-07-17 13:33:19 -0700 | [diff] [blame] | 248 | struct sigaction action; |
| 249 | memset(&action, 0, sizeof(action)); |
| 250 | sigemptyset(&action.sa_mask); |
| 251 | action.sa_sigaction = debuggerd_signal_handler; |
| 252 | action.sa_flags = SA_RESTART | SA_SIGINFO; |
Andy McFadden | ec92af8 | 2011-07-29 12:46:34 -0700 | [diff] [blame] | 253 | |
Elliott Hughes | 84114c8 | 2013-07-17 13:33:19 -0700 | [diff] [blame] | 254 | // Use the alternate signal stack if available so we can catch stack overflows. |
| 255 | action.sa_flags |= SA_ONSTACK; |
| 256 | |
| 257 | sigaction(SIGABRT, &action, NULL); |
| 258 | sigaction(SIGBUS, &action, NULL); |
| 259 | sigaction(SIGFPE, &action, NULL); |
| 260 | sigaction(SIGILL, &action, NULL); |
| 261 | sigaction(SIGPIPE, &action, NULL); |
| 262 | sigaction(SIGSEGV, &action, NULL); |
Raghu Gandham | d7daacb | 2012-07-31 12:07:22 -0700 | [diff] [blame] | 263 | #if defined(SIGSTKFLT) |
Elliott Hughes | 84114c8 | 2013-07-17 13:33:19 -0700 | [diff] [blame] | 264 | sigaction(SIGSTKFLT, &action, NULL); |
Raghu Gandham | d7daacb | 2012-07-31 12:07:22 -0700 | [diff] [blame] | 265 | #endif |
Elliott Hughes | 84114c8 | 2013-07-17 13:33:19 -0700 | [diff] [blame] | 266 | sigaction(SIGTRAP, &action, NULL); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 267 | } |