1
0
Fork 0
mirror of https://github.com/VSadov/Satori.git synced 2025-06-09 17:44:48 +09:00

[android] Don't include JNI_OnLoad in libSystem.Security.Cryptography.Native.Android.a (#103231)

I'm working on a feature in .NET For Android which will allow us to link
all the native bits into a single shared library at application build
time.  In order to make it possible, no archive (`.a`) may contain any
`JNI_OnLoad` functions (called by `JavaVM` when initializing a Java
extension DSO), because our runtime already contains one and there Can
be Only One(tm).

`libSystem.Security.Cryptography.Native.Android` is currently the only
BCL support native library which contains `JNI_OnLoad` and thus it
prevents us from linking it into our runtime.  This PR changes things
a bit my moving the initialization code to a separate
function (`AndroidCryptoNative_InitLibraryOnLoad `) which remains in the `.a` archive and
can be called by `.NET For Android` runtime from its own `JNI_OnLoad` as
well as by the `libSystem.Security.Cryptography.Native.Android.so` from
its `JNI_OnLoad`, which this PR moves to a separate source file that is
compiled only into the shared version of the crypto support library.
This commit is contained in:
Marek Habersack 2024-07-09 13:39:09 +02:00 committed by GitHub
parent 5b5d7919a6
commit 048c8ed16f
Signed by: github
GPG key ID: B5690EEEBB952194
4 changed files with 18 additions and 4 deletions

View file

@ -33,7 +33,7 @@ set(NATIVECRYPTO_SOURCES
add_library(System.Security.Cryptography.Native.Android
SHARED
${NATIVECRYPTO_SOURCES}
${NATIVECRYPTO_SOURCES} pal_jni_onload.c
${VERSION_FILE_PATH}
)

View file

@ -689,11 +689,10 @@ int GetEnumAsInt(JNIEnv *env, jobject enumObj)
return value;
}
JNIEXPORT jint JNICALL
JNI_OnLoad(JavaVM *vm, void *reserved)
jint AndroidCryptoNative_InitLibraryOnLoad (JavaVM *vm, void *reserved)
{
(void)reserved;
LOG_INFO("JNI_OnLoad in pal_jni.c");
LOG_DEBUG("%s in %s", __PRETTY_FUNCTION__, __FILE__);
gJvm = vm;
JNIEnv* env = GetJNIEnv();

View file

@ -605,6 +605,11 @@ jfieldID GetField(JNIEnv *env, bool isStatic, jclass klass, const char* name, co
jfieldID GetOptionalField(JNIEnv *env, bool isStatic, jclass klass, const char* name, const char* sig) ARGS_NON_NULL_ALL;
JNIEnv* GetJNIEnv(void);
// This is supposed to be called by embedders who link the **static** archive of this library.
// The function must be called from the embedder's `JNI_OnLoad` function prior to using any
// APIs in this library.
jint AndroidCryptoNative_InitLibraryOnLoad (JavaVM *vm, void *reserved);
int GetEnumAsInt(JNIEnv *env, jobject enumObj) ARGS_NON_NULL_ALL;
void* xmalloc (size_t size) __mallocfunc __BIONIC_ALLOC_SIZE(1) __wur;

View file

@ -0,0 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#include "pal_jni.h"
JNIEXPORT jint JNICALL
JNI_OnLoad(JavaVM *vm, void *reserved)
{
return AndroidCryptoNative_InitLibraryOnLoad (vm, reserved);
}