Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5a2098af authored by Nicolas Geoffray's avatar Nicolas Geoffray Committed by android-build-merger
Browse files

Merge "Make the native bridge API a C API."

am: 108ab211

Change-Id: Ice7b64b90e449f0ee9ee4606d5ba3796f1dbaafc
parents d6542635 108ab211
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -17,6 +17,11 @@ cc_library {
        "liblog",
    ],

    stubs: {
        symbol_file: "libnativebridge.map.txt",
        versions: ["1"],
    },

    export_include_dirs: ["include"],

    cflags: [
+31 −25
Original line number Diff line number Diff line
@@ -17,12 +17,17 @@
#ifndef NATIVE_BRIDGE_H_
#define NATIVE_BRIDGE_H_

#include "jni.h"
#include <signal.h>
#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>

#include "jni.h"

#ifdef __cplusplus
namespace android {
extern "C" {
#endif  // __cplusplus

struct NativeBridgeRuntimeCallbacks;
struct NativeBridgeRuntimeValues;
@@ -32,11 +37,10 @@ struct NativeBridgeRuntimeValues;
// to the chain.
typedef bool (*NativeBridgeSignalHandlerFn)(int, siginfo_t*, void*);


// 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.
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
// of the process.
@@ -138,19 +142,17 @@ bool NativeBridgeInitAnonymousNamespace(const char* public_ns_sonames,
//
// Starting with v3, NativeBridge has two scenarios: with/without namespace.
// Should not use in non-namespace scenario.
native_bridge_namespace_t* NativeBridgeCreateNamespace(const char* name,
                                                       const char* ld_library_path,
                                                       const char* default_library_path,
                                                       uint64_t type,
                                                       const char* permitted_when_isolated_path,
                                                       native_bridge_namespace_t* parent_ns);
struct native_bridge_namespace_t* NativeBridgeCreateNamespace(
    const char* name, const char* ld_library_path, const char* default_library_path, uint64_t type,
    const char* permitted_when_isolated_path, struct native_bridge_namespace_t* parent_ns);

// Creates a link which shares some libraries from one namespace to another.
// NativeBridge's peer of android_link_namespaces() of dynamic linker.
//
// Starting with v3, NativeBridge has two scenarios: with/without namespace.
// 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);

// Load a shared library with namespace key that is supported by the native bridge.
@@ -159,10 +161,11 @@ bool NativeBridgeLinkNamespaces(native_bridge_namespace_t* from, native_bridge_n
//
// Starting with v3, NativeBridge has two scenarios: with/without namespace.
// 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
native_bridge_namespace_t* NativeBridgeGetVendorNamespace();
struct native_bridge_namespace_t* NativeBridgeGetVendorNamespace();

// Native bridge interfaces to runtime.
struct NativeBridgeCallbacks {
@@ -177,8 +180,8 @@ struct NativeBridgeCallbacks {
  //   runtime_cbs [IN] the pointer to NativeBridgeRuntimeCallbacks.
  // Returns:
  //   true if initialization was successful.
  bool (*initialize)(const NativeBridgeRuntimeCallbacks* runtime_cbs, const char* private_dir,
                     const char* instruction_set);
  bool (*initialize)(const struct NativeBridgeRuntimeCallbacks* runtime_cbs,
                     const char* private_dir, const char* instruction_set);

  // Load a shared library that is supported by the native bridge.
  //
@@ -314,12 +317,12 @@ struct NativeBridgeCallbacks {
  //
  // Starting with v3, NativeBridge has two scenarios: with/without namespace.
  // 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* default_library_path,
                                                       uint64_t type,
                                                       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.
  // NativeBridge's peer of android_link_namespaces() of dynamic linker.
@@ -334,8 +337,8 @@ struct NativeBridgeCallbacks {
  //
  // Starting with v3, NativeBridge has two scenarios: with/without namespace.
  // Should not use in non-namespace scenario.
  bool (*linkNamespaces)(native_bridge_namespace_t* from, native_bridge_namespace_t* to,
                         const char* shared_libs_sonames);
  bool (*linkNamespaces)(struct native_bridge_namespace_t* from,
                         struct native_bridge_namespace_t* to, const char* shared_libs_sonames);

  // Load a shared library within a namespace.
  // NativeBridge's peer of android_dlopen_ext() of dynamic linker, only supports namespace
@@ -350,7 +353,7 @@ struct NativeBridgeCallbacks {
  //
  // Starting with v3, NativeBridge has two scenarios: with/without namespace.
  // 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.
  // The vendor namespace is the namespace used to load vendor public libraries.
@@ -359,7 +362,7 @@ struct NativeBridgeCallbacks {
  //
  // Returns:
  //   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.
@@ -396,6 +399,9 @@ struct NativeBridgeRuntimeCallbacks {
                               uint32_t method_count);
};

};  // namespace android
#ifdef __cplusplus
}  // extern "C"
}  // namespace android
#endif  // __cplusplus

#endif  // NATIVE_BRIDGE_H_
+45 −0
Original line number 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:
    *;
};
+5 −1
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@

namespace android {

extern "C" {

// Environment values required by the apps running with native bridge.
struct NativeBridgeRuntimeValues {
    const char* os_arch;
@@ -626,4 +628,6 @@ void* NativeBridgeLoadLibraryExt(const char* libpath, int flag, native_bridge_na
  return nullptr;
}

};  // namespace android
}  // extern "C"

}  // namespace android
+11 −0
Original line number Diff line number Diff line
@@ -86,3 +86,14 @@ cc_test {
    ],
    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