Chinaunix
标题:
insmod后显示Segmentation fault无法rmmod,请前辈指点~在线等
[打印本页]
作者:
dosnipe_judy
时间:
2006-03-09 15:59
标题:
insmod后显示Segmentation fault无法rmmod,请前辈指点~在线等
insmod后显示Segmentation fault无法rmmod
一直提示ERROR: Module test is in use
这是社么原因啊,郁闷~~~
请各位前辈指点~
[root@localhost modules]# insmod test.ko
Segmentation fault
[root@localhost modules]# lsmod
Module Size Used by
test 5939 1
iptable_filter 6721 0
ip_tables 20929 1 iptable_filter
md5 8001 1
ipv6 235105 12
dm_mod 56773 0
button 10449 0
battery 12485 0
ac 8773 0
uhci_hcd 32729 0
ehci_hcd 31941 0
8139too 27329 0
mii 8641 1 8139too
floppy 57297 0
ext3 117961 3
jbd 59353 1 ext3
作者:
albcamus
时间:
2006-03-09 16:04
module代码有问题。
作者:
dosnipe_judy
时间:
2006-03-09 16:12
我第一次写希望各位前辈不要扔鸡蛋~~帮我看看程序中有社么问题
谢谢了!!!
CODE:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/unistd.h>
#include <linux/slab.h>
MODULE_LICENSE("GPL");
unsigned long *sys_call_table=NULL;
#define __NR_used 233
static int(*anything_saved)(void);
#define CALLOFF 100
struct descriptor_idt
{
unsigned short offset_low;
unsigned short sel;
unsigned short none,flags;
unsigned short offset_high;
};
static struct
{
unsigned short limit;
unsigned long base;
}__attribute__((packed)) idtr;
unsigned long *getscTable(void){
unsigned sys_call_off;
unsigned sct;
char *p;
struct descriptor_idt *idt;
unsigned short offset_low,offset_high;
unsigned char *shell,*sort;
int i;
/*get idtr*/
__asm__ ("sidt %0" : "=m" (idtr));
printk("idtr base at 0x%X\n",(int)idtr.base);
idt=(struct descriptor_idt*)(idtr.base+8*0x80);
offset_low = idt->offset_low;
offset_high = idt->offset_high;
sys_call_off=(idt->offset_high<<16)|idt->offset_low;
shell=(char *)sys_call_off;
sort="\xff\x14\x85";
/* get the address of sys_call_table */
for(i=0;i<CALLOFF;i++)
if(shell[0]==sort[0]&&shell[i+1]==sort[1]&&shell[i+2]==sort[2])
break;
p=shell;
p+=3;
sct=*(unsigned long*)p;
return (unsigned long*)sct;
}
static int sys_used(void){
printk("hello word!!");
return 0;
}
static int __init used_init(void){
sys_call_table = getscTable();
anything_saved=(int(*)(void))sys_call_table[__NR_used];
sys_call_table[__NR_used]=(unsigned long)sys_used;
return 0;
}
static void __exit used_cleanup(void){
sys_call_table[__NR_used]=(unsigned long)anything_saved;
}
module_init(used_init);
module_exit(used_cleanup);
作者:
lijing0626
时间:
2006-03-09 23:20
程序有问题,自己检查下吧,printk
作者:
mq110
时间:
2006-03-10 07:20
在xfocus上看到的.2.6内核导出syscall_table的代码
#ifndef __SYSCALL_INCLUDE__
# define __SYSCALL_INCLUDE__
#endif
#ifdef MODVERSIONS
#include <linux/modversions.h>
#endif
#include <linux/module.h>
#include <linux/kernel.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("xinhe <xinhe007@163.com>");
MODULE_DESCRIPTION("export the sys_call_table");
#if !defined(symname)
#error symname not defined
#endif
#define CALLOFF 100
unsigned symname; /* #define */
struct {
unsigned short limit;
unsigned int base;
} __attribute__ ((packed)) idtr;
struct {
unsigned short off1;
unsigned short sel;
unsigned char none,
flags;
unsigned short off2;
} __attribute__ ((packed)) * idt;
void set_symbol_addr(unsigned old_value, unsigned new_value)
{
struct module *mod;
struct kernel_symbol *s;
int i;
for (mod = THIS_MODULE, s = mod->syms, i = 0; i < mod->num_syms; ++i, ++s)
if (s->value == old_value)
{
s->value = new_value;
return;
}
/*遍历本模块的符号表,把本模块的一个也叫sys_call_table的符号的地址
设置为系统真正的sys_call_table的实际地址。 */
}
char * findoffset(char *start)
{
char *p;
for (p = start; p < start + CALLOFF; p++)
if (*(p + 0) == '\xff' && *(p + 1) == '\x14' && *(p + 2) == '\x85')
return p;
/*查找ini 80处理函数对sys_call_table的引用*/
return NULL;
}
static int __init init(void)
{
unsigned sys_call_off;
unsigned sct;
char *p;
asm("sidt %0":"=m"(idtr));
idt = (void *) (idtr.base + 8 * 0x80);
sys_call_off = (idt->off2 << 16) | idt->off1;
/*查找int 80的入口地址*/
if ((p = findoffset((char *) sys_call_off)))
{
sct = *(unsigned *) (p + 3);
set_symbol_addr((unsigned) &symname, sct);
}
EXPORT_SYMBOL(sys_call_table);
return 0;
}
static void __exit fini(void)
{
}
module_init(init);
module_exit(fini);
复制代码
希望对你有所帮助.
作者:
dosnipe_judy
时间:
2006-03-10 10:26
谢谢~~
作者:
love_xn
时间:
2006-03-10 11:08
标题:
回复 5楼 mq110 的帖子
你好,我刚用您复制来的那段代码测试了一下
并且在init 和exit的部分加了两个printk,但是 make的时候出现了两个warning,warning如下
/root/pub/test/example.c: In function `set_symbol_addr':
/root/pub/test/example.c:35: warning: assignment discards qualifiers from pointer target type
/root/pub/test/example.c: In function `init':
/root/pub/test/example.c:69: warning: ISO C90 forbids mixed declarations and code
您能告诉我是什么原因导致warning的吗??谢谢
作者:
love_xn
时间:
2006-03-10 11:16
line35:for (mod = THIS_MODULE, s = mod->syms, i = 0; i < mod->num_syms; ++i, ++s)
line69:EXPORT_SYMBOL(sys_call_table);
作者:
guotie
时间:
2006-06-13 14:38
上面的代码编译出错啊!
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2