<br><br>
<div class="gmail_quote">On Sun, Jul 3, 2011 at 10:45 PM, Dave Hylands <span dir="ltr">&lt;<a href="mailto:dhylands@gmail.com">dhylands@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hi Vishal,<br>
<div class="im"><br>On Sun, Jul 3, 2011 at 5:09 AM, Vishal Thanki &lt;<a href="mailto:vishalthanki@gmail.com">vishalthanki@gmail.com</a>&gt; wrote:<br>&gt; Hi,<br>&gt;<br>&gt; We use copy_from_user/copy_to_user functions to copy data transfer<br>
&gt; user data between user space and kernel space. As per my<br>&gt; understanding, these functions are required because we cannot access<br>&gt; userspace data directly within kernel space. </div></blockquote>
<div> </div>
<div>Basically if you want to aceess some data from userspace and if that data is not present in memory...or if your user pointer is invalid then it can create lots of problem in your kernel module and kernel may crash.</div>

<div> </div>
<div>So, its better to acess something safely, thats why copy to usr/ copy from user is. it does all the validation on user space pointers. Try with memcpy also in your code in place of copy to usr. It will also work if your user space pointer is valid enough. if the user space address is swapped out,  this will not work. See what happens then... </div>

<div> </div>
<div> </div>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div class="im">But, the implementation<br>&gt; of these functions actually access the user-space data right? Can<br>&gt; someone explain me how this actually happens?<br><br></div>How it actually happens is architecture dependent. Whether kernel<br>
space can access user space while in the context of the user-process<br>is also architecture dependent. I know with ARM, for example, it&#39;s<br>possible to do memcpy instead of copy_to_user, but using memcpy isn&#39;t<br>
guaranteed to work on all architectures.<br><br>The other difference between memcpy and copy_to/from_user is that<br>memcpy will typically cause a segmentation fault if passed a bad<br>pointer, where copy_to/from_user won&#39;t.<br>
<font color="#888888"><br>--<br>Dave Hylands<br>Shuswap, BC, Canada<br><a href="http://www.davehylands.com/" target="_blank">http://www.davehylands.com</a><br></font>
<div>
<div></div>
<div class="h5"><br>_______________________________________________<br>Kernelnewbies mailing list<br><a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br><a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</div></div></blockquote></div><br>