gpt4 book ai didi

c++ - rmmod 当 char dev 打开时

转载 作者:太空宇宙 更新时间:2023-11-04 02:29:55 26 4
gpt4 key购买 nike

当设备在文件描述符(另一个 C++ 程序)中打开时,我尝试使用 rmmod 删除内核模块。当我关闭 C++ 程序时,我有这个:

Unable to handle kernel paging request at virtual address 7f023588
pgd = 80004000
[7f023588] *pgd=388aa811, *pte=00000000, *ppte=00000000
Internal error: Oops: 7 [#2] PREEMPT SMP ARM
Modules linked in: [last unloaded: dev]
CPU: 2 PID: 1272 Comm: helloWorld Tainted: P D W O 4.1.38-fslc+gee67fc7 #4
Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree)
task: a8c42d00 ti: a89f8000 task.ti: a89f8000
PC is at filp_close+0x2c/0x8c
LR is at put_files_struct+0xb4/0x10c
pc : [<8013266c>] lr : [<80150f28>] psr: 20070113
sp : a89f9dc0 ip : a89f9de0 fp : a89f9ddc
r10: a89f9edc r9 : a8ada8c0 r8 : 00000000
r7 : a89f4d00 r6 : a89f4d00 r5 : a8832f00 r4 : 00000001
r3 : 7f023554 r2 : a8832f00 r1 : a89f4d00 r0 : a8832f00
Flags: nzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user
Control: 10c53c7d Table: 38a0404a DAC: 00000015
Process helloWorld (pid: 1272, stack limit = 0xa89f8210)
Stack: (0xa89f9dc0 to 0xa89fa000)

这个问题可以解决吗?怎么办?

最佳答案

防止内核模块在文件打开时卸载的正确方法是设置file_operations结构的.owner字段:

static struct file_operations my_ops = {
.owner = THIS_MODULE,
//...
};

注意:try_module_get(THIS_MODULE)module_put(THIS_MODULE) 的手动使用受制于竞争条件 ,当模块在 try_module_get() 调用之前立即卸载时,因此可以取消映射更多代码。

关于c++ - rmmod 当 char dev 打开时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44776912/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com