Linux内核中的模块间通信 [英] Inter-module communication in Linux kernel

查看:324
本文介绍了Linux内核中的模块间通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个Linux内核模块,其中一个可以为另一个提供一些功能.但是使用该功能不是必不可少的,即使没有第一个模块,第二个模块也可以(并且应该)正常工作.

I have two Linux kernel modules, one of which may provide some function to another. But use of that function is not essential, the second module may (and should) work even if the first module is not present.

如果我只是从第一个模块导出功能并在第二个模块中使用它,则第二个模块取决于该符号,并且没有第一个模块就无法加载.

If I just export the function from the first module and use it in second module, the second module depends on that symbol and can't be loaded without first module.

一种解决方案是让用户脚本在/proc/kallsym中查找第一个模块中的功能,如果该脚本存在,则该脚本将其地址作为参数传递给第二个模块,然后该模块生成指针出来.但是出于明显的原因,我不喜欢这种解决方案.

One of the solutions is to have user script that looks into /proc/kallsym for the function in the first module, and if it's present there, the script passes its address as a parameter to the second module, which then makes pointer out of it. But I don't like that solution for obvious reasons.

如果有更正确,更优雅的解决方案,使第二个模块可以获取第一个模块中某个符号的地址,但要避免硬性依赖?

If there more correct and elegant solution that will allow second module go get address of some symbol in the first module, but avoid hard dependency ?

推荐答案

最后,我找到了解决方案:内核具有symbol_get()和symbol_put(),这使我有机会在另一个模块中查找任意符号(它需要当然可以导出),并防止在我使用其符号时卸载模块.

Finally I've found the solution: kernel has symbol_get() and symbol_put() which give me the opportunity to lookup arbitrary symbol in another module (it needs to be exported, of course) and prevent module from unloading while I'm using its symbol.

这篇关于Linux内核中的模块间通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆