From 1aa5d121d7eb21a96f42cfd396e56bf2acdca162 Mon Sep 17 00:00:00 2001 From: dimitry Date: Wed, 2 Aug 2023 22:26:34 +0200 Subject: 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 --- libnativebridge/native_bridge.cc | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'libnativebridge/native_bridge.cc') 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) { -- cgit v1.2.3-59-g8ed1b