PostgreSQL Source Code  git master
llvmjit_error.cpp File Reference
#include "postgres.h"
#include <llvm/Support/ErrorHandling.h>
#include "jit/llvmjit.h"
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 std::string &reason, bool gen_crash_diag)
 
void llvm_enter_fatal_on_oom (void)
 
void llvm_leave_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()

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

Definition at line 133 of file llvmjit_error.cpp.

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

Referenced by llvm_enter_fatal_on_oom().

136 {
137  ereport(FATAL,
138  (errcode(ERRCODE_OUT_OF_MEMORY),
139  errmsg("fatal llvm error: %s",
140  reason.c_str())));
141 }
int errcode(int sqlerrcode)
Definition: elog.c:570
#define FATAL
Definition: elog.h:52
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ fatal_system_new_handler()

static void fatal_system_new_handler ( void  )
static

Definition at line 111 of file llvmjit_error.cpp.

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

Referenced by llvm_enter_fatal_on_oom().

112 {
113  ereport(FATAL,
114  (errcode(ERRCODE_OUT_OF_MEMORY),
115  errmsg("out of memory"),
116  errdetail("while in LLVM")));
117 }
int errcode(int sqlerrcode)
Definition: elog.c:570
#define FATAL
Definition: elog.h:52
int errdetail(const char *fmt,...)
Definition: elog.c:860
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ llvm_assert_in_fatal_section()

void llvm_assert_in_fatal_section ( void  )

Definition at line 105 of file llvmjit_error.cpp.

References Assert, and fatal_new_handler_depth.

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

106 {
108 }
#define Assert(condition)
Definition: c.h:732
static int fatal_new_handler_depth

◆ llvm_enter_fatal_on_oom()

void llvm_enter_fatal_on_oom ( void  )

Definition at line 56 of file llvmjit_error.cpp.

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().

57 {
58  if (fatal_new_handler_depth == 0)
59  {
60  old_new_handler = std::set_new_handler(fatal_system_new_handler);
61 #if LLVM_VERSION_MAJOR > 4
62  llvm::install_bad_alloc_error_handler(fatal_llvm_new_handler);
63 #endif
64  llvm::install_fatal_error_handler(fatal_llvm_error_handler);
65  }
67 }
static void fatal_system_new_handler(void)
static void fatal_llvm_error_handler(void *user_data, const std::string &reason, bool gen_crash_diag)
static int fatal_new_handler_depth
static std::new_handler old_new_handler

◆ llvm_leave_fatal_on_oom()

void llvm_leave_fatal_on_oom ( void  )

Definition at line 73 of file llvmjit_error.cpp.

References fatal_new_handler_depth, and old_new_handler.

Referenced by ExecRunCompiledExpr(), and llvm_compile_expr().

74 {
76  if (fatal_new_handler_depth == 0)
77  {
78  std::set_new_handler(old_new_handler);
79 #if LLVM_VERSION_MAJOR > 4
80  llvm::remove_bad_alloc_error_handler();
81 #endif
82  llvm::remove_fatal_error_handler();
83  }
84 }
static int fatal_new_handler_depth
static std::new_handler old_new_handler

◆ llvm_reset_after_error()

void llvm_reset_after_error ( void  )

Definition at line 91 of file llvmjit_error.cpp.

References fatal_new_handler_depth, and old_new_handler.

Referenced by _PG_jit_provider_init().

92 {
93  if (fatal_new_handler_depth != 0)
94  {
95  std::set_new_handler(old_new_handler);
96 #if LLVM_VERSION_MAJOR > 4
97  llvm::remove_bad_alloc_error_handler();
98 #endif
99  llvm::remove_fatal_error_handler();
100  }
102 }
static int fatal_new_handler_depth
static std::new_handler old_new_handler

Variable Documentation

◆ fatal_new_handler_depth

int fatal_new_handler_depth = 0
static

◆ old_new_handler

std::new_handler old_new_handler = NULL
static