In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you the Linux kernel device driver Linux kernel module loading mechanism example analysis, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's learn about it!
# include
1. Module parameters
Define variables in the driver
Static int num = 0; / / 0 when the load module does not specify a value for num
Module_param (variable name, type, permission); type: byte, int, uint, short, ushort, long, ulong, bool, charp, permission cannot have write permission
Pass parameter: insmod test.ko variable name 1 = value 1 variable name 2 = value 2
The calling relationship of module_param is as follows:
# define module_param (name, type, perm)\ module_param_named (name, name, type, perm) # define module_param_named (name, value, type, perm)\ param_check_##type (name, & (value));\ module_param_call (name, param_set_##type, param_get_##type, & value, perm) \ _ MODULE_PARM_TYPE (name, # type) # define module_param_call (name, set, get, arg, perm)\ _ module_param_call (MODULE_PARAM_PREFIX,\ name, set, get, arg,\ _ same_type (* (arg), bool), perm) # define _ module_param_call (prefix, name, set, get, arg, isbool Perm)\ static int _ _ param_perm_check_##name _ attribute__ ((unused)) =\ BUILD_BUG_ON_ZERO ((perm))
< 0 || (perm) >0777 | | (perm) & 2)\ + BUILD_BUG_ON_ZERO (sizeof ("" prefix) > MAX_PARAM_PREFIX_LEN);\ static const char _ _ param_str_##name [] = prefix # name \ static struct kernel_param _ moduleparam_const _ param_##name\ _ used\ _ attribute__ ((unused,__section__ ("_ param"), aligned (sizeof (void *)\ = {_ param_str_##name, perm, isbool? KPARAM_ISBOOL: 0,\ set, get, {arg}}
Multiple c files are compiled into a module, which can be implemented using the instruction in xxx-objs, the Makefile, as follows:
Test-objs: = a.o b.o / / compiled into test.ko by A.C, b.c. Note that no .o file can have the same name as the target ko file obj-m + = test.o
You can view the module's information on the system under / sys/module/ module name /
1. View information about elf files
Readelf test.ko-a
Ko file composition
1. Elf file header
2. Text data...
3. Sections table
4. Symbol table
2. EXPORT_SYMBOL (function name / variable address) / / Export the address of the function / or variable to the kernel symbol table
EXPORT_SYMBOL_GPL (function name) /
/ proc/kallsyms view the symbol table of the current system
The above is all the contents of the article "sample Analysis of Linux Kernel Module loading Mechanism for Linux Kernel device drivers". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.