OSDN Git Service

Enable native bridge
[android-x86/device-generic-common.git] / nativebridge / bin / enable_nativebridge
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