What is the difference between module_init and init_module in a Linux kernel module?

前端 未结 3 1964
被撕碎了的回忆
被撕碎了的回忆 2020-12-28 20:56

I have been trying to port few linux drivers and realized that there is substantial difference between kernel version 2.4 and 2.6 of linux.

In the 2.4 version of ker

3条回答
  •  臣服心动
    2020-12-28 21:30

    If you look at the definition of the new functions:

    /* Each module must use one module_init(). */
    #define module_init(initfn)                 \
    static inline initcall_t __inittest(void)       \
    { return initfn; }                  \
    int init_module(void) __attribute__((alias(#initfn)));
    
    /* This is only required if you want to be unloadable. */
    #define module_exit(exitfn)                 \
    static inline exitcall_t __exittest(void)       \
    { return exitfn; }                  \
    void cleanup_module(void) __attribute__((alias(#exitfn)));
    

    You'll see it ensures that the right boilerplate is included so these special functions can be correctly treated by the compiler. It's what the internal API of Linux does, it evolves if there are better ways of solving the problem.

提交回复
热议问题