LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-29-2010, 11:35 PM   #1
ravishekhar.82
Member
 
Registered: Feb 2010
Posts: 30

Rep: Reputation: 15
Question How to use own function instead of Kernel one


Hi,

I am developing 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.

Last edited by ravishekhar.82; 03-31-2010 at 03:21 AM.
 
Old 03-30-2010, 07:29 AM   #2
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Hi,
See Implementing a System call in Linux

Last edited by Aquarius_Girl; 03-30-2010 at 07:38 AM.
 
Old 03-30-2010, 07:31 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
How are you accessing the kernel function? (e.g. do you want your function to be callable from the shell?)

Perhaps you are trying to write a kernel module?
 
Old 03-30-2010, 10:30 AM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Or, perhaps you are trying to replace a libc function. What specific function(s) are you trying to replace. It may be a as simple as controlling the order of files provided to the linker.
--- rod.
 
1 members found this post helpful.
Old 03-31-2010, 12:48 AM   #5
ravishekhar.82
Member
 
Registered: Feb 2010
Posts: 30

Original Poster
Rep: Reputation: 15
Hi,
Quote:
See Implementing a System call in Linux
I feel System Call may not work here.

Quote:
How are you accessing the kernel function? (e.g. do you want your function to be callable from the shell?)
I want kernel to use my function instead of its own, wherever it is using that function.

Quote:
Perhaps you are trying to write a kernel module?
I don't know kernel module will work or not ????
If module can do the same then how ?

Quote:
What specific function(s) are you trying to replace
I am trying to replace swp_entry_t get_swap_page(void).

Quote:
It may be a as simple as controlling the order of files provided to the linker.
Please elaborate.

Last edited by ravishekhar.82; 03-31-2010 at 12:53 AM.
 
Old 03-31-2010, 03:54 AM   #6
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Quote:
Originally Posted by ravishekhar.82
I am trying to replace swp_entry_t get_swap_page(void).

Quote:
It may be a as simple as controlling the order of files provided to the linker.
Please elaborate.
IMO it means compiler judges the function by its header file and executes whatever is written in its definition in the source file.

So if you link your function's header file instead of the default one, then compiler will work according to your function !
 
Old 03-31-2010, 11:39 AM   #7
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Okay, so now that it is more clear that you are actually dealing with a kernel matter, never mind the business about the order of linking; that was only in the case that you were really trying to over-ride a standard library function (distinct from a kernel function).
If you are going to replace functionality that is in the kernel, you will have to write a new kernel driver/module. It may have to be built into the kernel. It will probably be easiest to take the existing module, and modify it to do what you really want it to do.
Kernel programming is a whole different world from userspace programming. There are numerous good articles and even one popular online book that describes kernel level programming. Google is your friend.

--- rod.
 
Old 04-01-2010, 03:07 AM   #8
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Rep: Reputation: 62
Just to say - I like the idea that Ravi has about DOING this in the first place - this sounds immensely cool.
Ravi, when you get it working, please post back in this thread to let us know what worked .
 
  


Reply

Tags
function, kernel



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Threaded function cannot call a function with extern "C" but nonthreaded function can morty346 Programming 16 01-12-2010 05:00 PM
hash function in kernel vishalbutte Programming 11 02-26-2006 02:30 AM
calling function in kernel vishalbutte Programming 0 02-14-2006 07:34 AM
How to call function in kernel vishalbutte Programming 10 02-07-2006 02:50 AM
what does this function in mean in kernel frankli Programming 5 07-13-2004 03:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration