【问题标题】:How to export symbol from Linux kernel module in this case?在这种情况下如何从 Linux 内核模块中导出符号?
【发布时间】:2020-05-12 04:27:37
【问题描述】:

我已经构建了两个内核模块,其中一个是 net_device。我的 net_device 模块 A 依赖于模块 B,它提供了一些额外的控制机制来导出设备信息。

我希望模块 B 能够调用模块 A 中的“xmit”函数。因此,如果我从 A 中简单导出符号,模块 B 将依赖于模块 A。显然,这会创建一个“死锁”依赖情况。

有人有解决这个问题的经验吗?如何正确导出A中的“xmit”函数让B使用?

【问题讨论】:

    标签: linux linux-kernel linux-device-driver


    【解决方案1】:

    您可以提供来自模块 A 的回调函数。在这种情况下,您不需要将所需的每个函数导出到内核命名空间。我想你可以为 B 提供一些结构。比如:

    内部标题:

    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();
            ...
        }
    }
    

    【讨论】:

    • 非常感谢安迪。这完全符合我的要求。现在我有了从 A 到 B 内 xmit 的函数指针。:D
    猜你喜欢
    • 1970-01-01
    • 2012-04-21
    • 1970-01-01
    • 2012-02-26
    • 2023-03-30
    • 2011-02-12
    • 2016-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多