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=20
=20
mm_segment_t old_fs;
old_fs =3D get_fs();
=20
Then set this limit to that of the Kernel (i.e. the whole of 4 GB) by
doing
=20
set_fs (KERNEL_DS);
=20
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)
.......;
=20
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.
=20
=20
Regards,,
Aravind.
=20
"Dovie'andi se tovya sagain"
-Mat Cauthon (WoT).
________________________________
From: kernelnewbies-bounce@nl.linux.org
[mailto:kernelnewbies-bounce@nl.linux.org] On Behalf Of Wang Yu
Sent: Thursday, October 25, 2007 3:24 PM
To: kernelnewbies
Subject: get_fs( ) and set_fs( )
=20
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 =3D get_fs();
set_fs (KERNEL_DS);
...