Skip to content

App crashes related to JNI's AttachToCurrentThread #7623

Description

@grendello

Android application type

Android for .NET (net6.0-android, etc.)

Affected platform version

All

Description

Native crashes reported by Google Play:

SIGABRT on Android 9

/__w/1/s/src/libraries/Native/Unix/System.Security.Cryptography.Native.Android/pal_jni.c:621 (GetJNIEnv): Unable to attach thread to JVM
#00  pc 0x000000000001cf76  /system/lib/libc.so (abort+58)
#01  pc 0x0000000000008b7b  /data/app/com.sequrix.app-IAFmw0oXJlue17PBOBPjYw==/lib/arm/libSystem.Security.Cryptography.Native.Android.so
#02  pc 0x0000000000008cd9  /data/app/com.sequrix.app-IAFmw0oXJlue17PBOBPjYw==/lib/arm/libSystem.Security.Cryptography.Native.Android.so
#03  pc 0x0000000000010747  /data/app/com.sequrix.app-IAFmw0oXJlue17PBOBPjYw==/lib/arm/libSystem.Security.Cryptography.Native.Android.so (AndroidCryptoNative_SSLStreamWrite+58)

SIGSEGV on Android 8

#00  pc 0x000000000001cbe0  /system/lib64/libc.so (strlen+16)
#01  pc 0x0000000000461040  /system/lib64/libart.so (art::Thread::Attach(char const, bool, _jobject, bool)+196)
#02  pc 0x000000000043d84c  /system/lib64/libart.so (art::Runtime::AttachCurrentThread(char const, bool, _jobject, bool)+84)
#03  pc 0x00000000002de424  /system/lib64/libart.so (art::JII::AttachCurrentThreadInternal(_JavaVM, _JNIEnv**, void, bool)+268)
#04  pc 0x000000000002164c  /data/app/com.sequrix.app-QbvZn4-G-Erqd6bOwoeXpA==/lib/arm64/libmonodroid.so (xamarin::android::internal::MonodroidRuntime::thread_start(_MonoProfiler, unsigned long)+56)
#05  pc 0x00000000000ab44c  /data/app/com.sequrix.app-QbvZn4-G-Erqd6bOwoeXpA==/lib/arm64/libmonosgen-2.0.so
#06  pc 0x00000000000b2640  /data/app/com.sequrix.app-QbvZn4-G-Erqd6bOwoeXpA==/lib/arm64/libmonosgen-2.0.so
#07  pc 0x00000000000b2390  /data/app/com.sequrix.app-QbvZn4-G-Erqd6bOwoeXpA==/lib/arm64/libmonosgen-2.0.so
#08  pc 0x0000000000066f34  /system/lib64/libc.so (__pthread_start(void)+36)
#09  pc 0x000000000001eb94  /system/lib64/libc.so (__start_thread+68)

Relevant information gathered from Discord.

SIGABRT due to abort() call here. Error unknown as of now.

SIGSEGV might be caused by invalid pointer passed to AttachCurrentThread, as its 2nd argument. Xamarin.Android passes nullptr there (as allowed by the API, it's a valid input), so the pointer should be correctly ignored by the Java/JNI code, and yet it crashes somewhere in here. strlen in the stack trace suggests one of the LOG statements referring to thread_name which might be the pointer with garbage data?

Steps to Reproduce

None so far

Did you find any workaround?

Nope

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: App RuntimeIssues in `libmonodroid.so`.possibly-staleIssues that are potentially no longer relevant.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions