summaryrefslogtreecommitdiff
path: root/libs/samba/src/main/cpp/jni.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/samba/src/main/cpp/jni.cpp')
-rw-r--r--libs/samba/src/main/cpp/jni.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/libs/samba/src/main/cpp/jni.cpp b/libs/samba/src/main/cpp/jni.cpp
index aac1d28..5a69dc5 100644
--- a/libs/samba/src/main/cpp/jni.cpp
+++ b/libs/samba/src/main/cpp/jni.cpp
@@ -79,6 +79,22 @@ void _abort_with_exception(const char* file, int line, JNIEnv* env) {
}
}
+JNIEnv* NonFatalAttachCurrentThread() {
+#ifdef ANDROID
+ JNIEnv* env;
+ auto ret = g_vm->AttachCurrentThread(&env, nullptr);
+ if (ret == JNI_OK)
+ return env;
+ return nullptr;
+#else
+ void* v_env;
+ auto ret = g_vm->AttachCurrentThread(&v_env, nullptr);
+ if (ret == JNI_OK)
+ return reinterpret_cast<JNIEnv*>(v_env);
+ return nullptr;
+#endif
+}
+
} // namespace internal
JNIEnv* AttachCurrentThread() {
@@ -99,6 +115,7 @@ JNIEnv* OnLoad(JavaVM* vm) {
void* v_env;
auto ret = vm->GetEnv(&v_env, JNI_VERSION);
ABORT_IF_NOT_OK(ret);
+ g_vm = vm;
return reinterpret_cast<JNIEnv*>(v_env);
}