kmalloc 导致内核崩溃
我试图在内核代码中使用 kmalloc 实际上在排队规则中分配内存。我想将内存分配给 q->agg_queue_hdr
其中 q
是一个排队规则,而 agg_queue_hdr
是一个结构体,所以如果分配内存像这:
q->agg_queue_hdr=kmalloc(sizeof(struct agg_queue), GFP_ATOMIC);
内核崩溃了。根据我在搜索中看到的 kmalloc
示例,我现在将其更改为:
agg_queue_hdr=kmalloc(sizeof(struct agg_queue), GFP_ATOMIC);
内核不会崩溃。现在我想知道如何将内存分配给指针q->agg_queue_hdr
?
I am trying to assign memory using kmalloc
in kernel code in fact in a queueing discipline. I want to assign memory to q->agg_queue_hdr
of which q
is a queueing discipline and agg_queue_hdr
is a struct, so if assign memory like this:
q->agg_queue_hdr=kmalloc(sizeof(struct agg_queue), GFP_ATOMIC);
the kernel crashes. Based on the examples of kmalloc
I saw from searching, I now changed it to:
agg_queue_hdr=kmalloc(sizeof(struct agg_queue), GFP_ATOMIC);
with which the kernel doesn't crash. Now I want to know how can I assign memory to the pointer q->agg_queue_hdr
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保
q
指向有效的内存区域。然后您应该能够像开始时一样分配q->agg_queue_hdr
。Make sure
q
is pointed to a valid area of memory. Then you should be able to assignq->agg_queue_hdr
like you had it to begin with.为什么不使用以下方式修改代码,这样可以避免内核恐慌。
当反
汇编“q->agg_queue_hdr”时,“ldr”指令将在发生内核恐慌时起作用。
Why don't you modify your code with below way, which would avoid kernel panic.
}
When disassembing "q->agg_queue_hdr", "ldr" instruction will works where kernel panic occurs.