Loading libnativebridge/Android.bp +5 −0 Original line number Original line Diff line number Diff line Loading @@ -17,6 +17,11 @@ cc_library { "liblog", "liblog", ], ], stubs: { symbol_file: "libnativebridge.map.txt", versions: ["1"], }, export_include_dirs: ["include"], export_include_dirs: ["include"], cflags: [ cflags: [ Loading libnativebridge/include/nativebridge/native_bridge.h +31 −25 Original line number Original line Diff line number Diff line Loading @@ -17,12 +17,17 @@ #ifndef NATIVE_BRIDGE_H_ #ifndef NATIVE_BRIDGE_H_ #define NATIVE_BRIDGE_H_ #define NATIVE_BRIDGE_H_ #include "jni.h" #include <signal.h> #include <signal.h> #include <stdbool.h> #include <stdint.h> #include <stdint.h> #include <sys/types.h> #include <sys/types.h> #include "jni.h" #ifdef __cplusplus namespace android { namespace android { extern "C" { #endif // __cplusplus struct NativeBridgeRuntimeCallbacks; struct NativeBridgeRuntimeCallbacks; struct NativeBridgeRuntimeValues; struct NativeBridgeRuntimeValues; Loading @@ -32,11 +37,10 @@ struct NativeBridgeRuntimeValues; // to the chain. // to the chain. typedef bool (*NativeBridgeSignalHandlerFn)(int, siginfo_t*, void*); typedef bool (*NativeBridgeSignalHandlerFn)(int, siginfo_t*, void*); // Open the native bridge, if any. Should be called by Runtime::Init(). A null library filename // Open the native bridge, if any. Should be called by Runtime::Init(). A null library filename // signals that we do not want to load a native bridge. // signals that we do not want to load a native bridge. bool LoadNativeBridge(const char* native_bridge_library_filename, bool LoadNativeBridge(const char* native_bridge_library_filename, const NativeBridgeRuntimeCallbacks* runtime_callbacks); const struct NativeBridgeRuntimeCallbacks* runtime_callbacks); // Quick check whether a native bridge will be needed. This is based off of the instruction set // Quick check whether a native bridge will be needed. This is based off of the instruction set // of the process. // of the process. Loading Loading @@ -138,19 +142,17 @@ bool NativeBridgeInitAnonymousNamespace(const char* public_ns_sonames, // // // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Should not use in non-namespace scenario. // Should not use in non-namespace scenario. native_bridge_namespace_t* NativeBridgeCreateNamespace(const char* name, struct native_bridge_namespace_t* NativeBridgeCreateNamespace( const char* ld_library_path, const char* name, const char* ld_library_path, const char* default_library_path, uint64_t type, const char* default_library_path, const char* permitted_when_isolated_path, struct native_bridge_namespace_t* parent_ns); uint64_t type, const char* permitted_when_isolated_path, native_bridge_namespace_t* parent_ns); // Creates a link which shares some libraries from one namespace to another. // Creates a link which shares some libraries from one namespace to another. // NativeBridge's peer of android_link_namespaces() of dynamic linker. // NativeBridge's peer of android_link_namespaces() of dynamic linker. // // // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Should not use in non-namespace scenario. // Should not use in non-namespace scenario. bool NativeBridgeLinkNamespaces(native_bridge_namespace_t* from, native_bridge_namespace_t* to, bool NativeBridgeLinkNamespaces(struct native_bridge_namespace_t* from, struct native_bridge_namespace_t* to, const char* shared_libs_sonames); const char* shared_libs_sonames); // Load a shared library with namespace key that is supported by the native bridge. // Load a shared library with namespace key that is supported by the native bridge. Loading @@ -159,10 +161,11 @@ bool NativeBridgeLinkNamespaces(native_bridge_namespace_t* from, native_bridge_n // // // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Use NativeBridgeLoadLibrary() instead in non-namespace scenario. // Use NativeBridgeLoadLibrary() instead in non-namespace scenario. void* NativeBridgeLoadLibraryExt(const char* libpath, int flag, native_bridge_namespace_t* ns); void* NativeBridgeLoadLibraryExt(const char* libpath, int flag, struct native_bridge_namespace_t* ns); // Returns vendor namespace if it is enabled for the device and null otherwise // Returns vendor namespace if it is enabled for the device and null otherwise native_bridge_namespace_t* NativeBridgeGetVendorNamespace(); struct native_bridge_namespace_t* NativeBridgeGetVendorNamespace(); // Native bridge interfaces to runtime. // Native bridge interfaces to runtime. struct NativeBridgeCallbacks { struct NativeBridgeCallbacks { Loading @@ -177,8 +180,8 @@ struct NativeBridgeCallbacks { // runtime_cbs [IN] the pointer to NativeBridgeRuntimeCallbacks. // runtime_cbs [IN] the pointer to NativeBridgeRuntimeCallbacks. // Returns: // Returns: // true if initialization was successful. // true if initialization was successful. bool (*initialize)(const NativeBridgeRuntimeCallbacks* runtime_cbs, const char* private_dir, bool (*initialize)(const struct NativeBridgeRuntimeCallbacks* runtime_cbs, const char* instruction_set); const char* private_dir, const char* instruction_set); // Load a shared library that is supported by the native bridge. // Load a shared library that is supported by the native bridge. // // Loading Loading @@ -314,12 +317,12 @@ struct NativeBridgeCallbacks { // // // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Should not use in non-namespace scenario. // Should not use in non-namespace scenario. native_bridge_namespace_t* (*createNamespace)(const char* name, struct native_bridge_namespace_t* (*createNamespace)(const char* name, const char* ld_library_path, const char* ld_library_path, const char* default_library_path, const char* default_library_path, uint64_t type, uint64_t type, const char* permitted_when_isolated_path, const char* permitted_when_isolated_path, native_bridge_namespace_t* parent_ns); struct native_bridge_namespace_t* parent_ns); // Creates a link which shares some libraries from one namespace to another. // Creates a link which shares some libraries from one namespace to another. // NativeBridge's peer of android_link_namespaces() of dynamic linker. // NativeBridge's peer of android_link_namespaces() of dynamic linker. Loading @@ -334,8 +337,8 @@ struct NativeBridgeCallbacks { // // // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Should not use in non-namespace scenario. // Should not use in non-namespace scenario. bool (*linkNamespaces)(native_bridge_namespace_t* from, native_bridge_namespace_t* to, bool (*linkNamespaces)(struct native_bridge_namespace_t* from, const char* shared_libs_sonames); struct native_bridge_namespace_t* to, const char* shared_libs_sonames); // Load a shared library within a namespace. // Load a shared library within a namespace. // NativeBridge's peer of android_dlopen_ext() of dynamic linker, only supports namespace // NativeBridge's peer of android_dlopen_ext() of dynamic linker, only supports namespace Loading @@ -350,7 +353,7 @@ struct NativeBridgeCallbacks { // // // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Use loadLibrary instead in non-namespace scenario. // Use loadLibrary instead in non-namespace scenario. void* (*loadLibraryExt)(const char* libpath, int flag, native_bridge_namespace_t* ns); void* (*loadLibraryExt)(const char* libpath, int flag, struct native_bridge_namespace_t* ns); // Get native bridge version of vendor namespace. // Get native bridge version of vendor namespace. // The vendor namespace is the namespace used to load vendor public libraries. // The vendor namespace is the namespace used to load vendor public libraries. Loading @@ -359,7 +362,7 @@ struct NativeBridgeCallbacks { // // // Returns: // Returns: // vendor namespace or null if it was not set up for the device // vendor namespace or null if it was not set up for the device native_bridge_namespace_t* (*getVendorNamespace)(); struct native_bridge_namespace_t* (*getVendorNamespace)(); }; }; // Runtime interfaces to native bridge. // Runtime interfaces to native bridge. Loading Loading @@ -396,6 +399,9 @@ struct NativeBridgeRuntimeCallbacks { uint32_t method_count); uint32_t method_count); }; }; }; // namespace android #ifdef __cplusplus } // extern "C" } // namespace android #endif // __cplusplus #endif // NATIVE_BRIDGE_H_ #endif // NATIVE_BRIDGE_H_ libnativebridge/libnativebridge.map.txt 0 → 100644 +45 −0 Original line number Original line Diff line number Diff line # # Copyright (C) 2019 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # TODO(b/122710865): Most of these uses come from libnativeloader, which should be bundled # together with libnativebridge in the APEX. Once this happens, prune this list. LIBNATIVEBRIDGE_1 { global: NativeBridgeIsSupported; NativeBridgeLoadLibrary; NativeBridgeUnloadLibrary; NativeBridgeGetError; NativeBridgeIsPathSupported; NativeBridgeCreateNamespace; NativeBridgeGetVendorNamespace; NativeBridgeLinkNamespaces; NativeBridgeLoadLibraryExt; NativeBridgeInitAnonymousNamespace; NativeBridgeInitialized; NativeBridgeGetTrampoline; LoadNativeBridge; PreInitializeNativeBridge; InitializeNativeBridge; NativeBridgeGetVersion; NativeBridgeGetSignalHandler; UnloadNativeBridge; NativeBridgeAvailable; NeedsNativeBridge; NativeBridgeError; NativeBridgeNameAcceptable; local: *; }; libnativebridge/native_bridge.cc +5 −1 Original line number Original line Diff line number Diff line Loading @@ -33,6 +33,8 @@ namespace android { namespace android { extern "C" { // Environment values required by the apps running with native bridge. // Environment values required by the apps running with native bridge. struct NativeBridgeRuntimeValues { struct NativeBridgeRuntimeValues { const char* os_arch; const char* os_arch; Loading Loading @@ -626,4 +628,6 @@ void* NativeBridgeLoadLibraryExt(const char* libpath, int flag, native_bridge_na return nullptr; return nullptr; } } }; // namespace android } // extern "C" } // namespace android libnativebridge/tests/Android.bp +11 −0 Original line number Original line Diff line number Diff line Loading @@ -86,3 +86,14 @@ cc_test { ], ], header_libs: ["libbase_headers"], header_libs: ["libbase_headers"], } } // Build the test for the C API. art_cc_test { name: "libnativebridge-api-tests", host_supported: true, test_per_src: true, srcs: [ "NativeBridgeApi.c", ], header_libs: ["libnativebridge-dummy-headers"], } Loading
libnativebridge/Android.bp +5 −0 Original line number Original line Diff line number Diff line Loading @@ -17,6 +17,11 @@ cc_library { "liblog", "liblog", ], ], stubs: { symbol_file: "libnativebridge.map.txt", versions: ["1"], }, export_include_dirs: ["include"], export_include_dirs: ["include"], cflags: [ cflags: [ Loading
libnativebridge/include/nativebridge/native_bridge.h +31 −25 Original line number Original line Diff line number Diff line Loading @@ -17,12 +17,17 @@ #ifndef NATIVE_BRIDGE_H_ #ifndef NATIVE_BRIDGE_H_ #define NATIVE_BRIDGE_H_ #define NATIVE_BRIDGE_H_ #include "jni.h" #include <signal.h> #include <signal.h> #include <stdbool.h> #include <stdint.h> #include <stdint.h> #include <sys/types.h> #include <sys/types.h> #include "jni.h" #ifdef __cplusplus namespace android { namespace android { extern "C" { #endif // __cplusplus struct NativeBridgeRuntimeCallbacks; struct NativeBridgeRuntimeCallbacks; struct NativeBridgeRuntimeValues; struct NativeBridgeRuntimeValues; Loading @@ -32,11 +37,10 @@ struct NativeBridgeRuntimeValues; // to the chain. // to the chain. typedef bool (*NativeBridgeSignalHandlerFn)(int, siginfo_t*, void*); typedef bool (*NativeBridgeSignalHandlerFn)(int, siginfo_t*, void*); // Open the native bridge, if any. Should be called by Runtime::Init(). A null library filename // Open the native bridge, if any. Should be called by Runtime::Init(). A null library filename // signals that we do not want to load a native bridge. // signals that we do not want to load a native bridge. bool LoadNativeBridge(const char* native_bridge_library_filename, bool LoadNativeBridge(const char* native_bridge_library_filename, const NativeBridgeRuntimeCallbacks* runtime_callbacks); const struct NativeBridgeRuntimeCallbacks* runtime_callbacks); // Quick check whether a native bridge will be needed. This is based off of the instruction set // Quick check whether a native bridge will be needed. This is based off of the instruction set // of the process. // of the process. Loading Loading @@ -138,19 +142,17 @@ bool NativeBridgeInitAnonymousNamespace(const char* public_ns_sonames, // // // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Should not use in non-namespace scenario. // Should not use in non-namespace scenario. native_bridge_namespace_t* NativeBridgeCreateNamespace(const char* name, struct native_bridge_namespace_t* NativeBridgeCreateNamespace( const char* ld_library_path, const char* name, const char* ld_library_path, const char* default_library_path, uint64_t type, const char* default_library_path, const char* permitted_when_isolated_path, struct native_bridge_namespace_t* parent_ns); uint64_t type, const char* permitted_when_isolated_path, native_bridge_namespace_t* parent_ns); // Creates a link which shares some libraries from one namespace to another. // Creates a link which shares some libraries from one namespace to another. // NativeBridge's peer of android_link_namespaces() of dynamic linker. // NativeBridge's peer of android_link_namespaces() of dynamic linker. // // // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Should not use in non-namespace scenario. // Should not use in non-namespace scenario. bool NativeBridgeLinkNamespaces(native_bridge_namespace_t* from, native_bridge_namespace_t* to, bool NativeBridgeLinkNamespaces(struct native_bridge_namespace_t* from, struct native_bridge_namespace_t* to, const char* shared_libs_sonames); const char* shared_libs_sonames); // Load a shared library with namespace key that is supported by the native bridge. // Load a shared library with namespace key that is supported by the native bridge. Loading @@ -159,10 +161,11 @@ bool NativeBridgeLinkNamespaces(native_bridge_namespace_t* from, native_bridge_n // // // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Use NativeBridgeLoadLibrary() instead in non-namespace scenario. // Use NativeBridgeLoadLibrary() instead in non-namespace scenario. void* NativeBridgeLoadLibraryExt(const char* libpath, int flag, native_bridge_namespace_t* ns); void* NativeBridgeLoadLibraryExt(const char* libpath, int flag, struct native_bridge_namespace_t* ns); // Returns vendor namespace if it is enabled for the device and null otherwise // Returns vendor namespace if it is enabled for the device and null otherwise native_bridge_namespace_t* NativeBridgeGetVendorNamespace(); struct native_bridge_namespace_t* NativeBridgeGetVendorNamespace(); // Native bridge interfaces to runtime. // Native bridge interfaces to runtime. struct NativeBridgeCallbacks { struct NativeBridgeCallbacks { Loading @@ -177,8 +180,8 @@ struct NativeBridgeCallbacks { // runtime_cbs [IN] the pointer to NativeBridgeRuntimeCallbacks. // runtime_cbs [IN] the pointer to NativeBridgeRuntimeCallbacks. // Returns: // Returns: // true if initialization was successful. // true if initialization was successful. bool (*initialize)(const NativeBridgeRuntimeCallbacks* runtime_cbs, const char* private_dir, bool (*initialize)(const struct NativeBridgeRuntimeCallbacks* runtime_cbs, const char* instruction_set); const char* private_dir, const char* instruction_set); // Load a shared library that is supported by the native bridge. // Load a shared library that is supported by the native bridge. // // Loading Loading @@ -314,12 +317,12 @@ struct NativeBridgeCallbacks { // // // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Should not use in non-namespace scenario. // Should not use in non-namespace scenario. native_bridge_namespace_t* (*createNamespace)(const char* name, struct native_bridge_namespace_t* (*createNamespace)(const char* name, const char* ld_library_path, const char* ld_library_path, const char* default_library_path, const char* default_library_path, uint64_t type, uint64_t type, const char* permitted_when_isolated_path, const char* permitted_when_isolated_path, native_bridge_namespace_t* parent_ns); struct native_bridge_namespace_t* parent_ns); // Creates a link which shares some libraries from one namespace to another. // Creates a link which shares some libraries from one namespace to another. // NativeBridge's peer of android_link_namespaces() of dynamic linker. // NativeBridge's peer of android_link_namespaces() of dynamic linker. Loading @@ -334,8 +337,8 @@ struct NativeBridgeCallbacks { // // // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Should not use in non-namespace scenario. // Should not use in non-namespace scenario. bool (*linkNamespaces)(native_bridge_namespace_t* from, native_bridge_namespace_t* to, bool (*linkNamespaces)(struct native_bridge_namespace_t* from, const char* shared_libs_sonames); struct native_bridge_namespace_t* to, const char* shared_libs_sonames); // Load a shared library within a namespace. // Load a shared library within a namespace. // NativeBridge's peer of android_dlopen_ext() of dynamic linker, only supports namespace // NativeBridge's peer of android_dlopen_ext() of dynamic linker, only supports namespace Loading @@ -350,7 +353,7 @@ struct NativeBridgeCallbacks { // // // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Starting with v3, NativeBridge has two scenarios: with/without namespace. // Use loadLibrary instead in non-namespace scenario. // Use loadLibrary instead in non-namespace scenario. void* (*loadLibraryExt)(const char* libpath, int flag, native_bridge_namespace_t* ns); void* (*loadLibraryExt)(const char* libpath, int flag, struct native_bridge_namespace_t* ns); // Get native bridge version of vendor namespace. // Get native bridge version of vendor namespace. // The vendor namespace is the namespace used to load vendor public libraries. // The vendor namespace is the namespace used to load vendor public libraries. Loading @@ -359,7 +362,7 @@ struct NativeBridgeCallbacks { // // // Returns: // Returns: // vendor namespace or null if it was not set up for the device // vendor namespace or null if it was not set up for the device native_bridge_namespace_t* (*getVendorNamespace)(); struct native_bridge_namespace_t* (*getVendorNamespace)(); }; }; // Runtime interfaces to native bridge. // Runtime interfaces to native bridge. Loading Loading @@ -396,6 +399,9 @@ struct NativeBridgeRuntimeCallbacks { uint32_t method_count); uint32_t method_count); }; }; }; // namespace android #ifdef __cplusplus } // extern "C" } // namespace android #endif // __cplusplus #endif // NATIVE_BRIDGE_H_ #endif // NATIVE_BRIDGE_H_
libnativebridge/libnativebridge.map.txt 0 → 100644 +45 −0 Original line number Original line Diff line number Diff line # # Copyright (C) 2019 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # TODO(b/122710865): Most of these uses come from libnativeloader, which should be bundled # together with libnativebridge in the APEX. Once this happens, prune this list. LIBNATIVEBRIDGE_1 { global: NativeBridgeIsSupported; NativeBridgeLoadLibrary; NativeBridgeUnloadLibrary; NativeBridgeGetError; NativeBridgeIsPathSupported; NativeBridgeCreateNamespace; NativeBridgeGetVendorNamespace; NativeBridgeLinkNamespaces; NativeBridgeLoadLibraryExt; NativeBridgeInitAnonymousNamespace; NativeBridgeInitialized; NativeBridgeGetTrampoline; LoadNativeBridge; PreInitializeNativeBridge; InitializeNativeBridge; NativeBridgeGetVersion; NativeBridgeGetSignalHandler; UnloadNativeBridge; NativeBridgeAvailable; NeedsNativeBridge; NativeBridgeError; NativeBridgeNameAcceptable; local: *; };
libnativebridge/native_bridge.cc +5 −1 Original line number Original line Diff line number Diff line Loading @@ -33,6 +33,8 @@ namespace android { namespace android { extern "C" { // Environment values required by the apps running with native bridge. // Environment values required by the apps running with native bridge. struct NativeBridgeRuntimeValues { struct NativeBridgeRuntimeValues { const char* os_arch; const char* os_arch; Loading Loading @@ -626,4 +628,6 @@ void* NativeBridgeLoadLibraryExt(const char* libpath, int flag, native_bridge_na return nullptr; return nullptr; } } }; // namespace android } // extern "C" } // namespace android
libnativebridge/tests/Android.bp +11 −0 Original line number Original line Diff line number Diff line Loading @@ -86,3 +86,14 @@ cc_test { ], ], header_libs: ["libbase_headers"], header_libs: ["libbase_headers"], } } // Build the test for the C API. art_cc_test { name: "libnativebridge-api-tests", host_supported: true, test_per_src: true, srcs: [ "NativeBridgeApi.c", ], header_libs: ["libnativebridge-dummy-headers"], }