我猜在 insmod 时堆栈溢出
我在我的系统上构建了内核 2.6.35,并有一些特定的要求。我还使用相同的内核构建了一些应用程序定义的模块。我启动了构建版本,发现它无法正常工作,因为存在一些 gui 和其他模块丢失的问题。但是系统启动了,我执行了 insmod app.ko。我遇到了车祸。我发现这是一个堆栈问题。 APP 中的调用函数正在传递两个局部变量的地址。像 int a, b;添加(&a,&b);我在传递之前检查了 &a 和 &b 的值,它仍然为非空,但是当我在调用函数中收到相同的值时,&a、&b 都是 NULL 或一些垃圾值。我增加了堆栈大小但什么也没发生。当我跳过函数调用时,我可以看到许多内存分配也失败了。所以我认为应该是内存问题。我应该检查 gcc 选项来定义堆栈或检查堆栈溢出吗?任何关于这方面的提示都可以对我有很大帮助。提前致谢。我只是做了一些抽象的例子,因为原始代码部分需要很多时间来解释。
main()
{
struct DMAINFO* pDmaInfo;
struct DESC* pDesc;
/* printk("The function aruguments are Desc = %p and DmaInfo %p", &pDesc, &pDmaInfo); */
Create_DMA(&pDesc, &pDmaInfo);
}
void Create_DMA(**ppDesc, **ppDmaInfor)
{
printk("The function aruguments are Desc = %p and DmaInfo %p", ppDesc, ppDmaInfo);
}
create_DMA 中的 printk 语句给出了 NULL 值,但在 create_DMA 调用之前主函数中的相同 print 语句有一些值。
I have built kernel 2.6.35 on my system with some specific requirement. I also built some app defined module with the same kernel. I booted up the built version and I find it did not work properly as there is some gui and other modules missing problem. But the system booted up and I did a insmod app.ko. I faced a crash. I found out that it is a stack problem. A caller function in the APP is passing address of two local variable. like int a, b; add (&a, &b); I checked the values of &a and &b before passing and it remained non-null but when i receive the same in the calling function, both the &a, &b are NULL or some garbage value. I increased the stack size but nothing happened. When i skipped the function call, I could see that many allocation of memory has also failed. So I think it should be memory problem. Is there anything I should be checking for gcc option to define the stack or check for stack overflow. Any hints on this could help me a lot. Thanks in advance. I just made some abstract examples since the original code section takes lot of time to explain.
main()
{
struct DMAINFO* pDmaInfo;
struct DESC* pDesc;
/* printk("The function aruguments are Desc = %p and DmaInfo %p", &pDesc, &pDmaInfo); */
Create_DMA(&pDesc, &pDmaInfo);
}
void Create_DMA(**ppDesc, **ppDmaInfor)
{
printk("The function aruguments are Desc = %p and DmaInfo %p", ppDesc, ppDmaInfo);
}
The printk statement inside create_DMA gives me NULL values, but the same print statement in the main function before the create_DMA call has some values.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
pDesc
和pDmaInfo
在 Create_DMA() 之前未初始化,因此它包含垃圾值并导致主函数中的 print 语句在 create_DMA 调用输出一些值之前。当调用 Create_DMA() 时,Create_DMA() 尝试分配内存和一些其他资源,并将结果放入
pDesc
和pDmaInfo
。当Create_DMA()失败时,pDesc
和pDmaInfo
的值未定义,取决于Create_DMA()的进程。为了避免此类问题,您应该始终初始化
pDesc
和pDmaInfo
并仔细编写Create_DMA()。pDesc
andpDmaInfo
is un-initialed before Create_DMA(), so it contains garbage value and causes the print statement in the main function before the create_DMA call outputs some values.When Create_DMA() is called, Create_DMA() try to allocation memory and some other resources and put the result at
pDesc
andpDmaInfo
. When Create_DMA() fails, the value ofpDesc
andpDmaInfo
is undefined, depends on process of Create_DMA().To avoid such problem, you should always init the
pDesc
andpDmaInfo
and write the Create_DMA() carefully.