LinuxSir.cn,穿越时空的Linuxsir!

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

加载模块时出错,请指教

[复制链接]
发表于 2007-12-23 16:12:32 | 显示全部楼层 |阅读模式
源程序如下,主要实现系统调用的功能,用模块实现。

内核2.6.23.

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/unistd.h>
#include <linux/time.h>
#include <asm/uaccess.h>
#include <linux/sched.h>

#define __NR_pedagogictime 223

MODULE_DESCRIPTION("My Sys_pedagogictime()");
MODULE_AUTHOR("Youyou.");

static int (*anything_saved)(void);

static int sys_pedagogictime(struct timeval *tv)
{

struct timeval ktv;

do_gettimeofday(&ktv);
if(copy_to_user(tv,&ktv,sizeof(ktv)))
{
  return - EFAULT;
}

// printk(KERN_ALERT"id %ld called sys_gettimeofday().\n",(long)current->pid);

return 0;
}

int __init init_addsyscall(void)
{
// printk(KERN_ALERT"addsyscall initializing...\n");

unsigned long *syscaltable;
syscaltable=(unsigned long*)0xc061a540;//syscalltable的内存地址

anything_saved = (int(*)(void))(syscaltable[__NR_pedagogictime]);

syscaltable[__NR_pedagogictime] = (unsigned long)sys_pedagogictime;

return 0;
}

void __exit exit_addsyscall(void)
{
//printk(KERN_ALERT"addsyscall exiting...\n");

unsigned long *syscaltable;
syscaltable=(unsigned long*)0xc061a540;

syscaltable[__NR_pedagogictime] = (unsigned long)anything_saved;
}

module_init(init_addsyscall);
module_exit(exit_addsyscall);



加载时,错误如下

[root@localhost SysCallM]#
Message from syslogd@localhost at Dec 23 14:37:45 ...
kernel: Oops: 0003 [#1]

Message from syslogd@localhost at Dec 23 14:37:45 ...
kernel: SMP

Message from syslogd@localhost at Dec 23 14:37:45 ...
kernel: CPU:    0

Message from syslogd@localhost at Dec 23 14:37:45 ...
kernel: EIP:    0060:[<f898e005>]    Tainted: P        VLI

Message from syslogd@localhost at Dec 23 14:37:45 ...
kernel: EFLAGS: 00010286   (2.6.23.12 #1)

Message from syslogd@localhost at Dec 23 14:37:45 ...
kernel: EIP is at init_module+0x5/0x17 [pedagogictime]

Message from syslogd@localhost at Dec 23 14:37:45 ...
kernel: eax: c043d418   ebx: e8e5d174   ecx: 00000000   edx: ffffffff

Message from syslogd@localhost at Dec 23 14:37:45 ...
kernel: esi: e8e5d000   edi: e8e5d198   ebp: f8d36380   esp: e09b7ed0

Message from syslogd@localhost at Dec 23 14:37:45 ...
kernel: ds: 007b   es: 007b   fs: 00d8  gs: 0033  ss: 0068

Message from syslogd@localhost at Dec 23 14:37:45 ...
kernel: Process insmod (pid: 3493, ti=e09b7000 task=e8c9cc60 task.ti=e09b7000)

Message from syslogd@localhost at Dec 23 14:37:45 ...
kernel: Stack: c044a434 00000000 00000000 c06a6fc2 00000000 0000f18b 000004d8 ffffffff

Message from syslogd@localhost at Dec 23 14:37:45 ...
kernel:        00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

Message from syslogd@localhost at Dec 23 14:37:45 ...
kernel:        00000000 00000000 00000000 00000000 00000000 00000000 00000020 f8dd14fc

Message from syslogd@localhost at Dec 23 14:37:45 ...
kernel: Call Trace:

Message from syslogd@localhost at Dec 23 14:37:45 ...
kernel:  [<c044a434>] sys_init_module+0x133d/0x1481

Message from syslogd@localhost at Dec 23 14:37:45 ...
kernel:  [<c0457f85>] audit_syscall_exit+0x2aa/0x2c6

Message from syslogd@localhost at Dec 23 14:37:45 ...
kernel:  [<c04eb214>] copy_to_user+0x0/0x48

Message from syslogd@localhost at Dec 23 14:37:45 ...
kernel:  [<c0404fd6>] syscall_call+0x7/0xb

Message from syslogd@localhost at Dec 23 14:37:45 ...
kernel:  =======================

Message from syslogd@localhost at Dec 23 14:37:45 ...
kernel: Code: <c7> 05 bc a8 61 c0 00 60 d3 f8 a3 80 75 d3 f8 31 c0 c3 6e 61 6d 65

Message from syslogd@localhost at Dec 23 14:37:45 ...
kernel: EIP: [<f898e005>] init_module+0x5/0x17 [pedagogictime] SS:ESP 0068:e09b7ed0

[root@localhost SysCallM]#
发表于 2007-12-27 19:03:05 | 显示全部楼层
貌似你替换了一个223的系统调用,应该有上层应用调用这个系统调用才会被调到吧?两个系统调用的参数完全一样吗?
回复 支持 反对

使用道具 举报

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

本版积分规则

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