Linux reboot()系统调用的幻数 [英] Magic numbers of the Linux reboot() system call

查看:410
本文介绍了Linux reboot()系统调用的幻数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

> 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_MAGIC2C(537993216)之一.我无法用十六进制解释它们的含义.我还查看了/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?

编辑:我在kernel/sys.c中找到了定义.我只为sys_reboot进行了grep,而忘记了MAGIC编号的grep.我认为定义必须隐藏在某些宏技巧的后面,因此我查看了/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?

关于找到syscall实现,我做了git grep -n LINUX_REBOOT_MAGIC2并在kernel/sys.c中找到了定义.我怀疑符号sys_reboot是由SYSCALL_DEFINE4(reboot, ...小矮人生成的.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆