| 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> | 
|  | 20 | #include <errno.h> | 
| Josh Gao | 218f7fb | 2016-10-07 16:42:05 -0700 | [diff] [blame] | 21 | #include <fcntl.h> | 
| Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame] | 22 | #include <pthread.h> | 
|  | 23 | #include <sched.h> | 
|  | 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> | 
| Mark Salyzyn | f1a8dfa | 2014-04-30 09:24:08 -0700 | [diff] [blame] | 28 | #include <sys/cdefs.h> | 
| Brigid Smith | 8606eaa | 2014-07-07 12:33:50 -0700 | [diff] [blame] | 29 | #include <sys/mman.h> | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 30 | #include <sys/ptrace.h> | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 31 | #include <sys/socket.h> | 
| Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame] | 32 | #include <sys/wait.h> | 
|  | 33 | #include <unistd.h> | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 34 |  | 
| Mark Salyzyn | ff2dcd9 | 2016-09-28 15:54:45 -0700 | [diff] [blame] | 35 | #include <android/log.h> | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 36 | #include <cutils/sockets.h> | 
| Mark Salyzyn | f1a8dfa | 2014-04-30 09:24:08 -0700 | [diff] [blame] | 37 |  | 
| Josh Gao | 9c02dc5 | 2016-06-15 17:29:00 -0700 | [diff] [blame] | 38 | #if defined(STATIC_CRASHER) | 
|  | 39 | #include "debuggerd/client.h" | 
|  | 40 | #endif | 
|  | 41 |  | 
| Mark Salyzyn | f1a8dfa | 2014-04-30 09:24:08 -0700 | [diff] [blame] | 42 | #ifndef __unused | 
|  | 43 | #define __unused __attribute__((__unused__)) | 
|  | 44 | #endif | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 45 |  | 
| Elliott Hughes | 3808c4e | 2013-04-23 17:14:56 -0700 | [diff] [blame] | 46 | extern const char* __progname; | 
|  | 47 |  | 
| Elliott Hughes | 23d1cad | 2016-05-10 13:29:58 -0700 | [diff] [blame] | 48 | extern "C" void crash1(void); | 
|  | 49 | extern "C" void crashnostack(void); | 
|  | 50 |  | 
| Elliott Hughes | 6f40caf | 2013-06-12 14:04:34 -0700 | [diff] [blame] | 51 | static int do_action(const char* arg); | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 52 |  | 
| Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame] | 53 | static void maybe_abort() { | 
|  | 54 | if (time(0) != 42) { | 
| Elliott Hughes | 6f40caf | 2013-06-12 14:04:34 -0700 | [diff] [blame] | 55 | abort(); | 
|  | 56 | } | 
|  | 57 | } | 
|  | 58 |  | 
| Yabin Cui | 2331b95 | 2014-12-11 17:46:33 -0800 | [diff] [blame] | 59 | static char* smash_stack_dummy_buf; | 
|  | 60 | __attribute__ ((noinline)) static void smash_stack_dummy_function(volatile int* plen) { | 
|  | 61 | smash_stack_dummy_buf[*plen] = 0; | 
|  | 62 | } | 
|  | 63 |  | 
|  | 64 | // This must be marked with "__attribute__ ((noinline))", to ensure the | 
|  | 65 | // compiler generates the proper stack guards around this function. | 
|  | 66 | // Assign local array address to global variable to force stack guards. | 
|  | 67 | // Use another noinline function to corrupt the stack. | 
|  | 68 | __attribute__ ((noinline)) static int smash_stack(volatile int* plen) { | 
| Josh Gao | 9c02dc5 | 2016-06-15 17:29:00 -0700 | [diff] [blame] | 69 | printf("%s: deliberately corrupting stack...\n", __progname); | 
| Yabin Cui | 2331b95 | 2014-12-11 17:46:33 -0800 | [diff] [blame] | 70 |  | 
|  | 71 | char buf[128]; | 
|  | 72 | smash_stack_dummy_buf = buf; | 
|  | 73 | // This should corrupt stack guards and make process abort. | 
|  | 74 | smash_stack_dummy_function(plen); | 
|  | 75 | return 0; | 
| Elliott Hughes | df4200e | 2013-02-14 14:41:57 -0800 | [diff] [blame] | 76 | } | 
|  | 77 |  | 
| Stephen Hines | 9466bb2 | 2015-09-30 23:30:38 -0700 | [diff] [blame] | 78 | #if defined(__clang__) | 
| Stephen Hines | 18395cb | 2015-09-29 23:55:14 -0700 | [diff] [blame] | 79 | #pragma clang diagnostic push | 
|  | 80 | #pragma clang diagnostic ignored "-Winfinite-recursion" | 
| Stephen Hines | 9466bb2 | 2015-09-30 23:30:38 -0700 | [diff] [blame] | 81 | #endif | 
| Stephen Hines | 18395cb | 2015-09-29 23:55:14 -0700 | [diff] [blame] | 82 |  | 
| Elliott Hughes | b1be27e | 2013-07-15 17:19:02 -0700 | [diff] [blame] | 83 | static void* global = 0; // So GCC doesn't optimize the tail recursion out of overflow_stack. | 
|  | 84 |  | 
| Elliott Hughes | 6f40caf | 2013-06-12 14:04:34 -0700 | [diff] [blame] | 85 | __attribute__((noinline)) static void overflow_stack(void* p) { | 
| Elliott Hughes | 3808c4e | 2013-04-23 17:14:56 -0700 | [diff] [blame] | 86 | void* buf[1]; | 
|  | 87 | buf[0] = p; | 
| Elliott Hughes | b1be27e | 2013-07-15 17:19:02 -0700 | [diff] [blame] | 88 | global = buf; | 
| Elliott Hughes | 3808c4e | 2013-04-23 17:14:56 -0700 | [diff] [blame] | 89 | overflow_stack(&buf); | 
|  | 90 | } | 
|  | 91 |  | 
| Stephen Hines | 9466bb2 | 2015-09-30 23:30:38 -0700 | [diff] [blame] | 92 | #if defined(__clang__) | 
| Stephen Hines | 18395cb | 2015-09-29 23:55:14 -0700 | [diff] [blame] | 93 | #pragma clang diagnostic pop | 
| Stephen Hines | 9466bb2 | 2015-09-30 23:30:38 -0700 | [diff] [blame] | 94 | #endif | 
| Stephen Hines | 18395cb | 2015-09-29 23:55:14 -0700 | [diff] [blame] | 95 |  | 
| Elliott Hughes | 6f40caf | 2013-06-12 14:04:34 -0700 | [diff] [blame] | 96 | static void *noisy(void *x) | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 97 | { | 
| Elliott Hughes | 5d9fe77 | 2014-02-05 17:50:35 -0800 | [diff] [blame] | 98 | char c = (uintptr_t) x; | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 99 | for(;;) { | 
|  | 100 | usleep(250*1000); | 
|  | 101 | write(2, &c, 1); | 
| Chih-Hung Hsieh | a1ff475 | 2014-10-23 16:50:51 -0700 | [diff] [blame] | 102 | if(c == 'C') *((volatile unsigned*) 0) = 42; | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 103 | } | 
| Elliott Hughes | 5d9fe77 | 2014-02-05 17:50:35 -0800 | [diff] [blame] | 104 | return NULL; | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 105 | } | 
|  | 106 |  | 
| Elliott Hughes | 6f40caf | 2013-06-12 14:04:34 -0700 | [diff] [blame] | 107 | static int ctest() | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 108 | { | 
|  | 109 | pthread_t thr; | 
|  | 110 | pthread_attr_t attr; | 
|  | 111 | pthread_attr_init(&attr); | 
|  | 112 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); | 
|  | 113 | pthread_create(&thr, &attr, noisy, (void*) 'A'); | 
|  | 114 | pthread_create(&thr, &attr, noisy, (void*) 'B'); | 
|  | 115 | pthread_create(&thr, &attr, noisy, (void*) 'C'); | 
|  | 116 | for(;;) ; | 
|  | 117 | return 0; | 
|  | 118 | } | 
|  | 119 |  | 
| Elliott Hughes | aa42130 | 2012-12-10 14:15:42 -0800 | [diff] [blame] | 120 | static void* thread_callback(void* raw_arg) | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 121 | { | 
| Elliott Hughes | 5d9fe77 | 2014-02-05 17:50:35 -0800 | [diff] [blame] | 122 | return (void*) (uintptr_t) do_action((const char*) raw_arg); | 
| Elliott Hughes | aa42130 | 2012-12-10 14:15:42 -0800 | [diff] [blame] | 123 | } | 
|  | 124 |  | 
| Elliott Hughes | 6f40caf | 2013-06-12 14:04:34 -0700 | [diff] [blame] | 125 | static int do_action_on_thread(const char* arg) | 
| Elliott Hughes | aa42130 | 2012-12-10 14:15:42 -0800 | [diff] [blame] | 126 | { | 
|  | 127 | pthread_t t; | 
|  | 128 | pthread_create(&t, NULL, thread_callback, (void*) arg); | 
|  | 129 | void* result = NULL; | 
|  | 130 | pthread_join(t, &result); | 
| Elliott Hughes | 5d9fe77 | 2014-02-05 17:50:35 -0800 | [diff] [blame] | 131 | return (int) (uintptr_t) result; | 
| Elliott Hughes | aa42130 | 2012-12-10 14:15:42 -0800 | [diff] [blame] | 132 | } | 
|  | 133 |  | 
| Elliott Hughes | 6f40caf | 2013-06-12 14:04:34 -0700 | [diff] [blame] | 134 | __attribute__((noinline)) static int crash3(int a) { | 
|  | 135 | *((int*) 0xdead) = a; | 
|  | 136 | return a*4; | 
| Pavel Chupin | af2cb36 | 2013-03-08 13:17:35 +0400 | [diff] [blame] | 137 | } | 
|  | 138 |  | 
| Elliott Hughes | 6f40caf | 2013-06-12 14:04:34 -0700 | [diff] [blame] | 139 | __attribute__((noinline)) static int crash2(int a) { | 
|  | 140 | a = crash3(a) + 2; | 
|  | 141 | return a*3; | 
| Pavel Chupin | af2cb36 | 2013-03-08 13:17:35 +0400 | [diff] [blame] | 142 | } | 
|  | 143 |  | 
| Elliott Hughes | 6f40caf | 2013-06-12 14:04:34 -0700 | [diff] [blame] | 144 | __attribute__((noinline)) static int crash(int a) { | 
|  | 145 | a = crash2(a) + 1; | 
|  | 146 | return a*2; | 
| Pavel Chupin | af2cb36 | 2013-03-08 13:17:35 +0400 | [diff] [blame] | 147 | } | 
|  | 148 |  | 
| Elliott Hughes | 6f40caf | 2013-06-12 14:04:34 -0700 | [diff] [blame] | 149 | static void abuse_heap() { | 
|  | 150 | char buf[16]; | 
|  | 151 | free((void*) buf); // GCC is smart enough to warn about this, but we're doing it deliberately. | 
|  | 152 | } | 
|  | 153 |  | 
| Brigid Smith | 7b2078e | 2014-06-17 14:55:47 -0700 | [diff] [blame] | 154 | static void sigsegv_non_null() { | 
|  | 155 | int* a = (int *)(&do_action); | 
|  | 156 | *a = 42; | 
|  | 157 | } | 
|  | 158 |  | 
| Elliott Hughes | 6f40caf | 2013-06-12 14:04:34 -0700 | [diff] [blame] | 159 | static int do_action(const char* arg) | 
| Elliott Hughes | aa42130 | 2012-12-10 14:15:42 -0800 | [diff] [blame] | 160 | { | 
| Josh Gao | 9c02dc5 | 2016-06-15 17:29:00 -0700 | [diff] [blame] | 161 | fprintf(stderr, "%s: init pid=%d tid=%d\n", __progname, getpid(), gettid()); | 
| Elliott Hughes | 3808c4e | 2013-04-23 17:14:56 -0700 | [diff] [blame] | 162 |  | 
| Josh Gao | 218f7fb | 2016-10-07 16:42:05 -0700 | [diff] [blame] | 163 | if (!strncmp(arg, "exhaustfd-", strlen("exhaustfd-"))) { | 
|  | 164 | errno = 0; | 
|  | 165 | while (errno != EMFILE) { | 
|  | 166 | open("/dev/null", O_RDONLY); | 
|  | 167 | } | 
|  | 168 | return do_action(arg + strlen("exhaustfd-")); | 
|  | 169 | } else if (!strncmp(arg, "thread-", strlen("thread-"))) { | 
| Elliott Hughes | aa42130 | 2012-12-10 14:15:42 -0800 | [diff] [blame] | 170 | return do_action_on_thread(arg + strlen("thread-")); | 
| Brigid Smith | 7b2078e | 2014-06-17 14:55:47 -0700 | [diff] [blame] | 171 | } else if (!strcmp(arg, "SIGSEGV-non-null")) { | 
|  | 172 | sigsegv_non_null(); | 
| Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame] | 173 | } else if (!strcmp(arg, "smash-stack")) { | 
| Yabin Cui | 2331b95 | 2014-12-11 17:46:33 -0800 | [diff] [blame] | 174 | volatile int len = 128; | 
|  | 175 | return smash_stack(&len); | 
| Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame] | 176 | } else if (!strcmp(arg, "stack-overflow")) { | 
| Elliott Hughes | 3808c4e | 2013-04-23 17:14:56 -0700 | [diff] [blame] | 177 | overflow_stack(NULL); | 
| Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame] | 178 | } else if (!strcmp(arg, "nostack")) { | 
| Elliott Hughes | 3808c4e | 2013-04-23 17:14:56 -0700 | [diff] [blame] | 179 | crashnostack(); | 
| Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame] | 180 | } else if (!strcmp(arg, "ctest")) { | 
| Elliott Hughes | 3808c4e | 2013-04-23 17:14:56 -0700 | [diff] [blame] | 181 | return ctest(); | 
| Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame] | 182 | } else if (!strcmp(arg, "exit")) { | 
| Elliott Hughes | 3808c4e | 2013-04-23 17:14:56 -0700 | [diff] [blame] | 183 | exit(1); | 
| Elliott Hughes | 855fcc3 | 2014-04-25 16:05:34 -0700 | [diff] [blame] | 184 | } else if (!strcmp(arg, "crash") || !strcmp(arg, "SIGSEGV")) { | 
| Elliott Hughes | 3808c4e | 2013-04-23 17:14:56 -0700 | [diff] [blame] | 185 | return crash(42); | 
| Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame] | 186 | } else if (!strcmp(arg, "abort")) { | 
|  | 187 | maybe_abort(); | 
|  | 188 | } else if (!strcmp(arg, "assert")) { | 
|  | 189 | __assert("some_file.c", 123, "false"); | 
|  | 190 | } else if (!strcmp(arg, "assert2")) { | 
| Elliott Hughes | 3ecc421 | 2014-07-15 11:38:47 -0700 | [diff] [blame] | 191 | __assert2("some_file.c", 123, "some_function", "false"); | 
| Elliott Hughes | 23d1cad | 2016-05-10 13:29:58 -0700 | [diff] [blame] | 192 | } else if (!strcmp(arg, "fortify")) { | 
|  | 193 | char buf[10]; | 
|  | 194 | __read_chk(-1, buf, 32, 10); | 
|  | 195 | while (true) pause(); | 
| Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame] | 196 | } else if (!strcmp(arg, "LOG_ALWAYS_FATAL")) { | 
|  | 197 | LOG_ALWAYS_FATAL("hello %s", "world"); | 
|  | 198 | } else if (!strcmp(arg, "LOG_ALWAYS_FATAL_IF")) { | 
|  | 199 | LOG_ALWAYS_FATAL_IF(true, "hello %s", "world"); | 
| Elliott Hughes | 3ecc421 | 2014-07-15 11:38:47 -0700 | [diff] [blame] | 200 | } else if (!strcmp(arg, "SIGFPE")) { | 
|  | 201 | raise(SIGFPE); | 
|  | 202 | return EXIT_SUCCESS; | 
| Elliott Hughes | 7e35ae8 | 2014-05-16 17:05:19 -0700 | [diff] [blame] | 203 | } else if (!strcmp(arg, "SIGTRAP")) { | 
|  | 204 | raise(SIGTRAP); | 
|  | 205 | return EXIT_SUCCESS; | 
| Elliott Hughes | 6f40caf | 2013-06-12 14:04:34 -0700 | [diff] [blame] | 206 | } else if (!strcmp(arg, "heap-usage")) { | 
|  | 207 | abuse_heap(); | 
| Brigid Smith | 8606eaa | 2014-07-07 12:33:50 -0700 | [diff] [blame] | 208 | } else if (!strcmp(arg, "SIGSEGV-unmapped")) { | 
| Elliott Hughes | 23d1cad | 2016-05-10 13:29:58 -0700 | [diff] [blame] | 209 | char* map = reinterpret_cast<char*>(mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0)); | 
| Brigid Smith | 8606eaa | 2014-07-07 12:33:50 -0700 | [diff] [blame] | 210 | munmap(map, sizeof(int)); | 
|  | 211 | map[0] = '8'; | 
| Elliott Hughes | aa42130 | 2012-12-10 14:15:42 -0800 | [diff] [blame] | 212 | } | 
|  | 213 |  | 
| Elliott Hughes | 3808c4e | 2013-04-23 17:14:56 -0700 | [diff] [blame] | 214 | fprintf(stderr, "%s OP\n", __progname); | 
|  | 215 | fprintf(stderr, "where OP is:\n"); | 
| Elliott Hughes | 855fcc3 | 2014-04-25 16:05:34 -0700 | [diff] [blame] | 216 | fprintf(stderr, "  smash-stack           overwrite a stack-guard canary\n"); | 
|  | 217 | fprintf(stderr, "  stack-overflow        recurse until the stack overflows\n"); | 
|  | 218 | fprintf(stderr, "  heap-corruption       cause a libc abort by corrupting the heap\n"); | 
|  | 219 | fprintf(stderr, "  heap-usage            cause a libc abort by abusing a heap function\n"); | 
|  | 220 | fprintf(stderr, "  nostack               crash with a NULL stack pointer\n"); | 
|  | 221 | fprintf(stderr, "  ctest                 (obsoleted by thread-crash?)\n"); | 
|  | 222 | fprintf(stderr, "  exit                  call exit(1)\n"); | 
|  | 223 | fprintf(stderr, "  abort                 call abort()\n"); | 
|  | 224 | fprintf(stderr, "  assert                call assert() without a function\n"); | 
|  | 225 | fprintf(stderr, "  assert2               call assert() with a function\n"); | 
| Elliott Hughes | 23d1cad | 2016-05-10 13:29:58 -0700 | [diff] [blame] | 226 | fprintf(stderr, "  fortify               fail a _FORTIFY_SOURCE check\n"); | 
| Elliott Hughes | 855fcc3 | 2014-04-25 16:05:34 -0700 | [diff] [blame] | 227 | fprintf(stderr, "  LOG_ALWAYS_FATAL      call LOG_ALWAYS_FATAL\n"); | 
|  | 228 | fprintf(stderr, "  LOG_ALWAYS_FATAL_IF   call LOG_ALWAYS_FATAL\n"); | 
| Elliott Hughes | 3ecc421 | 2014-07-15 11:38:47 -0700 | [diff] [blame] | 229 | fprintf(stderr, "  SIGFPE                cause a SIGFPE\n"); | 
| Brigid Smith | 7b2078e | 2014-06-17 14:55:47 -0700 | [diff] [blame] | 230 | fprintf(stderr, "  SIGSEGV               cause a SIGSEGV at address 0x0 (synonym: crash)\n"); | 
|  | 231 | fprintf(stderr, "  SIGSEGV-non-null      cause a SIGSEGV at a non-zero address\n"); | 
| Brigid Smith | 8606eaa | 2014-07-07 12:33:50 -0700 | [diff] [blame] | 232 | fprintf(stderr, "  SIGSEGV-unmapped      mmap/munmap a region of memory and then attempt to access it\n"); | 
| Elliott Hughes | 7e35ae8 | 2014-05-16 17:05:19 -0700 | [diff] [blame] | 233 | fprintf(stderr, "  SIGTRAP               cause a SIGTRAP\n"); | 
| Elliott Hughes | 3808c4e | 2013-04-23 17:14:56 -0700 | [diff] [blame] | 234 | fprintf(stderr, "prefix any of the above with 'thread-' to not run\n"); | 
|  | 235 | fprintf(stderr, "on the process' main thread.\n"); | 
| Josh Gao | 218f7fb | 2016-10-07 16:42:05 -0700 | [diff] [blame] | 236 | fprintf(stderr, "prefix any of the above with 'exhaustfd-' to exhaust\n"); | 
|  | 237 | fprintf(stderr, "all available file descriptors before crashing.\n"); | 
| Elliott Hughes | 3808c4e | 2013-04-23 17:14:56 -0700 | [diff] [blame] | 238 | return EXIT_SUCCESS; | 
| Elliott Hughes | aa42130 | 2012-12-10 14:15:42 -0800 | [diff] [blame] | 239 | } | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 240 |  | 
| Elliott Hughes | aa42130 | 2012-12-10 14:15:42 -0800 | [diff] [blame] | 241 | int main(int argc, char **argv) | 
|  | 242 | { | 
| Josh Gao | 9c02dc5 | 2016-06-15 17:29:00 -0700 | [diff] [blame] | 243 | fprintf(stderr, "%s: built at " __TIME__ "!@\n", __progname); | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 244 |  | 
| Josh Gao | 9c02dc5 | 2016-06-15 17:29:00 -0700 | [diff] [blame] | 245 | #if defined(STATIC_CRASHER) | 
|  | 246 | debuggerd_callbacks_t callbacks = { | 
|  | 247 | .get_abort_message = []() { | 
|  | 248 | static struct { | 
|  | 249 | size_t size; | 
|  | 250 | char msg[32]; | 
|  | 251 | } msg; | 
|  | 252 |  | 
|  | 253 | msg.size = strlen("dummy abort message"); | 
|  | 254 | memcpy(msg.msg, "dummy abort message", strlen("dummy abort message")); | 
|  | 255 | return reinterpret_cast<abort_msg_t*>(&msg); | 
|  | 256 | }, | 
|  | 257 | .post_dump = nullptr | 
|  | 258 | }; | 
|  | 259 | debuggerd_init(&callbacks); | 
|  | 260 | #endif | 
|  | 261 |  | 
|  | 262 | if (argc > 1) { | 
| Elliott Hughes | aa42130 | 2012-12-10 14:15:42 -0800 | [diff] [blame] | 263 | return do_action(argv[1]); | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 264 | } else { | 
|  | 265 | crash1(); | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 266 | } | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 267 |  | 
| Elliott Hughes | 6f40caf | 2013-06-12 14:04:34 -0700 | [diff] [blame] | 268 | return 0; | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 269 | } |