sys_call_table

来源:互联网 发布:云计算的教育应用案例 编辑:程序博客网 时间:2024/06/05 17:48

今天看懂有意思的代码,以前没见过的思路,copy过来


#define MODULE

#define __KERNEL__

#ifdef MODVERSIONS
#include <linux/modversions.h>
#endif

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

unsigned long **sctable;

int init_module(void)
{

 unsigned long ptr;
 extern int loops_per_jiffy;
 int z;

  sctable = NULL;
  for (ptr = (unsigned long)&loops_per_jiffy;
       ptr < (unsigned long)&boot_cpu_data; ptr += sizeof(void *))
{
    
    unsigned long *p;
    p = (unsigned long *)ptr;
     if (p[__NR_close] == (unsigned long) sys_close){
      sctable = (unsigned long **)p;
      printk("The address of the system call table is: 0x%x\n",&sctable[0]);
       for(z=0;z<256;z++) //this max number of the system calls should be set
       printk("The address of %d system call is 0x%x\n",z, sctable[z]);
      break;
     }
  }
  return 0;
}

int cleanup_module(void)
{
    printk("Module is unloaded!\n");
      return 0;
}