#include<linux/module.h>#include<linux/init.h>#include<linux/moduleparam.h>intmath_add(inta,intb){returna+b;}EXPORT_SYMBOL(math_add);intmath_sub(inta,intb){returna-b;}EXPORT_SYMBOL(math_sub);staticint__initmath_init(void){return0;}module_init(math_init);MODULE_LICENSE("GPL"); math...
头文件module.h中定义了很多用于加载模块的symbol和参数,init.h是用于初始化和cleanup函数,这两个头文件是模块编程中所必须的。另外moduleparam.h用于在模块加载的过程中传递参数,也是常用的头文件。 module_init和module_exit用来kernel macros来表明模块加载时和卸载时的触发。这两个函数都是static,只用一次,因为不...
将__module_param_call展开,可以看到是定义了结构体kernel_param,如下: Static struct kernel_param __moduleparam_const __param_use_acm __used __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *))) = {.name= MODULE_PARAM_PREFIX#use_acm,.ops= ¶m_ops_bool,.Perm=0,...
可以在driver最后加入module_param()来注册一个参数,kernel启动时由cmdline指定该参数的值。 这里以drivers/usb/gadget/serial.c中的use_acm参数为例(这个例子有点偏。。因为最近在调试usb虚拟串口) 一kernel通用参数 对于这类通用参数,kernel留出单独一块data段,叫.ini.setup段。在arch/arm/kernel/vmlinux.lds中:...
第二种是kernel下各个driver中需要的参数,在写driver中,如果需要一些启动时可变参数。可以在driver最后加入module_param()来注册一个参数,kernel启动时由cmdline指定该参数的值。 这里以drivers/usb/gadget/serial.c中的use_acm参数为例(这个例子有点偏。。因为最近在调试usb虚拟串口) ...
int init_module(void) { printk(KERN_INFO “Hello World!\n”); return 0; } void cleanup_module(void) { printk(KERN_INFO “Goodbye!\n”); } MODULE_LICENSE(“GPL”); 说明: 任何模块程序的编写都需要包含linux/module.h这个头文件,这个文件包含了对模块的结构定义以及模块的版本控制。文件里的主要...
(allow_duplicates, bool, 0644);* For Windows 8 systems: if set ture and the GPU driver has* registered a backlight interface, skip registering ACPI video's.*/-static bool use_native_backlight = false;+static bool use_native_backlight = true;module_param(use_native_backlight, bool, ...
module_param(sysrq_rcu, bool, 0444); /* Dump grace-period-request information due to commandeered sysrq. */ static void sysrq_show_rcu(int key) { show_rcu_gp_kthreads(); } static const struct sysrq_key_op sysrq_rcudump_op = { .handler = sysrq_show_rcu, .help_msg...
typedef void (*rcu_tasks_gp_func_t)(struct rcu_tasks *rtp); typedef void (*pregp_func_t)(void); typedef void (*pertask_func_t)(struct task_struct *t, struct list_head *hop); typedef void (*postscan_func_t)(struct list_head *hop); ...
Usage: Usage: module_param(name, type, perm); module_param(name, type, perm); ##insmod hellop howmany=10 whom="Mom" insmod hellop howmany=10 whom="Mom" static char *whom = "world"; static char *whom = "world"; static int howmany = 1; static int howmany = 1; ...