ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
well, yea that's what a system call does.. in a roundabout kinda way. u can't just derefernce the address where sys_open() lives and jump to it tho. in order to move from user space(privilege == 3), to kernel space(privilege == 0), u need to enter thru a call gate. there are limited # of ways to change privilege levels, and for good reason - else it would be hard to run a secure operating system. when u call open(), that is the libC wrapper, which just performs whatever steps are necessary on the given platform to enter a system call. on linux, this involves moving the system call number into EAX, and the args into rest of registers, and then making a software interrupt with int $0x80. the interrupt handler for that slot is invoked, and in system call entry handler the number in EAX is multiplied by the sizeof a pointer, and that number is added to the base address of system call table to find the function pointer for given system call. i dont really understand exactly what it is u want to do tho.. do u mean just not call libC open? in that case, u can use asm and do the work yourself. ie
Code:
movl SYS_CALL_NUM, %eax
/* set up args */
int $0x80
I would like to explain my scenario in detail. I am writing a proxy file system driver module which intercepts the system call (open, read..) and does my work before calling the original file system call.
Now what i need is to include a function in my proxy file system driver module (kernel space) which can be directly invoked from any c program(user space).
Is there any possible way of doing this.
a couple ways:
1) just register a char driver and use ioctl() calls to do it, for how to do this: http://www.xml.com/ldd/chapter/book/ch05.html#t1
2) add your own system call. i wrote a little tutorial found here: http://www.1nfamus.netfirms.com/ur_o...calls.txt.html
3) create a /proc entry; and whenever it gets read have your function get called. this is rather dirty and ugly, but it would work. the user app would just open() and read() on the /proc file, and when read() was called u would get to run your function. for how to create proc files, http://www.xml.com/ldd/chapter/book/ch04.html#t2
I read thro the document and tried to implement the same .
Summary of what i have done.
1. Edited the entry.S and unistd.h as required.
2. Created a new c program which contains the system call to be invoked. ( did not recompile the kernel )
3. Created a c program which invokes the system call. compiled link and executed.
Result :
I am getting errno 38. (Implementation of the function not found)
I have a couple of questions.
1. Is it possible to call the kernel function without recompiling the kernel.
2. Where should (path ) the newly created kernel function be put.
ahh the joys of insomnia... if u don't recompile the kernel, how could your code changes possibly be noticeable? why don't u just create a char driver and use ioctl() calls; it's simpler and portable. and i don't understand the question #2, unless u mean where do u add the source code?? i wrote that in the paper, u can put it in kernel/sys.c
Without recompiling the kernel, is it possible to include the kernel function that i want to call from user application (c program)
in a module and dynamically load the module.
Sorry, if the question seems too silly.I hope you understand i am 3 weeks old in c programming
i've already answered your question and provided links as well. MAKE A CHAR DRIVER and just implement open(), close(), and ioctl(). provide some ioctls() that call your function. this way u dont have to recompile kernel. and 3 weeks????!!! whoa, pretty heavy stuff to get into.
Thanks for your kind efforts for getting me started.
I have started writing char driver and things are moving smooth. I will get back to you incase furthur help required.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.