Perl:linux 源代码中的 checkstack.pl 有什么作用? [英] Perl: what does checkstack.pl in linux source do?

查看:27
本文介绍了Perl:linux 源代码中的 checkstack.pl 有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 linux 内核中做一个项目,我想知道这个 checkstack.pl 有什么作用?我从来没有学过perl,所以不能理解这个程序.如果我不能逐行理解程序,那就太好了.任何努力都值得赞赏.

I am doing a project in linux kernel and I wanted to know what does this checkstack.pl do? I have never studied perl so cant understand the program. It will be great if I could understand the program conceptually if not line by line. Any effort appreciated.

来源:链接文字

假设我想编写我自己的代码,我可以在 C 程序中编写它吗?我的主要问题是:为什么这段代码是用 perl 编写或应该用 perl 编写的?

suppose i want to write the code of my own tweaking a bit, can i write it in a C program. My main Q is : why this code is written or should be written in perl?

推荐答案

创建内核中每个函数使用的堆栈帧大小的列表(即每个函数使用的本地暂存空间总量)变量等等).

It creates a listing of the size of the stack frame used by every function in the kernel (i.e. the total amount of local scratch space used by each function for local variables and whatnot).

它这样做的方法是通过内核的反汇编并寻找两件事:函数名和调整堆栈的指令.它通过查找与 $funcre (qr/^$x* <(.*)>:$/) 匹配的行来查找函数名称,它看起来对于匹配 $re$dre 的堆栈调整指令;后两者高度依赖于内核编译的架构,这是 if/else 语句正在检查的第一个大块.$re 搜索以固定量调整堆栈的函数(绝大多数函数),而 $dre 搜索以可变量调整堆栈的函数(很少见).

The way it does this is by going through the disassembly of the kernel and looking for 2 things: function names and instructions which adjust the stack. It looks for function names by looking for lines that match $funcre (qr/^$x* <(.*)>:$/), and it looks for stack adjustment instructions that match $re or $dre; the latter two depend highly on what architecture the kernel was compiled for, which is what the first big block if if/else statements is checking for. $re searches for functions which adjust the stack by a fixed amount (the vast majority of functions), and $dre searches for functions which adjust the stack by a variable amount (rare).

objdumpbinutils 的一部分;objdump -d 是反汇编目标文件的命令.该脚本的用途是反汇编内核(objdump -d vmlinux)并将输出通过管道传输到脚本中.脚本的输出是内核中所有函数的列表,按最大堆栈帧大小排序.我假设该脚本的目的是让内核维护者能够通过痛苦地确保所有内容的堆栈帧尽可能小来避免堆栈溢出,并且该脚本允许他们验证这一点.

objdump is part of binutils; objdump -d is the command to disassemble an object file. The usage of this script is to disassemble the kernel (objdump -d vmlinux) and pipe the output into the script. The output of the script is a listing of all of the functions in the kernel, sorted by the largest stack frame size. I assume the purpose of the script is for the kernel maintainers to be able to avoid stack overflows by painfully making sure that the stack frames of everything is as small as possible, and this script allows them to verify this.

这篇关于Perl:linux 源代码中的 checkstack.pl 有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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