{"id":1953,"date":"2010-11-13T12:07:48","date_gmt":"2010-11-13T04:07:48","guid":{"rendered":"http:\/\/edsionte.com\/techblog\/?p=1953"},"modified":"2012-05-15T09:24:07","modified_gmt":"2012-05-15T01:24:07","slug":"%e8%99%9a%e6%8b%9f%e5%86%85%e5%ad%98%e5%ae%9e%e8%b7%b5","status":"publish","type":"post","link":"http:\/\/edsionte.com\/techblog\/archives\/1953","title":{"rendered":"Linux\u5185\u5b58\u7ba1\u7406\u5b9e\u8df5-\u6253\u5370\u5185\u5b58\u533a\u57df"},"content":{"rendered":"<p>\u672c\u6587\u5c06\u901a\u8fc7\u4e00\u4e9b\u7b80\u5355\u7684\u5185\u6838\u6a21\u5757\u7a0b\u5e8f\uff0c\u663e\u793a\u4e00\u4e2a\u8fdb\u7a0b\u7684\u6240\u6709\u5185\u5b58\u533a\u57df\u3002\u901a\u8fc7\u6b64\u7a0b\u5e8f\u7406\u89e3\u8fdb\u7a0b\u7684\u6574\u4e2a\u5730\u5740\u7a7a\u95f4\u4e0e\u5185\u5b58\u533a\u57df\u4e4b\u95f4\u7684\u5173\u7cfb\u3002<br \/>\n<strong><\/strong><\/p>\n<p><strong>\u6253\u5370\u5185\u5b58\u533a\u57df<\/strong><\/p>\n<p>\u4e0a\u6587\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7\u6253\u5370\u67d0\u4e2a\u8fdb\u7a0b\u7684maps\u6587\u4ef6\u6765\u67e5\u770b\u67d0\u4e2a\u8fdb\u7a0b\u7684\u5185\u5b58\u533a\u57df\u3002\u5982\u679c\u4f60\u7406\u89e3\u4e86\u8fdb\u7a0b\uff0c\u8fdb\u7a0b\u7684\u7528\u6237\u7a7a\u95f4\uff0c\u5185\u5b58\u533a\u57df\u4e09\u8005\u4e4b\u95f4\u7684\u5173\u7cfb\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u901a\u8fc7\u5185\u6838\u6a21\u5757\u7684\u65b9\u5f0f\u6253\u5370\u6307\u5b9a\u8fdb\u7a0b\u7684\u5185\u5b58\u533a\u57df\u3002<\/p>\n<p>\u901a\u8fc7\u5728\u5185\u6838\u6a21\u5757\u52a0\u8f7d\u51fd\u6570\u4e2d\u8c03\u7528\u4e0b\u8ff0\u51fd\u6570\uff0c\u6765\u6253\u5370\u5f53\u524d\u8fdb\u7a0b\u7684\u5185\u5b58\u533a\u57df\u3002\u9996\u5148\u901a\u8fc7\u5168\u5c40\u53d8\u91cfcurrent\u83b7\u5f97\u5f53\u524d\u8fdb\u7a0b\u7684mm\u5b57\u6bb5\uff0c\u8be5\u5b57\u6bb5\u6307\u5411\u5f53\u524d\u8fdb\u7a0b\u7684\u7528\u6237\u7a7a\u95f4\uff08mm_struct\uff09\uff1b\u7531\u4e8e\u591a\u4e2a\u5185\u5b58\u533a\u57df\uff08vm_area_struct\uff09\u662f\u901a\u8fc7\u4e00\u4e2a\u53cc\u94fe\u8868\uff08\u6700\u65b0\u5185\u6838\u4e2d\uff09\u94fe\u63a5\u5728\u4e00\u8d77\u7684\uff0c\u6240\u4ee5\u5728\u63a5\u4e0b\u6765\u7684for\u5faa\u73af\u5f53\u4e2d\uff0c\u4f9d\u6b21\u904d\u5386\u5404\u4e2a\u5185\u5b58\u533a\u57df\uff0c\u6253\u5370\u5f53\u524d\u5185\u5b58\u533a\u57df\u7684\u8d77\u59cb\u5730\u5740\u548c\u7ec8\u6b62\u5730\u5740\uff0c\u5e76\u4e14\u6253\u5370\u5185\u6838\u5bf9\u8be5\u533a\u57df\u7684\u64cd\u4f5c\u6743\u9650\u3002\u5b8c\u6574\u4ee3\u7801\u5728<a href=\"http:\/\/download.csdn.net\/source\/2829674\" target=\"_blank\">\u8fd9\u91cc<\/a>\u3002<\/p>\n<pre class=\"brush:c\">static void list_myvma(void)\r\n{\r\n\tstruct mm_struct *mm = current-&gt;mm;\r\n\tstruct vm_area_struct *vma;\r\n\r\n\tprintk(\"list vma..\\n\");\r\n        \/\/print the current process's name and pid\r\n\tprintk(\"current:%s pid:%d\\n\",current-&gt;comm,current-&gt;pid);\r\n\r\n\tdown_read(&amp;mm-&gt;mmap_sem);\r\n\t\/\/vma is a linklist\r\n\tfor(vma = mm-&gt;mmap; vma; vma = vma-&gt;vm_next)\r\n\t{\r\n\t\t\/\/from the begining to the ending of a virtual memory area\r\n\t\tprintk(\"0x%lx-0x%lx \",vma-&gt;vm_start,vma-&gt;vm_end);\r\n\t\t\/\/check the flags of this VMA\r\n\t\tif(vma-&gt;vm_flags &amp; VM_READ)\r\n\t\t\tprintk(\"r\");\r\n\t\telse\r\n\t\t\tprintk(\"-\");\r\n\r\n\t\tif(vma-&gt;vm_flags &amp; VM_WRITE)\r\n\t\t\tprintk(\"w\");\r\n\t\telse\r\n\t\t\tprintk(\"-\");\r\n\r\n\t\tif(vma-&gt;vm_flags &amp; VM_EXEC)\r\n\t\t\tprintk(\"x\");\r\n\t\telse\r\n\t\t\tprintk(\"-\");\r\n\r\n\t\tif(vma-&gt;vm_flags &amp; VM_SHARED)\r\n\t\t\tprintk(\"s\");\r\n\t\telse\r\n\t\t\tprintk(\"p\");\r\n\r\n\t        printk(\"\\n\");\r\n\r\n\t}\r\n\tup_read(&amp;mm-&gt;mmap_sem);\r\n}<\/pre>\n<p>\u8bd5\u4e00\u4e0b\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u5c06\u901a\u8fc7\u4e00\u4e9b\u7b80\u5355\u7684\u5185\u6838\u6a21\u5757\u7a0b\u5e8f\uff0c\u663e\u793a\u4e00\u4e2a\u8fdb\u7a0b\u7684\u6240\u6709\u5185\u5b58\u533a\u57df\u3002\u901a\u8fc7\u6b64\u7a0b\u5e8f\u7406\u89e3\u8fdb\u7a0b\u7684\u6574\u4e2a\u5730\u5740\u7a7a\u95f4\u4e0e\u5185\u5b58\u533a\u57df\u4e4b\u95f4\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[266],"tags":[173],"class_list":["post-1953","post","type-post","status-publish","format-standard","hentry","category-266","tag-173"],"views":15582,"_links":{"self":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/1953","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=1953"}],"version-history":[{"count":0,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/1953\/revisions"}],"wp:attachment":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/media?parent=1953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/categories?post=1953"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/tags?post=1953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}