Oh my! Where do I start? My C++ Linux Kernel Module saga
Posted: Tue Jul 01, 2014 11:26 am
Hi all ,
I have a functionality previously implemented in C++ that I have to port to the Linux Kernel.
That functionality has been ported to the Windows Kernel just fine and is bug free at this time.
For the Linux port, the options were to re-write everything in C or find a way to make the C++ code work in the Linux Kernel.
The existing code is heavily polymorphic as it follows Object Oriented patterns. So, rewriting all that in procedural forms is last on my list of options (even though some might argue it should be first).
In any case, a good read here and here helped. I concocted something that mostly works. I ported much of what I could into the C world (mostly kernel ties and algorithms) and built a C++ library with what I did not feel like porting. Templates were replaced with macros and everything is free of the C++ standard library.
I say it "mostly works" because for the past week, I have been battling my compiler (GCC) to produce a bug free assembly.
I have been witnessing strange bugs that just make no sense. I am referring to getting various NULL dereference faults in places where it technically should not happen or deadlocks into infinite loops. When it happens though, the issue is consistent. Meaning the faults will always happen at the exact same place in the code.
I know my code is sound as it has been heavily tested in both user mode and kernel mode under Windows and in user mode under Linux.
I have played with various GCC/G++ flags for both the static lib and the kernel build processes, and things now seem to work. However, I am shaken from the whole experience and no longer trust the resulting runtime. I am just waiting to discover something else buggy.
I read a bit on the various GCC flags, but I don't understand how they translate into assemblies. For instance, using fstack-protector-all sends my test system into a epileptic spin whereas fstack-protector lets it work.
I know that the secret to understanding what is happening lies in assembly land, but I know nothing of assembly language.
So, has anyone here ported C++ code to the Linux kernel?
Is there anyone with good assembly skills here that would enjoy a few hours of Teamviewer session for a look into my madness? I am more than willing to compensate for the time given a reasonable rate.
Thanks.
I have a functionality previously implemented in C++ that I have to port to the Linux Kernel.
That functionality has been ported to the Windows Kernel just fine and is bug free at this time.
For the Linux port, the options were to re-write everything in C or find a way to make the C++ code work in the Linux Kernel.
The existing code is heavily polymorphic as it follows Object Oriented patterns. So, rewriting all that in procedural forms is last on my list of options (even though some might argue it should be first).
In any case, a good read here and here helped. I concocted something that mostly works. I ported much of what I could into the C world (mostly kernel ties and algorithms) and built a C++ library with what I did not feel like porting. Templates were replaced with macros and everything is free of the C++ standard library.
I say it "mostly works" because for the past week, I have been battling my compiler (GCC) to produce a bug free assembly.
I have been witnessing strange bugs that just make no sense. I am referring to getting various NULL dereference faults in places where it technically should not happen or deadlocks into infinite loops. When it happens though, the issue is consistent. Meaning the faults will always happen at the exact same place in the code.
I know my code is sound as it has been heavily tested in both user mode and kernel mode under Windows and in user mode under Linux.
I have played with various GCC/G++ flags for both the static lib and the kernel build processes, and things now seem to work. However, I am shaken from the whole experience and no longer trust the resulting runtime. I am just waiting to discover something else buggy.
I read a bit on the various GCC flags, but I don't understand how they translate into assemblies. For instance, using fstack-protector-all sends my test system into a epileptic spin whereas fstack-protector lets it work.
I know that the secret to understanding what is happening lies in assembly land, but I know nothing of assembly language.
So, has anyone here ported C++ code to the Linux kernel?
Is there anyone with good assembly skills here that would enjoy a few hours of Teamviewer session for a look into my madness? I am more than willing to compensate for the time given a reasonable rate.
Thanks.