On Tue, Oct 12, 2004 at 17:14:09 +1000, Aboo Valappil wrote: > Jon, > > You must be tired of answering questions :) > > > then how does copy_from_user and copy_to_user work? (I don't know > enough > > assembly to understand the code in uaccess.h) > > Roughly this goes on: > > *). Check validity of vma and process memory mapping. > *). Check page is available. > *). Copy the data accross. > > Point number 2 here ( check page is available ) ... What if page is not > available and there is no page table/page directory set up for this ? > Does it cause a page fault ? or it make sure that there is no page fault > by doing all the page table manipulation and getting the page frame for > the request ( pretty much does all the jobs by a page fault handler ) ? > > Why is copy_to_user() required ? can it be implemented inside the page > fault handler itself to take care of page faults happened addressing > user memory from kernel mode when doing a simple memcpy ? In either > case ( even we use copy_to_user) the process is going to be put to > sleep/block if the request can'nt be met immediately. It is NOT a memcpy on some architectures, though it basicaly is on many (just with appropriate access checks). Depending on how segmentation and paging are done on given architecture, a cross-segment version of mov instruction may be necessary or some other setup may be needed. An example is m68k. Normal memcpy uses movel instruction, but copy_to/from_user use movesl instruction, that uses different segment registers for the addressing (those registers are set with set_fs). Actualy i386 used to do the same. It used to use the fs register to access the user memory (which is where set_fs got it's name). Even more bizare variants are possible. User-mode-linux in skas mode has the kernel memory in one process and the user memory in another and uses ptrace to do the copy. ------------------------------------------------------------------------------- Jan 'Bulb' Hudec <bulb@xxxxxx>
Attachment:
signature.asc
Description: Digital signature