xref: /aosp_15_r20/art/libnativebridge/tests/NativeBridgeTestCase7.cpp (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 // An implementation of the native-bridge interface for testing.
18 
19 #include "NativeBridge7CriticalNative_lib.h"
20 #include "nativebridge/native_bridge.h"
21 
22 // NativeBridgeCallbacks implementations
native_bridge7_initialize(const android::NativeBridgeRuntimeCallbacks *,const char *,const char *)23 extern "C" bool native_bridge7_initialize(
24     const android::NativeBridgeRuntimeCallbacks* /* art_cbs */,
25     const char* /* app_code_cache_dir */,
26     const char* /* isa */) {
27   return true;
28 }
29 
native_bridge7_loadLibrary(const char *,int)30 extern "C" void* native_bridge7_loadLibrary(const char* /* libpath */, int /* flag */) {
31   return nullptr;
32 }
33 
native_bridge7_getTrampoline(void *,const char *,const char *,uint32_t)34 extern "C" void* native_bridge7_getTrampoline(void* /* handle */,
35                                               const char* /* name */,
36                                               const char* /* shorty */,
37                                               uint32_t /* len */) {
38   android::SetLegacyGetTrampolineCalled();
39   return nullptr;
40 }
41 
native_bridge7_getTrampoline2(void *,const char *,const char *,uint32_t,android::JNICallType jni_call_type)42 extern "C" void* native_bridge7_getTrampoline2(void* /* handle */,
43                                                const char* /* name */,
44                                                const char* /* shorty */,
45                                                uint32_t /* len */,
46                                                android::JNICallType jni_call_type) {
47   android::SetGetTrampoline2Called(jni_call_type);
48   return nullptr;
49 }
50 
native_bridge7_getTrampolineForFunctionPointer(const void *,const char *,uint32_t,android::JNICallType jni_call_type)51 extern "C" void* native_bridge7_getTrampolineForFunctionPointer(
52     const void* /* method */,
53     const char* /* shorty */,
54     uint32_t /* len */,
55     android::JNICallType jni_call_type) {
56   android::SetGetTrampolineFnPtrCalled(jni_call_type);
57   return nullptr;
58 }
59 
native_bridge7_isSupported(const char *)60 extern "C" bool native_bridge7_isSupported(const char* /* libpath */) { return false; }
61 
native_bridge7_getAppEnv(const char *)62 extern "C" const struct android::NativeBridgeRuntimeValues* native_bridge7_getAppEnv(
63     const char* /* abi */) {
64   return nullptr;
65 }
66 
native_bridge7_isCompatibleWith(uint32_t version)67 extern "C" bool native_bridge7_isCompatibleWith(uint32_t version) {
68   // For testing, allow 1-7, but disallow 8+.
69   return version <= 7;
70 }
71 
native_bridge7_getSignalHandler(int)72 extern "C" android::NativeBridgeSignalHandlerFn native_bridge7_getSignalHandler(int /* signal */) {
73   return nullptr;
74 }
75 
native_bridge7_unloadLibrary(void *)76 extern "C" int native_bridge7_unloadLibrary(void* /* handle */) { return 0; }
77 
native_bridge7_getError()78 extern "C" const char* native_bridge7_getError() { return nullptr; }
79 
native_bridge7_isPathSupported(const char *)80 extern "C" bool native_bridge7_isPathSupported(const char* /* path */) { return true; }
81 
native_bridge7_createNamespace(const char *,const char *,const char *,uint64_t,const char *,android::native_bridge_namespace_t *)82 extern "C" android::native_bridge_namespace_t* native_bridge7_createNamespace(
83     const char* /* name */,
84     const char* /* ld_library_path */,
85     const char* /* default_library_path */,
86     uint64_t /* type */,
87     const char* /* permitted_when_isolated_path */,
88     android::native_bridge_namespace_t* /* parent_ns */) {
89   return nullptr;
90 }
91 
native_bridge7_linkNamespaces(android::native_bridge_namespace_t *,android::native_bridge_namespace_t *,const char *)92 extern "C" bool native_bridge7_linkNamespaces(android::native_bridge_namespace_t* /* from */,
93                                               android::native_bridge_namespace_t* /* to */,
94                                               const char* /* shared_libs_soname */) {
95   return true;
96 }
97 
native_bridge7_loadLibraryExt(const char *,int,android::native_bridge_namespace_t *)98 extern "C" void* native_bridge7_loadLibraryExt(const char* /* libpath */,
99                                                int /* flag */,
100                                                android::native_bridge_namespace_t* /* ns */) {
101   return nullptr;
102 }
103 
native_bridge7_getVendorNamespace()104 extern "C" android::native_bridge_namespace_t* native_bridge7_getVendorNamespace() {
105   return nullptr;
106 }
107 
native_bridge7_getExportedNamespace(const char *)108 extern "C" android::native_bridge_namespace_t* native_bridge7_getExportedNamespace(
109     const char* /* name */) {
110   return nullptr;
111 }
112 
native_bridge7_preZygoteFork()113 extern "C" void native_bridge7_preZygoteFork() {}
114 
115 android::NativeBridgeCallbacks NativeBridgeItf{
116     // v1
117     .version = 7,
118     .initialize = &native_bridge7_initialize,
119     .loadLibrary = &native_bridge7_loadLibrary,
120     .getTrampoline = &native_bridge7_getTrampoline,
121     .isSupported = &native_bridge7_isSupported,
122     .getAppEnv = &native_bridge7_getAppEnv,
123     // v2
124     .isCompatibleWith = &native_bridge7_isCompatibleWith,
125     .getSignalHandler = &native_bridge7_getSignalHandler,
126     // v3
127     .unloadLibrary = &native_bridge7_unloadLibrary,
128     .getError = &native_bridge7_getError,
129     .isPathSupported = &native_bridge7_isPathSupported,
130     .unused_initAnonymousNamespace = nullptr,
131     .createNamespace = &native_bridge7_createNamespace,
132     .linkNamespaces = &native_bridge7_linkNamespaces,
133     .loadLibraryExt = &native_bridge7_loadLibraryExt,
134     // v4
135     &native_bridge7_getVendorNamespace,
136     // v5
137     &native_bridge7_getExportedNamespace,
138     // v6
139     &native_bridge7_preZygoteFork,
140     // v7
141     &native_bridge7_getTrampoline2,
142     &native_bridge7_getTrampolineForFunctionPointer,
143 };
144