在这种情况下如何从 Linux 内核模块导出符号? [英] How to export symbol from Linux kernel module in this case?
问题描述
我已经构建了两个内核模块,其中一个是 net_device.我的 net_device 模块 A 依赖于模块 B,它提供了一些额外的控制机制来导出设备信息.
I've got two kernel modules built, one of which is a net_device. My net_device module A depends on module B which provide some extra control mechanism to export device info.
我希望模块 B 能够调用模块 A 中的xmit"函数.因此,如果我从 A 简单导出符号,模块 B 将依赖于模块 A.这显然会创建一个死锁"依赖情况.
I want module B to be able to call the "xmit" function which is in module A. As a result, module B will become dependent on module A if I simple export symbol from A. This, obviously, creates a "deadlock" dependency situation.
有没有人有解决这个问题的经验?如何正确导出A中的xmit"函数让B使用?
Does anyone have experience resolving this? How can I properly export the "xmit" function in A and let B use it?
推荐答案
您可以从模块 A 中提供回调函数.在这种情况下,您不需要将每个需要的函数导出到内核命名空间.我想你可以为 B 提供一些结构.比如:
You may provide the callback function from module A. In that case you don't need to export each function you need to the kernel namespace. I presume you just could supply some structure to the B. Something like:
内部标题:
struct possible_ops {
int (*xmit)(...);
};
答:
struct private {
struct possible_ops *ops;
};
...
ops = kzalloc(sizeof(*ops));
ops->xmit = xmit;
乙:
whatever(struct possible_ops *ops) {
if (ops && ops->xmit) {
ret = ops->xmit();
...
}
}
这篇关于在这种情况下如何从 Linux 内核模块导出符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!