[email protected] | 9fc4416 | 2012-01-23 22:56:41 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/android/jni_android.h" |
| 6 | |
avi | b30f240 | 2015-12-24 03:43:28 | [diff] [blame] | 7 | #include <stddef.h> |
erikchen | 011ad3f | 2018-01-26 17:54:55 | [diff] [blame] | 8 | #include <sys/prctl.h> |
avi | b30f240 | 2015-12-24 03:43:28 | [diff] [blame] | 9 | |
[email protected] | 96e7ade | 2011-12-05 14:42:08 | [diff] [blame] | 10 | #include <map> |
| 11 | |
Joshua Peraza | 7814da2 | 2018-07-10 21:37:50 | [diff] [blame] | 12 | #include "base/android/java_exception_reporter.h" |
[email protected] | 1b46a53 | 2012-05-23 05:59:49 | [diff] [blame] | 13 | #include "base/android/jni_string.h" |
Scott Violet | 4416579 | 2018-02-22 02:08:08 | [diff] [blame] | 14 | #include "base/debug/debugging_buildflags.h" |
[email protected] | 96e7ade | 2011-12-05 14:42:08 | [diff] [blame] | 15 | #include "base/lazy_instance.h" |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 16 | #include "base/logging.h" |
dskiba | a8c951e | 2016-10-25 23:39:11 | [diff] [blame] | 17 | #include "base/threading/thread_local.h" |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 18 | |
| 19 | namespace { |
[email protected] | 1b46a53 | 2012-05-23 05:59:49 | [diff] [blame] | 20 | using base::android::GetClass; |
[email protected] | c410a2cb | 2012-10-16 18:35:10 | [diff] [blame] | 21 | using base::android::MethodID; |
[email protected] | 1b46a53 | 2012-05-23 05:59:49 | [diff] [blame] | 22 | using base::android::ScopedJavaLocalRef; |
[email protected] | fe0f1ab | 2012-02-09 21:02:27 | [diff] [blame] | 23 | |
[email protected] | 995a3ff | 2012-09-17 06:15:10 | [diff] [blame] | 24 | JavaVM* g_jvm = NULL; |
scottmg | 5e65e3a | 2017-03-08 08:48:46 | [diff] [blame] | 25 | base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject>>::Leaky |
[email protected] | d30dd6e | 2014-08-21 16:37:32 | [diff] [blame] | 26 | g_class_loader = LAZY_INSTANCE_INITIALIZER; |
| 27 | jmethodID g_class_loader_load_class_method_id = 0; |
[email protected] | 96e7ade | 2011-12-05 14:42:08 | [diff] [blame] | 28 | |
erikchen | f7c8a0d | 2017-04-06 21:15:27 | [diff] [blame] | 29 | #if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS) |
dskiba | a8c951e | 2016-10-25 23:39:11 | [diff] [blame] | 30 | base::LazyInstance<base::ThreadLocalPointer<void>>::Leaky |
| 31 | g_stack_frame_pointer = LAZY_INSTANCE_INITIALIZER; |
| 32 | #endif |
| 33 | |
Xianzhu Wang | ab2f366 | 2018-02-09 22:02:26 | [diff] [blame] | 34 | bool g_fatal_exception_occurred = false; |
| 35 | |
[email protected] | 1b46a53 | 2012-05-23 05:59:49 | [diff] [blame] | 36 | } // namespace |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 37 | |
| 38 | namespace base { |
| 39 | namespace android { |
| 40 | |
| 41 | JNIEnv* AttachCurrentThread() { |
[email protected] | 7a3b0e4 | 2012-10-09 19:43:10 | [diff] [blame] | 42 | DCHECK(g_jvm); |
erikchen | 011ad3f | 2018-01-26 17:54:55 | [diff] [blame] | 43 | JNIEnv* env = nullptr; |
| 44 | jint ret = g_jvm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_2); |
| 45 | if (ret == JNI_EDETACHED || !env) { |
| 46 | JavaVMAttachArgs args; |
| 47 | args.version = JNI_VERSION_1_2; |
| 48 | args.group = nullptr; |
| 49 | |
| 50 | // 16 is the maximum size for thread names on Android. |
| 51 | char thread_name[16]; |
| 52 | int err = prctl(PR_GET_NAME, thread_name); |
| 53 | if (err < 0) { |
| 54 | DPLOG(ERROR) << "prctl(PR_GET_NAME)"; |
| 55 | args.name = nullptr; |
| 56 | } else { |
| 57 | args.name = thread_name; |
| 58 | } |
| 59 | |
| 60 | ret = g_jvm->AttachCurrentThread(&env, &args); |
| 61 | DCHECK_EQ(JNI_OK, ret); |
| 62 | } |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 63 | return env; |
| 64 | } |
| 65 | |
[email protected] | f3225bdb | 2014-06-20 00:38:19 | [diff] [blame] | 66 | JNIEnv* AttachCurrentThreadWithName(const std::string& thread_name) { |
| 67 | DCHECK(g_jvm); |
| 68 | JavaVMAttachArgs args; |
| 69 | args.version = JNI_VERSION_1_2; |
| 70 | args.name = thread_name.c_str(); |
| 71 | args.group = NULL; |
| 72 | JNIEnv* env = NULL; |
| 73 | jint ret = g_jvm->AttachCurrentThread(&env, &args); |
| 74 | DCHECK_EQ(JNI_OK, ret); |
| 75 | return env; |
| 76 | } |
| 77 | |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 78 | void DetachFromVM() { |
| 79 | // Ignore the return value, if the thread is not attached, DetachCurrentThread |
| 80 | // will fail. But it is ok as the native thread may never be attached. |
[email protected] | 691b200 | 2014-01-07 19:51:37 | [diff] [blame] | 81 | if (g_jvm) |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 82 | g_jvm->DetachCurrentThread(); |
| 83 | } |
| 84 | |
| 85 | void InitVM(JavaVM* vm) { |
michaelbai | 25ec25c | 2015-10-22 19:40:22 | [diff] [blame] | 86 | DCHECK(!g_jvm || g_jvm == vm); |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 87 | g_jvm = vm; |
| 88 | } |
| 89 | |
[email protected] | 2e94463 | 2013-08-21 17:59:42 | [diff] [blame] | 90 | bool IsVMInitialized() { |
| 91 | return g_jvm != NULL; |
| 92 | } |
| 93 | |
[email protected] | d30dd6e | 2014-08-21 16:37:32 | [diff] [blame] | 94 | void InitReplacementClassLoader(JNIEnv* env, |
| 95 | const JavaRef<jobject>& class_loader) { |
| 96 | DCHECK(g_class_loader.Get().is_null()); |
| 97 | DCHECK(!class_loader.is_null()); |
| 98 | |
| 99 | ScopedJavaLocalRef<jclass> class_loader_clazz = |
| 100 | GetClass(env, "java/lang/ClassLoader"); |
| 101 | CHECK(!ClearException(env)); |
| 102 | g_class_loader_load_class_method_id = |
| 103 | env->GetMethodID(class_loader_clazz.obj(), |
| 104 | "loadClass", |
| 105 | "(Ljava/lang/String;)Ljava/lang/Class;"); |
| 106 | CHECK(!ClearException(env)); |
| 107 | |
| 108 | DCHECK(env->IsInstanceOf(class_loader.obj(), class_loader_clazz.obj())); |
| 109 | g_class_loader.Get().Reset(class_loader); |
| 110 | } |
| 111 | |
[email protected] | fe0f1ab | 2012-02-09 21:02:27 | [diff] [blame] | 112 | ScopedJavaLocalRef<jclass> GetClass(JNIEnv* env, const char* class_name) { |
[email protected] | d30dd6e | 2014-08-21 16:37:32 | [diff] [blame] | 113 | jclass clazz; |
| 114 | if (!g_class_loader.Get().is_null()) { |
torne | c16354c | 2015-03-16 22:53:33 | [diff] [blame] | 115 | // ClassLoader.loadClass expects a classname with components separated by |
| 116 | // dots instead of the slashes that JNIEnv::FindClass expects. The JNI |
| 117 | // generator generates names with slashes, so we have to replace them here. |
| 118 | // TODO(torne): move to an approach where we always use ClassLoader except |
| 119 | // for the special case of base::android::GetClassLoader(), and change the |
| 120 | // JNI generator to generate dot-separated names. http://crbug.com/461773 |
| 121 | size_t bufsize = strlen(class_name) + 1; |
| 122 | char dotted_name[bufsize]; |
| 123 | memmove(dotted_name, class_name, bufsize); |
| 124 | for (size_t i = 0; i < bufsize; ++i) { |
| 125 | if (dotted_name[i] == '/') { |
| 126 | dotted_name[i] = '.'; |
| 127 | } |
| 128 | } |
| 129 | |
[email protected] | d30dd6e | 2014-08-21 16:37:32 | [diff] [blame] | 130 | clazz = static_cast<jclass>( |
| 131 | env->CallObjectMethod(g_class_loader.Get().obj(), |
| 132 | g_class_loader_load_class_method_id, |
torne | c16354c | 2015-03-16 22:53:33 | [diff] [blame] | 133 | ConvertUTF8ToJavaString(env, dotted_name).obj())); |
[email protected] | d30dd6e | 2014-08-21 16:37:32 | [diff] [blame] | 134 | } else { |
| 135 | clazz = env->FindClass(class_name); |
| 136 | } |
yfriedman | e524fe7 | 2016-05-05 19:51:38 | [diff] [blame] | 137 | if (ClearException(env) || !clazz) { |
| 138 | LOG(FATAL) << "Failed to find class " << class_name; |
| 139 | } |
[email protected] | c7c2b46 | 2013-04-10 02:44:55 | [diff] [blame] | 140 | return ScopedJavaLocalRef<jclass>(env, clazz); |
[email protected] | fe0f1ab | 2012-02-09 21:02:27 | [diff] [blame] | 141 | } |
| 142 | |
[email protected] | d30dd6e | 2014-08-21 16:37:32 | [diff] [blame] | 143 | jclass LazyGetClass( |
| 144 | JNIEnv* env, |
| 145 | const char* class_name, |
Oleh Prypin | 54f75931 | 2018-08-02 14:33:32 | [diff] [blame] | 146 | std::atomic<jclass>* atomic_class_id) { |
| 147 | const jclass value = std::atomic_load(atomic_class_id); |
[email protected] | d30dd6e | 2014-08-21 16:37:32 | [diff] [blame] | 148 | if (value) |
Oleh Prypin | 54f75931 | 2018-08-02 14:33:32 | [diff] [blame] | 149 | return value; |
[email protected] | d30dd6e | 2014-08-21 16:37:32 | [diff] [blame] | 150 | ScopedJavaGlobalRef<jclass> clazz; |
| 151 | clazz.Reset(GetClass(env, class_name)); |
Oleh Prypin | 54f75931 | 2018-08-02 14:33:32 | [diff] [blame] | 152 | jclass cas_result = nullptr; |
| 153 | if (std::atomic_compare_exchange_strong(atomic_class_id, &cas_result, |
| 154 | clazz.obj())) { |
[email protected] | d30dd6e | 2014-08-21 16:37:32 | [diff] [blame] | 155 | // We intentionally leak the global ref since we now storing it as a raw |
| 156 | // pointer in |atomic_class_id|. |
| 157 | return clazz.Release(); |
| 158 | } else { |
Oleh Prypin | 54f75931 | 2018-08-02 14:33:32 | [diff] [blame] | 159 | return cas_result; |
[email protected] | d30dd6e | 2014-08-21 16:37:32 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | |
[email protected] | c410a2cb | 2012-10-16 18:35:10 | [diff] [blame] | 163 | template<MethodID::Type type> |
| 164 | jmethodID MethodID::Get(JNIEnv* env, |
| 165 | jclass clazz, |
| 166 | const char* method_name, |
| 167 | const char* jni_signature) { |
Oleh Prypin | 54f75931 | 2018-08-02 14:33:32 | [diff] [blame] | 168 | auto get_method_ptr = type == MethodID::TYPE_STATIC ? |
| 169 | &JNIEnv::GetStaticMethodID : |
| 170 | &JNIEnv::GetMethodID; |
| 171 | jmethodID id = (env->*get_method_ptr)(clazz, method_name, jni_signature); |
yfriedman | e524fe7 | 2016-05-05 19:51:38 | [diff] [blame] | 172 | if (base::android::ClearException(env) || !id) { |
| 173 | LOG(FATAL) << "Failed to find " << |
| 174 | (type == TYPE_STATIC ? "static " : "") << |
| 175 | "method " << method_name << " " << jni_signature; |
| 176 | } |
[email protected] | c410a2cb | 2012-10-16 18:35:10 | [diff] [blame] | 177 | return id; |
[email protected] | fae37d6 | 2012-03-08 12:39:13 | [diff] [blame] | 178 | } |
| 179 | |
[email protected] | c410a2cb | 2012-10-16 18:35:10 | [diff] [blame] | 180 | // If |atomic_method_id| set, it'll return immediately. Otherwise, it'll call |
| 181 | // into ::Get() above. If there's a race, it's ok since the values are the same |
| 182 | // (and the duplicated effort will happen only once). |
| 183 | template<MethodID::Type type> |
| 184 | jmethodID MethodID::LazyGet(JNIEnv* env, |
[email protected] | 3764dddb | 2012-10-02 21:13:55 | [diff] [blame] | 185 | jclass clazz, |
| 186 | const char* method_name, |
[email protected] | c410a2cb | 2012-10-16 18:35:10 | [diff] [blame] | 187 | const char* jni_signature, |
Oleh Prypin | 54f75931 | 2018-08-02 14:33:32 | [diff] [blame] | 188 | std::atomic<jmethodID>* atomic_method_id) { |
| 189 | const jmethodID value = std::atomic_load(atomic_method_id); |
[email protected] | c410a2cb | 2012-10-16 18:35:10 | [diff] [blame] | 190 | if (value) |
Oleh Prypin | 54f75931 | 2018-08-02 14:33:32 | [diff] [blame] | 191 | return value; |
[email protected] | c410a2cb | 2012-10-16 18:35:10 | [diff] [blame] | 192 | jmethodID id = MethodID::Get<type>(env, clazz, method_name, jni_signature); |
Oleh Prypin | 54f75931 | 2018-08-02 14:33:32 | [diff] [blame] | 193 | std::atomic_store(atomic_method_id, id); |
[email protected] | c410a2cb | 2012-10-16 18:35:10 | [diff] [blame] | 194 | return id; |
[email protected] | fe0f1ab | 2012-02-09 21:02:27 | [diff] [blame] | 195 | } |
| 196 | |
[email protected] | c410a2cb | 2012-10-16 18:35:10 | [diff] [blame] | 197 | // Various template instantiations. |
| 198 | template jmethodID MethodID::Get<MethodID::TYPE_STATIC>( |
| 199 | JNIEnv* env, jclass clazz, const char* method_name, |
| 200 | const char* jni_signature); |
[email protected] | fae37d6 | 2012-03-08 12:39:13 | [diff] [blame] | 201 | |
[email protected] | c410a2cb | 2012-10-16 18:35:10 | [diff] [blame] | 202 | template jmethodID MethodID::Get<MethodID::TYPE_INSTANCE>( |
| 203 | JNIEnv* env, jclass clazz, const char* method_name, |
| 204 | const char* jni_signature); |
[email protected] | 3764dddb | 2012-10-02 21:13:55 | [diff] [blame] | 205 | |
[email protected] | c410a2cb | 2012-10-16 18:35:10 | [diff] [blame] | 206 | template jmethodID MethodID::LazyGet<MethodID::TYPE_STATIC>( |
| 207 | JNIEnv* env, jclass clazz, const char* method_name, |
Oleh Prypin | 54f75931 | 2018-08-02 14:33:32 | [diff] [blame] | 208 | const char* jni_signature, std::atomic<jmethodID>* atomic_method_id); |
[email protected] | fe0f1ab | 2012-02-09 21:02:27 | [diff] [blame] | 209 | |
[email protected] | c410a2cb | 2012-10-16 18:35:10 | [diff] [blame] | 210 | template jmethodID MethodID::LazyGet<MethodID::TYPE_INSTANCE>( |
| 211 | JNIEnv* env, jclass clazz, const char* method_name, |
Oleh Prypin | 54f75931 | 2018-08-02 14:33:32 | [diff] [blame] | 212 | const char* jni_signature, std::atomic<jmethodID>* atomic_method_id); |
[email protected] | fe0f1ab | 2012-02-09 21:02:27 | [diff] [blame] | 213 | |
[email protected] | fe0f1ab | 2012-02-09 21:02:27 | [diff] [blame] | 214 | bool HasException(JNIEnv* env) { |
| 215 | return env->ExceptionCheck() != JNI_FALSE; |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 216 | } |
| 217 | |
[email protected] | fe0f1ab | 2012-02-09 21:02:27 | [diff] [blame] | 218 | bool ClearException(JNIEnv* env) { |
| 219 | if (!HasException(env)) |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 220 | return false; |
[email protected] | 1b46a53 | 2012-05-23 05:59:49 | [diff] [blame] | 221 | env->ExceptionDescribe(); |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 222 | env->ExceptionClear(); |
| 223 | return true; |
| 224 | } |
| 225 | |
[email protected] | fe0f1ab | 2012-02-09 21:02:27 | [diff] [blame] | 226 | void CheckException(JNIEnv* env) { |
[email protected] | 909193c | 2014-06-28 01:58:04 | [diff] [blame] | 227 | if (!HasException(env)) |
| 228 | return; |
[email protected] | 1b46a53 | 2012-05-23 05:59:49 | [diff] [blame] | 229 | |
[email protected] | 1b46a53 | 2012-05-23 05:59:49 | [diff] [blame] | 230 | jthrowable java_throwable = env->ExceptionOccurred(); |
[email protected] | 909193c | 2014-06-28 01:58:04 | [diff] [blame] | 231 | if (java_throwable) { |
| 232 | // Clear the pending exception, since a local reference is now held. |
| 233 | env->ExceptionDescribe(); |
| 234 | env->ExceptionClear(); |
| 235 | |
Xianzhu Wang | ab2f366 | 2018-02-09 22:02:26 | [diff] [blame] | 236 | if (g_fatal_exception_occurred) { |
| 237 | // Another exception (probably OOM) occurred during GetJavaExceptionInfo. |
Joshua Peraza | 7814da2 | 2018-07-10 21:37:50 | [diff] [blame] | 238 | base::android::SetJavaException( |
Xianzhu Wang | ab2f366 | 2018-02-09 22:02:26 | [diff] [blame] | 239 | "Java OOM'ed in exception handling, check logcat"); |
| 240 | } else { |
| 241 | g_fatal_exception_occurred = true; |
Xianzhu Wang | ab2f366 | 2018-02-09 22:02:26 | [diff] [blame] | 242 | // RVO should avoid any extra copies of the exception string. |
Joshua Peraza | 7814da2 | 2018-07-10 21:37:50 | [diff] [blame] | 243 | base::android::SetJavaException( |
| 244 | GetJavaExceptionInfo(env, java_throwable).c_str()); |
Xianzhu Wang | ab2f366 | 2018-02-09 22:02:26 | [diff] [blame] | 245 | } |
[email protected] | fe0f1ab | 2012-02-09 21:02:27 | [diff] [blame] | 246 | } |
[email protected] | 1b46a53 | 2012-05-23 05:59:49 | [diff] [blame] | 247 | |
[email protected] | 1b46a53 | 2012-05-23 05:59:49 | [diff] [blame] | 248 | // Now, feel good about it and die. |
yfriedman | e524fe7 | 2016-05-05 19:51:38 | [diff] [blame] | 249 | LOG(FATAL) << "Please include Java exception stack in crash report"; |
[email protected] | fe0f1ab | 2012-02-09 21:02:27 | [diff] [blame] | 250 | } |
| 251 | |
cjhopman | 060e007 | 2015-05-06 21:37:48 | [diff] [blame] | 252 | std::string GetJavaExceptionInfo(JNIEnv* env, jthrowable java_throwable) { |
| 253 | ScopedJavaLocalRef<jclass> throwable_clazz = |
| 254 | GetClass(env, "java/lang/Throwable"); |
| 255 | jmethodID throwable_printstacktrace = |
| 256 | MethodID::Get<MethodID::TYPE_INSTANCE>( |
| 257 | env, throwable_clazz.obj(), "printStackTrace", |
| 258 | "(Ljava/io/PrintStream;)V"); |
| 259 | |
| 260 | // Create an instance of ByteArrayOutputStream. |
| 261 | ScopedJavaLocalRef<jclass> bytearray_output_stream_clazz = |
| 262 | GetClass(env, "java/io/ByteArrayOutputStream"); |
| 263 | jmethodID bytearray_output_stream_constructor = |
| 264 | MethodID::Get<MethodID::TYPE_INSTANCE>( |
| 265 | env, bytearray_output_stream_clazz.obj(), "<init>", "()V"); |
| 266 | jmethodID bytearray_output_stream_tostring = |
| 267 | MethodID::Get<MethodID::TYPE_INSTANCE>( |
| 268 | env, bytearray_output_stream_clazz.obj(), "toString", |
| 269 | "()Ljava/lang/String;"); |
| 270 | ScopedJavaLocalRef<jobject> bytearray_output_stream(env, |
| 271 | env->NewObject(bytearray_output_stream_clazz.obj(), |
| 272 | bytearray_output_stream_constructor)); |
Xianzhu Wang | ab2f366 | 2018-02-09 22:02:26 | [diff] [blame] | 273 | CheckException(env); |
cjhopman | 060e007 | 2015-05-06 21:37:48 | [diff] [blame] | 274 | |
| 275 | // Create an instance of PrintStream. |
| 276 | ScopedJavaLocalRef<jclass> printstream_clazz = |
| 277 | GetClass(env, "java/io/PrintStream"); |
| 278 | jmethodID printstream_constructor = |
| 279 | MethodID::Get<MethodID::TYPE_INSTANCE>( |
| 280 | env, printstream_clazz.obj(), "<init>", |
| 281 | "(Ljava/io/OutputStream;)V"); |
| 282 | ScopedJavaLocalRef<jobject> printstream(env, |
| 283 | env->NewObject(printstream_clazz.obj(), printstream_constructor, |
| 284 | bytearray_output_stream.obj())); |
Xianzhu Wang | ab2f366 | 2018-02-09 22:02:26 | [diff] [blame] | 285 | CheckException(env); |
cjhopman | 060e007 | 2015-05-06 21:37:48 | [diff] [blame] | 286 | |
| 287 | // Call Throwable.printStackTrace(PrintStream) |
| 288 | env->CallVoidMethod(java_throwable, throwable_printstacktrace, |
| 289 | printstream.obj()); |
Xianzhu Wang | ab2f366 | 2018-02-09 22:02:26 | [diff] [blame] | 290 | CheckException(env); |
cjhopman | 060e007 | 2015-05-06 21:37:48 | [diff] [blame] | 291 | |
| 292 | // Call ByteArrayOutputStream.toString() |
| 293 | ScopedJavaLocalRef<jstring> exception_string( |
| 294 | env, static_cast<jstring>( |
| 295 | env->CallObjectMethod(bytearray_output_stream.obj(), |
| 296 | bytearray_output_stream_tostring))); |
Xianzhu Wang | ab2f366 | 2018-02-09 22:02:26 | [diff] [blame] | 297 | CheckException(env); |
cjhopman | 060e007 | 2015-05-06 21:37:48 | [diff] [blame] | 298 | |
| 299 | return ConvertJavaStringToUTF8(exception_string); |
| 300 | } |
| 301 | |
erikchen | f7c8a0d | 2017-04-06 21:15:27 | [diff] [blame] | 302 | #if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS) |
dskiba | a8c951e | 2016-10-25 23:39:11 | [diff] [blame] | 303 | |
| 304 | JNIStackFrameSaver::JNIStackFrameSaver(void* current_fp) { |
| 305 | previous_fp_ = g_stack_frame_pointer.Pointer()->Get(); |
| 306 | g_stack_frame_pointer.Pointer()->Set(current_fp); |
| 307 | } |
| 308 | |
| 309 | JNIStackFrameSaver::~JNIStackFrameSaver() { |
| 310 | g_stack_frame_pointer.Pointer()->Set(previous_fp_); |
| 311 | } |
| 312 | |
| 313 | void* JNIStackFrameSaver::SavedFrame() { |
| 314 | return g_stack_frame_pointer.Pointer()->Get(); |
| 315 | } |
| 316 | |
erikchen | f7c8a0d | 2017-04-06 21:15:27 | [diff] [blame] | 317 | #endif // BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS) |
cjhopman | 060e007 | 2015-05-06 21:37:48 | [diff] [blame] | 318 | |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 319 | } // namespace android |
| 320 | } // namespace base |