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_new_handler (void *user_data, const char *reason, bool gen_crash_diag)
 
static void fatal_llvm_new_handler (void *user_data, const std::string &reason, bool gen_crash_diag)
 
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 149 of file llvmjit_error.cpp.

152 {
153  ereport(FATAL,
154  (errcode(ERRCODE_OUT_OF_MEMORY),
155  errmsg("fatal llvm error: %s", reason)));
156 }
int errcode(int sqlerrcode)
Definition: elog.c:859
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#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 160 of file llvmjit_error.cpp.

163 {
164  fatal_llvm_error_handler(user_data, reason.c_str(), gen_crash_diag);
165 }
static void fatal_llvm_error_handler(void *user_data, const char *reason, bool gen_crash_diag)

References fatal_llvm_error_handler().

◆ fatal_llvm_new_handler() [1/2]

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

Definition at line 129 of file llvmjit_error.cpp.

132 {
133  ereport(FATAL,
134  (errcode(ERRCODE_OUT_OF_MEMORY),
135  errmsg("out of memory"),
136  errdetail("While in LLVM: %s", reason)));
137 }
int errdetail(const char *fmt,...)
Definition: elog.c:1205

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

Referenced by fatal_llvm_new_handler(), and llvm_enter_fatal_on_oom().

◆ fatal_llvm_new_handler() [2/2]

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

Definition at line 140 of file llvmjit_error.cpp.

143 {
144  fatal_llvm_new_handler(user_data, reason.c_str(), gen_crash_diag);
145 }
static void fatal_llvm_new_handler(void *user_data, const char *reason, bool gen_crash_diag)

References fatal_llvm_new_handler().

◆ fatal_system_new_handler()

static void fatal_system_new_handler ( void  )
static

Definition at line 120 of file llvmjit_error.cpp.

121 {
122  ereport(FATAL,
123  (errcode(ERRCODE_OUT_OF_MEMORY),
124  errmsg("out of memory"),
125  errdetail("while in LLVM")));
126 }

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

115 {
117 }
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 61 of file llvmjit_error.cpp.

62 {
63  if (fatal_new_handler_depth == 0)
64  {
65  old_new_handler = std::set_new_handler(fatal_system_new_handler);
66  llvm::install_bad_alloc_error_handler(fatal_llvm_new_handler);
67  llvm::install_fatal_error_handler(fatal_llvm_error_handler);
68  }
70 }
static std::new_handler old_new_handler
static void fatal_system_new_handler(void)

References fatal_llvm_error_handler(), fatal_llvm_new_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 92 of file llvmjit_error.cpp.

93 {
94  return fatal_new_handler_depth > 0;
95 }

References fatal_new_handler_depth.

Referenced by llvm_shutdown().

◆ llvm_leave_fatal_on_oom()

void llvm_leave_fatal_on_oom ( void  )

Definition at line 76 of file llvmjit_error.cpp.

77 {
79  if (fatal_new_handler_depth == 0)
80  {
81  std::set_new_handler(old_new_handler);
82  llvm::remove_bad_alloc_error_handler();
83  llvm::remove_fatal_error_handler();
84  }
85 }

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

103 {
104  if (fatal_new_handler_depth != 0)
105  {
106  std::set_new_handler(old_new_handler);
107  llvm::remove_bad_alloc_error_handler();
108  llvm::remove_fatal_error_handler();
109  }
111 }

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