| 5 |
| #include <string> |
| 6 |
| 7 | #include <android/log.h> |
| 8 | #include "breakpad/src/client/linux/handler/exception_handler.h" |
| 9 | #include "breakpad/src/client/linux/handler/minidump_descriptor.h" |
| 10 |
| 11 |
| 12 | thread_local static char buf[PATH_MAX + 1]; |
| 13 |
| 14 | extern "C" JNIEXPORT jstring Java_org_telegram_messenger_Utilities_readlink(JNIEnv *env, jclass clazz, jstring path) { |
| 15 | const char *fileName = env->GetStringUTFChars(path, NULL); |
| 16 | ssize_t result = readlink(fileName, buf, PATH_MAX); |
| 17 | jstring value = 0; |
| 18 | if (result != -1) { |
| 19 | buf[result] = '\0'; |
| 20 | value = env->NewStringUTF(buf); |
| 21 | } |
| 22 | env->ReleaseStringUTFChars(path, fileName); |
| 23 | return value; |
| 24 | } |
| 25 |
| 26 | extern "C" JNIEXPORT jstring Java_org_telegram_messenger_Utilities_readlinkFd(JNIEnv *env, jclass clazz, int fd) { |
| 27 | std::string path = "/proc/self/fd/"; |
| 28 | path += fd; |
| 29 | ssize_t result = readlink(path.c_str(), buf, PATH_MAX); |
| 30 | jstring value = 0; |
| 31 | if (result != -1) { |
| 32 | buf[result] = '\0'; |
| 33 | value = env->NewStringUTF(buf); |
| 34 | } |
| 35 | return value; |
| 36 | } |
| 37 |
| 38 | bool dumpCallback(const google_breakpad::MinidumpDescriptor &descriptor, |
| 39 | void *context, |
| 40 | bool succeeded) { |
| 41 |
| 42 | __android_log_print(ANDROID_LOG_DEBUG, "tmessages", |
| 43 | "Wrote breakpad minidump at %s succeeded=%d\n", descriptor.path(), |
| 44 | succeeded); |
| 45 | return false; |
| 46 | } |
| 47 |
| 48 | extern "C" |
| 49 | JNIEXPORT void JNICALL |
| 50 | Java_org_telegram_messenger_Utilities_setupNativeCrashesListener(JNIEnv *env, jclass clazz, |
| 51 | jstring path) { |
| 52 | const char *dumpPath = (char *) env->GetStringUTFChars(path, NULL); |
| 53 | google_breakpad::MinidumpDescriptor descriptor(dumpPath); |
| 54 | new google_breakpad::ExceptionHandler(descriptor, NULL, dumpCallback, NULL, true, -1); |
| 55 | env->ReleaseStringUTFChars(path, dumpPath); |
| 56 | } |
| 57 |