|
大家好!
代码是我在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 ]---
- /*mem.c*/
- #include <linux/module.h>
- #include <linux/init.h>
- #include <linux/interrupt.h>
- #include <linux/sched.h>
- #include <linux/version.h>
- static int pid;
- module_param(pid,int,0644);
- static int __init memtest_init(void)
- {
- struct task_struct *p;
- struct vm_area_struct *temp;
- printk("My module worked!\n");
- // p = find_task_by_vpid(pid);
- #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
- p = find_task_by_pid( pid );
- #elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
- p = find_task_by_vpid( pid );
- #else
- p = pid_task((struct pid *)&pid, PIDTYPE_PID );
- #endif
- temp = p->mm->mmap;
- while(temp) {
- printk("start:%p\tend:%p\n", (unsigned long *)temp->vm_start,
- (unsigned long *)temp->vm_end);
- temp = temp->vm_next;
- }
- return 0;
- }
- static void __exit memtest_exit(void)
- {
- printk("Unloading my module.\n");
- return;
- }
- module_init(memtest_init);
- module_exit(memtest_exit);
- MODULE_LICENSE("GPL");
复制代码 |
|