diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
commit | 59203c63bb777a3bacec32fb8830fba33540e809 (patch) | |
tree | 58298e711c0ff0575818c30485b44a2f21bf28a0 /widget/android/jni/Utils.cpp | |
parent | Adding upstream version 126.0.1. (diff) | |
download | firefox-59203c63bb777a3bacec32fb8830fba33540e809.tar.xz firefox-59203c63bb777a3bacec32fb8830fba33540e809.zip |
Adding upstream version 127.0.upstream/127.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'widget/android/jni/Utils.cpp')
-rw-r--r-- | widget/android/jni/Utils.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/widget/android/jni/Utils.cpp b/widget/android/jni/Utils.cpp index 8d3800fd03..78e1ab647a 100644 --- a/widget/android/jni/Utils.cpp +++ b/widget/android/jni/Utils.cpp @@ -9,6 +9,7 @@ #include <android/log.h> #include <pthread.h> +#include <sys/prctl.h> #include "mozilla/Assertions.h" #include "mozilla/java/GeckoAppShellWrappers.h" @@ -164,10 +165,20 @@ JNIEnv* GetEnvForThread() { return env; } + // By default the VM has a nasty habit of overwriting our lovely + // thread names with "Thread-<n>" making them hard to identify in a debugger, + // so we pass the name in AttachArgs below to prevent that from happening. + // PR_GET_NAME requires a 16 byte buffer: https://linux.die.net/man/2/prctl. + // JNI_VERSION_1_4 is required for NewDirectByteBuffer. + char threadName[16] = {'\0'}; + prctl(PR_GET_NAME, threadName); + JavaVMAttachArgs attachArgs{ + .version = JNI_VERSION_1_4, .name = threadName, .group = nullptr}; + // We don't have a saved JNIEnv, so try to get one. // AttachCurrentThread() does the same thing as GetEnv() when a thread is // already attached, so we don't have to call GetEnv() at all. - if (!sJavaVM->AttachCurrentThread(&env, nullptr)) { + if (!sJavaVM->AttachCurrentThread(&env, &attachArgs)) { MOZ_ASSERT(env); MOZ_ALWAYS_TRUE(!pthread_setspecific(sThreadEnvKey, env)); return env; |