• Linux操作系统下 内核模块开发详细解析 java程序员


    导读:
      
      1. modprobe 加载内核模块
      a) 在 /etc/module.conf 中查找别名
      b) 在 lib/modules/version/module.dep 中判断是否有依赖模块需要被提前加载(该文件被depmod-a建立)
      2. 2.4内核中不一定非用init_module和cleanup_module做开始和结束的函数,但需要用module_init和
      module_exit申明。
      3. 宏 __init 和 __exit 可以使函数在运行完成后自动回收内存(限模块中),__initdata用于变量,
      举例:
      #include //需要包含的头文件
      static int ntest __initdata = 3;
      static int __init test_init(void)
      static void __exit test_exit(void)
      module_init(test_init); //申明放在实现函数后
      module_exit(test_exit);
      4. 一些模块说明的相关宏,可以用objdump可以查看相关信息。
      MODULE_LICENSE() 说明代码许可类型
      MODULE_DESCRIPTION() 模块描述
      MODULE_AUTHOR() 作者
      MODULE_SUPPORTED_DEVICE() 模块支持的设备
      5. 参数传递使用宏 MODULE_PARM(变量名,类型)。
      支持的类型有"b"比特 "h"短整 "i"整数 "l"长整 "s"字符串
      static int myint = 9;
      static char *mystr = "test"; //注意需要传递参数的默认值
      MODULE_PARM(myint, "i");
      MODULE_PARM(mystr, "s");
      6. 多个文件编译成一个内核模块:
      a) 需要在一个源程序中加入
      #define __NO_VERSION__
      #include
      b) 编译同普通的单个内核文件
      c) 连接:ld -m elf_i386 -r -o <1st src file.o> <2nd src file.o>
      7. strace 查一个程序所用到的系统调用
      8. 关于file_operations结构体定义在linux/fs.h文件中。
      使用方式:
      struct file_operations fops = {
      read: device_read,
      write: device_write,
      open: device_open,
      release: device_release
      }
      C99的使用方式:
      struct file_operations fops = {
      .read = device_read,
      .write = device_write,
      .open = device_open,
      .release = device_release
      }

    本文转自
    http://soft.zdnet.com.cn/software_zone/2007/1108/617890.shtml
  • 相关阅读:
    stream to byte[], byte[] to srting
    内容输出为每行的字符串的方法
    .net面式题
    .net多站点通过StateServer实现session共享
    .net 数据绑定gridview 和Repeater 序号,Container.ItemIndex
    js实现table用鼠标改变td的宽度,固定table宽度和高度超过显示点
    .aspx、MasterPage、.ascx加载顺序
    IIS删除http header信息如Server, X-Powered-By, 和X-AspNet-Version
    基于Asp.net C#实现HTML转图片(网页快照)
    js获取页面宽度高度及屏幕分辨率
  • 原文地址:https://www.cnblogs.com/java20130725/p/3215963.html
Copyright © 2020-2023  润新知