• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 "NativeBridge8IdentifyTrampolines_lib.h"
20 #include "nativebridge/native_bridge.h"
21 
22 // NativeBridgeCallbacks implementations
native_bridge8_initialize(const android::NativeBridgeRuntimeCallbacks *,const char *,const char *)23 extern "C" bool native_bridge8_initialize(
24     const android::NativeBridgeRuntimeCallbacks* /* art_cbs */,
25     const char* /* app_code_cache_dir */,
26     const char* /* isa */) {
27   return true;
28 }
29 
native_bridge8_loadLibrary(const char *,int)30 extern "C" void* native_bridge8_loadLibrary(const char* /* libpath */, int /* flag */) {
31   return nullptr;
32 }
33 
native_bridge8_getTrampoline(void *,const char *,const char *,uint32_t)34 extern "C" void* native_bridge8_getTrampoline(void* /* handle */,
35                                               const char* /* name */,
36                                               const char* /* shorty */,
37                                               uint32_t /* len */) {
38   return nullptr;
39 }
40 
native_bridge8_getTrampoline2(void *,const char *,const char *,uint32_t,android::JNICallType)41 extern "C" void* native_bridge8_getTrampoline2(void* /* handle */,
42                                                const char* /* name */,
43                                                const char* /* shorty */,
44                                                uint32_t /* len */,
45                                                android::JNICallType /* jni_call_type */) {
46   return nullptr;
47 }
48 
native_bridge8_getTrampolineForFunctionPointer(const void *,const char *,uint32_t,android::JNICallType)49 extern "C" void* native_bridge8_getTrampolineForFunctionPointer(
50     const void* /* method */,
51     const char* /* shorty */,
52     uint32_t /* len */,
53     android::JNICallType /* jni_call_type */) {
54   return nullptr;
55 }
56 
native_bridge8_isSupported(const char *)57 extern "C" bool native_bridge8_isSupported(const char* /* libpath */) { return false; }
58 
native_bridge8_getAppEnv(const char *)59 extern "C" const struct android::NativeBridgeRuntimeValues* native_bridge8_getAppEnv(
60     const char* /* abi */) {
61   return nullptr;
62 }
63 
native_bridge8_isCompatibleWith(uint32_t version)64 extern "C" bool native_bridge8_isCompatibleWith(uint32_t version) {
65   // For testing, allow 1-8, but disallow 9+.
66   return version <= 8;
67 }
68 
native_bridge8_getSignalHandler(int)69 extern "C" android::NativeBridgeSignalHandlerFn native_bridge8_getSignalHandler(int /* signal */) {
70   return nullptr;
71 }
72 
native_bridge8_unloadLibrary(void *)73 extern "C" int native_bridge8_unloadLibrary(void* /* handle */) { return 0; }
74 
native_bridge8_getError()75 extern "C" const char* native_bridge8_getError() { return nullptr; }
76 
native_bridge8_isPathSupported(const char *)77 extern "C" bool native_bridge8_isPathSupported(const char* /* path */) { return true; }
78 
native_bridge8_createNamespace(const char *,const char *,const char *,uint64_t,const char *,android::native_bridge_namespace_t *)79 extern "C" android::native_bridge_namespace_t* native_bridge8_createNamespace(
80     const char* /* name */,
81     const char* /* ld_library_path */,
82     const char* /* default_library_path */,
83     uint64_t /* type */,
84     const char* /* permitted_when_isolated_path */,
85     android::native_bridge_namespace_t* /* parent_ns */) {
86   return nullptr;
87 }
88 
native_bridge8_linkNamespaces(android::native_bridge_namespace_t *,android::native_bridge_namespace_t *,const char *)89 extern "C" bool native_bridge8_linkNamespaces(android::native_bridge_namespace_t* /* from */,
90                                               android::native_bridge_namespace_t* /* to */,
91                                               const char* /* shared_libs_soname */) {
92   return true;
93 }
94 
native_bridge8_loadLibraryExt(const char *,int,android::native_bridge_namespace_t *)95 extern "C" void* native_bridge8_loadLibraryExt(const char* /* libpath */,
96                                                int /* flag */,
97                                                android::native_bridge_namespace_t* /* ns */) {
98   return nullptr;
99 }
100 
native_bridge8_getVendorNamespace()101 extern "C" android::native_bridge_namespace_t* native_bridge8_getVendorNamespace() {
102   return nullptr;
103 }
104 
native_bridge8_getExportedNamespace(const char *)105 extern "C" android::native_bridge_namespace_t* native_bridge8_getExportedNamespace(
106     const char* /* name */) {
107   return nullptr;
108 }
109 
native_bridge8_isNativeBridgeFunctionPointer(const void * ptr)110 extern "C" bool native_bridge8_isNativeBridgeFunctionPointer(const void* ptr) {
111   android::SetIsNativeBridgeFunctionPointerCalledFor(ptr);
112   return true;
113 }
114 
native_bridge8_preZygoteFork()115 extern "C" void native_bridge8_preZygoteFork() {}
116 
117 android::NativeBridgeCallbacks NativeBridgeItf{
118     // v1
119     .version = 8,
120     .initialize = &native_bridge8_initialize,
121     .loadLibrary = &native_bridge8_loadLibrary,
122     .getTrampoline = &native_bridge8_getTrampoline,
123     .isSupported = &native_bridge8_isSupported,
124     .getAppEnv = &native_bridge8_getAppEnv,
125     // v2
126     .isCompatibleWith = &native_bridge8_isCompatibleWith,
127     .getSignalHandler = &native_bridge8_getSignalHandler,
128     // v3
129     .unloadLibrary = &native_bridge8_unloadLibrary,
130     .getError = &native_bridge8_getError,
131     .isPathSupported = &native_bridge8_isPathSupported,
132     .unused_initAnonymousNamespace = nullptr,
133     .createNamespace = &native_bridge8_createNamespace,
134     .linkNamespaces = &native_bridge8_linkNamespaces,
135     .loadLibraryExt = &native_bridge8_loadLibraryExt,
136     // v4
137     &native_bridge8_getVendorNamespace,
138     // v5
139     &native_bridge8_getExportedNamespace,
140     // v6
141     &native_bridge8_preZygoteFork,
142     // v7
143     &native_bridge8_getTrampoline2,
144     &native_bridge8_getTrampolineForFunctionPointer,
145     // v8
146     &native_bridge8_isNativeBridgeFunctionPointer,
147 };
148