aboutsummaryrefslogtreecommitdiff
path: root/src/backend/jit/llvm/llvmjit_error.cpp
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2021-09-13 18:07:19 -0700
committerAndres Freund <andres@anarazel.de>2021-09-13 18:15:28 -0700
commit4e86887e0922f20add67e2473c7baae8c7f05d5e (patch)
treebdfc08668a42c5fff3e173f0ac01132f32a28b2b /src/backend/jit/llvm/llvmjit_error.cpp
parent0d0bbee5e3ee2eabe3a1f6081cbc4226520764c0 (diff)
downloadpostgresql-4e86887e0922f20add67e2473c7baae8c7f05d5e.tar.gz
postgresql-4e86887e0922f20add67e2473c7baae8c7f05d5e.zip
jit: Do not try to shut down LLVM state in case of LLVM triggered errors.
If an allocation failed within LLVM it is not safe to call back into LLVM as LLVM is not generally safe against exceptions / stack-unwinding. Thus errors while in LLVM code are promoted to FATAL. However llvm_shutdown() did call back into LLVM even in such cases, while llvm_release_context() was careful not to do so. We cannot generally skip shutting down LLVM, as that can break profiling. But it's OK to do so if there was an error from within LLVM. Reported-By: Jelte Fennema <Jelte.Fennema@microsoft.com> Author: Andres Freund <andres@anarazel.de> Author: Justin Pryzby <pryzby@telsasoft.com> Discussion: https://postgr.es/m/AM5PR83MB0178C52CCA0A8DEA0207DC14F7FF9@AM5PR83MB0178.EURPRD83.prod.outlook.com Backpatch: 11-, where jit was introduced
Diffstat (limited to 'src/backend/jit/llvm/llvmjit_error.cpp')
-rw-r--r--src/backend/jit/llvm/llvmjit_error.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/backend/jit/llvm/llvmjit_error.cpp b/src/backend/jit/llvm/llvmjit_error.cpp
index 26bc828875e..daefb3e1fd9 100644
--- a/src/backend/jit/llvm/llvmjit_error.cpp
+++ b/src/backend/jit/llvm/llvmjit_error.cpp
@@ -84,6 +84,16 @@ llvm_leave_fatal_on_oom(void)
}
/*
+ * Are we currently in an fatal-on-oom section? Useful to skip cleanup in case
+ * of errors.
+ */
+bool
+llvm_in_fatal_on_oom(void)
+{
+ return fatal_new_handler_depth > 0;
+}
+
+/*
* Reset fatal error handling. This should only be called in error recovery
* loops like PostgresMain()'s.
*/