如何编写跨版本/平台的Linux内核模块? [英] how to write cross-version/platform Linux kernel modules?

查看:165
本文介绍了如何编写跨版本/平台的Linux内核模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Linux内核模块编程的新手,有关该主题的许多入门指南都很少提供有关如何构建可在Linux的许多版本和CPU平台上运行的内核模块的信息.我看过的大多数指南都只是简单地指出诸如"Linux不能确保版本之间的任何 ABI/API兼容性".但是,其他操作系统的确为主要版本提供了这些保证,并且这些指南主要针对2.7(现在有点老了).

I'm new to programming Linux kernel modules, and many getting started guides on the topic include little information about how to build a kernel module which will run on many versions and CPU platforms of Linux. Most of the guides I've seen simply state things like, "Linux doesn't ensure any ABI/API compatibility between versions." However, other OSes do provide these guarantees for major versions, and the guides are mostly targeting 2.7 (which is a bit old now).

我想知道现在是否存在任何类型的ABI/API兼容性,或者是否存在任何标准的方式来处理版本控制,而不是使用大量的预处理程序指令将我的代码的内核相关位隔离到文件中. (还有,在第二种情况下我应该使用任何标准的预处理器符号吗?)

I was wondering if there is any kind of ABI/API compatibility now, or if there are any standard ways to deal with versioning other than isolating the kernel-dependent bits of my code into files with a ton of preprocessor directives. (Also, are there any standard preprocessor symbols I should be using in the second case?)

推荐答案

Linux, ying yang . Tangrs 答案是好的;它回答了您的问题.但是,有 linux compat 项目.请参见 backports Wiki .基本上,有一些库为较新的Linux ABI提供 shim 功能,您可以使用它们来链接代码. Eugene 记录的KERNEL_VERSION宏在 compat.h 中进行了检查,并且适当地<包括em> compat-2.6.38.h 等,每个版本都有宏和/或库函数来提供 forward API.

Linux, the ying and the yang. Tangrs answer is good; it answers your question. However, there is the linux compat projects. See the backports wiki. Basically, there are libraries that provide shim functionality for newer Linux ABI's which you can use to link your code. The KERNEL_VERSION macro that Eugene notes is inspected in a compat.h, and appropriate compat-2.6.38.h, etc are included where each version has either macros and/or library functions to provide a forward API.

这使Linux Wifi小组可以为出血边缘内核编写代码,同时仍然可以在较旧的内核版本上进行编译.

This lets the Linux Wifi group write code for the bleeding edge kernel, while still making it possible to compile on older kernel versions.

我想这回答了这个问题,

I guess this answers the question,

是否有处理版本控制的标准方法?

if there are any standard ways to deal with versioning?

compat 库不是万能药,但至少它已经存在并且正在开发中.

The compat library is not a panacea, but at least it is there and under development.

开放源代码-有很多突变.他们都有不同的计划.

这篇关于如何编写跨版本/平台的Linux内核模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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