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; 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);
Regards,, Aravind. "Dovie'andi
se tovya sagain" -Mat Cauthon (WoT). From:
kernelnewbies-bounce@xxxxxxxxxxxx [mailto:kernelnewbies-bounce@xxxxxxxxxxxx] On Behalf Of Wang Yu Hi,all |