<br><br><div class="gmail_quote">2012/10/19 Rohan Puri <span dir="ltr"><<a href="mailto:rohan.puri15@gmail.com" target="_blank">rohan.puri15@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br><br><div class="gmail_quote">On Fri, Oct 19, 2012 at 7:38 PM, Anuz Pratap Singh Tomar <span dir="ltr"><<a href="mailto:chambilkethakur@gmail.com" target="_blank">chambilkethakur@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br><br><div class="gmail_quote"><div><div>On Fri, Oct 19, 2012 at 2:46 PM, Fan Yang <span dir="ltr"><<a href="mailto:lljyangfan@gmail.com" target="_blank">lljyangfan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div><br><br>2012/10/19 Arun KS <<a href="mailto:getarunks@gmail.com" target="_blank">getarunks@gmail.com</a>><br>><br>> Hi Fan,<br>><br>> On Fri, Oct 19, 2012 at 6:50 PM, Fan Yang <<a href="mailto:lljyangfan@gmail.com" target="_blank">lljyangfan@gmail.com</a>> wrote:<br>
>><br>>> HI ALL:<br>>> I just run a module on my machine, but it can't work. When the module run the kernel will painc. I don't know where is wrong. This is my code:<br>>><br>>> 1 #include<linux/module.h><br>
>> 2 #include<linux/kernel.h><br>>> 3 #include<linux/init.h><br>>> 4 #include<linux/sched.h><br>>> 5<br>>> 6 int input = 1;<br>>> 7 module_param (input, int, S_IRUGO);<br>
>> 8<br>>> 9 static int __init printvma_init (void)<br>>> 10 {<br>>> 11 struct vm_area_struct *p, *start;<br>>> 12 int i;<br>>> 13 struct task_struct *thread; <br>
>> 14<br>>> 15 thread = current;<br>>> 16<br>>> 17 while (1)<br>>> 18 {<br>>> 19 if (thread->pid == input)<br>>> 20 break;<br>>> 21 thread = list_entry (thread->tasks.next, struct task_struct, tasks);<br>
>> 22 }<br>>> 23 p = thread->mm->mmap;<br>>> 24<br>>> 25 do{<br>>> 26 printk ("%lx\t%lx\t%s\n", p->vm_start,\<br>>> 27 p->vm_end, p->vm_file->f_path.dentry->d_iname);<br>
>> 28 p = p->vm_next;<br>>> 29 }while (p != NULL);<br>>> 30<br>>> 31 printk ("vm_file address is:%d\tf_path address is:%d\<br>>> 32 \tname is:%s",& p->vm_file->f_path,\<br>
>> 33 p->vm_file->f_path.dentry->d_iname);<br>>> 34<br>>> 35 printk ("info from the kernel space:%s\n", thread->comm);<br>>> 36 return 0;<br>>> 37 }<br>
>> 38<br>>> 39 static void __exit printvma_exit (void)<br>>> 40 {<br>>> 41 printk ("the module will leave the kernel space..\n");<br>>> 42 }<br>>> 43<br>>> 44 module_init (printvma_init);<br>
>> 45 module_exit (printvma_exit);<br>>> 46 MODULE_LICENSE ("GPL"); <br>>><br>>><br>>> what's wrong?<br>><br>><br>> It would be good if you paste your crash log here.<br>
><br>> Thanks,<br>> Arun<br>>><br>>><br>>> thanks<br>>><br>>> _______________________________________________<br>>> Kernelnewbies mailing list<br>>> <a href="mailto:Kernelnewbies@kernelnewbies.org" target="_blank">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>>><br>><br></div></div><div style="text-align:left">
The module run in a virtual machine, I can't control the machine when it crashed, so I just got a picture when the kernel panic.<br>
<br></div></blockquote></div></div><div>you can run the module under uml, it wont be hard to copy the crash log from terminal in uml. <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="text-align:left"><br><img alt=""><br>
<br><br>Thanks<span><font color="#888888"><br>Fan<br></font></span></div><div>
<br>_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org" target="_blank">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>
<br></div></blockquote></div><br>
<br>_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org" target="_blank">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>
<br></blockquote></div><br></div></div>Hi Fan,<br><br>See the issue is thread->mm is NULL in your case. The simplest way to test this in your case is by the following : -<br><br>Put these statements after the while loop <br>
<br>if(!thread->mm) { printk("thread->mm is NULL\n"); return 0; }<br>
<br>After this compile and load the module, you will see this statement printed in dmesg command output.<br><br><br>General programming practice : -<br><br>Always make checks for NULL pointer in your code, before dereferencing your code.<span class="HOEnZb"><font color="#888888"><br>
<br>- Rohan <br>
</font></span></blockquote></div>Hi Rohan,<div><br></div><div>I don't think the thread->mm is NULL, because when I print the several vm_area_struct of the thread->mm it work well, but if put the code in the loop to print all the vma, it crashed.</div>
<div><br></div><div>Thinks</div><div>Fan</div>