diff options
author | 2023-08-02 22:26:34 +0200 | |
---|---|---|
committer | 2023-08-08 15:01:51 +0000 | |
commit | 1aa5d121d7eb21a96f42cfd396e56bf2acdca162 (patch) | |
tree | 116a50933b659cade5816cc1a8ea237e76e4c3f2 /libnativebridge/native_bridge.cc | |
parent | 473c5a01699e82723c936bfd47ceac9abee70e09 (diff) |
nativebridge: Add getTrampoline2 function to pass JNICallType
NativeBridge needs to know if JNI call is @CriticalNative, starting with
v7 getTrampoline2 is used in place of getTrampoline.
Bug: https://issuetracker.google.com/288392666
Test: art/libnativebridge/tests/runtests.sh --skip-target
Change-Id: I60a2fd6ab2fb9d19dda7bbdcbe09144797bd1d49
Diffstat (limited to 'libnativebridge/native_bridge.cc')
-rw-r--r-- | libnativebridge/native_bridge.cc | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/libnativebridge/native_bridge.cc b/libnativebridge/native_bridge.cc index fb13d62be0..aabdae6205 100644 --- a/libnativebridge/native_bridge.cc +++ b/libnativebridge/native_bridge.cc @@ -131,6 +131,8 @@ enum NativeBridgeImplementationVersion { RUNTIME_NAMESPACE_VERSION = 5, // The version with pre-zygote-fork hook to support app-zygotes. PRE_ZYGOTE_FORK_VERSION = 6, + // The version with critical_native support + CRITICAL_NATIVE_SUPPORT_VERSION = 7, }; // Whether we had an error at some point. @@ -569,10 +571,26 @@ void* NativeBridgeLoadLibrary(const char* libpath, int flag) { void* NativeBridgeGetTrampoline(void* handle, const char* name, const char* shorty, uint32_t len) { - if (NativeBridgeInitialized()) { + return NativeBridgeGetTrampoline2(handle, name, shorty, len, kJNICallTypeRegular); +} + +void* NativeBridgeGetTrampoline2( + void* handle, const char* name, const char* shorty, uint32_t len, JNICallType jni_call_type) { + if (!NativeBridgeInitialized()) { + return nullptr; + } + + // For version 1 isCompatibleWith is always true, even though the extensions + // are not supported, so we need to handle it separately. + if (callbacks != nullptr && callbacks->version == DEFAULT_VERSION) { return callbacks->getTrampoline(handle, name, shorty, len); } - return nullptr; + + if (isCompatibleWith(CRITICAL_NATIVE_SUPPORT_VERSION)) { + return callbacks->getTrampolineWithJNICallType(handle, name, shorty, len, jni_call_type); + } + + return callbacks->getTrampoline(handle, name, shorty, len); } bool NativeBridgeIsSupported(const char* libpath) { |