Linux reboot() 系统调用的幻数 [英] Magic numbers of the Linux reboot() system call
问题描述
Linux 编程接口在第 3 章中有一个练习是这样的:
The Linux Programming Interface has an exercise in Chapter 3 that goes like this:
当使用 Linux 特定的 reboot()重新启动系统的系统调用,第二个参数,magic2,必须是指定为一组魔法之一数字(例如,LINUX_REBOOT_MAGIC2).这些有什么意义数字?(将它们转换为十六进制提供了线索.)
When using the Linux-specific reboot() system call to reboot the system, the second argument, magic2, must be specified as one of a set of magic numbers (e.g., LINUX_REBOOT_MAGIC2). What is the significance of these numbers? (Converting them to hexadecimal provides a clue.)
手册页告诉我们 magic2
可以是 LINUX_REBOOT_MAGIC2 (672274793)、LINUX_REBOOT_MAGIC2A (85072278)、LINUX_REBOOT_MAGIC2B (369367448) 或 LINUX_REBOOT_MAGIC2B (369367448) 之一.我没能破译它们的十六进制含义.我还查看了 /usr/include/linux/reboot.h
,它也没有给出任何有用的评论.
The man page tells us magic2
can be one of LINUX_REBOOT_MAGIC2 (672274793), LINUX_REBOOT_MAGIC2A (85072278), LINUX_REBOOT_MAGIC2B (369367448), or LINUX_REBOOT_MAGIC2C (537993216). I failed to decipher their meaning in hex. I also looked at /usr/include/linux/reboot.h
, which didn't give any helpful comment either.
然后我在内核的源代码中搜索了 sys_reboot
的定义.我发现的只是头文件中的声明.
I then searched in the kernel's source code for sys_reboot
's definition. All I found was a declaration in a header file.
因此,我的第一个问题是,这些数字的意义是什么?我的第二个问题是,sys_reboot
的定义在哪里,你是怎么找到的?
Therefore, my first question is, what is the significance of these numbers? My second question is, where's sys_reboot
's definition, and how did you find it?
EDIT:我在 kernel/sys.c
中找到了定义.我只对 sys_reboot
进行了搜索,而忘了对 MAGIC 数字进行搜索.我想这个定义一定隐藏在一些宏技巧后面,所以我查看了 /boot
下的 System.map
文件,并在 ctrl_alt_del旁边找到了它代码>.然后我搜索了那个符号,这让我找到了正确的文件.如果我从源代码编译内核,我可以尝试找到定义符号的目标文件,然后从那里开始.
EDIT: I found the definition in kernel/sys.c
. I only grepped for sys_reboot
, and forgot to grep for the MAGIC numbers. I figured the definition must be hidden behind some macro trick, so I looked at the System.map
file under /boot
, and found it next to ctrl_alt_del
. I then grepped for that symbol, which led me to the correct file. If I had compiled the kernel from source code, I could try to find which object file defined the symbol, and go from there.
推荐答案
只是猜测,但这些数字在十六进制中看起来更有趣:
Just a guess, but those numbers look more interesting in hex:
672274793 = 0x28121969
85072278 = 0x05121996
369367448 = 0x16041998
537993216 = 0x20112000
开发者或开发者孩子的生日?
Developers' or developers' children's birthdays?
关于找到系统调用的实现,我做了一个 git grep -n LINUX_REBOOT_MAGIC2
并在 kernel/sys.c 中找到了定义.符号 sys_reboot
是由 SYSCALL_DEFINE4(reboot, ...
gubbins,我怀疑生成的.
Regarding finding the syscall implementation, I did a git grep -n LINUX_REBOOT_MAGIC2
and found the definition in kernel/sys.c. The symbol sys_reboot
is generated by the SYSCALL_DEFINE4(reboot, ...
gubbins, I suspect.
这篇关于Linux reboot() 系统调用的幻数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!