linux module

insmod 是靠一个在kernel/module.c里定义的系统调用来实现的。

1. 此系统调用(sys_init_module )分配内核存储空间(kernel memory)给相关的模块,这个内存分配动作是由vmalloc完成;

2. 然后将该模块内容拷贝到这块存储空间里;

3. 接着声明内核引用该模块;

4. 呼叫该模块的初始化涵数

这样,一个插入模块的过程就完成了。

该函数准确应该是在 linux/kernel/module.c里, 但是在里面你不会找到sys_init_module这个函数,因为这个函数是通过一个宏来实现的,

> /* This is where the real work happens */
> SYSCALL_DEFINE3(init_module, void __user *, umod,
> unsigned long, len, const char __user *, uargs)

这个宏就代表了sys_init_module这个函数。

********************modprobe 与 insmod的区别********************

modprobe 能 实现 insmod的功能, 而且比insmod要强大一些。


在加载模块的时候,自己检查模块里有没有一些symbol在内核里没有定义的,如果有这样的symbol,modprobe函数会搜索其他模块,看其他模
块里有没有相关的symbol,如果有,则将此模块也一起加载,这样的话,就算模块里有一些没有定义的symbol也能成功加载。但如果用insmod去
加载的话,遇到这种情况就会加载失败。会出现"unresolved symbols"信息。

********************lsmod 命令********************

lsmod命令用来查看当前已经被加载的模块。 它是通过读出/proc/modules 这个虚拟文件来实现。 更多的关于当前已加载模块的信息可以在/sys/module中查看

时间: 2024-08-28 04:25:18

linux module的相关文章

linux/module.h: No such file or directory 内核模块编译过程

1.缺少Linux kernel头文件 To install just the headers in Ubuntu: sudo apt-get install linux-headers-$(uname -r) To install the entire Linux kernel source in Ubuntu: sudo apt-get install linux-source Note that you should use the kernel headers that match th

My First Linux Module

My First Linux Module Today, I successfully build my first linux hello module. First of all add a directory named hello in the kernel/driver, and add a file hello.c, write codes like bellow: #include <linux/init.h> #include <linux/module.h> st

linux module 模块编程

转载自:http://blog.csdn.net/eroswang/archive/2008/09/13/2924875.aspx 摘要Linux内核模块编程的资料有些纷繁复杂,有的过于简单,有的过于庞杂,我试图用笔记的形式想读者展示怎样来进程Linux模块编程,力图做到简明扼要,这篇文章也是作为本人备忘的资料,所以有些地方过于简略是难免的.本来这篇文章的目的就是让用户知其然,至于所以然还是请参考相应的资料,其实最好的资料莫过于Linux Kernel Source. 适用范围: Linux K

简单实例讲解linux的module模块编译步骤(转)

注:原博文讲述较为详尽细致,故转到本地--aaronGao ------------------------------------------------------------------------------------------------------------------------------------------- 本文将直接了当的带你进入linux的模块编译.当然在介绍的过程当中,我也会添加一些必要的注释,以便初学者能够看懂.之所以要写这篇文章,主要是因为从书本上学的话,

linux kernel module

#include <linux/init.h>#include <linux/module.h>#include <linux/kernel.h> static int hello_init(void){ printk(KERN_ALERT "hello world!\n"); return 0;} static void hello_exit(void){ printk(KERN_ALERT "exit ok!\n");} mo

13.Linux键盘按键驱动 (详解)

版权声明:本文为博主原创文章,未经博主允许不得转载. 在上一节分析输入子系统内的intput_handler软件处理部分后,接下来我们开始写input_dev驱动 本节目标: 实现键盘驱动,让开发板的4个按键代表键盘中的L.S.空格键.回车键 1.先来介绍以下几个结构体使用和函数,下面代码中会用到 1)input_dev驱动设备结构体中常用成员如下: struct input_dev { void *private; const char *name; //设备名字 const char *ph

linux内核编译与开发

一.Linux内核简介linux kernel map: linux 系统体系结构: linux kernel体系结构: arm有7种工作模式,x86也实现了4个不同级别RING0-RING3,RING0级别最高, 这样linux用户代码运行在RING3下,内核运行在RING0,这样系统本身就得到了 充分的保护 用户空间(用户模式)转到内核空间(系统模式)方法: ·系统调用 ·硬件中断 linux kernel 体系结构: 虚拟文件系统VFS: VFS(虚拟文件系统)隐藏各种文件系统的具体细节,

Linux 内核模块设计

一.  内核模块 1.  头文件 Linux/init.h  和 Linux/module.h 2.  装载内核 insmod  对应的转载函数 module_init(); 3.  卸载内核 rmmod  对应的卸载函数 module_exit(); 二.  编写 helloworld.c 三.编写Makefile 四 .  把 helloworld.ko 移到Part3/rootfs 打开开发板下载. 直接运行Uboot insmod 挂载一下 helloworld.ko lsmod   查

Process Kill Technology &amp;&amp; Process Protection Against In Linux

目录 0. 引言 1. Kill Process By Kill Command 2. Kill Process By Resource Limits 3. Kill Process By Code Injection Into Running Process Via GDB 4. Kill Process By Using Cross Process Virtual Memory Modify 5. Kill Process By Using ptrace To Inject .so 6. P