gpt4 book ai didi

linux - 注册的自定义可执行文件格式是否也由类型为 `linux_binfmt` 的对象描述?

转载 作者:太空宇宙 更新时间:2023-11-04 10:06:12 25 4
gpt4 key购买 nike

了解 Linux 内核

An executable format is described by an object of type linux_binfmt, which essentially provides three methods: load_binary, load_shlib, and core_dump.

Linux allows users to register their own custom executable formats. To register a new format, the user writes into the register file of the binfmt_misc special filesystem (usually mounted on /proc/sys/fs/binfmt_misc) a string with the following format:

:name:type:offset:string:mask:interpreter:flags

When the kernel determines that the executable file has a custom format, it starts the proper interpreter program. The interpreter program runs in User Mode, receives as its parameter the pathname of the executable file, and carries on the computation. As an example, an executable file containing a Java program is dealt by a java virtual machine such as /usr/lib/java/bin/java.

虽然它没有提到这一点,但注册的自定义可执行文件格式是否也由 linux_binfmt 类型的对象描述?

如果是,注册自定义可执行格式不需要我们显式提供load_binaryload_shlibcore_dump 方法。这三种方法是从注册中隐式创建的吗?

如果没有load_binary方法,内核通过相应的解释器调用什么方法来执行注册的可执行格式的可执行文件?

最佳答案

binfmt-misc 的情况下,linux_binfmt 对象对应于 binfmt-misc 模块本身。模块不必提供所有功能的实现; binfmt-杂项 only declares an implementation of load_binary :

static struct linux_binfmt misc_format = {
.module = THIS_MODULE,
.load_binary = load_misc_binary,
};

(binfmt_script 实现了对基于 shebang 的脚本的支持,具有类似的声明。)

load_misc_binary当内核调用它时处理所有已注册的可执行文件类型的细节。内核调用 load_misc_binary,然后该函数找到匹配的已注册可执行文件类型(如果有),加载相应的解释器,并根据需要设置执行环境。

关于linux - 注册的自定义可执行文件格式是否也由类型为 `linux_binfmt` 的对象描述?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52416969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com