1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/mac/os_crash_dumps.h" 6 7 #include <signal.h> 8 #include <unistd.h> 9 10 #include "base/basictypes.h" 11 12 namespace base { 13 namespace mac { 14 15 namespace { 16 ExitSignalHandler(int sig)17void ExitSignalHandler(int sig) { 18 // A call to exit() can call atexit() handlers. If we SIGSEGV due 19 // to a corrupt heap, and if we have an atexit handler that 20 // allocates or frees memory, we are in trouble if we do not _exit. 21 _exit(128 + sig); 22 } 23 24 } // namespace 25 DisableOSCrashDumps()26void DisableOSCrashDumps() { 27 // These are the POSIX signals corresponding to the Mach exceptions that 28 // Apple Crash Reporter handles. See ux_exception() in xnu's 29 // bsd/uxkern/ux_exception.c and machine_exception() in xnu's 30 // bsd/dev/*/unix_signal.c. 31 const int signals_to_intercept[] = { 32 SIGILL, // EXC_BAD_INSTRUCTION 33 SIGTRAP, // EXC_BREAKPOINT 34 SIGFPE, // EXC_ARITHMETIC 35 SIGBUS, // EXC_BAD_ACCESS 36 SIGSEGV // EXC_BAD_ACCESS 37 }; 38 39 // For all these signals, just wire things up so we exit immediately. 40 for (size_t i = 0; i < arraysize(signals_to_intercept); ++i) 41 signal(signals_to_intercept[i], ExitSignalHandler); 42 } 43 44 } // namespace mac 45 } // namespace base 46