On Friday 01 August 2008 10:41:55 Prasad Joshi wrote: > Hi All, > > Here is the code for __do_clear_user, I am not getting how does it work. > Can any one please explain? I think the easiest way, would be to find a chart over all assembly-instructions and then go through the function step by step (see references below). a few notes: might_sleep() is a kernel-macro that yields if there are other tasks that have a job to do. And, even though I don't fully know what all instructions do, I assume it iterates over the memoryregion, zeroing it out as it goes.(as the comment suggests). > > #define __do_clear_user(addr,size) \ > do { \ > int __d0; \ > might_sleep(); \ > __asm__ __volatile__( \ > "0: rep; stosl\n" \ > " movl %2,%0\n" \ > "1: rep; stosb\n" \ > "2:\n" \ > ".section .fixup,\"ax\"\n" \ > "3: lea 0(%2,%0,4),%0\n" \ > " jmp 2b\n" \ > ".previous\n" \ > _ASM_EXTABLE(0b,3b) \ > _ASM_EXTABLE(1b,2b) \ > > : "=&c"(size), "=&D" (__d0) \ > : "r"(size & 3), "0"(size / 4), "1"(addr), "a"(0)); \ > > } while (0) > > /** > * clear_user: - Zero a block of memory in user space. > * @to: Destination address, in user space. > * @n: Number of bytes to zero. > * > * Zero a block of memory in user space. > * > * Returns number of bytes that could not be cleared. > * On success, this will be zero. > */ > unsigned long > clear_user(void __user *to, unsigned long n) > { > might_sleep(); > if (access_ok(VERIFY_WRITE, to, n)) > __do_clear_user(to, n); > return n; > } > EXPORT_SYMBOL(clear_user); > > > clear_user() is the function which is calling __do_clear_user(), from the > context I can understand it is clearing the user space buffer. But how does > it work? Have a look here: http://www.ibm.com/developerworks/library/l-ia.html http://docs.sun.com/app/docs/doc/817-5477/ http://oopweb.com/Assembly/Documents/ArtOfAssembly/Volume/toc.html Sorry for not giving you a 'this function does ...' kind of explaination, but hopefully you can gather some more insight from these pages. -- mvh Henrik Austad
Attachment:
signature.asc
Description: This is a digitally signed message part.