Getting kernel version from linux kernel module at runtime

后端 未结 3 2068
后悔当初
后悔当初 2020-12-06 20:03

how can I obtain runtime information about which version of kernel is running from inside linux kernel module code (kernel mode)?

3条回答
  •  没有蜡笔的小新
    2020-12-06 20:33

    Why can't I build a kernel module for any version?

    Because the kernel module API is unstable by design as explained in the kernel tree at: Documentation/stable_api_nonsense.txt. The summary reads:

    Executive Summary
    -----------------
    You think you want a stable kernel interface, but you really do not, and
    you don't even know it.  What you want is a stable running driver, and
    you get that only if your driver is in the main kernel tree.  You also
    get lots of other good benefits if your driver is in the main kernel
    tree, all of which has made Linux into such a strong, stable, and mature
    operating system which is the reason you are using it in the first
    place.
    

    See also: How to build a Linux kernel module so that it is compatible with all kernel releases?

    How to do it at compile time was asked at: Is there a macro definition to check the Linux kernel version?

提交回复
热议问题