How to call exported kernel module functions from another module?

后端 未结 3 1143
难免孤独
难免孤独 2020-11-29 05:29

I\'m writing an API as a kernel module that provides device drivers with various functions. I wrote three functions in mycode.c. I then built and loaded the

3条回答
  •  抹茶落季
    2020-11-29 05:54

    OK: You have one module where the function is and one place what wants to import it right?

    You must use "EXPORT_SYMBOL("name of the function") such as foo in the place where the function is. So in the "c" file have the function "foo" defined and put in: EXPORT_SYMBOL(foo)

    Make sure you have the prototype for "foo" in a common header file (you can have it in separate places for each module and it will work but you are asking for trouble if the signatures change). So say: void foo(void *arg);

    Then the other module that wants it just invoke "foo" and you are good.

    Also: Make sure that you load the module with foo first. If you have cross dependencies like module2 needs foo from module1 and module1 needs bar from module2 you need to have one register functions with another. If you want to know please ask a separate Q.

提交回复
热议问题