📄 module_init.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head> <title></title> <link rel="stylesheet" media="screen" type="text/css" href="./style.css" /> <link rel="stylesheet" media="screen" type="text/css" href="./design.css" /> <link rel="stylesheet" media="print" type="text/css" href="./print.css" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><a href=start.html>start</a></br><h3><a name="kernel_module_init" id="kernel_module_init">Kernel Module init</a></h3><div class="level3"><p> The module_init() and module_exit() macros are used to define the entry and exit points of the modules. </p><p>Note that the module_init() function must return 0 to indicate that the module <strong>HAS</strong> loaded.</p><p> Here is a code example: </p><pre class="code C"> <span class="co2">#include <linux/init.h> </span> <span class="co2">#include <linux/module.h> </span> <span class="co2">#include <linux/kernel.h> </span> <span class="co1">// simply use the kernel printk function</span> <span class="co1">// on module init and exit </span> <span class="kw4">static</span> <span class="kw4">int</span> __init mymod_init<span class="br0">(</span><span class="kw4">void</span><span class="br0">)</span> <span class="br0">{</span> printk<span class="br0">(</span>KERN_INFO <span class="st0">"Hello, my module<span class="es0">\n</span>"</span><span class="br0">)</span>; <span class="kw1">return</span> <span class="nu0">0</span>; <span class="br0">}</span> <span class="kw4">static</span> <span class="kw4">void</span> __exit mymod_exit<span class="br0">(</span><span class="kw4">void</span><span class="br0">)</span> <span class="br0">{</span> printk<span class="br0">(</span>KERN_INFO <span class="st0">"Goodbye my module<span class="es0">\n</span>"</span><span class="br0">)</span>; <span class="br0">}</span> <span class="co1">// </span> <span class="co1">// this is correct </span> <span class="co1">// </span>module_init<span class="br0">(</span>mymod_init<span class="br0">)</span>; module_exit<span class="br0">(</span>mymod_exit<span class="br0">)</span>; <span class="co1">// </span><span class="co1">// Add this to stop the tainted message on dumps</span>MODULE_LICENSE<span class="br0">(</span><span class="st0">"GPL"</span><span class="br0">)</span> <span class="co1">// </span></pre></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -