Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to write cross-version/platform Linux kernel modules?

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).

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?)

like image 964
Dan Avatar asked Jun 16 '13 22:06

Dan


People also ask

Are kernel modules specific to kernel version?

Kernel VersionsKernel modules must be specifically built to work with the Linux Kernel. To successfully run a Kernel Module on your target it must be built with the exact toolchain with the same header files that were used to build the Linux Distribution on your target.

Can you write kernel modules in Rust?

For most purposes, if you're interested in writing Linux kernel modules in Rust, you should look at https://github.com/Rust-for-Linux/linux, which is an effort to contribute that process to the upstream kernel.


1 Answers

There isn't a stable ABI for the kernel and most likely never will be because it'd make Linux suck. The reasons for not having one are all pretty much documented in that link.

The best way to deal with this is to get your driver merged upstream where it'll be maintained by other kernel developers.

As to being cross-platform, that pretty much comes free with the Linux kernel as long as you only use the standard, platform-independent functions provided in the API.

like image 93
tangrs Avatar answered Nov 01 '22 15:11

tangrs