1961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle/*
2961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle * Copyright (C) 2014 The Android Open Source Project
3961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle *
4961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle * Licensed under the Apache License, Version 2.0 (the "License");
5961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle * you may not use this file except in compliance with the License.
6961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle * You may obtain a copy of the License at
7961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle *
8961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle *      http://www.apache.org/licenses/LICENSE-2.0
9961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle *
10961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle * Unless required by applicable law or agreed to in writing, software
11961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle * distributed under the License is distributed on an "AS IS" BASIS,
12961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle * See the License for the specific language governing permissions and
14961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle * limitations under the License.
15961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle */
16961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle
17961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle#ifndef NATIVE_BRIDGE_H_
18961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle#define NATIVE_BRIDGE_H_
19961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle
20961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle#include "jni.h"
21a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe#include <signal.h>
22961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle#include <stdint.h>
23ab0da5a9a6860046619629b8e6b83692d35dff86jgu#include <sys/types.h>
24961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle
25961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravlenamespace android {
26961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle
27961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravlestruct NativeBridgeRuntimeCallbacks;
28ab0da5a9a6860046619629b8e6b83692d35dff86jgustruct NativeBridgeRuntimeValues;
29961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle
30a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe// Function pointer type for sigaction. This is mostly the signature of a signal handler, except
31a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe// for the return type. The runtime needs to know whether the signal was handled or should be given
32a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe// to the chain.
33a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampetypedef bool (*NativeBridgeSignalHandlerFn)(int, siginfo_t*, void*);
34a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe
35a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe
36035bd7541ed909344348b6a4e17a7ef01a434653Andreas Gampe// Open the native bridge, if any. Should be called by Runtime::Init(). A null library filename
37035bd7541ed909344348b6a4e17a7ef01a434653Andreas Gampe// signals that we do not want to load a native bridge.
38035bd7541ed909344348b6a4e17a7ef01a434653Andreas Gampebool LoadNativeBridge(const char* native_bridge_library_filename,
39035bd7541ed909344348b6a4e17a7ef01a434653Andreas Gampe                      const NativeBridgeRuntimeCallbacks* runtime_callbacks);
40961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle
41ab0da5a9a6860046619629b8e6b83692d35dff86jgu// Quick check whether a native bridge will be needed. This is based off of the instruction set
42ab0da5a9a6860046619629b8e6b83692d35dff86jgu// of the process.
43ab0da5a9a6860046619629b8e6b83692d35dff86jgubool NeedsNativeBridge(const char* instruction_set);
44ab0da5a9a6860046619629b8e6b83692d35dff86jgu
45ab0da5a9a6860046619629b8e6b83692d35dff86jgu// Do the early initialization part of the native bridge, if necessary. This should be done under
46ab0da5a9a6860046619629b8e6b83692d35dff86jgu// high privileges.
47f9d9e2a2d96559c3165405d572b08e260156074aCalin Juravlebool PreInitializeNativeBridge(const char* app_data_dir, const char* instruction_set);
48ab0da5a9a6860046619629b8e6b83692d35dff86jgu
49ab0da5a9a6860046619629b8e6b83692d35dff86jgu// Initialize the native bridge, if any. Should be called by Runtime::DidForkFromZygote. The JNIEnv*
50ab0da5a9a6860046619629b8e6b83692d35dff86jgu// will be used to modify the app environment for the bridge.
51ab0da5a9a6860046619629b8e6b83692d35dff86jgubool InitializeNativeBridge(JNIEnv* env, const char* instruction_set);
52035bd7541ed909344348b6a4e17a7ef01a434653Andreas Gampe
53035bd7541ed909344348b6a4e17a7ef01a434653Andreas Gampe// Unload the native bridge, if any. Should be called by Runtime::DidForkFromZygote.
54035bd7541ed909344348b6a4e17a7ef01a434653Andreas Gampevoid UnloadNativeBridge();
55035bd7541ed909344348b6a4e17a7ef01a434653Andreas Gampe
56035bd7541ed909344348b6a4e17a7ef01a434653Andreas Gampe// Check whether a native bridge is available (opened or initialized). Requires a prior call to
57035bd7541ed909344348b6a4e17a7ef01a434653Andreas Gampe// LoadNativeBridge.
58049249ce7addafaa0bd09480cd8858cd2c54138fAndreas Gampebool NativeBridgeAvailable();
59049249ce7addafaa0bd09480cd8858cd2c54138fAndreas Gampe
60035bd7541ed909344348b6a4e17a7ef01a434653Andreas Gampe// Check whether a native bridge is available (initialized). Requires a prior call to
61035bd7541ed909344348b6a4e17a7ef01a434653Andreas Gampe// LoadNativeBridge & InitializeNativeBridge.
62035bd7541ed909344348b6a4e17a7ef01a434653Andreas Gampebool NativeBridgeInitialized();
63035bd7541ed909344348b6a4e17a7ef01a434653Andreas Gampe
64961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle// Load a shared library that is supported by the native bridge.
65f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG//
66f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG// Starting with v3, NativeBridge has two scenarios: with/without namespace.
67f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG// Use NativeBridgeLoadLibraryExt() instead in namespace scenario.
68961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravlevoid* NativeBridgeLoadLibrary(const char* libpath, int flag);
69961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle
70961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle// Get a native bridge trampoline for specified native method.
71961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravlevoid* NativeBridgeGetTrampoline(void* handle, const char* name, const char* shorty, uint32_t len);
72961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle
73f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG// True if native library paths are valid and is for an ABI that is supported by native bridge.
74f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG// The *libpath* must point to a library.
75f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG//
76f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG// Starting with v3, NativeBridge has two scenarios: with/without namespace.
77f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG// Use NativeBridgeIsPathSupported() instead in namespace scenario.
78961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravlebool NativeBridgeIsSupported(const char* libpath);
79961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle
80a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe// Returns the version number of the native bridge. This information is available after a
81a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe// successful LoadNativeBridge() and before closing it, that is, as long as NativeBridgeAvailable()
82a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe// returns true. Returns 0 otherwise.
83a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampeuint32_t NativeBridgeGetVersion();
84a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe
85a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe// Returns a signal handler that the bridge would like to be managed. Only valid for a native
86a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe// bridge supporting the version 2 interface. Will return null if the bridge does not support
87a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe// version 2, or if it doesn't have a signal handler it wants to be known.
88a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas GampeNativeBridgeSignalHandlerFn NativeBridgeGetSignalHandler(int signal);
89a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe
90049249ce7addafaa0bd09480cd8858cd2c54138fAndreas Gampe// Returns whether we have seen a native bridge error. This could happen because the library
91049249ce7addafaa0bd09480cd8858cd2c54138fAndreas Gampe// was not found, rejected, could not be initialized and so on.
92049249ce7addafaa0bd09480cd8858cd2c54138fAndreas Gampe//
93049249ce7addafaa0bd09480cd8858cd2c54138fAndreas Gampe// This functionality is mainly for testing.
94049249ce7addafaa0bd09480cd8858cd2c54138fAndreas Gampebool NativeBridgeError();
95049249ce7addafaa0bd09480cd8858cd2c54138fAndreas Gampe
96049249ce7addafaa0bd09480cd8858cd2c54138fAndreas Gampe// Returns whether a given string is acceptable as a native bridge library filename.
97049249ce7addafaa0bd09480cd8858cd2c54138fAndreas Gampe//
98049249ce7addafaa0bd09480cd8858cd2c54138fAndreas Gampe// This functionality is exposed mainly for testing.
99049249ce7addafaa0bd09480cd8858cd2c54138fAndreas Gampebool NativeBridgeNameAcceptable(const char* native_bridge_library_filename);
100049249ce7addafaa0bd09480cd8858cd2c54138fAndreas Gampe
101f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG// Decrements the reference count on the dynamic library handler. If the reference count drops
102f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG// to zero then the dynamic library is unloaded.
103f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANGint NativeBridgeUnloadLibrary(void* handle);
104f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG
105f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG// Get last error message of native bridge when fail to load library or search symbol.
106f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG// This is reflection of dlerror() for native bridge.
107d836ab005a3fd70e477a01d4200483131a285c9aDimitry Ivanovconst char* NativeBridgeGetError();
108f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG
109f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANGstruct native_bridge_namespace_t;
110f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG
111f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG// True if native library paths are valid and is for an ABI that is supported by native bridge.
112f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG// Different from NativeBridgeIsSupported(), the *path* here must be a directory containing
113f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG// libraries of an ABI.
114f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG//
115f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG// Starting with v3, NativeBridge has two scenarios: with/without namespace.
116f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG// Use NativeBridgeIsSupported() instead in non-namespace scenario.
117f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANGbool NativeBridgeIsPathSupported(const char* path);
118f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG
119caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG// Initializes anonymous namespace.
120caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG// NativeBridge's peer of android_init_anonymous_namespace() of dynamic linker.
121caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG//
122caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG// The anonymous namespace is used in the case when a NativeBridge implementation
123caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG// cannot identify the caller of dlopen/dlsym which happens for the code not loaded
124caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG// by dynamic linker; for example calls from the mono-compiled code.
125f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG//
126f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG// Starting with v3, NativeBridge has two scenarios: with/without namespace.
127f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG// Should not use in non-namespace scenario.
128caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANGbool NativeBridgeInitAnonymousNamespace(const char* public_ns_sonames,
129caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG                                        const char* anon_ns_library_path);
130f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG
131caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG// Create new namespace in which native libraries will be loaded.
132caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG// NativeBridge's peer of android_create_namespace() of dynamic linker.
133caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG//
134caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG// The libraries in the namespace are searched by folowing order:
135caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG// 1. ld_library_path (Think of this as namespace-local LD_LIBRARY_PATH)
136caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG// 2. In directories specified by DT_RUNPATH of the "needed by" binary.
137caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG// 3. deault_library_path (This of this as namespace-local default library path)
138f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG//
139f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG// Starting with v3, NativeBridge has two scenarios: with/without namespace.
140f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG// Should not use in non-namespace scenario.
141f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANGnative_bridge_namespace_t* NativeBridgeCreateNamespace(const char* name,
142f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG                                                       const char* ld_library_path,
143f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG                                                       const char* default_library_path,
144f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG                                                       uint64_t type,
145f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG                                                       const char* permitted_when_isolated_path,
146f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG                                                       native_bridge_namespace_t* parent_ns);
147f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG
148caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG// Creates a link which shares some libraries from one namespace to another.
149caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG// NativeBridge's peer of android_link_namespaces() of dynamic linker.
150caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG//
151caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG// Starting with v3, NativeBridge has two scenarios: with/without namespace.
152caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG// Should not use in non-namespace scenario.
153caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANGbool NativeBridgeLinkNamespaces(native_bridge_namespace_t* from, native_bridge_namespace_t* to,
154caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG                                const char* shared_libs_sonames);
155caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG
156f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG// Load a shared library with namespace key that is supported by the native bridge.
157caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG// NativeBridge's peer of android_dlopen_ext() of dynamic linker, only supports namespace
158caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG// extension.
159f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG//
160f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG// Starting with v3, NativeBridge has two scenarios: with/without namespace.
161f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG// Use NativeBridgeLoadLibrary() instead in non-namespace scenario.
162f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANGvoid* NativeBridgeLoadLibraryExt(const char* libpath, int flag, native_bridge_namespace_t* ns);
163f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG
164af0264bbe9f5e1228eb8fb486fa3d0d8e6e8605eDimitry Ivanov// Returns vendor namespace if it is enabled for the device and null otherwise
165af0264bbe9f5e1228eb8fb486fa3d0d8e6e8605eDimitry Ivanovnative_bridge_namespace_t* NativeBridgeGetVendorNamespace();
166af0264bbe9f5e1228eb8fb486fa3d0d8e6e8605eDimitry Ivanov
167961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle// Native bridge interfaces to runtime.
168961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravlestruct NativeBridgeCallbacks {
169ab0da5a9a6860046619629b8e6b83692d35dff86jgu  // Version number of the interface.
170ab0da5a9a6860046619629b8e6b83692d35dff86jgu  uint32_t version;
171ab0da5a9a6860046619629b8e6b83692d35dff86jgu
172961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // Initialize native bridge. Native bridge's internal implementation must ensure MT safety and
173961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // that the native bridge is initialized only once. Thus it is OK to call this interface for an
174961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // already initialized native bridge.
175961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //
176961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // Parameters:
177961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //   runtime_cbs [IN] the pointer to NativeBridgeRuntimeCallbacks.
178961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // Returns:
179caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   true if initialization was successful.
180ab0da5a9a6860046619629b8e6b83692d35dff86jgu  bool (*initialize)(const NativeBridgeRuntimeCallbacks* runtime_cbs, const char* private_dir,
181ab0da5a9a6860046619629b8e6b83692d35dff86jgu                     const char* instruction_set);
182961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle
183961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // Load a shared library that is supported by the native bridge.
184961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //
185961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // Parameters:
186961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //   libpath [IN] path to the shared library
187961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //   flag [IN] the stardard RTLD_XXX defined in bionic dlfcn.h
188961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // Returns:
189961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //   The opaque handle of the shared library if sucessful, otherwise NULL
190f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  //
191f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Starting with v3, NativeBridge has two scenarios: with/without namespace.
192f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Use loadLibraryExt instead in namespace scenario.
193961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  void* (*loadLibrary)(const char* libpath, int flag);
194961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle
195961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // Get a native bridge trampoline for specified native method. The trampoline has same
196961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // sigature as the native method.
197961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //
198961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // Parameters:
199961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //   handle [IN] the handle returned from loadLibrary
200961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //   shorty [IN] short descriptor of native method
201961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //   len [IN] length of shorty
202961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // Returns:
203961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //   address of trampoline if successful, otherwise NULL
204961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  void* (*getTrampoline)(void* handle, const char* name, const char* shorty, uint32_t len);
205961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle
206961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // Check whether native library is valid and is for an ABI that is supported by native bridge.
207961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //
208961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // Parameters:
209961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //   libpath [IN] path to the shared library
210961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // Returns:
211961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //   TRUE if library is supported by native bridge, FALSE otherwise
212f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  //
213f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Starting with v3, NativeBridge has two scenarios: with/without namespace.
214f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Use isPathSupported instead in namespace scenario.
215961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  bool (*isSupported)(const char* libpath);
216ab0da5a9a6860046619629b8e6b83692d35dff86jgu
217ab0da5a9a6860046619629b8e6b83692d35dff86jgu  // Provide environment values required by the app running with native bridge according to the
218ab0da5a9a6860046619629b8e6b83692d35dff86jgu  // instruction set.
219ab0da5a9a6860046619629b8e6b83692d35dff86jgu  //
220ab0da5a9a6860046619629b8e6b83692d35dff86jgu  // Parameters:
221caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   instruction_set [IN] the instruction set of the app
222ab0da5a9a6860046619629b8e6b83692d35dff86jgu  // Returns:
223caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   NULL if not supported by native bridge.
224caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   Otherwise, return all environment values to be set after fork.
225ab0da5a9a6860046619629b8e6b83692d35dff86jgu  const struct NativeBridgeRuntimeValues* (*getAppEnv)(const char* instruction_set);
226a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe
227a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe  // Added callbacks in version 2.
228a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe
229a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe  // Check whether the bridge is compatible with the given version. A bridge may decide not to be
230a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe  // forwards- or backwards-compatible, and libnativebridge will then stop using it.
231a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe  //
232a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe  // Parameters:
233caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   bridge_version [IN] the version of libnativebridge.
234a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe  // Returns:
235caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   true if the native bridge supports the given version of libnativebridge.
236a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe  bool (*isCompatibleWith)(uint32_t bridge_version);
237a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe
238a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe  // A callback to retrieve a native bridge's signal handler for the specified signal. The runtime
239a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe  // will ensure that the signal handler is being called after the runtime's own handler, but before
240a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe  // all chained handlers. The native bridge should not try to install the handler by itself, as
241a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe  // that will potentially lead to cycles.
242a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe  //
243a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe  // Parameters:
244caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   signal [IN] the signal for which the handler is asked for. Currently, only SIGSEGV is
245a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe  //                 supported by the runtime.
246a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe  // Returns:
247caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   NULL if the native bridge doesn't use a handler or doesn't want it to be managed by the
248caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   runtime.
249caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   Otherwise, a pointer to the signal handler.
250a6ac9ce98bd38099a4e89010111d14e4d5fc190eAndreas Gampe  NativeBridgeSignalHandlerFn (*getSignalHandler)(int signal);
251f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG
252f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Added callbacks in version 3.
253f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG
254f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Decrements the reference count on the dynamic library handler. If the reference count drops
255f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // to zero then the dynamic library is unloaded.
256f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  //
257f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Parameters:
258caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   handle [IN] the handler of a dynamic library.
259f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  //
260f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Returns:
261f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  //   0 on success, and nonzero on error.
262f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  int (*unloadLibrary)(void* handle);
263f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG
264f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Dump the last failure message of native bridge when fail to load library or search symbol.
265f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  //
266f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Parameters:
267f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  //
268f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Returns:
269f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  //   A string describing the most recent error that occurred when load library
270f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  //   or lookup symbol via native bridge.
271d836ab005a3fd70e477a01d4200483131a285c9aDimitry Ivanov  const char* (*getError)();
272f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG
273f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Check whether library paths are supported by native bridge.
274f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  //
275f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Parameters:
276f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  //   library_path [IN] search paths for native libraries (directories separated by ':')
277f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Returns:
278f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  //   TRUE if libraries within search paths are supported by native bridge, FALSE otherwise
279f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  //
280f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Starting with v3, NativeBridge has two scenarios: with/without namespace.
281f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Use isSupported instead in non-namespace scenario.
282f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  bool (*isPathSupported)(const char* library_path);
283f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG
284caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  // Initializes anonymous namespace at native bridge side.
285caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  // NativeBridge's peer of android_init_anonymous_namespace() of dynamic linker.
286caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //
287caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  // The anonymous namespace is used in the case when a NativeBridge implementation
288caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  // cannot identify the caller of dlopen/dlsym which happens for the code not loaded
289caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  // by dynamic linker; for example calls from the mono-compiled code.
290f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  //
291f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Parameters:
292caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   public_ns_sonames [IN] the name of "public" libraries.
293caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   anon_ns_library_path [IN] the library search path of (anonymous) namespace.
294f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Returns:
295caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   true if the pass is ok.
296caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   Otherwise, false.
297f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  //
298f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Starting with v3, NativeBridge has two scenarios: with/without namespace.
299f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Should not use in non-namespace scenario.
300caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  bool (*initAnonymousNamespace)(const char* public_ns_sonames, const char* anon_ns_library_path);
301f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG
302caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  // Create new namespace in which native libraries will be loaded.
303caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  // NativeBridge's peer of android_create_namespace() of dynamic linker.
304f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  //
305f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Parameters:
306caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   name [IN] the name of the namespace.
307caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   ld_library_path [IN] the first set of library search paths of the namespace.
308caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   default_library_path [IN] the second set of library search path of the namespace.
309caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   type [IN] the attribute of the namespace.
310caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   permitted_when_isolated_path [IN] the permitted path for isolated namespace(if it is).
311caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   parent_ns [IN] the pointer of the parent namespace to be inherited from.
312f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Returns:
313caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   native_bridge_namespace_t* for created namespace or nullptr in the case of error.
314f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  //
315f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Starting with v3, NativeBridge has two scenarios: with/without namespace.
316f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Should not use in non-namespace scenario.
317f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  native_bridge_namespace_t* (*createNamespace)(const char* name,
318f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG                                                const char* ld_library_path,
319f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG                                                const char* default_library_path,
320f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG                                                uint64_t type,
321f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG                                                const char* permitted_when_isolated_path,
322f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG                                                native_bridge_namespace_t* parent_ns);
323f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG
324caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  // Creates a link which shares some libraries from one namespace to another.
325caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  // NativeBridge's peer of android_link_namespaces() of dynamic linker.
326caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //
327caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  // Parameters:
328caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   from [IN] the namespace where libraries are accessed.
329caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   to [IN] the namespace where libraries are loaded.
330caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   shared_libs_sonames [IN] the libraries to be shared.
331caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //
332caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  // Returns:
333caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //   Whether successed or not.
334caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  //
335caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  // Starting with v3, NativeBridge has two scenarios: with/without namespace.
336caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  // Should not use in non-namespace scenario.
337caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  bool (*linkNamespaces)(native_bridge_namespace_t* from, native_bridge_namespace_t* to,
338caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG                         const char* shared_libs_sonames);
339caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG
340f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Load a shared library within a namespace.
341caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  // NativeBridge's peer of android_dlopen_ext() of dynamic linker, only supports namespace
342caf7750f3f3d658512f5221ad72d1d3d19e0a55cZhenhua WANG  // extension.
343f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  //
344f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Parameters:
345f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  //   libpath [IN] path to the shared library
346f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  //   flag [IN] the stardard RTLD_XXX defined in bionic dlfcn.h
347f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  //   ns [IN] the pointer of the namespace in which the library should be loaded.
348f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Returns:
349f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  //   The opaque handle of the shared library if sucessful, otherwise NULL
350f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  //
351f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Starting with v3, NativeBridge has two scenarios: with/without namespace.
352f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  // Use loadLibrary instead in non-namespace scenario.
353f2804e59854c2c7e7d3d5b58f987e5ec5cdc5b66Zhenhua WANG  void* (*loadLibraryExt)(const char* libpath, int flag, native_bridge_namespace_t* ns);
354af0264bbe9f5e1228eb8fb486fa3d0d8e6e8605eDimitry Ivanov
355af0264bbe9f5e1228eb8fb486fa3d0d8e6e8605eDimitry Ivanov  // Get native bridge version of vendor namespace.
356af0264bbe9f5e1228eb8fb486fa3d0d8e6e8605eDimitry Ivanov  // The vendor namespace is the namespace used to load vendor public libraries.
357af0264bbe9f5e1228eb8fb486fa3d0d8e6e8605eDimitry Ivanov  // With O release this namespace can be different from the default namespace.
358af0264bbe9f5e1228eb8fb486fa3d0d8e6e8605eDimitry Ivanov  // For the devices without enable vendor namespaces this function should return null
359af0264bbe9f5e1228eb8fb486fa3d0d8e6e8605eDimitry Ivanov  //
360af0264bbe9f5e1228eb8fb486fa3d0d8e6e8605eDimitry Ivanov  // Returns:
361af0264bbe9f5e1228eb8fb486fa3d0d8e6e8605eDimitry Ivanov  //   vendor namespace or null if it was not set up for the device
362af0264bbe9f5e1228eb8fb486fa3d0d8e6e8605eDimitry Ivanov  native_bridge_namespace_t* (*getVendorNamespace)();
363961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle};
364961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle
365961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle// Runtime interfaces to native bridge.
366961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravlestruct NativeBridgeRuntimeCallbacks {
367961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // Get shorty of a Java method. The shorty is supposed to be persistent in memory.
368961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //
369961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // Parameters:
370961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //   env [IN] pointer to JNIenv.
371961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //   mid [IN] Java methodID.
372961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // Returns:
373961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //   short descriptor for method.
374961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  const char* (*getMethodShorty)(JNIEnv* env, jmethodID mid);
375961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle
376961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // Get number of native methods for specified class.
377961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //
378961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // Parameters:
379961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //   env [IN] pointer to JNIenv.
380961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //   clazz [IN] Java class object.
381961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // Returns:
382961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //   number of native methods.
383961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  uint32_t (*getNativeMethodCount)(JNIEnv* env, jclass clazz);
384961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle
385961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // Get at most 'method_count' native methods for specified class 'clazz'. Results are outputed
386961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // via 'methods' [OUT]. The signature pointer in JNINativeMethod is reused as the method shorty.
387961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //
388961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // Parameters:
389961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //   env [IN] pointer to JNIenv.
390961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //   clazz [IN] Java class object.
391961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //   methods [OUT] array of method with the name, shorty, and fnPtr.
392961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //   method_count [IN] max number of elements in methods.
393961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  // Returns:
394961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  //   number of method it actually wrote to methods.
395961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle  uint32_t (*getNativeMethods)(JNIEnv* env, jclass clazz, JNINativeMethod* methods,
396961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle                               uint32_t method_count);
397961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle};
398961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle
399961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle};  // namespace android
400961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle
401961ae12dea419ff0965f00e50dd16ef07181fba5Calin Juravle#endif  // NATIVE_BRIDGE_H_
402