Re: socket programming in kernel space

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 7/24/05, Xiangfei Jia <xjianz@xxxxxxxxx> wrote:
> 
>  
> > mem_segment_t old_fs=get_fs();
> > set_fs(get_ds());
> > /*****Add your Code here******/ 
> >     //to create a socket use sys_socket or sock_create look at
> > function sys_socket in linux/net/socket.c
> > //similary you could use functions sock_sendmsg/sock_recvmsg to send
> > /recv messages
> > /*****************************/ 
> > set_fs(old_fs);
> > 
> > 
> 
>  Why do I have to use "set_fs(get_ds())" in order to use the available
> system calls? Can't I just be able to use them straight way?  
>  
>  Is there any performance penalty for using system call this way?


I don't know abt the socket programming in kernel till now, but I can
say that for making a system call from with-in the kernel, one have do
this in the above mentioned way ....

Here I m quoting a little explaination of get_fs etc by Alessandro
Rubini from his article Kernel System Calls ................

/*
The first implementation of the kernel-space memory map used virtual
addresses that mapped one-to-one to physical addresses. The user-space
memory map on the other hand was dictated by the binary formats in use
for executable files, and all of them use low virtual addresses for
executable and data pages. Therefore, executing system calls required
switching to a completely different memory map than the one of user
space, and this was accomplished by using different descriptors for
the memory map associated to the code and data segment in charge in
user-space and kernel-space. Since several system calls need to access
the user address space, the FS register was reserved to hold the user
memory map while in kernel space.

This explains the name of the macros:

    * get_fs returns the current segment descriptor stored in FS.
    * get_ds returns the segment descriptor associated to kernel
space, currently stored in DS.
    * set_fs stores a descriptor into FS, so it will be used for data
transfer instructions.

This layout of virtual memory and segment descriptors remained in use
up to version 2.0 of the kernel, included. The first great innovation
brought in by version 2.1 was the switch to a different approach,
consistent to what other platforms were already doing. The user and
the kernel descriptors now share the lower 3GB of the virtual address
space, and life is both easier and more performant. The FS segment
register has been put to rest and user memory is now accessed by the
DS register, just like kernel memory. FS only survives in the names of
a few preprocessor macros.
*/

But I do mention that there are better ways of doing socket/network
programming in kernel rather doing it through system calls ...... just
search for them on the google .......

-- 
Fawad Lateef

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux