<<linux device driver,third edition>> Chapter 2: Building and Running Modules
Kernel Modules Versus Applications
Kernel modules programming is similar to event driven programming.
the task of the module's initialization function is to perpare for later invocation of the module's functions;it's as though the module were saying,"Here I am,and this is what I can do."The module's exit function gets invoked just before the module is unloaded.it should tell the kernel,"I'm not there anymore;don't ask me to do anything else".
A module,is linked only to the kernel,and the only functions it can call are the ones exported by the kernel
Concurrency in the kernel
- interrupt handlers
- symmetric multiprocessor(SMP)
- kernel code has been made preemptible
As a result,Linux kernel code,including driver code,must be reentrant.
A Few Other Details
Kernel code cannot do floating point arithmetic.
Kernel has very small stack.
Often,as you look at the kernel API,you will encounter function name starting with a double undersore(__).Essentially,it says to the programmer:"if you call this function,be sure you know what you are doing"
Compiling Modules
obj-m := hello.o
hello-objs := main.o add.o
all:
make -C /usr/src/XXX/ M=`pwd` modules
clean:
make -C /usr/src/XXX/ M=`pwd` clean
Loading and Unloading Modules
insmod
The program loads the module code and data into the kernel,which,in turn,performs a function similar to the of ld,in that it links any unresolved symbol in the module to the symbol table of the kernel
modprobe
like insmod,load a module into the kernel.It differs in that it will look at the module to be loaded to see whether it references any symbols that are not currently defined in the kernel.If any such references are found,modprobe looks for other modules in the current module search path that define the relevant symbols.When modprobe finds those modules,it loads them into the kernel as well.
The kernel symbol table
EXPORT_SYMBOL(name)
EXPORT_SYMBOL_GPL(name)
Module Parameters
insmod hello.ko howmany=10 whom="Mom"
Parameters are declared with the module_param macro,which is defined in moduleparam.h .module_param takes three parameters: the name of the variable,its type , and a permissions mask to be used for an accompanying sysfs entry.
eg:
static char *whom="world";
static int howmany=1;
module_param(howmany,int,S_IRUGO);
module_param(whom,charp,S_IRUGO);
<<linux device driver,third edition>> Chapter 2: Building and Running Modules的更多相关文章
- <<linux device driver,third edition>> Chapter 4:Debugging Techniques
Debugging by Printing printk lets you classify messages accoring to their severity by associating di ...
- <<linux device driver,third edition>> Chapter 3:Char Drivers
The Internal Representation of Device Numbers Within the kernel,the dev_t type(defined in linux/type ...
- linux device driver —— 环形缓冲区的实现
还是没有接触到怎么控制硬件,但是在书里看到了一个挺巧妙的环形缓冲区实现. 此环形缓冲区实际为一个大小为bufsize的一维数组,有一个rp的读指针,一个wp的写指针. 在数据满时写进程会等待读进程读取 ...
- Linux Device Driver 学习(1)
Linux Device Driver 学习(1) 一.搭建虚拟机开发环境 1.选择虚拟机VirtualBox,官网下载.deb包安装: VirtualBox Linux 5.1.6 下载fedora ...
- how to write your first linux device driver
how to write your first linux device driver 0. environment-ubuntu 1804 64bit 1. apt-get install linu ...
- Linux Device Driver && Device File
catalog . 设备驱动程序简介 . I/O体系结构 . 访问设备 . 与文件系统关联 . 字符设备操作 . 块设备操作 . 资源分配 . 总线系统 1. 设备驱动程序简介 设备驱动程序是内核的关 ...
- How to learn linux device driver
To learn device driver development, like any other new knowledge, the bestapproach for me is to lear ...
- linux device driver —— ioctl
实现了应用程序和设备驱动通过ioctl通信.还是对设备驱动没什么感觉,贴一下代码吧. 在Ubuntu 16.04 64bit中测试通过 ioctldemo.c #include <linux/m ...
- linux device driver —— 字符设备
现在对linux设备驱动还没有什么认识,跟着书上敲了一个字符驱动,这里把代码贴一下. 测试环境是 Ubuntu 16.04 64bit 驱动程序: #include <linux/fs.h> ...
随机推荐
- Mybatis 与hibernate
共同点 (1)Hibernate与MyBatis都是通过SessionFactoryBuider由XML配置文件生成SessionFactory,由SessionFactory 生成Session,由 ...
- 性能监控(1)--linux下的top命令
Linux下的监控工具 top命令 top命令能够实时显示系统中各个进程的资源占用情况,其输出信息分为两部分,前半部分为系统统计信息,后半部分是进程信息. 第一行是任务队列信息,它的结果等同于upti ...
- Git实战手册(二): 标签应用和版本管理
教程所示图片使用的是 github 仓库图片,墙内朋友请移步原文地址 有空就来看看个人技术小站, 我一直都在 0. 背景介绍 当一个代码仓库进过长时间的迭代,针对不同的时期和需求,必定会有不同的版本. ...
- Vue 系列之 组件
一个简单的 TodoList <body> <div id="root"> <div> <input type="text&qu ...
- Java String的简单介绍
一.String类的构造方法(先粗略介绍三种 分别是s1,s2,s3) 二.String的常用判断方法 三.String类的常用获取方法 三.Sting的常用转换方法 四.String其他功能 五 ...
- array.js
// “最后加” concat 连接两个或更多的数组,并返回结果. var a = ['a','b','c']; var b = ['x','y','z']; var c = a.concat(b,t ...
- 项目启动时发生NOT found
一直想记录一下这个小问题 情景: 我昨晚美滋滋的做完功能,测了测没bug提交到git上之后就屁颠屁颠的回家了,结果今天早上来就失了智,git pull拉了一下代码后,一运行,我去,我的页面呢,页面上直 ...
- 如何解决用CMake未定义引用`JNI_CreateJavaVM'?
我需要从C ++运行Java,一般来说问题已经解决,但我的make系统或脚本出了问题,有一个创建JVM的C ++文件: #include <jni.h> #include <iost ...
- DirectX SDK (June 2010)安装错误S1023,解决方法
转自:http://hi.baidu.com/rootcat/item/6730f15f85e2c1958c12ed81 DirectX SDK (June 2010)安装错误S1023,解决方法 导 ...
- VisualStudio编译项目时,提示bin目录和obj目录下的文件不能写的错误处理的解决办法
具体错误信息如下: Error 139 Could not write lines to file "obj\Debug\SanSuiWeb.csproj.FileListAbsolute. ...