Results 1 to 5 of 5
Hi,
I have developed a function say my_abc() which does the same thing as kernel function abc(). Now I want that instead of using predefined kernel function kernel starts using ...
- 03-31-2010 #1Just Joined!
- Join Date
- Mar 2010
- Posts
- 2
How to use own function instead of Kernel one ???
Hi,
I have developed a function say my_abc() which does the same thing as kernel function abc(). Now I want that instead of using predefined kernel function kernel starts using my function. It might be possible that the kernel function has been used so many places. Anyone having idea how to achieve this.
Thanks.
- 03-31-2010 #2
I am not a developer, but this is surely not a trivial task.
As you already wrote yourself: It is not easy to think of all consequences.
If you want/must do this, then my advise would be to start here
Linux Kernel Newbies - Linux Kernel Newbies
That is: reading, reading, read again, then start from the beginning
You must always face the curtain with a bow.
- 03-31-2010 #3
Are you trying to replace a kernel function for ALL other modules? Or just your own? If it is just your own, simply name it as you have my_whateverfunction(). If you want to change it for all other modules, you have a lot of work ahead of you as you have to peel apart the kernel to suppress the current function and replace your own. Essentially you would have to rebuild your kernel from modified source.
Now some driver modules have some interesting features (like layering) to allow you to augment functionality, like the tty drivers, where you can add functionality to the drivers (like line discipline in tty). It depends on what you are trying to do. Is that what you are really trying to achieve?
But in general I think if you tried to simply swap out a particular kernel function, you need to do some serious, serious regression test. Most likely, something would break because it counted on the replaced function to behave a certain way.
- 03-31-2010 #4
Fortunately, it's a bit easier than everyone is explaining.
When you make a system call like read, for instance, you are not actually going into the kernel. You are actually making a call into libc, which makes the system call for you. This is done to encourage portability, and allows libc to play behind-the-scene tricks. So really, all you have to do is change the linking between your program and libc.
This can be done by using an obscure set of functions in the dlopen family, which allow you to open your own library and make calls into it. These functions can also be used to establish a link between a name and a function: if you link the abc function to YOUR implementation instead of the libc implementation, the program will use your abc function instead of the libc one.
How to use dlopen to do this, I don't fully understand, but it can be done, so perhaps you can find something on Google.DISTRO=Arch
Registered Linux User #388732
- 03-31-2010 #5
Maybe I over-read the OP. I read it as "I want to change the kernel function." Sorry if I misread your intention.
If all you want to do is use your own function instead of libc functions, you can do some shared library and linking tricks.


Reply With Quote