OSDN Git Service

Enable native bridge
authorChih-Wei Huang <cwhuang@linux.org.tw>
Wed, 30 Sep 2015 10:07:42 +0000 (18:07 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Thu, 5 May 2016 18:17:11 +0000 (02:17 +0800)
Add the library libnb and script to support the arm translator.

BoardConfig.mk
device.mk
nativebridge/Android.mk [new file with mode: 0644]
nativebridge/bin/enable_nativebridge [new file with mode: 0644]
nativebridge/lib/arm/cpuinfo [new file with mode: 0644]
nativebridge/lib64/arm64/cpuinfo [new file with mode: 0644]
nativebridge/lib64/arm64/cpuinfo.64in32mode [new file with mode: 0644]
nativebridge/nativebridge.mk [new file with mode: 0644]
nativebridge/src/libnb.cpp [new file with mode: 0644]

index b46d85c..81867e3 100644 (file)
@@ -51,6 +51,8 @@ BUILD_EMULATOR_GPS_MODULE ?= false
 BUILD_EMULATOR_LIGHTS_MODULE ?= false
 BUILD_EMULATOR_SENSORS_MODULE ?= false
 
+BUILD_ARM_FOR_X86 := $(WITH_NATIVE_BRIDGE)
+
 BOARD_USE_LIBVA_INTEL_DRIVER := true
 BOARD_USE_LIBVA := true
 BOARD_USE_LIBMIX := true
index f60b5c4..559a3cb 100644 (file)
--- a/device.mk
+++ b/device.mk
@@ -103,5 +103,5 @@ $(call inherit-product,frameworks/native/build/tablet-10in-xhdpi-2048-dalvik-hea
 # Get GMS
 $(call inherit-product-if-exists,vendor/google/products/gms.mk)
 
-# Get Arm translator
-$(call inherit-product-if-exists,vendor/intel/houdini/houdini.mk)
+# Get native bridge settings
+$(call inherit-product-if-exists,$(LOCAL_PATH)/nativebridge/nativebridge.mk)
diff --git a/nativebridge/Android.mk b/nativebridge/Android.mk
new file mode 100644 (file)
index 0000000..e24dda5
--- /dev/null
@@ -0,0 +1,22 @@
+#
+# Copyright (C) 2015 The Android-x86 Open Source Project
+#
+# Licensed under the GNU General Public License Version 2 or later.
+# You may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.gnu.org/licenses/gpl.html
+#
+
+LOCAL_PATH := $(my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := libnb
+LOCAL_SRC_FILES := src/libnb.cpp
+LOCAL_CFLAGS := -Werror -Wall
+LOCAL_CPPFLAGS := -std=c++11
+LOCAL_SHARED_LIBRARIES := libdl liblog
+LOCAL_MULTILIB := both
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/nativebridge/bin/enable_nativebridge b/nativebridge/bin/enable_nativebridge
new file mode 100644 (file)
index 0000000..ef00891
--- /dev/null
@@ -0,0 +1,73 @@
+#!/system/bin/sh
+
+PATH=/system/bin:/system/xbin
+
+houdini_bin=0
+dest_dir=/system/lib$1/arm$1
+binfmt_misc_dir=/proc/sys/fs/binfmt_misc
+
+cd $dest_dir
+
+if [ ! -s libhoudini.so ]; then
+       if touch .dl_houdini; then
+               rm -f .dl_houdini
+       else
+               cd .. && cp -a arm$1 /data/local/tmp
+               mount -t tmpfs tmpfs arm$1 && cd arm$1 &&
+                       cp -a /data/local/tmp/arm$1/* . && rm -rf /data/local/tmp/arm$1
+       fi
+fi
+
+cd /data/local/tmp
+while [ ! -s $dest_dir/libhoudini.so ]; do
+       while [ "$(getprop net.dns1)" = "" ]; do
+               sleep 10
+       done
+       if [ -z "$1" ]; then
+               [ "`uname -m`" = "x86_64" ] && url=http://goo.gl/Xl1str || url=http://goo.gl/PA2qZ7
+       else
+               url=http://goo.gl/L00S7l
+       fi
+       wget $url -cO houdini.tgz &&
+               bzcat houdini.tgz | tar xvf - -C $dest_dir && rm -f houdini.tgz && break
+       rm -f houdini.tgz
+       sleep 30
+done
+
+
+# if you don't see the files 'register' and 'status' in /proc/sys/fs/binfmt_misc
+# then run the following command:
+# mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
+
+# this is to add the supported binary formats via binfmt_misc
+
+if [ ! -e $binfmt_misc_dir/register ]; then
+       mount -t binfmt_misc none $binfmt_misc_dir
+fi
+
+cd $binfmt_misc_dir
+if [ -e register ]; then
+       # register Houdini for arm binaries
+       if [ -z "$1" ]; then
+               echo ':arm_exe:M::\\x7f\\x45\\x4c\\x46\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x28::'"$dest_dir/houdini:P" > register
+               echo ':arm_dyn:M::\\x7f\\x45\\x4c\\x46\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x03\\x00\\x28::'"$dest_dir/houdini:P" > register
+       else
+               echo ':arm64_exe:M::\\x7f\\x45\\x4c\\x46\\x02\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\xb7::'"$dest_dir/houdini64:P" > register
+               echo ':arm64_dyn:M::\\x7f\\x45\\x4c\\x46\\x02\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x03\\x00\\xb7::'"$dest_dir/houdini64:P" > register
+       fi
+       if [ -e arm${1}_exe ]; then
+               houdini_bin=1
+       fi
+else
+       log -pe -thoudini "No binfmt_misc support"
+fi
+
+if [ $houdini_bin -eq 0 ]; then
+       log -pe -thoudini "houdini$1 enabling failed!"
+else
+       log -pi -thoudini "houdini$1 enabled"
+fi
+
+[ "$(getprop ro.zygote)" = "zygote64_32" -a -z "$1" ] && exec $0 64
+
+exit 0
diff --git a/nativebridge/lib/arm/cpuinfo b/nativebridge/lib/arm/cpuinfo
new file mode 100644 (file)
index 0000000..1940ac6
--- /dev/null
@@ -0,0 +1,12 @@
+Processor      : ARMv7 processor rev 1 (v7l)
+BogoMIPS       : 1500.0
+Features       : neon vfp swp half thumb fastmult edsp vfpv3
+CPU implementer        : 0x69
+CPU architecture: 7
+CPU variant    : 0x1
+CPU part       : 0x001
+CPU revision   : 1
+
+Hardware       : placeholder
+Revision       : 0001
+Serial         : 0000000000000001
diff --git a/nativebridge/lib64/arm64/cpuinfo b/nativebridge/lib64/arm64/cpuinfo
new file mode 100644 (file)
index 0000000..3b848dd
--- /dev/null
@@ -0,0 +1,13 @@
+Processor      : ARMv8 processor rev 1 (aarch64)
+processor       : 0
+processor       : 1
+Features       : fp asimd aes pmull sha1 sha2
+CPU implementer        : 0x4e
+CPU architecture: AArch64
+CPU variant    : 0x0
+CPU part       : 0x000
+CPU revision    : 0
+
+Hardware       : placeholder
+Revision       : 0000
+Serial         : 0000000000000000
diff --git a/nativebridge/lib64/arm64/cpuinfo.64in32mode b/nativebridge/lib64/arm64/cpuinfo.64in32mode
new file mode 100644 (file)
index 0000000..a80db5e
--- /dev/null
@@ -0,0 +1,13 @@
+Processor      : ARMv8 processor rev 1 (aarch64)
+processor      : 0
+processor      : 1
+Features       : fp asimd aes pmull sha1 sha2 wp half thumb fastmult vfp edsp neon vfpv3 tlsi vfpv4 idiva idivt
+CPU implementer        : 0x4e
+CPU architecture: 8
+CPU variant    : 0x0
+CPU part       : 0x000
+CPU revision   : 0
+
+Hardware       : placeholder
+Revision       : 0000
+Serial         : 0000000000000000
diff --git a/nativebridge/nativebridge.mk b/nativebridge/nativebridge.mk
new file mode 100644 (file)
index 0000000..6f25686
--- /dev/null
@@ -0,0 +1,46 @@
+#
+# Copyright (C) 2015 The Android-x86 Open Source Project
+#
+# Licensed under the GNU General Public License Version 2 or later.
+# You may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.gnu.org/licenses/gpl.html
+#
+
+# Enable native bridge
+WITH_NATIVE_BRIDGE := true
+
+# Native Bridge ABI List
+NATIVE_BRIDGE_ABI_LIST_32_BIT := armeabi-v7a armeabi
+NATIVE_BRIDGE_ABI_LIST_64_BIT := arm64-v8a
+
+LOCAL_SRC_FILES := bin/enable_nativebridge
+
+ifneq ($(filter %x86_64/,$(PRODUCT_DIR)),)
+
+LOCAL_SRC_FILES += $(subst $(LOCAL_PATH)/,,$(shell find $(LOCAL_PATH)/lib64/arm64 -type f))
+
+PRODUCT_PROPERTY_OVERRIDES := \
+    ro.dalvik.vm.isa.arm64=x86_64 \
+    ro.enable.native.bridge.exec64=1 \
+
+else
+
+PRODUCT_PROPERTY_OVERRIDES :=
+
+endif
+
+LOCAL_SRC_FILES += $(subst $(LOCAL_PATH)/,,$(shell find $(LOCAL_PATH)/lib/arm -type f))
+
+PRODUCT_COPY_FILES := $(foreach f,$(LOCAL_SRC_FILES),$(LOCAL_PATH)/$(f):system/$(f))
+
+PRODUCT_PROPERTY_OVERRIDES += \
+    ro.dalvik.vm.isa.arm=x86 \
+    ro.enable.native.bridge.exec=1 \
+
+PRODUCT_DEFAULT_PROPERTY_OVERRIDES := ro.dalvik.vm.native.bridge=libnb.so
+
+PRODUCT_PACKAGES := libnb
+
+$(call inherit-product-if-exists,vendor/intel/houdini/houdini.mk)
diff --git a/nativebridge/src/libnb.cpp b/nativebridge/src/libnb.cpp
new file mode 100644 (file)
index 0000000..72e334d
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2015 The Android-x86 Open Source Project
+ *
+ * by Chih-Wei Huang <cwhuang@linux.org.tw>
+ *
+ * Licensed under the GNU General Public License Version 2 or later.
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/gpl.html
+ *
+ */
+
+#define LOG_TAG "libnb"
+
+#include <dlfcn.h>
+#include <cutils/log.h>
+#include "nativebridge/native_bridge.h"
+
+namespace android {
+
+static void *native_handle = nullptr;
+
+static NativeBridgeCallbacks *get_callbacks()
+{
+    static NativeBridgeCallbacks *callbacks = nullptr;
+
+    if (!callbacks) {
+        const char *libnb = "/system/"
+#ifdef __LP64__
+                "lib64/arm64/"
+#else
+                "lib/arm/"
+#endif
+                "libhoudini.so";
+        if (!native_handle) {
+            native_handle = dlopen(libnb, RTLD_LAZY);
+            if (!native_handle) {
+                ALOGE("Unable to open %s", libnb);
+                return nullptr;
+            }
+        }
+        callbacks = reinterpret_cast<NativeBridgeCallbacks *>(dlsym(native_handle, "NativeBridgeItf"));
+    }
+    return callbacks;
+}
+
+// NativeBridgeCallbacks implementations
+static bool native_bridge2_initialize(const NativeBridgeRuntimeCallbacks *art_cbs,
+                                      const char *app_code_cache_dir,
+                                      const char *isa)
+{
+    ALOGV("enter native_bridge2_initialize %s %s", app_code_cache_dir, isa);
+    NativeBridgeCallbacks *cb = get_callbacks();
+    return cb ? cb->initialize(art_cbs, app_code_cache_dir, isa) : false;
+}
+
+static void *native_bridge2_loadLibrary(const char *libpath, int flag)
+{
+    ALOGV("enter native_bridge2_loadLibrary %s", libpath);
+    NativeBridgeCallbacks *cb = get_callbacks();
+    return cb ? cb->loadLibrary(libpath, flag) : nullptr;
+}
+
+static void *native_bridge2_getTrampoline(void *handle, const char *name,
+                                          const char* shorty, uint32_t len)
+{
+    ALOGV("enter native_bridge2_getTrampoline %s", name);
+    NativeBridgeCallbacks *cb = get_callbacks();
+    return cb ? cb->getTrampoline(handle, name, shorty, len) : nullptr;
+}
+
+static bool native_bridge2_isSupported(const char *libpath)
+{
+    ALOGV("enter native_bridge2_isSupported %s", libpath);
+    NativeBridgeCallbacks *cb = get_callbacks();
+    return cb ? cb->isSupported(libpath) : false;
+}
+
+static const struct NativeBridgeRuntimeValues *native_bridge2_getAppEnv(const char *abi)
+{
+    ALOGV("enter native_bridge2_getAppEnv %s", abi);
+    NativeBridgeCallbacks *cb = get_callbacks();
+    return cb ? cb->getAppEnv(abi) : nullptr;
+}
+
+static bool native_bridge2_is_compatible_compatible_with(uint32_t version)
+{
+    // For testing, allow 1 and 2, but disallow 3+.
+    return version <= 2;
+}
+
+static NativeBridgeSignalHandlerFn native_bridge2_get_signal_handler(int signal)
+{
+    ALOGV("enter native_bridge2_getAppEnv %d", signal);
+    NativeBridgeCallbacks *cb = get_callbacks();
+    return cb ? cb->getSignalHandler(signal) : nullptr;
+}
+
+static void __attribute__ ((destructor)) on_dlclose()
+{
+    if (native_handle) {
+        dlclose(native_handle);
+        native_handle = nullptr;
+    }
+}
+
+extern "C" {
+
+NativeBridgeCallbacks NativeBridgeItf = {
+    version: 2,
+    initialize: &native_bridge2_initialize,
+    loadLibrary: &native_bridge2_loadLibrary,
+    getTrampoline: &native_bridge2_getTrampoline,
+    isSupported: &native_bridge2_isSupported,
+    getAppEnv: &native_bridge2_getAppEnv,
+    isCompatibleWith: &native_bridge2_is_compatible_compatible_with,
+    getSignalHandler: &native_bridge2_get_signal_handler,
+};
+
+} // extern "C"
+} // namespace android