• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//===- Signals.cpp - Generic Unix Signals Implementation -----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines some helpful functions for dealing with the possibility of
10// Unix signals occurring while your program is running.
11//
12//===----------------------------------------------------------------------===//
13//
14// This file is extremely careful to only do signal-safe things while in a
15// signal handler. In particular, memory allocation and acquiring a mutex
16// while in a signal handler should never occur. ManagedStatic isn't usable from
17// a signal handler for 2 reasons:
18//
19//  1. Creating a new one allocates.
20//  2. The signal handler could fire while llvm_shutdown is being processed, in
21//     which case the ManagedStatic is in an unknown state because it could
22//     already have been destroyed, or be in the process of being destroyed.
23//
24// Modifying the behavior of the signal handlers (such as registering new ones)
25// can acquire a mutex, but all this guarantees is that the signal handler
26// behavior is only modified by one thread at a time. A signal handler can still
27// fire while this occurs!
28//
29// Adding work to a signal handler requires lock-freedom (and assume atomics are
30// always lock-free) because the signal handler could fire while new work is
31// being added.
32//
33//===----------------------------------------------------------------------===//
34
35#include "Unix.h"
36#include "llvm/ADT/STLExtras.h"
37#include "llvm/Config/config.h"
38#include "llvm/Demangle/Demangle.h"
39#include "llvm/Support/FileSystem.h"
40#include "llvm/Support/FileUtilities.h"
41#include "llvm/Support/Format.h"
42#include "llvm/Support/MemoryBuffer.h"
43#include "llvm/Support/Mutex.h"
44#include "llvm/Support/Program.h"
45#include "llvm/Support/SaveAndRestore.h"
46#include "llvm/Support/raw_ostream.h"
47#include <algorithm>
48#include <string>
49#include <sysexits.h>
50#ifdef HAVE_BACKTRACE
51# include BACKTRACE_HEADER         // For backtrace().
52#endif
53#if HAVE_SIGNAL_H
54#include <signal.h>
55#endif
56#if HAVE_SYS_STAT_H
57#include <sys/stat.h>
58#endif
59#if HAVE_DLFCN_H
60#include <dlfcn.h>
61#endif
62#if HAVE_MACH_MACH_H
63#include <mach/mach.h>
64#endif
65#if HAVE_LINK_H
66#include <link.h>
67#endif
68#ifdef HAVE__UNWIND_BACKTRACE
69// FIXME: We should be able to use <unwind.h> for any target that has an
70// _Unwind_Backtrace function, but on FreeBSD the configure test passes
71// despite the function not existing, and on Android, <unwind.h> conflicts
72// with <link.h>.
73#ifdef __GLIBC__
74#include <unwind.h>
75#else
76#undef HAVE__UNWIND_BACKTRACE
77#endif
78#endif
79
80using namespace llvm;
81
82static RETSIGTYPE SignalHandler(int Sig);  // defined below.
83static RETSIGTYPE InfoSignalHandler(int Sig);  // defined below.
84
85using SignalHandlerFunctionType = void (*)();
86/// The function to call if ctrl-c is pressed.
87static std::atomic<SignalHandlerFunctionType> InterruptFunction{nullptr};
88static std::atomic<SignalHandlerFunctionType> InfoSignalFunction{nullptr};
89/// The function to call on SIGPIPE (one-time use only).
90static std::atomic<SignalHandlerFunctionType> OneShotPipeSignalFunction{
91    nullptr};
92
93namespace {
94/// Signal-safe removal of files.
95/// Inserting and erasing from the list isn't signal-safe, but removal of files
96/// themselves is signal-safe. Memory is freed when the head is freed, deletion
97/// is therefore not signal-safe either.
98class FileToRemoveList {
99  std::atomic<char *> Filename{nullptr};
100  std::atomic<FileToRemoveList *> Next{nullptr};
101
102  FileToRemoveList() = default;
103  // Not signal-safe.
104  FileToRemoveList(const std::string &str) : Filename(strdup(str.c_str())) {}
105
106public:
107  // Not signal-safe.
108  ~FileToRemoveList() {
109    if (FileToRemoveList *N = Next.exchange(nullptr))
110      delete N;
111    if (char *F = Filename.exchange(nullptr))
112      free(F);
113  }
114
115  // Not signal-safe.
116  static void insert(std::atomic<FileToRemoveList *> &Head,
117                     const std::string &Filename) {
118    // Insert the new file at the end of the list.
119    FileToRemoveList *NewHead = new FileToRemoveList(Filename);
120    std::atomic<FileToRemoveList *> *InsertionPoint = &Head;
121    FileToRemoveList *OldHead = nullptr;
122    while (!InsertionPoint->compare_exchange_strong(OldHead, NewHead)) {
123      InsertionPoint = &OldHead->Next;
124      OldHead = nullptr;
125    }
126  }
127
128  // Not signal-safe.
129  static void erase(std::atomic<FileToRemoveList *> &Head,
130                    const std::string &Filename) {
131    // Use a lock to avoid concurrent erase: the comparison would access
132    // free'd memory.
133    static ManagedStatic<sys::SmartMutex<true>> Lock;
134    sys::SmartScopedLock<true> Writer(*Lock);
135
136    for (FileToRemoveList *Current = Head.load(); Current;
137         Current = Current->Next.load()) {
138      if (char *OldFilename = Current->Filename.load()) {
139        if (OldFilename != Filename)
140          continue;
141        // Leave an empty filename.
142        OldFilename = Current->Filename.exchange(nullptr);
143        // The filename might have become null between the time we
144        // compared it and we exchanged it.
145        if (OldFilename)
146          free(OldFilename);
147      }
148    }
149  }
150
151  // Signal-safe.
152  static void removeAllFiles(std::atomic<FileToRemoveList *> &Head) {
153    // If cleanup were to occur while we're removing files we'd have a bad time.
154    // Make sure we're OK by preventing cleanup from doing anything while we're
155    // removing files. If cleanup races with us and we win we'll have a leak,
156    // but we won't crash.
157    FileToRemoveList *OldHead = Head.exchange(nullptr);
158
159    for (FileToRemoveList *currentFile = OldHead; currentFile;
160         currentFile = currentFile->Next.load()) {
161      // If erasing was occuring while we're trying to remove files we'd look
162      // at free'd data. Take away the path and put it back when done.
163      if (char *path = currentFile->Filename.exchange(nullptr)) {
164        // Get the status so we can determine if it's a file or directory. If we
165        // can't stat the file, ignore it.
166        struct stat buf;
167        if (stat(path, &buf) != 0)
168          continue;
169
170        // If this is not a regular file, ignore it. We want to prevent removal
171        // of special files like /dev/null, even if the compiler is being run
172        // with the super-user permissions.
173        if (!S_ISREG(buf.st_mode))
174          continue;
175
176        // Otherwise, remove the file. We ignore any errors here as there is
177        // nothing else we can do.
178        unlink(path);
179
180        // We're done removing the file, erasing can safely proceed.
181        currentFile->Filename.exchange(path);
182      }
183    }
184
185    // We're done removing files, cleanup can safely proceed.
186    Head.exchange(OldHead);
187  }
188};
189static std::atomic<FileToRemoveList *> FilesToRemove{nullptr};
190
191/// Clean up the list in a signal-friendly manner.
192/// Recall that signals can fire during llvm_shutdown. If this occurs we should
193/// either clean something up or nothing at all, but we shouldn't crash!
194struct FilesToRemoveCleanup {
195  // Not signal-safe.
196  ~FilesToRemoveCleanup() {
197    FileToRemoveList *Head = FilesToRemove.exchange(nullptr);
198    if (Head)
199      delete Head;
200  }
201};
202} // namespace
203
204static StringRef Argv0;
205
206/// Signals that represent requested termination. There's no bug or failure, or
207/// if there is, it's not our direct responsibility. For whatever reason, our
208/// continued execution is no longer desirable.
209static const int IntSigs[] = {
210  SIGHUP, SIGINT, SIGTERM, SIGUSR2
211};
212
213/// Signals that represent that we have a bug, and our prompt termination has
214/// been ordered.
215static const int KillSigs[] = {
216  SIGILL, SIGTRAP, SIGABRT, SIGFPE, SIGBUS, SIGSEGV, SIGQUIT
217#ifdef SIGSYS
218  , SIGSYS
219#endif
220#ifdef SIGXCPU
221  , SIGXCPU
222#endif
223#ifdef SIGXFSZ
224  , SIGXFSZ
225#endif
226#ifdef SIGEMT
227  , SIGEMT
228#endif
229};
230
231/// Signals that represent requests for status.
232static const int InfoSigs[] = {
233  SIGUSR1
234#ifdef SIGINFO
235  , SIGINFO
236#endif
237};
238
239static const size_t NumSigs =
240    array_lengthof(IntSigs) + array_lengthof(KillSigs) +
241    array_lengthof(InfoSigs) + 1 /* SIGPIPE */;
242
243
244static std::atomic<unsigned> NumRegisteredSignals{0};
245static struct {
246  struct sigaction SA;
247  int SigNo;
248} RegisteredSignalInfo[NumSigs];
249
250#if defined(HAVE_SIGALTSTACK)
251// Hold onto both the old and new alternate signal stack so that it's not
252// reported as a leak. We don't make any attempt to remove our alt signal
253// stack if we remove our signal handlers; that can't be done reliably if
254// someone else is also trying to do the same thing.
255static stack_t OldAltStack;
256static void* NewAltStackPointer;
257
258static void CreateSigAltStack() {
259  const size_t AltStackSize = MINSIGSTKSZ + 64 * 1024;
260
261  // If we're executing on the alternate stack, or we already have an alternate
262  // signal stack that we're happy with, there's nothing for us to do. Don't
263  // reduce the size, some other part of the process might need a larger stack
264  // than we do.
265  if (sigaltstack(nullptr, &OldAltStack) != 0 ||
266      OldAltStack.ss_flags & SS_ONSTACK ||
267      (OldAltStack.ss_sp && OldAltStack.ss_size >= AltStackSize))
268    return;
269
270  stack_t AltStack = {};
271  AltStack.ss_sp = static_cast<char *>(safe_malloc(AltStackSize));
272  NewAltStackPointer = AltStack.ss_sp; // Save to avoid reporting a leak.
273  AltStack.ss_size = AltStackSize;
274  if (sigaltstack(&AltStack, &OldAltStack) != 0)
275    free(AltStack.ss_sp);
276}
277#else
278static void CreateSigAltStack() {}
279#endif
280
281static void RegisterHandlers() { // Not signal-safe.
282  // The mutex prevents other threads from registering handlers while we're
283  // doing it. We also have to protect the handlers and their count because
284  // a signal handler could fire while we're registeting handlers.
285  static ManagedStatic<sys::SmartMutex<true>> SignalHandlerRegistrationMutex;
286  sys::SmartScopedLock<true> Guard(*SignalHandlerRegistrationMutex);
287
288  // If the handlers are already registered, we're done.
289  if (NumRegisteredSignals.load() != 0)
290    return;
291
292  // Create an alternate stack for signal handling. This is necessary for us to
293  // be able to reliably handle signals due to stack overflow.
294  CreateSigAltStack();
295
296  enum class SignalKind { IsKill, IsInfo };
297  auto registerHandler = [&](int Signal, SignalKind Kind) {
298    unsigned Index = NumRegisteredSignals.load();
299    assert(Index < array_lengthof(RegisteredSignalInfo) &&
300           "Out of space for signal handlers!");
301
302    struct sigaction NewHandler;
303
304    switch (Kind) {
305    case SignalKind::IsKill:
306      NewHandler.sa_handler = SignalHandler;
307      NewHandler.sa_flags = SA_NODEFER | SA_RESETHAND | SA_ONSTACK;
308      break;
309    case SignalKind::IsInfo:
310      NewHandler.sa_handler = InfoSignalHandler;
311      NewHandler.sa_flags = SA_ONSTACK;
312      break;
313    }
314    sigemptyset(&NewHandler.sa_mask);
315
316    // Install the new handler, save the old one in RegisteredSignalInfo.
317    sigaction(Signal, &NewHandler, &RegisteredSignalInfo[Index].SA);
318    RegisteredSignalInfo[Index].SigNo = Signal;
319    ++NumRegisteredSignals;
320  };
321
322  for (auto S : IntSigs)
323    registerHandler(S, SignalKind::IsKill);
324  for (auto S : KillSigs)
325    registerHandler(S, SignalKind::IsKill);
326  if (OneShotPipeSignalFunction)
327    registerHandler(SIGPIPE, SignalKind::IsKill);
328  for (auto S : InfoSigs)
329    registerHandler(S, SignalKind::IsInfo);
330}
331
332static void UnregisterHandlers() {
333  // Restore all of the signal handlers to how they were before we showed up.
334  for (unsigned i = 0, e = NumRegisteredSignals.load(); i != e; ++i) {
335    sigaction(RegisteredSignalInfo[i].SigNo,
336              &RegisteredSignalInfo[i].SA, nullptr);
337    --NumRegisteredSignals;
338  }
339}
340
341/// Process the FilesToRemove list.
342static void RemoveFilesToRemove() {
343  FileToRemoveList::removeAllFiles(FilesToRemove);
344}
345
346void sys::CleanupOnSignal(uintptr_t Context) {
347  int Sig = (int)Context;
348
349  if (llvm::is_contained(InfoSigs, Sig)) {
350    InfoSignalHandler(Sig);
351    return;
352  }
353
354  RemoveFilesToRemove();
355
356  if (llvm::is_contained(IntSigs, Sig) || Sig == SIGPIPE)
357    return;
358
359  llvm::sys::RunSignalHandlers();
360}
361
362// The signal handler that runs.
363static RETSIGTYPE SignalHandler(int Sig) {
364  // Restore the signal behavior to default, so that the program actually
365  // crashes when we return and the signal reissues.  This also ensures that if
366  // we crash in our signal handler that the program will terminate immediately
367  // instead of recursing in the signal handler.
368  UnregisterHandlers();
369
370  // Unmask all potentially blocked kill signals.
371  sigset_t SigMask;
372  sigfillset(&SigMask);
373  sigprocmask(SIG_UNBLOCK, &SigMask, nullptr);
374
375  {
376    RemoveFilesToRemove();
377
378    if (Sig == SIGPIPE)
379      if (auto OldOneShotPipeFunction =
380              OneShotPipeSignalFunction.exchange(nullptr))
381        return OldOneShotPipeFunction();
382
383    if (std::find(std::begin(IntSigs), std::end(IntSigs), Sig)
384        != std::end(IntSigs)) {
385      if (auto OldInterruptFunction = InterruptFunction.exchange(nullptr))
386        return OldInterruptFunction();
387
388      raise(Sig);   // Execute the default handler.
389      return;
390   }
391  }
392
393  // Otherwise if it is a fault (like SEGV) run any handler.
394  llvm::sys::RunSignalHandlers();
395
396#ifdef __s390__
397  // On S/390, certain signals are delivered with PSW Address pointing to
398  // *after* the faulting instruction.  Simply returning from the signal
399  // handler would continue execution after that point, instead of
400  // re-raising the signal.  Raise the signal manually in those cases.
401  if (Sig == SIGILL || Sig == SIGFPE || Sig == SIGTRAP)
402    raise(Sig);
403#endif
404}
405
406static RETSIGTYPE InfoSignalHandler(int Sig) {
407  SaveAndRestore<int> SaveErrnoDuringASignalHandler(errno);
408  if (SignalHandlerFunctionType CurrentInfoFunction = InfoSignalFunction)
409    CurrentInfoFunction();
410}
411
412void llvm::sys::RunInterruptHandlers() {
413  RemoveFilesToRemove();
414}
415
416void llvm::sys::SetInterruptFunction(void (*IF)()) {
417  InterruptFunction.exchange(IF);
418  RegisterHandlers();
419}
420
421void llvm::sys::SetInfoSignalFunction(void (*Handler)()) {
422  InfoSignalFunction.exchange(Handler);
423  RegisterHandlers();
424}
425
426void llvm::sys::SetOneShotPipeSignalFunction(void (*Handler)()) {
427  OneShotPipeSignalFunction.exchange(Handler);
428  RegisterHandlers();
429}
430
431void llvm::sys::DefaultOneShotPipeSignalHandler() {
432  // Send a special return code that drivers can check for, from sysexits.h.
433  exit(EX_IOERR);
434}
435
436// The public API
437bool llvm::sys::RemoveFileOnSignal(StringRef Filename,
438                                   std::string* ErrMsg) {
439  // Ensure that cleanup will occur as soon as one file is added.
440  static ManagedStatic<FilesToRemoveCleanup> FilesToRemoveCleanup;
441  *FilesToRemoveCleanup;
442  FileToRemoveList::insert(FilesToRemove, Filename.str());
443  RegisterHandlers();
444  return false;
445}
446
447// The public API
448void llvm::sys::DontRemoveFileOnSignal(StringRef Filename) {
449  FileToRemoveList::erase(FilesToRemove, Filename.str());
450}
451
452/// Add a function to be called when a signal is delivered to the process. The
453/// handler can have a cookie passed to it to identify what instance of the
454/// handler it is.
455void llvm::sys::AddSignalHandler(sys::SignalHandlerCallback FnPtr,
456                                 void *Cookie) { // Signal-safe.
457  insertSignalHandler(FnPtr, Cookie);
458  RegisterHandlers();
459}
460
461#if defined(HAVE_BACKTRACE) && ENABLE_BACKTRACES && HAVE_LINK_H &&    \
462    (defined(__linux__) || defined(__FreeBSD__) ||                             \
463     defined(__FreeBSD_kernel__) || defined(__NetBSD__))
464struct DlIteratePhdrData {
465  void **StackTrace;
466  int depth;
467  bool first;
468  const char **modules;
469  intptr_t *offsets;
470  const char *main_exec_name;
471};
472
473static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) {
474  DlIteratePhdrData *data = (DlIteratePhdrData*)arg;
475  const char *name = data->first ? data->main_exec_name : info->dlpi_name;
476  data->first = false;
477  for (int i = 0; i < info->dlpi_phnum; i++) {
478    const auto *phdr = &info->dlpi_phdr[i];
479    if (phdr->p_type != PT_LOAD)
480      continue;
481    intptr_t beg = info->dlpi_addr + phdr->p_vaddr;
482    intptr_t end = beg + phdr->p_memsz;
483    for (int j = 0; j < data->depth; j++) {
484      if (data->modules[j])
485        continue;
486      intptr_t addr = (intptr_t)data->StackTrace[j];
487      if (beg <= addr && addr < end) {
488        data->modules[j] = name;
489        data->offsets[j] = addr - info->dlpi_addr;
490      }
491    }
492  }
493  return 0;
494}
495
496/// If this is an ELF platform, we can find all loaded modules and their virtual
497/// addresses with dl_iterate_phdr.
498static bool findModulesAndOffsets(void **StackTrace, int Depth,
499                                  const char **Modules, intptr_t *Offsets,
500                                  const char *MainExecutableName,
501                                  StringSaver &StrPool) {
502  DlIteratePhdrData data = {StackTrace, Depth,   true,
503                            Modules,    Offsets, MainExecutableName};
504  dl_iterate_phdr(dl_iterate_phdr_cb, &data);
505  return true;
506}
507#else
508/// This platform does not have dl_iterate_phdr, so we do not yet know how to
509/// find all loaded DSOs.
510static bool findModulesAndOffsets(void **StackTrace, int Depth,
511                                  const char **Modules, intptr_t *Offsets,
512                                  const char *MainExecutableName,
513                                  StringSaver &StrPool) {
514  return false;
515}
516#endif // defined(HAVE_BACKTRACE) && ENABLE_BACKTRACES && ...
517
518#if ENABLE_BACKTRACES && defined(HAVE__UNWIND_BACKTRACE)
519static int unwindBacktrace(void **StackTrace, int MaxEntries) {
520  if (MaxEntries < 0)
521    return 0;
522
523  // Skip the first frame ('unwindBacktrace' itself).
524  int Entries = -1;
525
526  auto HandleFrame = [&](_Unwind_Context *Context) -> _Unwind_Reason_Code {
527    // Apparently we need to detect reaching the end of the stack ourselves.
528    void *IP = (void *)_Unwind_GetIP(Context);
529    if (!IP)
530      return _URC_END_OF_STACK;
531
532    assert(Entries < MaxEntries && "recursively called after END_OF_STACK?");
533    if (Entries >= 0)
534      StackTrace[Entries] = IP;
535
536    if (++Entries == MaxEntries)
537      return _URC_END_OF_STACK;
538    return _URC_NO_REASON;
539  };
540
541  _Unwind_Backtrace(
542      [](_Unwind_Context *Context, void *Handler) {
543        return (*static_cast<decltype(HandleFrame) *>(Handler))(Context);
544      },
545      static_cast<void *>(&HandleFrame));
546  return std::max(Entries, 0);
547}
548#endif
549
550// In the case of a program crash or fault, print out a stack trace so that the
551// user has an indication of why and where we died.
552//
553// On glibc systems we have the 'backtrace' function, which works nicely, but
554// doesn't demangle symbols.
555void llvm::sys::PrintStackTrace(raw_ostream &OS) {
556#if ENABLE_BACKTRACES
557  static void *StackTrace[256];
558  int depth = 0;
559#if defined(HAVE_BACKTRACE)
560  // Use backtrace() to output a backtrace on Linux systems with glibc.
561  if (!depth)
562    depth = backtrace(StackTrace, static_cast<int>(array_lengthof(StackTrace)));
563#endif
564#if defined(HAVE__UNWIND_BACKTRACE)
565  // Try _Unwind_Backtrace() if backtrace() failed.
566  if (!depth)
567    depth = unwindBacktrace(StackTrace,
568                        static_cast<int>(array_lengthof(StackTrace)));
569#endif
570  if (!depth)
571    return;
572
573  if (printSymbolizedStackTrace(Argv0, StackTrace, depth, OS))
574    return;
575#if HAVE_DLFCN_H && HAVE_DLADDR
576  int width = 0;
577  for (int i = 0; i < depth; ++i) {
578    Dl_info dlinfo;
579    dladdr(StackTrace[i], &dlinfo);
580    const char* name = strrchr(dlinfo.dli_fname, '/');
581
582    int nwidth;
583    if (!name) nwidth = strlen(dlinfo.dli_fname);
584    else       nwidth = strlen(name) - 1;
585
586    if (nwidth > width) width = nwidth;
587  }
588
589  for (int i = 0; i < depth; ++i) {
590    Dl_info dlinfo;
591    dladdr(StackTrace[i], &dlinfo);
592
593    OS << format("%-2d", i);
594
595    const char* name = strrchr(dlinfo.dli_fname, '/');
596    if (!name) OS << format(" %-*s", width, dlinfo.dli_fname);
597    else       OS << format(" %-*s", width, name+1);
598
599    OS << format(" %#0*lx", (int)(sizeof(void*) * 2) + 2,
600                 (unsigned long)StackTrace[i]);
601
602    if (dlinfo.dli_sname != nullptr) {
603      OS << ' ';
604      int res;
605      char* d = itaniumDemangle(dlinfo.dli_sname, nullptr, nullptr, &res);
606      if (!d) OS << dlinfo.dli_sname;
607      else    OS << d;
608      free(d);
609
610      OS << format(" + %tu", (static_cast<const char*>(StackTrace[i])-
611                              static_cast<const char*>(dlinfo.dli_saddr)));
612    }
613    OS << '\n';
614  }
615#elif defined(HAVE_BACKTRACE)
616  backtrace_symbols_fd(StackTrace, depth, STDERR_FILENO);
617#endif
618#endif
619}
620
621static void PrintStackTraceSignalHandler(void *) {
622  sys::PrintStackTrace(llvm::errs());
623}
624
625void llvm::sys::DisableSystemDialogsOnCrash() {}
626
627/// When an error signal (such as SIGABRT or SIGSEGV) is delivered to the
628/// process, print a stack trace and then exit.
629void llvm::sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
630                                             bool DisableCrashReporting) {
631  ::Argv0 = Argv0;
632
633  AddSignalHandler(PrintStackTraceSignalHandler, nullptr);
634
635#if defined(__APPLE__) && ENABLE_CRASH_OVERRIDES
636  // Environment variable to disable any kind of crash dialog.
637  if (DisableCrashReporting || getenv("LLVM_DISABLE_CRASH_REPORT")) {
638    mach_port_t self = mach_task_self();
639
640    exception_mask_t mask = EXC_MASK_CRASH;
641
642    kern_return_t ret = task_set_exception_ports(self,
643                             mask,
644                             MACH_PORT_NULL,
645                             EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES,
646                             THREAD_STATE_NONE);
647    (void)ret;
648  }
649#endif
650}
651