QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1849|回复: 0

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

[复制链接]
发表于 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) << + (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[CODESIZE];
static char hserials_jump[CODESIZE]="\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[1] = (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");
您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-4-16 12:38 , Processed in 0.055994 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

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