• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

device/generic/common


Commit MetaInfo

Revision747cb9f8c687f77dcf5a70cdfd72ab7ede94c0fc (tree)
Time2015-09-30 19:07:42
AuthorChih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

Enable native bridge

Add the library libnb and script to support the arm translator.

Change Summary

Incremental Difference

--- a/BoardConfig.mk
+++ b/BoardConfig.mk
@@ -51,6 +51,8 @@ BUILD_EMULATOR_GPS_MODULE ?= false
5151 BUILD_EMULATOR_LIGHTS_MODULE ?= false
5252 BUILD_EMULATOR_SENSORS_MODULE ?= false
5353
54+BUILD_ARM_FOR_X86 := $(WITH_NATIVE_BRIDGE)
55+
5456 BOARD_USE_LIBVA_INTEL_DRIVER := true
5557 BOARD_USE_LIBVA := true
5658 BOARD_USE_LIBMIX := true
--- a/device.mk
+++ b/device.mk
@@ -103,5 +103,5 @@ $(call inherit-product,frameworks/native/build/tablet-10in-xhdpi-2048-dalvik-hea
103103 # Get GMS
104104 $(call inherit-product-if-exists,vendor/google/products/gms.mk)
105105
106-# Get Arm translator
107-$(call inherit-product-if-exists,vendor/intel/houdini/houdini.mk)
106+# Get native bridge settings
107+$(call inherit-product-if-exists,$(LOCAL_PATH)/nativebridge/nativebridge.mk)
--- /dev/null
+++ b/nativebridge/Android.mk
@@ -0,0 +1,22 @@
1+#
2+# Copyright (C) 2015 The Android-x86 Open Source Project
3+#
4+# Licensed under the GNU General Public License Version 2 or later.
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.gnu.org/licenses/gpl.html
9+#
10+
11+LOCAL_PATH := $(my-dir)
12+
13+include $(CLEAR_VARS)
14+
15+LOCAL_MODULE := libnb
16+LOCAL_SRC_FILES := src/libnb.cpp
17+LOCAL_CFLAGS := -Werror -Wall
18+LOCAL_CPPFLAGS := -std=c++11
19+LOCAL_SHARED_LIBRARIES := libdl liblog
20+LOCAL_MULTILIB := both
21+
22+include $(BUILD_SHARED_LIBRARY)
--- /dev/null
+++ b/nativebridge/bin/enable_nativebridge
@@ -0,0 +1,73 @@
1+#!/system/bin/sh
2+
3+PATH=/system/bin:/system/xbin
4+
5+houdini_bin=0
6+dest_dir=/system/lib$1/arm$1
7+binfmt_misc_dir=/proc/sys/fs/binfmt_misc
8+
9+cd $dest_dir
10+
11+if [ ! -s libhoudini.so ]; then
12+ if touch .dl_houdini; then
13+ rm -f .dl_houdini
14+ else
15+ cd .. && cp -a arm$1 /data/local/tmp
16+ mount -t tmpfs tmpfs arm$1 && cd arm$1 &&
17+ cp -a /data/local/tmp/arm$1/* . && rm -rf /data/local/tmp/arm$1
18+ fi
19+fi
20+
21+cd /data/local/tmp
22+while [ ! -s $dest_dir/libhoudini.so ]; do
23+ while [ "$(getprop net.dns1)" = "" ]; do
24+ sleep 10
25+ done
26+ if [ -z "$1" ]; then
27+ [ "`uname -m`" = "x86_64" ] && url=http://goo.gl/Xl1str || url=http://goo.gl/PA2qZ7
28+ else
29+ url=http://goo.gl/L00S7l
30+ fi
31+ wget $url -cO houdini.tgz &&
32+ bzcat houdini.tgz | tar xvf - -C $dest_dir && rm -f houdini.tgz && break
33+ rm -f houdini.tgz
34+ sleep 30
35+done
36+
37+
38+# if you don't see the files 'register' and 'status' in /proc/sys/fs/binfmt_misc
39+# then run the following command:
40+# mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
41+
42+# this is to add the supported binary formats via binfmt_misc
43+
44+if [ ! -e $binfmt_misc_dir/register ]; then
45+ mount -t binfmt_misc none $binfmt_misc_dir
46+fi
47+
48+cd $binfmt_misc_dir
49+if [ -e register ]; then
50+ # register Houdini for arm binaries
51+ if [ -z "$1" ]; then
52+ 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
53+ 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
54+ else
55+ 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
56+ 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
57+ fi
58+ if [ -e arm${1}_exe ]; then
59+ houdini_bin=1
60+ fi
61+else
62+ log -pe -thoudini "No binfmt_misc support"
63+fi
64+
65+if [ $houdini_bin -eq 0 ]; then
66+ log -pe -thoudini "houdini$1 enabling failed!"
67+else
68+ log -pi -thoudini "houdini$1 enabled"
69+fi
70+
71+[ "$(getprop ro.zygote)" = "zygote64_32" -a -z "$1" ] && exec $0 64
72+
73+exit 0
--- /dev/null
+++ b/nativebridge/lib/arm/cpuinfo
@@ -0,0 +1,12 @@
1+Processor : ARMv7 processor rev 1 (v7l)
2+BogoMIPS : 1500.0
3+Features : neon vfp swp half thumb fastmult edsp vfpv3
4+CPU implementer : 0x69
5+CPU architecture: 7
6+CPU variant : 0x1
7+CPU part : 0x001
8+CPU revision : 1
9+
10+Hardware : placeholder
11+Revision : 0001
12+Serial : 0000000000000001
--- /dev/null
+++ b/nativebridge/lib64/arm64/cpuinfo
@@ -0,0 +1,13 @@
1+Processor : ARMv8 processor rev 1 (aarch64)
2+processor : 0
3+processor : 1
4+Features : fp asimd aes pmull sha1 sha2
5+CPU implementer : 0x4e
6+CPU architecture: AArch64
7+CPU variant : 0x0
8+CPU part : 0x000
9+CPU revision : 0
10+
11+Hardware : placeholder
12+Revision : 0000
13+Serial : 0000000000000000
--- /dev/null
+++ b/nativebridge/lib64/arm64/cpuinfo.64in32mode
@@ -0,0 +1,13 @@
1+Processor : ARMv8 processor rev 1 (aarch64)
2+processor : 0
3+processor : 1
4+Features : fp asimd aes pmull sha1 sha2 wp half thumb fastmult vfp edsp neon vfpv3 tlsi vfpv4 idiva idivt
5+CPU implementer : 0x4e
6+CPU architecture: 8
7+CPU variant : 0x0
8+CPU part : 0x000
9+CPU revision : 0
10+
11+Hardware : placeholder
12+Revision : 0000
13+Serial : 0000000000000000
--- /dev/null
+++ b/nativebridge/nativebridge.mk
@@ -0,0 +1,46 @@
1+#
2+# Copyright (C) 2015 The Android-x86 Open Source Project
3+#
4+# Licensed under the GNU General Public License Version 2 or later.
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.gnu.org/licenses/gpl.html
9+#
10+
11+# Enable native bridge
12+WITH_NATIVE_BRIDGE := true
13+
14+# Native Bridge ABI List
15+NATIVE_BRIDGE_ABI_LIST_32_BIT := armeabi-v7a armeabi
16+NATIVE_BRIDGE_ABI_LIST_64_BIT := arm64-v8a
17+
18+LOCAL_SRC_FILES := bin/enable_nativebridge
19+
20+ifneq ($(filter %x86_64/,$(PRODUCT_DIR)),)
21+
22+LOCAL_SRC_FILES += $(subst $(LOCAL_PATH)/,,$(shell find $(LOCAL_PATH)/lib64/arm64 -type f))
23+
24+PRODUCT_PROPERTY_OVERRIDES := \
25+ ro.dalvik.vm.isa.arm64=x86_64 \
26+ ro.enable.native.bridge.exec64=1 \
27+
28+else
29+
30+PRODUCT_PROPERTY_OVERRIDES :=
31+
32+endif
33+
34+LOCAL_SRC_FILES += $(subst $(LOCAL_PATH)/,,$(shell find $(LOCAL_PATH)/lib/arm -type f))
35+
36+PRODUCT_COPY_FILES := $(foreach f,$(LOCAL_SRC_FILES),$(LOCAL_PATH)/$(f):system/$(f))
37+
38+PRODUCT_PROPERTY_OVERRIDES += \
39+ ro.dalvik.vm.isa.arm=x86 \
40+ ro.enable.native.bridge.exec=1 \
41+
42+PRODUCT_DEFAULT_PROPERTY_OVERRIDES := ro.dalvik.vm.native.bridge=libnb.so
43+
44+PRODUCT_PACKAGES := libnb
45+
46+$(call inherit-product-if-exists,vendor/intel/houdini/houdini.mk)
--- /dev/null
+++ b/nativebridge/src/libnb.cpp
@@ -0,0 +1,122 @@
1+/*
2+ * Copyright (C) 2015 The Android-x86 Open Source Project
3+ *
4+ * by Chih-Wei Huang <cwhuang@linux.org.tw>
5+ *
6+ * Licensed under the GNU General Public License Version 2 or later.
7+ * You may not use this file except in compliance with the License.
8+ * You may obtain a copy of the License at
9+ *
10+ * http://www.gnu.org/licenses/gpl.html
11+ *
12+ */
13+
14+#define LOG_TAG "libnb"
15+
16+#include <dlfcn.h>
17+#include <cutils/log.h>
18+#include "nativebridge/native_bridge.h"
19+
20+namespace android {
21+
22+static void *native_handle = nullptr;
23+
24+static NativeBridgeCallbacks *get_callbacks()
25+{
26+ static NativeBridgeCallbacks *callbacks = nullptr;
27+
28+ if (!callbacks) {
29+ const char *libnb = "/system/"
30+#ifdef __LP64__
31+ "lib64/arm64/"
32+#else
33+ "lib/arm/"
34+#endif
35+ "libhoudini.so";
36+ if (!native_handle) {
37+ native_handle = dlopen(libnb, RTLD_LAZY);
38+ if (!native_handle) {
39+ ALOGE("Unable to open %s", libnb);
40+ return nullptr;
41+ }
42+ }
43+ callbacks = reinterpret_cast<NativeBridgeCallbacks *>(dlsym(native_handle, "NativeBridgeItf"));
44+ }
45+ return callbacks;
46+}
47+
48+// NativeBridgeCallbacks implementations
49+static bool native_bridge2_initialize(const NativeBridgeRuntimeCallbacks *art_cbs,
50+ const char *app_code_cache_dir,
51+ const char *isa)
52+{
53+ ALOGV("enter native_bridge2_initialize %s %s", app_code_cache_dir, isa);
54+ NativeBridgeCallbacks *cb = get_callbacks();
55+ return cb ? cb->initialize(art_cbs, app_code_cache_dir, isa) : false;
56+}
57+
58+static void *native_bridge2_loadLibrary(const char *libpath, int flag)
59+{
60+ ALOGV("enter native_bridge2_loadLibrary %s", libpath);
61+ NativeBridgeCallbacks *cb = get_callbacks();
62+ return cb ? cb->loadLibrary(libpath, flag) : nullptr;
63+}
64+
65+static void *native_bridge2_getTrampoline(void *handle, const char *name,
66+ const char* shorty, uint32_t len)
67+{
68+ ALOGV("enter native_bridge2_getTrampoline %s", name);
69+ NativeBridgeCallbacks *cb = get_callbacks();
70+ return cb ? cb->getTrampoline(handle, name, shorty, len) : nullptr;
71+}
72+
73+static bool native_bridge2_isSupported(const char *libpath)
74+{
75+ ALOGV("enter native_bridge2_isSupported %s", libpath);
76+ NativeBridgeCallbacks *cb = get_callbacks();
77+ return cb ? cb->isSupported(libpath) : false;
78+}
79+
80+static const struct NativeBridgeRuntimeValues *native_bridge2_getAppEnv(const char *abi)
81+{
82+ ALOGV("enter native_bridge2_getAppEnv %s", abi);
83+ NativeBridgeCallbacks *cb = get_callbacks();
84+ return cb ? cb->getAppEnv(abi) : nullptr;
85+}
86+
87+static bool native_bridge2_is_compatible_compatible_with(uint32_t version)
88+{
89+ // For testing, allow 1 and 2, but disallow 3+.
90+ return version <= 2;
91+}
92+
93+static NativeBridgeSignalHandlerFn native_bridge2_get_signal_handler(int signal)
94+{
95+ ALOGV("enter native_bridge2_getAppEnv %d", signal);
96+ NativeBridgeCallbacks *cb = get_callbacks();
97+ return cb ? cb->getSignalHandler(signal) : nullptr;
98+}
99+
100+static void __attribute__ ((destructor)) on_dlclose()
101+{
102+ if (native_handle) {
103+ dlclose(native_handle);
104+ native_handle = nullptr;
105+ }
106+}
107+
108+extern "C" {
109+
110+NativeBridgeCallbacks NativeBridgeItf = {
111+ version: 2,
112+ initialize: &native_bridge2_initialize,
113+ loadLibrary: &native_bridge2_loadLibrary,
114+ getTrampoline: &native_bridge2_getTrampoline,
115+ isSupported: &native_bridge2_isSupported,
116+ getAppEnv: &native_bridge2_getAppEnv,
117+ isCompatibleWith: &native_bridge2_is_compatible_compatible_with,
118+ getSignalHandler: &native_bridge2_get_signal_handler,
119+};
120+
121+} // extern "C"
122+} // namespace android