binfmt misc
binfmt_misc is a capability of the Linux kernel which allows arbitrary executable file formats to be recognized and passed to certain user space applications, such as emulators and virtual machines.
The executable formats are registered through a special purpose file system interface (similar to /proc). Debian-based distributions provide the functionality through an extra binfmt-support package.[1]
Registration
The register file contains lines which define executable types to be handled. Each line is of the form:
:name:type:offset:magic:mask:interpreter:flags
- name is the name of the binary format.
- type is either E or M
- If it is E, the executable file format is identified by its filename extension: magic is the file extension to be associated with the binary format; offset and mask are ignored.
- If it is M, the format is identified by magic number at an absolute offset (defaults to 0) in the file and mask is a bitmask (defaults to all 0xFF) indicating which bits in the number are significant.
- interpreter is a program that is to be run with the matching file as an argument.
- flags (optional) is a string of letters, each controlling a certain aspect of interpreter invocation:
- P to preserve the original program name typed by user in command line — by adding that name to argv; the interpreter has to be aware of this so it can correctly pass that additional parameter to the interpreted program as its argv[0].
- O to open the program file and pass its file descriptor to the interpreter so it could read an otherwise unreadable file (for which the user does not have the "Read" permission).
- C to determine new process credentials based on program file rather than interpreter file (see setuid); implies O flag.
- F to make the kernel open the binary at configuration time instead of lazily at startup time, so that it is available inside other mount namespaces and chroots as well.
Each format has a corresponding file entry in the /proc/sys/fs/binfmt_misc directory which can be read to get information about a given file format.
Common usage
binfmt_misc allows Java programs to be passed directly to the Java virtual machine.[2]
Another common usage is to execute PE executables (compiled for MS-DOS or Microsoft Windows) through Wine. For example, the following line will run DOS and Windows EXE files (identified by
the "MZ" type code) using Wine:
:DOSWin:M::MZ::/usr/bin/wine:
To run EXE (.NET) files with Mono:[3][4]
:CLR:M::MZ::/usr/bin/mono:
See also
References
- Documentation/binfmt_misc.txt in the Linux kernel source tree
- ↑ http://packages.debian.org/sid/binfmt-support
- ↑ https://git.kernel.org/gitweb.cgi?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/java.txt;hb=HEAD
- ↑ https://git.kernel.org/gitweb.cgi?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/mono.txt;hb=HEAD
- ↑ Guide:Running Mono Applications