qiaiduo 发表于 2006-11-11 11:54:24

加载模块时出现的问题??

以下代码编译后,加载的时候出现BAD EIP VALUE 类似内存溢出的错误
然后机器就死机了。望高手指点
#ifndef __KERNEL_SYSCALLS__
#define __KERNEL_SYSCALLS__
#endif

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/string.h>
#include <linux/interrupt.h>
#include <asm/semaphore.h>
#include <linux/init.h>
#include <linux/inet.h>


#ifndef KERNEL_VERSION
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
#endif

#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include <linux/modversions.h>
#endif
//#define printk printk_R1B7D4074
void (*handle_scancode)(unsigned char,int) =(void(*)(unsigned char,int))
HS_ADDRESS;
static struct semaphore hserials_sem;
static int logging=1;

#define CODESIZE 7

static char hserials_code;
static char hserials_jump="\xb8\x00\x00\x00"
            "\xff\xe0";



void _handle_scancode(unsigned char scancode,int keydown)
{
    if (logging && keydown)
    //    sprintf(KERN_ALERT "SCAN CODE %x .\n",(int)*((char *)scancode)&0x7F);
   //   log_scancode(scancode,LOGFILE);
   printk("Scan Code %x %s.\n",
          (int) *((char *) scancode) & 0x7F,
          *((char *) scancode) & 0x80 ? "Released" : "Pressed");
    down(&hserials_sem);
    memcpy(handle_scancode,hserials_code,CODESIZE);
    handle_scancode(scancode,keydown);                        ///ÔËÐÐÔ­À´µÄ
    memcpy(handle_scancode,hserials_jump,CODESIZE);
    up(&hserials_sem);
}

static int __init initmodule(void)
{
        *(long *)&hserials_jump = (long)_handle_scancode; /* ¸³Ìæ»»º¯ÊýµØÖ· */
        memcpy (hserials_code, handle_scancode, CODESIZE);
        memcpy (handle_scancode, hserials_jump, CODESIZE);
        return 0;

}


static void __exit exitmodule(void)
{

   memcpy (handle_scancode, hserials_code, CODESIZE);
return;
}


module_init(initmodule);
module_exit(exitmodule);

MODULE_LICENSE("GPL");
页: [1]
查看完整版本: 加载模块时出现的问题??