PostgreSQL Source Code  git master
llvmjit_error.cpp File Reference
#include "postgres.h"
#include <llvm/Support/ErrorHandling.h>
#include "jit/llvmjit.h"
#include <new>
Include dependency graph for llvmjit_error.cpp:

Go to the source code of this file.

Functions

static void fatal_system_new_handler (void)
 
static void fatal_llvm_error_handler (void *user_data, const char *reason, bool gen_crash_diag)
 
static void fatal_llvm_error_handler (void *user_data, const std::string &reason, bool gen_crash_diag)
 
void llvm_enter_fatal_on_oom (void)
 
void llvm_leave_fatal_on_oom (void)
 
bool llvm_in_fatal_on_oom (void)
 
void llvm_reset_after_error (void)
 
void llvm_assert_in_fatal_section (void)
 

Variables

static int fatal_new_handler_depth = 0
 
static std::new_handler old_new_handler = NULL
 

Function Documentation

◆ fatal_llvm_error_handler() [1/2]

static void fatal_llvm_error_handler ( void *  user_data,
const char *  reason,
bool  gen_crash_diag 
)
static

Definition at line 159 of file llvmjit_error.cpp.

162 {
163  ereport(FATAL,
164  (errcode(ERRCODE_OUT_OF_MEMORY),
165  errmsg("fatal llvm error: %s", reason)));
166 }
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define FATAL
Definition: elog.h:41
#define ereport(elevel,...)
Definition: elog.h:149

References ereport, errcode(), errmsg(), and FATAL.

Referenced by fatal_llvm_error_handler(), and llvm_enter_fatal_on_oom().

◆ fatal_llvm_error_handler() [2/2]

static void fatal_llvm_error_handler ( void *  user_data,
const std::string reason,
bool  gen_crash_diag 
)
static

Definition at line 170 of file llvmjit_error.cpp.

173 {
174  fatal_llvm_error_handler(user_data, reason.c_str(), gen_crash_diag);
175 }
static void fatal_llvm_error_handler(void *user_data, const char *reason, bool gen_crash_diag)

References fatal_llvm_error_handler().

◆ fatal_system_new_handler()

static void fatal_system_new_handler ( void  )
static

Definition at line 128 of file llvmjit_error.cpp.

129 {
130  ereport(FATAL,
131  (errcode(ERRCODE_OUT_OF_MEMORY),
132  errmsg("out of memory"),
133  errdetail("while in LLVM")));
134 }
int errdetail(const char *fmt,...)
Definition: elog.c:1202

References ereport, errcode(), errdetail(), errmsg(), and FATAL.

Referenced by llvm_enter_fatal_on_oom().

◆ llvm_assert_in_fatal_section()

void llvm_assert_in_fatal_section ( void  )

Definition at line 122 of file llvmjit_error.cpp.

123 {
125 }
Assert(fmt[strlen(fmt) - 1] !='\n')
static int fatal_new_handler_depth

References Assert(), and fatal_new_handler_depth.

Referenced by llvm_create_context(), llvm_get_function(), and llvm_mutable_module().

◆ llvm_enter_fatal_on_oom()

void llvm_enter_fatal_on_oom ( void  )

Definition at line 63 of file llvmjit_error.cpp.

64 {
65  if (fatal_new_handler_depth == 0)
66  {
67  old_new_handler = std::set_new_handler(fatal_system_new_handler);
68 #if LLVM_VERSION_MAJOR > 4
69  llvm::install_bad_alloc_error_handler(fatal_llvm_new_handler);
70 #endif
71  llvm::install_fatal_error_handler(fatal_llvm_error_handler);
72  }
74 }
static std::new_handler old_new_handler
static void fatal_system_new_handler(void)

References fatal_llvm_error_handler(), fatal_new_handler_depth, fatal_system_new_handler(), and old_new_handler.

Referenced by ExecRunCompiledExpr(), llvm_compile_expr(), and llvm_release_context().

◆ llvm_in_fatal_on_oom()

bool llvm_in_fatal_on_oom ( void  )

Definition at line 98 of file llvmjit_error.cpp.

99 {
100  return fatal_new_handler_depth > 0;
101 }

References fatal_new_handler_depth.

Referenced by llvm_shutdown().

◆ llvm_leave_fatal_on_oom()

void llvm_leave_fatal_on_oom ( void  )

Definition at line 80 of file llvmjit_error.cpp.

81 {
83  if (fatal_new_handler_depth == 0)
84  {
85  std::set_new_handler(old_new_handler);
86 #if LLVM_VERSION_MAJOR > 4
87  llvm::remove_bad_alloc_error_handler();
88 #endif
89  llvm::remove_fatal_error_handler();
90  }
91 }

References fatal_new_handler_depth, and old_new_handler.

Referenced by ExecRunCompiledExpr(), and llvm_release_context().

◆ llvm_reset_after_error()

void llvm_reset_after_error ( void  )

Definition at line 108 of file llvmjit_error.cpp.

109 {
110  if (fatal_new_handler_depth != 0)
111  {
112  std::set_new_handler(old_new_handler);
113 #if LLVM_VERSION_MAJOR > 4
114  llvm::remove_bad_alloc_error_handler();
115 #endif
116  llvm::remove_fatal_error_handler();
117  }
119 }

References fatal_new_handler_depth, and old_new_handler.

Referenced by _PG_jit_provider_init().

Variable Documentation

◆ fatal_new_handler_depth

int fatal_new_handler_depth = 0
static

◆ old_new_handler

std::new_handler old_new_handler = NULL
static