{"id":3064,"date":"2011-05-29T16:47:00","date_gmt":"2011-05-29T08:47:00","guid":{"rendered":"http:\/\/edsionte.com\/techblog\/?p=3064"},"modified":"2011-05-31T10:31:47","modified_gmt":"2011-05-31T02:31:47","slug":"%e5%86%85%e6%a0%b8%e6%a8%a1%e5%9d%97%e5%86%8d%e5%ad%a6%e4%b9%a0-%e6%a8%a1%e5%9d%97%e7%9a%84%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"http:\/\/edsionte.com\/techblog\/archives\/3064","title":{"rendered":"\u5185\u6838\u6a21\u5757\u7684\u5b9e\u73b0"},"content":{"rendered":"<h3>\u5185\u6838\u6a21\u5757\u518d\u5b66\u4e60\u4e4b\u6a21\u5757\u7684\u5b9e\u73b0<\/h3>\n<p>\u5982\u679c\u4f60\u5bf9\u5185\u6838\u6a21\u5757\u7f16\u7a0b\u5df2\u7ecf\u6709\u4e86\u7b80\u5355\u7684\u8ba4\u8bc6\uff0c\u90a3\u4e48\u53ef\u4ee5\u66f4\u8fdb\u4e00\u6b65\u5b66\u4e60\u6a21\u5757\u5728\u5185\u6838\u4e2d\u7684\u5b9e\u73b0\u3002\u5bf9\u4e8e\u6bcf\u4e2a\u5185\u6838\u6a21\u5757\u6765\u8bf4\uff0c\u7cfb\u7edf\u90fd\u4e3a\u5176\u5206\u914d\u4e00\u5757\u5185\u5b58\u533a\uff0c\u8fd9\u5757\u5185\u5b58\u533a\u5305\u62ec\uff1a\u4e00\u4e2amodule\u7ed3\u6784\u3001\u552f\u4e00\u8868\u793a\u6a21\u5757\u540d\u79f0\u7684\u5b57\u7b26\u4e32\u548c\u5b9e\u73b0\u6a21\u5757\u529f\u80fd\u7684\u4ee3\u7801\u3002<\/p>\n<p>module\u7ed3\u6784\u4e2d\u5305\u542b\u4f17\u591a\u5b57\u6bb5\uff0c\u4ece\u591a\u4e2a\u65b9\u9762\u5bf9\u5185\u6838\u6a21\u5757\u8fdb\u884c\u63cf\u8ff0\uff0c\u8fd9\u4e00\u70b9\u5982\u540ctask_struct\u7ed3\u6784\u5bf9\u4e00\u4e2a\u8fdb\u7a0b\u7684\u5168\u9762\u63cf\u8ff0\u4e00\u6837\u3002\u6211\u4eec\u63a5\u4e0b\u6765\u53ea\u5173\u6ce8\u51e0\u4e2a\u4e0e\u6211\u4eec\u5e73\u65f6\u7b80\u5355\u7684\u5185\u6838\u6a21\u5757\u7f16\u7a0b\u76f8\u5173\u7684\u5b57\u6bb5\u3002<\/p>\n<p><strong>enum module_state state<\/strong>\uff1a\u663e\u793a\u5185\u6838\u6a21\u5757\u7684\u72b6\u6001\uff1b\u8be5\u679a\u4e3e\u7c7b\u578b\u5305\u542b\u4e09\u79cd\u6a21\u5757\u72b6\u6001\uff1aMODULE_STATE_COMING\u3001MODULE_STATE_LIVE\u548cMODULE_STATE_GOING\u3002\u5206\u522b\u8868\u793a\u6b63\u5728\u52a0\u8f7d\u6a21\u5757\u3001\u6a21\u5757\u5df2\u7ecf\u52a0\u8f7d\u5e76\u4e14\u53ef\u7528\u3001\u6b63\u5728\u5378\u8f7d\u6a21\u5757\u3002<br \/>\n<strong>struct list_head list<\/strong>\uff1a\u5185\u6838\u4e2d\u7684\u6240\u6709\u6a21\u5757\u7ed3\u6784\u901a\u8fc7\u53cc\u94fe\u8868\u7ec4\u7ec7\u5728\u4e00\u8d77\uff0c\u8be5\u5b57\u6bb5\u8868\u793a\u5f53\u524d\u6a21\u5757\u5728\u53cc\u94fe\u8868\u4e2d\u7684\u8282\u70b9\u3002<br \/>\n<strong>char name[MODULE_NAME_LEN]<\/strong>\uff1a\u6a21\u5757\u7684\u540d\u79f0\uff0c\u6bcf\u4e2a\u6a21\u5757\u7684\u540d\u79f0\u90fd\u662f\u552f\u4e00\u7684\u3002<br \/>\n<strong>int (*init)(void)<\/strong>\uff1ainit\u662f\u4e00\u4e2a\u51fd\u6570\u6307\u9488\uff0c\u5b83\u6307\u5411\u6a21\u5757\u7684\u52a0\u8f7d\u51fd\u6570\u3002<br \/>\n<strong>void (*exit)(void)<\/strong>\uff1aexit\u662f\u4e00\u4e2a\u51fd\u6570\u6307\u9488\uff0c\u5b83\u6307\u5411\u6a21\u5757\u7684\u5378\u8f7d\u51fd\u6570\u3002<br \/>\n<strong>unsigned int core_size<\/strong>\uff1a\u7528\u4e8e\u6a21\u5757\u6838\u5fc3\u51fd\u6570\u4e0e\u6570\u636e\u7ed3\u6784\u7684\u52a8\u6001\u5185\u5b58\u533a\u5927\u5c0f\u3002<\/p>\n<p>\u901a\u8fc7\u4e0a\u8ff0\u7684\u5b57\u6bb5\u5206\u6790\uff0c\u6211\u4eec\u77e5\u9053\u5185\u6838\u4e2d\u7684\u6a21\u5757\u662f\u901a\u8fc7\u53cc\u94fe\u8868\u8fdb\u884c\u7ec4\u7ec7\u7684\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u901a\u8fc7\u53cc\u94fe\u8868\u7684\u64cd\u4f5c\u51fd\u6570\u6765\u6253\u5370\u5185\u6838\u4e2d\u6bcf\u4e2a\u6a21\u5757\u7684\u76f8\u5173\u4fe1\u606f\u3002\u4e0d\u8fc7\uff0c\u6a21\u5757\u94fe\u8868\u7684\u5934\u6307\u9488modules\u5e76\u672a\u88ab\u5bfc\u51fa\uff0c\u6240\u4ee5\u6211\u4eec\u901a\u8fc7\u5728\u7b26\u53f7\u8868\u4e2d\u67e5\u770bmodules\u5728\u5185\u5b58\u4e2d\u7684\u5730\u5740\u6765\u5bf9\u5176\u8fdb\u884c\u64cd\u4f5c\uff08\u5173\u4e8e\u901a\u8fc7\u7b26\u53f7\u8868\u5f97\u5230\u5185\u6838\u4e2d\u67d0\u4e2a\u672a\u5bfc\u51fa\u7b26\u53f7\u7684\u5730\u5740\u53ef\u67e5\u770b<a href=\"http:\/\/edsionte.com\/techblog\/archives\/2054\" target=\"_blank\">\u8fd9\u91cc<\/a>\u7684\u6587\u7ae0\uff09\u3002\u6574\u4e2a\u7a0b\u5e8f\u7684\u5173\u952e\u4ee3\u7801\u53c2\u8003\u5982\u4e0b\u3002<\/p>\n<pre class=\"brush:c\">#define modules 0xc0771264\r\n\r\nstatic int __init print_module_init(void)\r\n{\r\n\tstruct module *p;\r\n\tstruct list_head *module_head;\r\n\tstruct list_head *pos;\r\n\tint i = 0;\r\n\r\n\tprintk(\"print_module module is starting..\\n\");\r\n\r\n\tmodule_head = (struct list_head *)modules;\r\n\tlist_for_each(pos, module_head) {\r\n\t\tp = list_entry(pos, struct module, list);\r\n\t\tprintk(\"%3d %20s %10d\\n\", ++i, p-&gt;name, p-&gt;core_size);\r\n\t}\r\n\r\n\treturn 0;\r\n}<\/pre>\n<p>\u904d\u5386\u7684\u65b9\u6cd5\u5f88\u7b80\u5355\uff0c\u5148\u5f97\u5230\u6a21\u5757\u94fe\u8868\u7684\u5934\u6307\u9488module_head\uff0c\u518d\u901a\u8fc7list_for_each\u51fd\u6570\u4f9d\u6b21\u904d\u5386\u6bcf\u4e2a\u5185\u6838\u6a21\u5757\u3002\u6211\u4eec\u5728\u6b64\u6253\u5370\u7684\u6a21\u5757\u4fe1\u606f\u662f\u6a21\u5757\u7684\u540d\u79f0\u548c\u6a21\u5757\u7684\u5927\u5c0f\uff0c\u5176\u8f93\u51fa\u7ed3\u679c\u548clsmod\u547d\u4ee4\u7684\u8f93\u51fa\u7ed3\u679c\u76f8\u540c\u3002\u5982\u4e0b\u6240\u793a\u3002<\/p>\n<pre class=\"brush:c\">\r\n[ 7405.518605] print_module module is starting..\r\n[ 7405.518610]   1         print_module        632\r\n[ 7405.518613]   2                hello        830\r\n[ 7405.518616]   3          binfmt_misc       6587\r\n[ 7405.518618]   4           vboxnetadp       6808\r\n[ 7405.518621]   5           vboxnetflt      18753\r\n[ 7405.518624]   6                  via      37920\r\n[ 7405.518626]   7                  drm     162345\r\n[ 7405.518629]   8              vboxdrv     229952\r\n\u2026\u2026\u2026\u2026\r\n<\/pre>\n<p>\u5b8c\u6574\u4ee3\u7801\u53ef\u4ee5\u5728<a href=\"http:\/\/edsionte.download.csdn.net\/\" target=\"_blank\">\u8fd9\u91cc<\/a>\u4e0b\u8f7d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5185\u6838\u6a21\u5757\u518d\u5b66\u4e60\u4e4b\u6a21\u5757\u7684\u5b9e\u73b0 \u5982\u679c\u4f60\u5bf9\u5185\u6838\u6a21\u5757\u7f16\u7a0b\u5df2\u7ecf\u6709\u4e86\u7b80\u5355\u7684\u8ba4\u8bc6\uff0c\u90a3\u4e48\u53ef\u4ee5\u66f4\u8fdb\u4e00\u6b65\u5b66\u4e60\u6a21\u5757\u5728\u5185\u6838\u4e2d\u7684\u5b9e\u73b0\u3002\u5bf9 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[110],"tags":[],"class_list":["post-3064","post","type-post","status-publish","format-standard","hentry","category-linux"],"views":5051,"_links":{"self":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/3064","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/comments?post=3064"}],"version-history":[{"count":0,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/3064\/revisions"}],"wp:attachment":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/media?parent=3064"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/categories?post=3064"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/tags?post=3064"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}