do i need to learn c before learning to create Linux modules?

so far i have covered the basics of c++, including loops, arrays, pointers, classes, etc. after creating a few command line programs, along with a (in my opinion) pretty neat game of hangman, i started to consider learning to develop modules for the Linux kernel. however, a lot of people say C is a prerequisite to developing Linux modules, but will it be fine if i knew only c++.

additionally, are their any other prerequisites before starting to learn about Linux modules, such as another language, or perhaps some more c++. Any help will be appreciated. :)
Last edited on
make sure you read a little bit about programming linux kernel modules and why you have to be careful and should have a good understanding


http://www.tldp.org/LDP/lkmpg/2.6/html/lkmpg.html#AEN40
"now you want to get to where the real action is, to where a single wild pointer can wipe out your file system and a core dump means a reboot"


The other problem you have that you have to use C
http://www.tux.org/lkml/#s15-3
Is it a good idea to write a new driver in C++? The short answer is no, because there isn't any support for C++ drivers in the kernel.

Why not add a C++ interface layer to the kernel to support C++ drivers? The short answer is why bother, since there aren't any C++ drivers for Linux.



As far as I can tell from what I've read in the last 5-10 minutes you are not really ready BUT nobody is just ready for something, if you want to do it then go for it, you will learn the needed stuff on your way ;)
If you wanna get a little bit more ready you should work with the c standard library for a while, you should also get comfortable with pointers, malloc & free.
With getting comfortable I mean you should really know how to manage your resources and how to prevent memory leaks.

Almost none of the header files in the Linux kernel are C++ compatible. You'd have to recreate all of them, in some cases changing keywords since some keywords used are not compatible with C++ (such as the struct named class).

You need to know C. In order to even begin making a C++ layer over Linux, you need an even more extensive understanding of C. It's simply not a viable option.

You also cannot just use C++ syntax while using the C interface. There are various keyword incompatibilities and GNU extensions available only in C in use.

There's nothing wrong with crashing the kernel a million times trying to make a kernel module. For the most part, I'd say this is actually pretty normal. Just don't do it on your main system. Create a virtual machine with Linux or use a junk machine.

Also, the most debugging your going to get out of the kernel is backtraces and the state of the system at which something bad happened. While this by default prints to your system log, journalctl apparently doesn't handle this very well and it sometimes doesn't get output or cached. You need to setup a serial output.

I've not found using a debugger to be a very viable method. With much turmoil, you could probably get it working. Here's a presentation on current debugging techniques: https://www.kernel.org/pub/linux/kernel/people/jwessel/dbg_webinar/State_Of_kernel_debugging_LinuxCon2014.pdf

Good luck!
Registered users can post here. Sign in or register to post.