Signals.h revision 221345
1239671Srwatson//===- llvm/Support/Signals.h - Signal Handling support ----------*- C++ -*-===// 2239671Srwatson// 3244899Srwatson// The LLVM Compiler Infrastructure 4239671Srwatson// 5239671Srwatson// This file is distributed under the University of Illinois Open Source 6244899Srwatson// License. See LICENSE.TXT for details. 7244899Srwatson// 8244899Srwatson//===----------------------------------------------------------------------===// 9244899Srwatson// 10239671Srwatson// This file defines some helpful functions for dealing with the possibility of 11239671Srwatson// unix signals occurring while your program is running. 12239671Srwatson// 13239671Srwatson//===----------------------------------------------------------------------===// 14239671Srwatson 15239671Srwatson#ifndef LLVM_SYSTEM_SIGNALS_H 16239671Srwatson#define LLVM_SYSTEM_SIGNALS_H 17239671Srwatson 18239671Srwatson#include "llvm/Support/Path.h" 19239671Srwatson 20239671Srwatsonnamespace llvm { 21239671Srwatsonnamespace sys { 22239671Srwatson 23239671Srwatson /// This function runs all the registered interrupt handlers, including the 24239671Srwatson /// removal of files registered by RemoveFileOnSignal. 25239671Srwatson void RunInterruptHandlers(); 26239671Srwatson 27239671Srwatson /// This function registers signal handlers to ensure that if a signal gets 28239671Srwatson /// delivered that the named file is removed. 29239671Srwatson /// @brief Remove a file if a fatal signal occurs. 30239671Srwatson bool RemoveFileOnSignal(const Path &Filename, std::string* ErrMsg = 0); 31239671Srwatson 32239671Srwatson /// This function removes a file from the list of files to be removed on 33239671Srwatson /// signal delivery. 34239671Srwatson void DontRemoveFileOnSignal(const Path &Filename); 35244899Srwatson 36239671Srwatson /// When an error signal (such as SIBABRT or SIGSEGV) is delivered to the 37239671Srwatson /// process, print a stack trace and then exit. 38239671Srwatson /// @brief Print a stack trace if a fatal signal occurs. 39239671Srwatson void PrintStackTraceOnErrorSignal(); 40239671Srwatson 41239671Srwatson /// AddSignalHandler - Add a function to be called when an abort/kill signal 42239671Srwatson /// is delivered to the process. The handler can have a cookie passed to it 43239671Srwatson /// to identify what instance of the handler it is. 44239671Srwatson void AddSignalHandler(void (*FnPtr)(void *), void *Cookie); 45239671Srwatson 46239671Srwatson /// This function registers a function to be called when the user "interrupts" 47239671Srwatson /// the program (typically by pressing ctrl-c). When the user interrupts the 48245330Srwatson /// program, the specified interrupt function is called instead of the program 49239671Srwatson /// being killed, and the interrupt function automatically disabled. Note 50239671Srwatson /// that interrupt functions are not allowed to call any non-reentrant 51239671Srwatson /// functions. An null interrupt function pointer disables the current 52239671Srwatson /// installed function. Note also that the handler may be executed on a 53239671Srwatson /// different thread on some platforms. 54239671Srwatson /// @brief Register a function to be called when ctrl-c is pressed. 55239671Srwatson void SetInterruptFunction(void (*IF)()); 56239671Srwatson} // End sys namespace 57239671Srwatson} // End llvm namespace 58239671Srwatson 59244942Srwatson#endif 60244899Srwatson