num_unsaved_files, options, 0 };
llvm::CrashRecoveryContext CRC;
- if (!CRC.RunSafely(clang_parseTranslationUnit_Impl, &PTUI)) {
+ if (!RunSafely(CRC, clang_parseTranslationUnit_Impl, &PTUI)) {
fprintf(stderr, "libclang: crash detected during parsing: {\n");
fprintf(stderr, " 'source_filename' : '%s'\n", source_filename);
fprintf(stderr, " 'command_line_args' : [");
options, 0 };
llvm::CrashRecoveryContext CRC;
- if (!CRC.RunSafely(clang_reparseTranslationUnit_Impl, &RTUI)) {
+ if (!RunSafely(CRC, clang_reparseTranslationUnit_Impl, &RTUI)) {
fprintf(stderr, "libclang: crash detected during reparsing\n");
static_cast<ASTUnit *>(TU)->setUnsafeToFree(true);
return 1;
// Misc. utility functions.
//===----------------------------------------------------------------------===//
+static unsigned SafetyStackThreadSize = 0;
+
+namespace clang {
+
+bool RunSafely(llvm::CrashRecoveryContext &CRC,
+ void (*Fn)(void*), void *UserData) {
+ if (unsigned Size = GetSafetyThreadStackSize())
+ return CRC.RunSafelyOnThread(Fn, UserData, Size);
+ return CRC.RunSafely(Fn, UserData);
+}
+
+unsigned GetSafetyThreadStackSize() {
+ return SafetyStackThreadSize;
+}
+
+void SetSafetyThreadStackSize(unsigned Value) {
+ SafetyStackThreadSize = Value;
+}
+
+}
+
extern "C" {
CXString clang_getClangVersion() {
options, 0 };
llvm::CrashRecoveryContext CRC;
- if (!CRC.RunSafely(clang_codeCompleteAt_Impl, &CCAI)) {
+ if (!RunSafely(CRC, clang_codeCompleteAt_Impl, &CCAI)) {
fprintf(stderr, "libclang: crash detected in code completion\n");
static_cast<ASTUnit *>(TU)->setUnsafeToFree(true);
return 0;
-//===- CIndexer.h - Clang-C Source Indexing Library -----------------------===//
+//===- CIndexer.h - Clang-C Source Indexing Library -------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
#include "llvm/System/Path.h"
#include <vector>
+namespace llvm {
+ class CrashRecoveryContext;
+}
+
namespace clang {
namespace cxstring {
CXString createCXString(const char *String, bool DupString = false);
struct CXUnsavedFile *unsaved_files,
std::vector<std::string> &RemapArgs,
std::vector<llvm::sys::Path> &TemporaryFiles);
+
+ /// \brief Return the current size to request for "safety".
+ unsigned GetSafetyThreadStackSize();
+
+ /// \brief Set the current size to request for "safety" (or 0, if safety
+ /// threads should not be used).
+ void SetSafetyThreadStackSize(unsigned Value);
+
+ /// \brief Execution the given code "safely", using crash recovery or safety
+ /// threads when possible.
+ ///
+ /// \return False if a crash was detected.
+ bool RunSafely(llvm::CrashRecoveryContext &CRC,
+ void (*Fn)(void*), void *UserData);
}
#endif