| Mark Salyzyn | cfd5b08 | 2016-10-17 14:28:00 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright 2006, The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *     http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | #define LOG_TAG "crasher" | 
|  | 18 |  | 
| Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame] | 19 | #include <assert.h> | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 20 | #include <dirent.h> | 
| Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame] | 21 | #include <errno.h> | 
| Josh Gao | 218f7fb | 2016-10-07 16:42:05 -0700 | [diff] [blame] | 22 | #include <fcntl.h> | 
| Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame] | 23 | #include <pthread.h> | 
| Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame] | 24 | #include <signal.h> | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 25 | #include <stdio.h> | 
|  | 26 | #include <stdlib.h> | 
|  | 27 | #include <string.h> | 
| Brigid Smith | 8606eaa | 2014-07-07 12:33:50 -0700 | [diff] [blame] | 28 | #include <sys/mman.h> | 
| Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame] | 29 | #include <unistd.h> | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 30 |  | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 31 | // We test both kinds of logging. | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 32 | #include <android-base/logging.h> | 
| Mark Salyzyn | 51c33b7 | 2017-01-12 15:44:06 -0800 | [diff] [blame] | 33 | #include <log/log.h> | 
| Mark Salyzyn | f1a8dfa | 2014-04-30 09:24:08 -0700 | [diff] [blame] | 34 |  | 
| Josh Gao | 9c02dc5 | 2016-06-15 17:29:00 -0700 | [diff] [blame] | 35 | #if defined(STATIC_CRASHER) | 
|  | 36 | #include "debuggerd/client.h" | 
|  | 37 | #endif | 
|  | 38 |  | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 39 | #define noinline __attribute__((__noinline__)) | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 40 |  | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 41 | // Avoid name mangling so that stacks are more readable. | 
|  | 42 | extern "C" { | 
| Elliott Hughes | 3808c4e | 2013-04-23 17:14:56 -0700 | [diff] [blame] | 43 |  | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 44 | void crash1(void); | 
|  | 45 | void crashnostack(void); | 
| Elliott Hughes | 23d1cad | 2016-05-10 13:29:58 -0700 | [diff] [blame] | 46 |  | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 47 | int do_action(const char* arg); | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 48 |  | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 49 | noinline void maybe_abort() { | 
| Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame] | 50 | if (time(0) != 42) { | 
| Elliott Hughes | 6f40caf | 2013-06-12 14:04:34 -0700 | [diff] [blame] | 51 | abort(); | 
|  | 52 | } | 
|  | 53 | } | 
|  | 54 |  | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 55 | char* smash_stack_dummy_buf; | 
|  | 56 | noinline void smash_stack_dummy_function(volatile int* plen) { | 
| Yabin Cui | 2331b95 | 2014-12-11 17:46:33 -0800 | [diff] [blame] | 57 | smash_stack_dummy_buf[*plen] = 0; | 
|  | 58 | } | 
|  | 59 |  | 
|  | 60 | // This must be marked with "__attribute__ ((noinline))", to ensure the | 
|  | 61 | // compiler generates the proper stack guards around this function. | 
|  | 62 | // Assign local array address to global variable to force stack guards. | 
|  | 63 | // Use another noinline function to corrupt the stack. | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 64 | noinline int smash_stack(volatile int* plen) { | 
|  | 65 | printf("%s: deliberately corrupting stack...\n", getprogname()); | 
| Yabin Cui | 2331b95 | 2014-12-11 17:46:33 -0800 | [diff] [blame] | 66 |  | 
|  | 67 | char buf[128]; | 
|  | 68 | smash_stack_dummy_buf = buf; | 
|  | 69 | // This should corrupt stack guards and make process abort. | 
|  | 70 | smash_stack_dummy_function(plen); | 
|  | 71 | return 0; | 
| Elliott Hughes | df4200e | 2013-02-14 14:41:57 -0800 | [diff] [blame] | 72 | } | 
|  | 73 |  | 
| Stephen Hines | 18395cb | 2015-09-29 23:55:14 -0700 | [diff] [blame] | 74 | #pragma clang diagnostic push | 
|  | 75 | #pragma clang diagnostic ignored "-Winfinite-recursion" | 
|  | 76 |  | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 77 | void* global = 0; // So GCC doesn't optimize the tail recursion out of overflow_stack. | 
| Elliott Hughes | b1be27e | 2013-07-15 17:19:02 -0700 | [diff] [blame] | 78 |  | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 79 | noinline void overflow_stack(void* p) { | 
| Elliott Hughes | 3808c4e | 2013-04-23 17:14:56 -0700 | [diff] [blame] | 80 | void* buf[1]; | 
|  | 81 | buf[0] = p; | 
| Elliott Hughes | b1be27e | 2013-07-15 17:19:02 -0700 | [diff] [blame] | 82 | global = buf; | 
| Elliott Hughes | 3808c4e | 2013-04-23 17:14:56 -0700 | [diff] [blame] | 83 | overflow_stack(&buf); | 
|  | 84 | } | 
|  | 85 |  | 
| Stephen Hines | 18395cb | 2015-09-29 23:55:14 -0700 | [diff] [blame] | 86 | #pragma clang diagnostic pop | 
|  | 87 |  | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 88 | noinline void* thread_callback(void* raw_arg) { | 
|  | 89 | const char* arg = reinterpret_cast<const char*>(raw_arg); | 
|  | 90 | return reinterpret_cast<void*>(static_cast<uintptr_t>(do_action(arg))); | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 91 | } | 
|  | 92 |  | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 93 | noinline int do_action_on_thread(const char* arg) { | 
| Elliott Hughes | aa42130 | 2012-12-10 14:15:42 -0800 | [diff] [blame] | 94 | pthread_t t; | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 95 | pthread_create(&t, nullptr, thread_callback, const_cast<char*>(arg)); | 
|  | 96 | void* result = nullptr; | 
| Elliott Hughes | aa42130 | 2012-12-10 14:15:42 -0800 | [diff] [blame] | 97 | pthread_join(t, &result); | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 98 | return reinterpret_cast<uintptr_t>(result); | 
| Elliott Hughes | aa42130 | 2012-12-10 14:15:42 -0800 | [diff] [blame] | 99 | } | 
|  | 100 |  | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 101 | noinline int crash3(int a) { | 
|  | 102 | *reinterpret_cast<int*>(0xdead) = a; | 
| Elliott Hughes | 6f40caf | 2013-06-12 14:04:34 -0700 | [diff] [blame] | 103 | return a*4; | 
| Pavel Chupin | af2cb36 | 2013-03-08 13:17:35 +0400 | [diff] [blame] | 104 | } | 
|  | 105 |  | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 106 | noinline int crash2(int a) { | 
| Elliott Hughes | 6f40caf | 2013-06-12 14:04:34 -0700 | [diff] [blame] | 107 | a = crash3(a) + 2; | 
|  | 108 | return a*3; | 
| Pavel Chupin | af2cb36 | 2013-03-08 13:17:35 +0400 | [diff] [blame] | 109 | } | 
|  | 110 |  | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 111 | noinline int crash(int a) { | 
| Elliott Hughes | 6f40caf | 2013-06-12 14:04:34 -0700 | [diff] [blame] | 112 | a = crash2(a) + 1; | 
|  | 113 | return a*2; | 
| Pavel Chupin | af2cb36 | 2013-03-08 13:17:35 +0400 | [diff] [blame] | 114 | } | 
|  | 115 |  | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 116 | noinline void abuse_heap() { | 
| Elliott Hughes | 6f40caf | 2013-06-12 14:04:34 -0700 | [diff] [blame] | 117 | char buf[16]; | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 118 | free(buf); // GCC is smart enough to warn about this, but we're doing it deliberately. | 
| Elliott Hughes | 6f40caf | 2013-06-12 14:04:34 -0700 | [diff] [blame] | 119 | } | 
|  | 120 |  | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 121 | noinline void sigsegv_non_null() { | 
| Brigid Smith | 7b2078e | 2014-06-17 14:55:47 -0700 | [diff] [blame] | 122 | int* a = (int *)(&do_action); | 
|  | 123 | *a = 42; | 
|  | 124 | } | 
|  | 125 |  | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 126 | noinline void fprintf_null() { | 
|  | 127 | fprintf(nullptr, "oops"); | 
|  | 128 | } | 
| Elliott Hughes | 3808c4e | 2013-04-23 17:14:56 -0700 | [diff] [blame] | 129 |  | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 130 | noinline void readdir_null() { | 
|  | 131 | readdir(nullptr); | 
|  | 132 | } | 
|  | 133 |  | 
|  | 134 | noinline int strlen_null() { | 
|  | 135 | char* sneaky_null = nullptr; | 
|  | 136 | return strlen(sneaky_null); | 
|  | 137 | } | 
|  | 138 |  | 
|  | 139 | static int usage() { | 
|  | 140 | fprintf(stderr, "usage: %s KIND\n", getprogname()); | 
|  | 141 | fprintf(stderr, "\n"); | 
|  | 142 | fprintf(stderr, "where KIND is:\n"); | 
|  | 143 | fprintf(stderr, "  smash-stack           overwrite a -fstack-protector guard\n"); | 
|  | 144 | fprintf(stderr, "  stack-overflow        recurse until the stack overflows\n"); | 
|  | 145 | fprintf(stderr, "  heap-corruption       cause a libc abort by corrupting the heap\n"); | 
|  | 146 | fprintf(stderr, "  heap-usage            cause a libc abort by abusing a heap function\n"); | 
|  | 147 | fprintf(stderr, "  nostack               crash with a NULL stack pointer\n"); | 
|  | 148 | fprintf(stderr, "  abort                 call abort()\n"); | 
|  | 149 | fprintf(stderr, "  assert                call assert() without a function\n"); | 
|  | 150 | fprintf(stderr, "  assert2               call assert() with a function\n"); | 
|  | 151 | fprintf(stderr, "  exit                  call exit(1)\n"); | 
|  | 152 | fprintf(stderr, "  fortify               fail a _FORTIFY_SOURCE check\n"); | 
|  | 153 | fprintf(stderr, "  LOG_ALWAYS_FATAL      call liblog LOG_ALWAYS_FATAL\n"); | 
|  | 154 | fprintf(stderr, "  LOG_ALWAYS_FATAL_IF   call liblog LOG_ALWAYS_FATAL_IF\n"); | 
|  | 155 | fprintf(stderr, "  LOG-FATAL             call libbase LOG(FATAL)\n"); | 
|  | 156 | fprintf(stderr, "  SIGFPE                cause a SIGFPE\n"); | 
|  | 157 | fprintf(stderr, "  SIGSEGV               cause a SIGSEGV at address 0x0 (synonym: crash)\n"); | 
|  | 158 | fprintf(stderr, "  SIGSEGV-non-null      cause a SIGSEGV at a non-zero address\n"); | 
|  | 159 | fprintf(stderr, "  SIGSEGV-unmapped      mmap/munmap a region of memory and then attempt to access it\n"); | 
|  | 160 | fprintf(stderr, "  SIGTRAP               cause a SIGTRAP\n"); | 
|  | 161 | fprintf(stderr, "  fprintf-NULL          pass a null pointer to fprintf\n"); | 
|  | 162 | fprintf(stderr, "  readdir-NULL          pass a null pointer to readdir\n"); | 
|  | 163 | fprintf(stderr, "  strlen-NULL           pass a null pointer to strlen\n"); | 
|  | 164 | fprintf(stderr, "\n"); | 
|  | 165 | fprintf(stderr, "prefix any of the above with 'thread-' to run on a new thread\n"); | 
|  | 166 | fprintf(stderr, "prefix any of the above with 'exhaustfd-' to exhaust\n"); | 
|  | 167 | fprintf(stderr, "all available file descriptors before crashing.\n"); | 
|  | 168 | fprintf(stderr, "prefix any of the above with 'wait-' to wait until input is received on stdin\n"); | 
|  | 169 |  | 
|  | 170 | return EXIT_FAILURE; | 
|  | 171 | } | 
|  | 172 |  | 
|  | 173 | noinline int do_action(const char* arg) { | 
|  | 174 | // Prefixes. | 
| Josh Gao | 100ce39 | 2016-10-31 17:37:37 -0700 | [diff] [blame] | 175 | if (!strncmp(arg, "wait-", strlen("wait-"))) { | 
|  | 176 | char buf[1]; | 
|  | 177 | TEMP_FAILURE_RETRY(read(STDIN_FILENO, buf, sizeof(buf))); | 
|  | 178 | return do_action(arg + strlen("wait-")); | 
|  | 179 | } else if (!strncmp(arg, "exhaustfd-", strlen("exhaustfd-"))) { | 
| Josh Gao | 218f7fb | 2016-10-07 16:42:05 -0700 | [diff] [blame] | 180 | errno = 0; | 
|  | 181 | while (errno != EMFILE) { | 
|  | 182 | open("/dev/null", O_RDONLY); | 
|  | 183 | } | 
|  | 184 | return do_action(arg + strlen("exhaustfd-")); | 
|  | 185 | } else if (!strncmp(arg, "thread-", strlen("thread-"))) { | 
| Elliott Hughes | aa42130 | 2012-12-10 14:15:42 -0800 | [diff] [blame] | 186 | return do_action_on_thread(arg + strlen("thread-")); | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 187 | } | 
|  | 188 |  | 
|  | 189 | // Actions. | 
|  | 190 | if (!strcasecmp(arg, "SIGSEGV-non-null")) { | 
| Brigid Smith | 7b2078e | 2014-06-17 14:55:47 -0700 | [diff] [blame] | 191 | sigsegv_non_null(); | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 192 | } else if (!strcasecmp(arg, "smash-stack")) { | 
| Yabin Cui | 2331b95 | 2014-12-11 17:46:33 -0800 | [diff] [blame] | 193 | volatile int len = 128; | 
|  | 194 | return smash_stack(&len); | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 195 | } else if (!strcasecmp(arg, "stack-overflow")) { | 
|  | 196 | overflow_stack(nullptr); | 
|  | 197 | } else if (!strcasecmp(arg, "nostack")) { | 
| Elliott Hughes | 3808c4e | 2013-04-23 17:14:56 -0700 | [diff] [blame] | 198 | crashnostack(); | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 199 | } else if (!strcasecmp(arg, "exit")) { | 
| Elliott Hughes | 3808c4e | 2013-04-23 17:14:56 -0700 | [diff] [blame] | 200 | exit(1); | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 201 | } else if (!strcasecmp(arg, "crash") || !strcmp(arg, "SIGSEGV")) { | 
| Elliott Hughes | 3808c4e | 2013-04-23 17:14:56 -0700 | [diff] [blame] | 202 | return crash(42); | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 203 | } else if (!strcasecmp(arg, "abort")) { | 
| Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame] | 204 | maybe_abort(); | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 205 | } else if (!strcasecmp(arg, "assert")) { | 
| Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame] | 206 | __assert("some_file.c", 123, "false"); | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 207 | } else if (!strcasecmp(arg, "assert2")) { | 
| Elliott Hughes | 3ecc421 | 2014-07-15 11:38:47 -0700 | [diff] [blame] | 208 | __assert2("some_file.c", 123, "some_function", "false"); | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 209 | } else if (!strcasecmp(arg, "fortify")) { | 
| Elliott Hughes | 23d1cad | 2016-05-10 13:29:58 -0700 | [diff] [blame] | 210 | char buf[10]; | 
|  | 211 | __read_chk(-1, buf, 32, 10); | 
|  | 212 | while (true) pause(); | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 213 | } else if (!strcasecmp(arg, "LOG(FATAL)")) { | 
|  | 214 | LOG(FATAL) << "hello " << 123; | 
|  | 215 | } else if (!strcasecmp(arg, "LOG_ALWAYS_FATAL")) { | 
| Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame] | 216 | LOG_ALWAYS_FATAL("hello %s", "world"); | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 217 | } else if (!strcasecmp(arg, "LOG_ALWAYS_FATAL_IF")) { | 
| Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame] | 218 | LOG_ALWAYS_FATAL_IF(true, "hello %s", "world"); | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 219 | } else if (!strcasecmp(arg, "SIGFPE")) { | 
| Elliott Hughes | 3ecc421 | 2014-07-15 11:38:47 -0700 | [diff] [blame] | 220 | raise(SIGFPE); | 
|  | 221 | return EXIT_SUCCESS; | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 222 | } else if (!strcasecmp(arg, "SIGTRAP")) { | 
| Elliott Hughes | 7e35ae8 | 2014-05-16 17:05:19 -0700 | [diff] [blame] | 223 | raise(SIGTRAP); | 
|  | 224 | return EXIT_SUCCESS; | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 225 | } else if (!strcasecmp(arg, "fprintf-NULL")) { | 
|  | 226 | fprintf_null(); | 
|  | 227 | } else if (!strcasecmp(arg, "readdir-NULL")) { | 
|  | 228 | readdir_null(); | 
|  | 229 | } else if (!strcasecmp(arg, "strlen-NULL")) { | 
|  | 230 | return strlen_null(); | 
|  | 231 | } else if (!strcasecmp(arg, "heap-usage")) { | 
| Elliott Hughes | 6f40caf | 2013-06-12 14:04:34 -0700 | [diff] [blame] | 232 | abuse_heap(); | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 233 | } else if (!strcasecmp(arg, "SIGSEGV-unmapped")) { | 
|  | 234 | char* map = reinterpret_cast<char*>(mmap(nullptr, sizeof(int), PROT_READ | PROT_WRITE, | 
|  | 235 | MAP_SHARED | MAP_ANONYMOUS, -1, 0)); | 
| Brigid Smith | 8606eaa | 2014-07-07 12:33:50 -0700 | [diff] [blame] | 236 | munmap(map, sizeof(int)); | 
|  | 237 | map[0] = '8'; | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 238 | } else { | 
|  | 239 | return usage(); | 
| Elliott Hughes | aa42130 | 2012-12-10 14:15:42 -0800 | [diff] [blame] | 240 | } | 
|  | 241 |  | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 242 | fprintf(stderr, "%s: exiting normally!\n", getprogname()); | 
| Elliott Hughes | 3808c4e | 2013-04-23 17:14:56 -0700 | [diff] [blame] | 243 | return EXIT_SUCCESS; | 
| Elliott Hughes | aa42130 | 2012-12-10 14:15:42 -0800 | [diff] [blame] | 244 | } | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 245 |  | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 246 | int main(int argc, char** argv) { | 
| Josh Gao | 9c02dc5 | 2016-06-15 17:29:00 -0700 | [diff] [blame] | 247 | #if defined(STATIC_CRASHER) | 
|  | 248 | debuggerd_callbacks_t callbacks = { | 
|  | 249 | .get_abort_message = []() { | 
|  | 250 | static struct { | 
|  | 251 | size_t size; | 
|  | 252 | char msg[32]; | 
|  | 253 | } msg; | 
|  | 254 |  | 
|  | 255 | msg.size = strlen("dummy abort message"); | 
|  | 256 | memcpy(msg.msg, "dummy abort message", strlen("dummy abort message")); | 
|  | 257 | return reinterpret_cast<abort_msg_t*>(&msg); | 
|  | 258 | }, | 
|  | 259 | .post_dump = nullptr | 
|  | 260 | }; | 
|  | 261 | debuggerd_init(&callbacks); | 
|  | 262 | #endif | 
|  | 263 |  | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 264 | if (argc == 1) crash1(); | 
|  | 265 | else if (argc == 2) return do_action(argv[1]); | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 266 |  | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 267 | return usage(); | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 268 | } | 
| Elliott Hughes | 400628a | 2016-12-14 17:33:46 -0800 | [diff] [blame] | 269 |  | 
|  | 270 | }; |