We know that not all binaries in the Linux environment have the same format, and the Linux system uses binary file handlers to implement separate processing for different binary format files. The binary handler identifies the file through a "feature sequence" (a special sequence of bytes) embedded at the beginning of the file. Sometimes, some features of the filename, such as the Elf file, begin with the ' E ' L ' F ' character, and the Java file starts with the first four bytes in 0xcafebabe.
Linux loads executable binaries with sys_execve.
1. The current Linux version (2.2) provides the following binary file handlers:
a.out: Primarily for compatibility with the previous, because a.out is difficult to implement dynamic links to be taken by the elf.
Elf: Now the mainstream Linux binaries. Still, she wants to use a binary handler just like any other format.
em86: The primary role is to run Intel's Linux binaries on Alpha hosts as if they were alpha local binaries.
Java: The handler returns an interpreter that executes the bytecode by using the file name of the. class file as a parameter.
Misc: The wisest method of binary handler. She identifies the binary format by embedding a feature number or filename suffix. In addition, she can run a period of configuration, rather than only at compile-time configuration, so that you can add new binary format file support without recompiling the kernel. There are said to replace the Java and EM86 binary handlers with her.
• Script: Main support shell script, Perl script, easy to say, all the preceding two characters is #! Executable file is handled by her.
We must first understand a data structure linux_binfmt before proceeding with the downward introduction;
struct linux_binfmt{
struct linux_binfmt * next;
long *use_count;
int (*load_binary)(struct linux_binprm *,struct pt_regs *regs);
int (*load_shlib)(int fd);
int (*core_dump)(long signr,struct pt_regs *regs);
};
The linux_binfmt contains two pointers to important functions, load_binary loading executable code, load_shlib loading the shared library. Core_dump is a dump function pointer.
Obviously, next forms a linked list, and the header is directed by formats:
static struct linux_binfmt *formats=(struct linux_binfmt *)NULL;
The system defines a corresponding object for each of the different file formats:
static struct linux_binfmt elf_format;
static struct linux_binfmt java_format;
static struct linux_binfmt em86_format;
……
The Linux_binfmt list (pointed to by formats) is a linked list of linux_binfmt of these different file formats. The processing of different format binaries is implemented by registering functions in the corresponding linux_binfmt, where object-oriented thinking has been used, which is often seen in Linux kernel source code.