Signals.h revision 218885
1218885Sdim//===- llvm/Support/Signals.h - Signal Handling support ----------*- C++ -*-===// 2218885Sdim// 3218885Sdim// The LLVM Compiler Infrastructure 4218885Sdim// 5218885Sdim// This file is distributed under the University of Illinois Open Source 6218885Sdim// License. See LICENSE.TXT for details. 7218885Sdim// 8218885Sdim//===----------------------------------------------------------------------===// 9218885Sdim// 10218885Sdim// This file defines some helpful functions for dealing with the possibility of 11218885Sdim// unix signals occuring while your program is running. 12218885Sdim// 13218885Sdim//===----------------------------------------------------------------------===// 14218885Sdim 15218885Sdim#ifndef LLVM_SYSTEM_SIGNALS_H 16218885Sdim#define LLVM_SYSTEM_SIGNALS_H 17218885Sdim 18218885Sdim#include "llvm/Support/Path.h" 19218885Sdim 20218885Sdimnamespace llvm { 21218885Sdimnamespace sys { 22218885Sdim 23218885Sdim /// This function runs all the registered interrupt handlers, including the 24218885Sdim /// removal of files registered by RemoveFileOnSignal. 25218885Sdim void RunInterruptHandlers(); 26218885Sdim 27218885Sdim /// This function registers signal handlers to ensure that if a signal gets 28218885Sdim /// delivered that the named file is removed. 29218885Sdim /// @brief Remove a file if a fatal signal occurs. 30218885Sdim bool RemoveFileOnSignal(const Path &Filename, std::string* ErrMsg = 0); 31218885Sdim 32218885Sdim /// This function removes a file from the list of files to be removed on 33218885Sdim /// signal delivery. 34218885Sdim void DontRemoveFileOnSignal(const Path &Filename); 35218885Sdim 36218885Sdim /// When an error signal (such as SIBABRT or SIGSEGV) is delivered to the 37218885Sdim /// process, print a stack trace and then exit. 38218885Sdim /// @brief Print a stack trace if a fatal signal occurs. 39218885Sdim void PrintStackTraceOnErrorSignal(); 40218885Sdim 41218885Sdim /// AddSignalHandler - Add a function to be called when an abort/kill signal 42218885Sdim /// is delivered to the process. The handler can have a cookie passed to it 43218885Sdim /// to identify what instance of the handler it is. 44218885Sdim void AddSignalHandler(void (*FnPtr)(void *), void *Cookie); 45218885Sdim 46218885Sdim /// This function registers a function to be called when the user "interrupts" 47218885Sdim /// the program (typically by pressing ctrl-c). When the user interrupts the 48218885Sdim /// program, the specified interrupt function is called instead of the program 49218885Sdim /// being killed, and the interrupt function automatically disabled. Note 50218885Sdim /// that interrupt functions are not allowed to call any non-reentrant 51218885Sdim /// functions. An null interrupt function pointer disables the current 52218885Sdim /// installed function. Note also that the handler may be executed on a 53218885Sdim /// different thread on some platforms. 54218885Sdim /// @brief Register a function to be called when ctrl-c is pressed. 55218885Sdim void SetInterruptFunction(void (*IF)()); 56218885Sdim} // End sys namespace 57218885Sdim} // End llvm namespace 58218885Sdim 59218885Sdim#endif 60