summaryrefslogtreecommitdiff
path: root/jvmfwk/plugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2020-05-15 20:30:12 +0200
committerStephan Bergmann <sbergman@redhat.com>2020-05-15 23:29:12 +0200
commitdd372b444f1f1821048e197768d5095e6204a102 (patch)
tree894d128e3b9b0e0a3cf51d82bedec516a5775e63 /jvmfwk/plugins
parent649593b5232beade06d279981c045c6388f9163a (diff)
Avoid any false GCC -Wclobbered
...by moving the code that calls JNI_CreateJavaVM and the setjmp that it may longjmp to (from abort_handler that may be called from within JNI_CreateJavaVM) into its own small function. That way, no local variables in jfw_plugin_startJavaVirtualMachine should produce any such false "variable might be clobbered by ‘longjmp’ or ‘vfork’" GCC warnings any longer, and all the workarounds to silence such warnings can be removed. Change-Id: I6de134628e8efbf2d67fcd83a9cc2623b55762a7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94330 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'jvmfwk/plugins')
-rw-r--r--jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx69
1 files changed, 33 insertions, 36 deletions
diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
index 6397cda3c045..46f5cfba1281 100644
--- a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
+++ b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
@@ -200,6 +200,36 @@ extern "C" void JNICALL abort_handler()
}
}
+typedef jint JNICALL JNI_CreateVM_Type(JavaVM **, JNIEnv **, void *);
+
+int createJvm(
+ JNI_CreateVM_Type * pCreateJavaVM, JavaVM ** pJavaVM, JNIEnv ** ppEnv, JavaVMInitArgs * vm_args)
+{
+ /* We set a global flag which is used by the abort handler in order to
+ determine whether it is should use longjmp to get back into this function.
+ That is, the abort handler determines if it is on the same stack as this function
+ and then jumps back into this function.
+ */
+ g_bInGetJavaVM = 1;
+ jint err;
+ memset( jmp_jvm_abort, 0, sizeof(jmp_jvm_abort));
+ int jmpval= setjmp( jmp_jvm_abort );
+ /* If jmpval is not "0" then this point was reached by a longjmp in the
+ abort_handler, which was called indirectly by JNI_CreateVM.
+ */
+ if( jmpval == 0)
+ {
+ //returns negative number on failure
+ err= pCreateJavaVM(pJavaVM, ppEnv, vm_args);
+ g_bInGetJavaVM = 0;
+ }
+ else
+ // set err to a positive number, so as or recognize that an abort (longjmp)
+ //occurred
+ err= 1;
+ return err;
+}
+
/** helper function to check Java version requirements
This function checks if the Java version of the given VendorBase
@@ -587,12 +617,8 @@ javaPluginError jfw_plugin_startJavaVirtualMachine(
assert(pInfo != nullptr);
assert(ppVm != nullptr);
assert(ppEnv != nullptr);
- // unless guard is volatile the following warning occurs on gcc:
- // warning: variable 't' might be clobbered by `longjmp' or `vfork'
- volatile osl::MutexGuard guard(PluginMutex::get());
- // unless errorcode is volatile the following warning occurs on gcc:
- // warning: variable 'errorcode' might be clobbered by `longjmp' or `vfork'
- volatile javaPluginError errorcode = javaPluginError::NONE;
+ osl::MutexGuard guard(PluginMutex::get());
+ javaPluginError errorcode = javaPluginError::NONE;
#ifdef MACOSX
rtl::Reference<VendorBase> aVendorInfo = getJREInfoByPath( pInfo->sLocation );
if ( !aVendorInfo.is() || aVendorInfo->compareVersions( pInfo->sVersion ) < 0 )
@@ -644,7 +670,6 @@ javaPluginError jfw_plugin_startJavaVirtualMachine(
osl_setEnvironment(OUString("JAVA_HOME").pData, sPathLocation.pData);
#endif
- typedef jint JNICALL JNI_CreateVM_Type(JavaVM **, JNIEnv **, void *);
OUString sSymbolCreateJava("JNI_CreateJavaVM");
JNI_CreateVM_Type * pCreateJavaVM =
@@ -763,29 +788,8 @@ javaPluginError jfw_plugin_startJavaVirtualMachine(
vm_args.nOptions= options.size(); //TODO overflow
vm_args.ignoreUnrecognized= JNI_TRUE;
- /* We set a global flag which is used by the abort handler in order to
- determine whether it is should use longjmp to get back into this function.
- That is, the abort handler determines if it is on the same stack as this function
- and then jumps back into this function.
- */
- g_bInGetJavaVM = 1;
- jint err;
JavaVM * pJavaVM = nullptr;
- memset( jmp_jvm_abort, 0, sizeof(jmp_jvm_abort));
- int jmpval= setjmp( jmp_jvm_abort );
- /* If jmpval is not "0" then this point was reached by a longjmp in the
- abort_handler, which was called indirectly by JNI_CreateVM.
- */
- if( jmpval == 0)
- {
- //returns negative number on failure
- err= pCreateJavaVM(&pJavaVM, ppEnv, &vm_args);
- g_bInGetJavaVM = 0;
- }
- else
- // set err to a positive number, so as or recognize that an abort (longjmp)
- //occurred
- err= 1;
+ jint err = createJvm(pCreateJavaVM, &pJavaVM, ppEnv, &vm_args);
if(err != 0)
{
@@ -818,14 +822,7 @@ javaPluginError jfw_plugin_startJavaVirtualMachine(
#endif
return errorcode;
-#if defined __GNUC__ && !defined __clang__
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wclobbered"
-#endif
}
-#if defined __GNUC__ && !defined __clang__
-#pragma GCC diagnostic pop
-#endif
javaPluginError jfw_plugin_existJRE(const JavaInfo *pInfo, bool *exist)
{