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

查看:150
本文介绍了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).

objdump binutils 的一部分; 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天全站免登陆