[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Re: Yet, another question about writing a module.....
Hi,
The deal in using system calls in kernel space..is for faster execution as u don't have the overhead of saving process registers and switching to kernel mode ( which involves copying of all the swapper_pg_dir contents to process pgd table i suppose) and vice versa..could be useful in implenting a web server that operates from kernel space entirely etc etc.....refer to rubini article
about this...
http://www.linux-mag.com/2000-11/gear_01.html
of course i guess you can always add ur functions etc
but AFAIK EXPORT_SYMBOL can be used when u are exporting a function within the kernel source.I don't know how can u use that to access a normal file of course if it a special device file u can always add ur own functions to access the device thorugh a a set of function pointers(refer to char device drivers )
bye
sand
------------- Original Message --------------
Guennadi Liakhovetski <g.liakhovetski@ragingbull.com> wrote:
To:anand kumar <a_santha@rediffmail.com>
From:Guennadi Liakhovetski <g.liakhovetski@ragingbull.com>
Date:Mon, 26 Feb 2001 10:06:35 +0000 (GMT)
Subject: Re: Yet, another question about writing a module.....
Hi
Hm, should you ever allow system calls from the kernel space - with all
those danders that you described (and possibly with some others?). Can't
you just do a 'normal' function call, once you are in the kernel
space? Isn't it what all those EXPORT_SYMBOL are for?
Cheers
Guennadi
On 26 Feb 2001, anand kumar wrote:
> Hi,
>
> O.k here it goes...
>
> Actually you are trying to use a system call from kernel space instead off from user space(which is why system calls are for).
> In conventional use (i.e system calls from user space) before switching from user land to kernel space the system call does some checking whether to see the buffer address is valid i.e it has to be within user space( < 3GB limit ) if it is then it has to transfer control to proper kernel func like sys_read,sys_write etc..(actually it saves the process registers on a stack before switching to kernel mode for it to return user space as soon the kernel stuff is done with.
>
> In your scenario you are trying to call the system call from kernel space so the system call check will fail because tyhe buffer address is in kernel space( > 3GB)
> so the code given below is to make the system call check pass
>
> It makes use of field called addr_limit in task_struct which gives the max valid address for making a sys call from user land.getfs gets that and saves it and setfs sets the new max valid address using KERNEL_DS which is the segment descriptor associated with kernel space so now system call check passes as we have passed a new valid address from kernel space thro KERNEL_DS
>
> then do whatever u want in kernel space...use filp directly to open file and read blah,blah,...
>
> but remember to put original address back before switching back otherwise the user program will have access to kernel space and god knows what will happen after that....
>
> bye
> sand
>
> Thank you for your help!! Can you explain the code you suggested me? Where I can find prototype of functions get_fs(), set_fs() and why you use this functions?
>
> ----- Original Message -----
> From: Tiziano Fagni
> To: kernelnewbies@nl.linux.org
> Sent: Friday, February 16, 2001 11:40 AM
> Subject: Yet, another question about writing a module.....
>
> The first thing: THANK YOU to all people that give me any tips!!
>
> Ok, suppose I want to write a module and I want to access to a file in the filesystem to read and save its content into a previous allocated kernel buffer.
> The use of module could be "modprobe module /tmp/pippo".
> I think I can't use open() function because I know that I can olny call function listed in ksym.c file. It's true?
> So, is there any function that I can use to read the content of a file?
> Any tip will be useful.....
>
> So, is there any function that I can use to read the content of a file?Any tip will be useful.....
> try this
>
> struct file *filp;
>
> mm_segment_t old_fs;
>
> filp = filp_open(name,flags,mode);
>
> old_fs= getfs();
>
> set_fs(KERNEL_DS);
>
> filp->f_op->read(filp,buffer,count,&filp->f_pos);
>
> But you should keep one thing in mind that before this code is executed you have the filesystem on this this particular file exists has been already mounted
> otherwise you risk the crashing of kernel.
>
> _____________________________________________________
> Chat with your friends as soon as they come online. Get Rediff Bol at
> http://bol.rediff.com
>
>
>
>
> -
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive: http://mail.nl.linux.org/
> IRC Channel: irc.openprojects.net / #kernelnewbies
> Web Page: http://www.surriel.com/kernelnewbies.shtml
>
___
Dr. Guennadi V. Liakhovetski
Department of Applied Mathematics
University of Sheffield, U.K.
email: G.Liakhovetski@sheffield.ac.uk
_____________________________________________________
Chat with your friends as soon as they come online. Get Rediff Bol at
http://bol.rediff.com
-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/
IRC Channel: irc.openprojects.net / #kernelnewbies
Web Page: http://www.surriel.com/kernelnewbies.shtml