RE: get_fs( ) and set_fs( )

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

 



 

When you make a system call from user space, the first thing that is checked is if the address of the parameter is well within the legal virtual address space (i.e. 0 to 3 GB for the user space). If this is not so, the call will fail. If you want to make the same system call from the Kernel Space( Virtual Address 3 – 4 GB) however, this address checking has to be avoided so that the call will not fail. Now, every process has a tak_struct associated with it and this structure contains the legal virtual address boundaries for that process( Virtual Address space represented by mm_segment_t). The get_fs() macro will retrieve this boundary and the set_fs() will set it with a value. So, when you want to access a memory region which is beyond the User Space Virtual Address limit( i.e. falling in the Kernel Space Virtual Address region), you first of all store the current limit by doing

 

            mm_segment_t old_fs;
            old_fs = get_fs();

 

 Then set this limit to that of the Kernel (i.e. the whole of 4 GB) by doing

           

set_fs (KERNEL_DS);

 

 Do your memory accessing operations here (for ex: - read from a buffer which is in the kernel space from a user context thru a system call)

            …….;

 

Set the address limit back to the original limit that was stored in the old_fs variable by doing.

set_fs(old_fs);


Hope this helped. Google for more answers and please let me know if you find more details.

 

Regards,,

Aravind.

 

"Dovie'andi se tovya sagain"

 -Mat Cauthon (WoT).


From: kernelnewbies-bounce@xxxxxxxxxxxx [mailto:kernelnewbies-bounce@xxxxxxxxxxxx] On Behalf Of Wang Yu
Sent: Thursday, October 25, 2007 3:24 PM
To: kernelnewbies
Subject: get_fs( ) and set_fs( )

 

Hi,all
I have seen the following codes, but do not know what's the meaning of them:
       mm_segment_t old_fs;
      old_fs = get_fs();
      set_fs (KERNEL_DS);
     ........
     set_fs(old_fs);
What is the usage of these codes and in what condition they will be used?
Thanks!

--
National Research Center for Intelligent Computing Systems
Institute of Computing Technology, Chinese Academy of Sciences


[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