Disable the new avatar menu in a test.
[chromium-blink-merge.git] / base / mac / os_crash_dumps.cc
blob5d65b469dddaf3932a97366b919415cc00e10a33
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.
5 #include "base/mac/os_crash_dumps.h"
7 #include <signal.h>
8 #include <unistd.h>
10 #include "base/basictypes.h"
11 #include "base/logging.h"
13 namespace base {
14 namespace mac {
16 namespace {
18 void ExitSignalHandler(int sig) {
19 // A call to exit() can call atexit() handlers. If we SIGSEGV due
20 // to a corrupt heap, and if we have an atexit handler that
21 // allocates or frees memory, we are in trouble if we do not _exit.
22 _exit(128 + sig);
25 } // namespace
27 void DisableOSCrashDumps() {
28 // These are the POSIX signals corresponding to the Mach exceptions that
29 // Apple Crash Reporter handles. See ux_exception() in xnu's
30 // bsd/uxkern/ux_exception.c and machine_exception() in xnu's
31 // bsd/dev/*/unix_signal.c.
32 const int signals_to_intercept[] = {
33 // Hardware faults
34 SIGILL, // EXC_BAD_INSTRUCTION
35 SIGTRAP, // EXC_BREAKPOINT
36 SIGFPE, // EXC_ARITHMETIC
37 SIGBUS, // EXC_BAD_ACCESS
38 SIGSEGV, // EXC_BAD_ACCESS
39 // Not a hardware fault
40 SIGABRT
43 // For all these signals, just wire things up so we exit immediately.
44 for (size_t i = 0; i < arraysize(signals_to_intercept); ++i) {
45 struct sigaction act = {};
46 act.sa_handler = ExitSignalHandler;
48 // It is better to allow the signal handler to run on the stack
49 // registered with sigaltstack(), if one is present.
50 act.sa_flags = SA_ONSTACK;
52 if (sigemptyset(&act.sa_mask) != 0)
53 DPLOG(FATAL) << "sigemptyset() failed";
54 if (sigaction(signals_to_intercept[i], &act, NULL) != 0)
55 DPLOG(FATAL) << "sigaction() failed";
59 } // namespace mac
60 } // namespace base