LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1417|回复: 1

---打印进程占用虚拟地址空间出错!

[复制链接]
发表于 2009-12-26 05:33:20 | 显示全部楼层 |阅读模式
大家好!

  代码是我在Lupa上拷贝过来的,原本是在下面条件编译部分只有:
  (http://www.lupaworld.com/26540/viewspace-137650.html)
  p = find_task_by_vpid( pid );
并且lupa上讲是可以工作的。

但是我在2.6.31下编译不过,就加了条件编译以便使用新的的函数。
编译过来以后,就sudo insmod mem.ko pid=3647 测试结果kernel打印出错(看如下log),之后系统没死,但是也不能rmmod mem 了。
我看了表面代码结构的定义是没问题的,请大家帮助。

[  429.133080] My module worked!                                                                    
[  429.133092] BUG: unable to handle kernel NULL pointer dereference at 000001e4                    
[  429.133096] IP: [<f80cd01f>] memtest_init+0x1f/0x52 [mem]                                       
[  429.133102] *pde = 280cf067 *pte = 00000000
[  429.133105] Oops: 0000 [#1] SMP
[  429.133108] last sysfs file: /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
[  429.133111] Modules linked in: mem(+) binfmt_misc vboxnetadp vboxnetflt vboxdrv tun snd_hda_codec_realtek snd_hda_intel snd_hda_codec iptable_filter snd_hwdep snd_pcm_oss snd_mixer_oss snd_pcm ip_tables x_tables snd_seq_dummy snd_seq_oss snd_seq_midi snd_rawmidi snd_seq_midi_event snd_seq snd_timer ppdev snd_seq_device parport_pc snd soundcore snd_page_alloc lp parport usbhid fbcon tileblit font bitblit softcursor i915 drm i2c_algo_bit 8139too 8139cp r8169 mii intel_agp agpgart video output
[  429.133145]
[  429.133148] Pid: 2788, comm: insmod Not tainted (2.6.31-17-generic #54-Ubuntu) G41M-ES2L
[  429.133151] EIP: 0060:[<f80cd01f>] EFLAGS: 00010246 CPU: 0
[  429.133154] EIP is at memtest_init+0x1f/0x52 [mem]
[  429.133156] EAX: 00000000 EBX: fffffffc ECX: ffffffdc EDX: 00000000
[  429.133158] ESI: f80b73c0 EDI: 00000000 EBP: e81b9f5c ESP: e81b9f4c
[  429.133160]  DS: 007b ES: 007b FS: 00d8 GS: 00e0 SS: 0068
[  429.133162] Process insmod (pid: 2788, ti=e81b8000 task=e977cb60 task.ti=e81b8000)
[  429.133164] Stack:
[  429.133166]  f80b7052 00000000 e81b9f78 fffffffc e81b9f88 c010112c f80b73c0 c0750a50
[  429.133171] <0> fffffffc f80b73c0 003f8ff4 f80cd000 fffffffc f80b73c0 003f8ff4 e81b9fac
[  429.133178] <0> c0173711 f5ff08f8 e977cb60 f5ff08c0 00000004 09b52018 09b52018 00004000
[  429.133184] Call Trace:
[  429.133190]  [<c010112c>] ? do_one_initcall+0x2c/0x190
[  429.133193]  [<f80cd000>] ? memtest_init+0x0/0x52 [mem]
[  429.133198]  [<c0173711>] ? sys_init_module+0xb1/0x1f0
[  429.133201]  [<c010336c>] ? syscall_call+0x7/0xb
[  429.133203] Code: <8b> 80 e4 01 00 00 8b 18 eb 1d 8b 43 08 89 44 24 08 8b 43 04 c7 04
[  429.133218] EIP: [<f80cd01f>] memtest_init+0x1f/0x52 [mem] SS:ESP 0068:e81b9f4c
[  429.133223] CR2: 00000000000001e4
[  429.133225] ---[ end trace d6cfe8147efa4d76 ]---

  1. /*mem.c*/
  2. #include <linux/module.h>                                                                                                                                                                              
  3. #include <linux/init.h>                                                                           
  4. #include <linux/interrupt.h>                                                                       
  5. #include <linux/sched.h>                                                                           
  6. #include <linux/version.h>                                                                          
  7. static int pid;
  8. module_param(pid,int,0644);
  9. static int __init memtest_init(void)
  10. {                                   
  11.          struct task_struct *p;      
  12.          struct vm_area_struct *temp;
  13.          printk("My module worked!\n");
  14. //         p = find_task_by_vpid(pid);
  15. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
  16.     p = find_task_by_pid( pid );
  17. #elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  18.     p = find_task_by_vpid( pid );
  19. #else
  20.     p = pid_task((struct  pid *)&pid, PIDTYPE_PID );
  21. #endif
  22.          temp = p->mm->mmap;
  23.          while(temp) {
  24.                  printk("start:%p\tend:%p\n", (unsigned long *)temp->vm_start,
  25. (unsigned long *)temp->vm_end);
  26.                  temp = temp->vm_next;
  27.          }
  28.          return 0;
  29. }
  30. static void __exit memtest_exit(void)
  31. {
  32.          printk("Unloading my module.\n");
  33.          return;
  34. }
  35. module_init(memtest_init);
  36. module_exit(memtest_exit);
  37. MODULE_LICENSE("GPL");
复制代码
 楼主| 发表于 2009-12-26 17:59:51 | 显示全部楼层
我自己搞好了,自己是最好的好的老师!



  1. /*mem.c*/
  2. #include <linux/module.h>
  3. #include <linux/init.h>
  4. #include <linux/interrupt.h>
  5. #include <linux/sched.h>
  6. #include <linux/version.h>
  7. #include <linux/pid.h>
  8. static int pid_no;
  9. module_param(pid_no,int,0644);
  10. static int __init memtest_init(void)
  11. {
  12. struct task_struct *p;
  13. struct pid_sturct *pid;
  14. struct vm_area_struct *temp;
  15. printk("My module worked!\n");

  16. // p = find_task_by_vpid(pid);

  17. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
  18. p = find_task_by_pid( pid_no );
  19. #elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  20. p = find_task_by_vpid( pid_no );
  21. #else
  22. pid=find_vpid(pid_no);
  23. p = pid_task(pid, PIDTYPE_PID );
  24. #endif

  25. #if 1
  26. temp = p->mm->mmap;
  27. while(temp) {
  28. printk("start:%p\tend:%p\n", (unsigned long *)temp->vm_start,
  29. (unsigned long *)temp->vm_end);
  30. temp = temp->vm_next;
  31. }
  32. #endif
  33. return 0;
  34. }
  35. static void __exit memtest_exit(void)
  36. {
  37. printk("Unloading my module.\n");
  38. return;
  39. }
  40. module_init(memtest_init);
  41. module_exit(memtest_exit);
  42. MODULE_LICENSE("GPL");
复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表