2016-01-13

houdini and binfmt_misc


houdini and binfmt_misc


qemu user mode and binfmt_misc
http://alanyih.blogspot.tw/2013/06/slitaz-qemu-user-mode-and-binfmtmisc.html
Kernel Support for miscellaneous (your favourite) Binary Formats v1.1
==============================================================
https://www.kernel.org/doc/Documentation/binfmt_misc.txt
This Kernel feature allows you to invoke almost (for restrictions see below)
every program by simply typing its name in the shell.
This includes for example compiled Java(TM), Python or Emacs programs.
To achieve this you must tell binfmt_misc which interpreter has to be invoked
with which binary. Binfmt_misc recognises the binary-type by matching some bytes
at the beginning of the file with a magic byte sequence (masking out specified
bits) you have supplied. Binfmt_misc can also recognise a filename extension
aka '.com' or '.exe'.
First you must mount binfmt_misc:
mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
Chrooting to: /opt/rootfs-armhf/
http://alanyih.blogspot.tw/2013/06/slitaz-setup-rootfs-armhf.html
3. Mount the binfmt_misc handler
# modprobe binfmt_misc
# mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc 
4. register our format with the kernel via the procfs
root@slitaz:~# echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\x00\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm-static:' > /proc/sys/fs/binfmt_misc/register
5. check register
root@slitaz:~# cat /proc/sys/fs/binfmt_misc/arm
enabled
interpreter /usr/bin/qemu-arm-static
flags:
offset 0
magic 7f454c4601010100000000000000000002002800
mask ffffffffffffff00ffffffffffff00fffeffffff

1.
tux@slitaz:~ $ adb shell
shell@Z00A:/ $ mount | grep binfmt
binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0


2.
shell@Z00A:/ $ grep bridge /default.prop
ro.dalvik.vm.native.bridge=libhoudini.so


3.
shell@Z00A:/ $ ls -l /proc/sys/fs/binfmt_misc
-rw-r--r-- root root 0 2015-12-20 21:24 arm_dyn
-rw-r--r-- root root 0 2015-12-20 21:24 arm_exe
--w------- root root 0 2015-12-20 21:24 register
-rw-r--r-- root root 0 2015-12-20 21:24 status


4.
shell@Z00A:/ $ cat /proc/sys/fs/binfmt_misc/status
enabled


5.
shell@Z00A:/ $ cat /proc/sys/fs/binfmt_misc/arm_exe
enabled
interpreter /system/bin/houdini
flags: P
offset 0
magic 7f454c46010101000000000000000000020028


6.
shell@Z00A:/ $ cat /proc/sys/fs/binfmt_misc/arm_dyn
enabled
interpreter /system/bin/houdini
flags: P
offset 0
magic 7f454c46010101000000000000000000030028
shell@Z00A:/ $