如何在tmpfs中找到Linux驱动程序的代码段? (实时) [英] How to find the code segment of a Linux driver in tmpfs? (in real-time)
问题描述
我有一个名为 drv1 的字符驱动程序,用户应用程序使用 ioctl
来与它通信,它将传输参数 struct file * filp
。现在我想找出 drv1 的代码段的地址,但是我遇到了一些问题。
I have a character driver called drv1, and a user application uses ioctl
to communicate with it, which will transmit the parameter struct file *filp
. Now I want to find out the address of the code segment of drv1, but I came across some problems.
首先, code> struct file * filp 可能是有用的,所以我查看了源代码中的定义,并找到一个指针 struct inode * f_inode; / *缓存值* /
。然后我大致搜索了 struct inode
的定义(我不确定是否正确,因为我不熟悉tmpfs);名为 struct address_space * i_mapping 的指针似乎是我需要的。但我不知道如何深入挖掘,在 struct address_space
中有一些复杂的数据结构,例如:
At first, I guess struct file *filp
might be useful so I looked at the definition in source code, and find a pointer struct inode *f_inode; /* cached value */
. Then I roughly searched the definition of struct inode
(I'm not sure whether it is right as I'm not familiar when tmpfs); a pointer named struct address_space *i_mapping seems to be what I need. But I don't know how to dig deeper and get stuck; there are some complicated data structures in the struct address_space
, such as:
struct radix_tree_root page_tree; /* radix tree of all pages */
和
struct rb_root i_mmap; /* tree of private and shared mappings */
这是否意味着驱动程序的数据 drv1 被组织为 radix_tree_root
的形式。或者这是否意味着我错过了其他的东西?
Does it mean that the data of the driver drv1 is organized as the form of radix_tree_root
? Or does it mean that I've missed something else?
推荐答案
对于构建为LKM的模块,在 MODULES_VADDR
和 MODULES_END
之间动态分配(参见 module.c
in arch /($ YOUR_ARCH)/kernel/module.c
)。我可以通过使用shell命令 cat / proc / kallsyms
来获得其函数地址的起始地址,但是在我的代码中没有很好的方法。
It seems that for modules that are built as LKM, the memory is dynamically allocated between MODULES_VADDR
and MODULES_END
(see module.c
in arch/($YOUR_ARCH)/kernel/module.c
). I can get the start address of its function adress by using a shell command cat /proc/kallsyms
, but no good method to do it in my code yet.
对于构建在内核映像中的模块,System.map文件将提供这些信息。无论哪种方式,我不知道如何在代码中动态获取地址。
As for module that are built into the kernel image, the System.map file will give the information. Either way, I don't know how to get the address dynamically in the code.
这篇关于如何在tmpfs中找到Linux驱动程序的代码段? (实时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!