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

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

Definition at line 143 of file llvmjit_error.cpp.

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

Referenced by llvm_enter_fatal_on_oom().

146 {
147  ereport(FATAL,
148  (errcode(ERRCODE_OUT_OF_MEMORY),
149  errmsg("fatal llvm error: %s",
150  reason.c_str())));
151 }
int errcode(int sqlerrcode)
Definition: elog.c:698
#define FATAL
Definition: elog.h:49
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ fatal_system_new_handler()

static void fatal_system_new_handler ( void  )
static

Definition at line 121 of file llvmjit_error.cpp.

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

Referenced by llvm_enter_fatal_on_oom().

122 {
123  ereport(FATAL,
124  (errcode(ERRCODE_OUT_OF_MEMORY),
125  errmsg("out of memory"),
126  errdetail("while in LLVM")));
127 }
int errcode(int sqlerrcode)
Definition: elog.c:698
#define FATAL
Definition: elog.h:49
int errdetail(const char *fmt,...)
Definition: elog.c:1042
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ llvm_assert_in_fatal_section()

void llvm_assert_in_fatal_section ( void  )

Definition at line 115 of file llvmjit_error.cpp.

References Assert, and fatal_new_handler_depth.

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

116 {
118 }
#define Assert(condition)
Definition: c.h:804
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_in_fatal_on_oom()

bool llvm_in_fatal_on_oom ( void  )

Definition at line 91 of file llvmjit_error.cpp.

References fatal_new_handler_depth.

Referenced by llvm_shutdown().

92 {
93  return fatal_new_handler_depth > 0;
94 }
static int fatal_new_handler_depth

◆ 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 101 of file llvmjit_error.cpp.

References fatal_new_handler_depth, and old_new_handler.

Referenced by _PG_jit_provider_init().

102 {
103  if (fatal_new_handler_depth != 0)
104  {
105  std::set_new_handler(old_new_handler);
106 #if LLVM_VERSION_MAJOR > 4
107  llvm::remove_bad_alloc_error_handler();
108 #endif
109  llvm::remove_fatal_error_handler();
110  }
112 }
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